π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix(nc-gui): hide column local state update cause sideeffect which lead to show column again for few sec
Ramesh Manec1d23cbb10c0
diff --git a/packages/nc-gui/components/smartsheet/header/ColumnMenu.vue b/packages/nc-gui/components/smartsheet/header/ColumnMenu.vueindex 82d0b2eeec..d806d8abdd 100644--- a/packages/nc-gui/components/smartsheet/header/ColumnMenu.vue+++ b/packages/nc-gui/components/smartsheet/header/ColumnMenu.vue@@ -55,7 +55,7 @@ const { addUndo, defineModelScope, defineViewScope, clone } = useUndoRedo()const showDeleteColumnModal = ref(false)-const { gridViewCols, fieldsMap, skipShowViewColumnsLoading } = useViewColumnsOrThrow()+const { gridViewCols, fieldsMap, hidingViewColumnsMap } = useViewColumnsOrThrow()const { fieldsToGroupBy, groupByLimit } = useViewGroupByOrThrow()@@ -286,13 +286,14 @@ const hideOrShowField = async () => {const viewId = getViewId() as string- const currentViewColumn = gridViewCols.value[column.value.id] ? clone(gridViewCols.value[column.value.id]) : null+ const currentViewColumn = gridViewCols.value[column.value.id!] ? clone(gridViewCols.value[column.value.id!]) : null- if (currentViewColumn && currentViewColumn.show && fieldsMap.value[column.value.id]) {- skipShowViewColumnsLoading.value = true+ if (currentViewColumn && currentViewColumn.show && fieldsMap.value[column.value.id!]) {+ hidingViewColumnsMap.value[column.value.id!] = true- fieldsMap.value[column.value.id].show = false+ fieldsMap.value[column.value.id!].show = falseupdateDefaultViewColVisibility(column?.value.id, false)+ isOpen.value = false}try {@@ -301,7 +302,7 @@ const hideOrShowField = async () => {await $api.dbViewColumn.update(view.value!.id!, currentColumn!.id!, { show: !currentColumn.show })- if (!skipShowViewColumnsLoading.value) {+ if (!hidingViewColumnsMap.value[column.value.id!]) {if (isExpandedForm.value) {await getMeta(meta?.value?.id as string, true)} else {@@ -309,6 +310,9 @@ const hideOrShowField = async () => {}}+ // delete current columnId from hidingViewColumnsMap so that while loading view columns, we can use db stored value+ delete hidingViewColumnsMap.value[column.value.id!]+eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD)if (!currentColumn.show) {reloadDataHook?.trigger()@@ -354,16 +358,24 @@ const hideOrShowField = async () => {})} catch (e: any) {console.log('error', e)- if (skipShowViewColumnsLoading.value) {- fieldsMap.value[column.value.id].show = true+ if (hidingViewColumnsMap.value[column.value.id!]) {+ fieldsMap.value[column.value.id!].show = trueupdateDefaultViewColVisibility(column?.value.id, true)++ delete hidingViewColumnsMap.value[column.value.id!]++ eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD)+ reloadDataHook?.trigger()}message.error(t('msg.error.columnVisibilityUpdateFailed'))} finally {- skipShowViewColumnsLoading.value = falseisLoading.value = ''- isOpen.value = false+ delete hidingViewColumnsMap.value[column.value.id!]++ if (isOpen.value) {+ isOpen.value = false+ }}}diff --git a/packages/nc-gui/composables/useViewColumns.ts b/packages/nc-gui/composables/useViewColumns.tsindex 1f31d80b63..ec6643f5bf 100644--- a/packages/nc-gui/composables/useViewColumns.ts+++ b/packages/nc-gui/composables/useViewColumns.ts@@ -43,7 +43,7 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(const isViewColumnsLoading = ref(true)- const skipShowViewColumnsLoading = ref(false)+ const hidingViewColumnsMap = ref<Record<string, boolean>>({})const { addUndo, defineViewScope } = useUndoRedo()@@ -80,7 +80,8 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(const data = ((isPublic ? meta.value?.columns : (await $api.dbViewColumn.list(view.value.id)).list) as any[]) ?? []const fieldById = data.reduce<Record<string, any>>((acc, curr) => {- curr.show = !!curr.show+ // If hide column api is in progress and we try to load columns before that then we need to assign local visibility state+ curr.show = hidingViewColumnsMap.value[curr.fk_column_id] && !!curr.show ? false : !!curr.showreturn {...acc,@@ -491,8 +492,13 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(// or when columns changes(delete/add)watch([() => view?.value?.id, () => meta.value?.columns],- async ([newViewId]) => {- if (skipShowViewColumnsLoading.value) return+ async ([newViewId], [oldViewId]) => {+ // If we change view, we need to reset the hidingViewColumnsMap+ if (oldViewId && oldViewId !== newViewId) {+ hidingViewColumnsMap.value = {}+ }++ if (!ncIsEmptyArray(hidingViewColumnsMap.value) && Object.values(hidingViewColumnsMap.value).some((v) => v)) return// reload only if view belongs to current tableif (newViewId && view.value?.fk_model_id === meta.value?.id) {@@ -624,12 +630,12 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(toggleFieldVisibility,toggleFieldStyles,isViewColumnsLoading,- skipShowViewColumnsLoading,updateGridViewColumn,gridViewCols,resizingColOldWith,isLocalMode,updateDefaultViewColumnMeta,+ hidingViewColumnsMap,}},'useViewColumnsOrThrow',