Browse Source

fix: Fixed multiple api call happening for view data reload on field reorder

pull/6815/head
Muhammed Mustafa 1 year ago
parent
commit
f5e11c740f
  1. 21
      packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue
  2. 8
      packages/nc-gui/composables/useViewColumns.ts

21
packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue

@ -27,6 +27,8 @@ const activeView = inject(ActiveViewInj, ref())
const reloadViewMetaHook = inject(ReloadViewMetaHookInj, undefined)! const reloadViewMetaHook = inject(ReloadViewMetaHookInj, undefined)!
const reloadViewDataHook = inject(ReloadViewDataHookInj, undefined)!
const rootFields = inject(FieldsInj) const rootFields = inject(FieldsInj)
const { isMobileMode } = useGlobal() const { isMobileMode } = useGlobal()
@ -79,7 +81,7 @@ const gridDisplayValueField = computed(() => {
return filteredFieldList.value?.find((field) => field.fk_column_id === pvCol?.id) return filteredFieldList.value?.find((field) => field.fk_column_id === pvCol?.id)
}) })
const onMove = (_event: { moved: { newIndex: number; oldIndex: number } }, undo = false) => { const onMove = async (_event: { moved: { newIndex: number; oldIndex: number } }, undo = false) => {
// todo : sync with server // todo : sync with server
if (!fields.value) return if (!fields.value) return
@ -119,12 +121,17 @@ const onMove = (_event: { moved: { newIndex: number; oldIndex: number } }, undo
if (fields.value.length < 2) return if (fields.value.length < 2) return
fields.value.forEach((field, index) => { await Promise.all(
if (field.order !== index + 1) { fields.value.map(async (field, index) => {
field.order = index + 1 if (field.order !== index + 1) {
saveOrUpdate(field, index) field.order = index + 1
} saveOrUpdate(field, index, true)
}) }
}),
)
await loadViewColumns()
reloadViewDataHook?.trigger()
$e('a:fields:reorder') $e('a:fields:reorder')
} }

8
packages/nc-gui/composables/useViewColumns.ts

@ -155,7 +155,7 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
$e('a:fields:show-all') $e('a:fields:show-all')
} }
const saveOrUpdate = async (field: any, index: number) => { const saveOrUpdate = async (field: any, index: number, disableDataReload: boolean = false) => {
if (isLocalMode.value && fields.value) { if (isLocalMode.value && fields.value) {
fields.value[index] = field fields.value[index] = field
meta.value!.columns = meta.value!.columns?.map((column: ColumnType) => { meta.value!.columns = meta.value!.columns?.map((column: ColumnType) => {
@ -185,8 +185,10 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
} }
} }
await loadViewColumns() if (!disableDataReload) {
reloadData?.() await loadViewColumns()
reloadData?.()
}
} }
const showSystemFields = computed({ const showSystemFields = computed({

Loading…
Cancel
Save