Browse Source

fix(gui): avoid duplicate loadData invoke

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3830/head
Pranav C 2 years ago
parent
commit
40b8144955
  1. 32
      packages/nc-gui/components/smartsheet/Grid.vue

32
packages/nc-gui/components/smartsheet/Grid.vue

@ -161,16 +161,6 @@ openNewRecordFormHook?.on(async () => {
expandForm(newRow, undefined, true) expandForm(newRow, undefined, true)
}) })
watch(
() => view.value?.id,
async (next, old) => {
if (next && old && next !== old) {
await loadData()
}
},
{ immediate: true },
)
const onresize = (colID: string, event: any) => { const onresize = (colID: string, event: any) => {
updateWidth(colID, event.detail) updateWidth(colID, event.detail)
} }
@ -239,14 +229,13 @@ useEventListener(document, 'keyup', async (e: KeyboardEvent) => {
/** On clicking outside of table reset active cell */ /** On clicking outside of table reset active cell */
const smartTable = ref(null) const smartTable = ref(null)
onClickOutside(smartTable, () => { onClickOutside(smartTable, () => {
clearRangeRows()
if (selected.col === null) return if (selected.col === null) return
const activeCol = fields.value[selected.col] const activeCol = fields.value[selected.col]
if (editEnabled && (isVirtualCol(activeCol) || activeCol.uidt === UITypes.JSON)) return if (editEnabled && (isVirtualCol(activeCol) || activeCol.uidt === UITypes.JSON)) return
selected.row = null selected.row = null
selected.col = null selected.col = null
}) })
@ -328,7 +317,15 @@ provide(ReloadRowDataHookInj, reloadViewDataHook)
// trigger initial data load in grid // trigger initial data load in grid
// reloadViewDataHook.trigger() // reloadViewDataHook.trigger()
watch(meta, () => reloadViewDataHook.trigger(), { immediate: true }) watch(
() => view.value?.id,
async (next, old) => {
if (next && next !== old) {
await loadData()
}
},
{ immediate: true },
)
</script> </script>
<template> <template>
@ -414,8 +411,7 @@ watch(meta, () => reloadViewDataHook.trigger(), { immediate: true })
</th> </th>
</tr> </tr>
</thead> </thead>
<!-- this prevent select text from field if not in edit mode --> <tbody>
<tbody @selectstart.prevent>
<LazySmartsheetRow v-for="(row, rowIndex) of data" ref="rowRefs" :key="rowIndex" :row="row"> <LazySmartsheetRow v-for="(row, rowIndex) of data" ref="rowRefs" :key="rowIndex" :row="row">
<template #default="{ state }"> <template #default="{ state }">
<tr class="nc-grid-row"> <tr class="nc-grid-row">
@ -464,17 +460,13 @@ watch(meta, () => reloadViewDataHook.trigger(), { immediate: true })
:key="columnObj.id" :key="columnObj.id"
class="cell relative cursor-pointer nc-grid-cell" class="cell relative cursor-pointer nc-grid-cell"
:class="{ :class="{
active: active: isUIAllowed('xcDatatableEditable') && selected.col === colIndex && selected.row === rowIndex,
(isUIAllowed('xcDatatableEditable') && selected.col === colIndex && selected.row === rowIndex) ||
(isUIAllowed('xcDatatableEditable') && selectedRange(rowIndex, colIndex)),
}" }"
:data-key="rowIndex + columnObj.id" :data-key="rowIndex + columnObj.id"
:data-col="columnObj.id" :data-col="columnObj.id"
:data-title="columnObj.title" :data-title="columnObj.title"
@click="selectCell(rowIndex, colIndex)" @click="selectCell(rowIndex, colIndex)"
@dblclick="makeEditable(row, columnObj)" @dblclick="makeEditable(row, columnObj)"
@mousedown="startSelectRange($event, rowIndex, colIndex)"
@mouseover="selectBlock(rowIndex, colIndex)"
@contextmenu="showContextMenu($event, { row: rowIndex, col: colIndex })" @contextmenu="showContextMenu($event, { row: rowIndex, col: colIndex })"
> >
<div class="w-full h-full"> <div class="w-full h-full">

Loading…
Cancel
Save