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. 15
      packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue
  2. 4
      packages/nc-gui/composables/useViewColumns.ts

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

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

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

@ -155,7 +155,7 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
$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) {
fields.value[index] = field
meta.value!.columns = meta.value!.columns?.map((column: ColumnType) => {
@ -185,9 +185,11 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
}
}
if (!disableDataReload) {
await loadViewColumns()
reloadData?.()
}
}
const showSystemFields = computed({
get() {

Loading…
Cancel
Save