From f385f3a8f3735986c76d7e87351c30f89e2b22e3 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 11 Jul 2022 23:01:28 +0530 Subject: [PATCH] feat(gui-v2): show all/hide all integration, reload data after change Signed-off-by: Pranav C --- .../smartsheet-toolbar/FieldsMenu.vue | 13 ++++--- .../smartsheet-toolbar/FieldsMenuItem.vue | 35 ------------------- .../nc-gui-v2/composables/useViewColumns.ts | 18 +++++++--- 3 files changed, 23 insertions(+), 43 deletions(-) delete mode 100644 packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenuItem.vue diff --git a/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue b/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue index 6d6d27e854..1b08282cf1 100644 --- a/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue +++ b/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue @@ -23,7 +23,12 @@ const isAnyFieldHidden = computed(() => { // return meta?.fields?.some(field => field.hidden) }) -const { fields, loadViewColumns, filteredFieldList, filterQuery, showAll, hideAll, sync } = useViewColumns(activeView, meta) +const { fields, loadViewColumns, filteredFieldList, filterQuery, showAll, hideAll, saveOrUpdate } = useViewColumns( + activeView, + meta, + false, + () => reloadDataHook?.trigger(), +) watch( () => activeView?.value?.id, @@ -328,7 +333,7 @@ export default { type="checkbox" class="mt-0 pt-0" @click.stop - @change="sync(field, i)" + @change="saveOrUpdate(field, i)" /> - + {{ $t('general.showAll') }} - + {{ $t('general.hideAll') }} diff --git a/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenuItem.vue b/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenuItem.vue deleted file mode 100644 index daa18355d0..0000000000 --- a/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenuItem.vue +++ /dev/null @@ -1,35 +0,0 @@ - - - - - diff --git a/packages/nc-gui-v2/composables/useViewColumns.ts b/packages/nc-gui-v2/composables/useViewColumns.ts index 5abfed65a5..e357ec876b 100644 --- a/packages/nc-gui-v2/composables/useViewColumns.ts +++ b/packages/nc-gui-v2/composables/useViewColumns.ts @@ -6,6 +6,7 @@ export default function ( view: Ref<(GridType | FormType | GalleryType) & { id?: string }> | undefined, meta: Ref | undefined, isPublic = false, + reloadData?: () => void, ) { const fields = ref< { @@ -51,16 +52,25 @@ export default function ( } } - const showAll = () => {} - const hideAll = () => {} + const showAll = async () => { + await $api.dbView.showAllColumn(view?.value?.id as string) + await loadViewColumns() + reloadData?.() + } + const hideAll = async () => { + await $api.dbView.hideAllColumn(view?.value?.id as string) + await loadViewColumns() + reloadData?.() + } - const sync = async (field: any, index: number) => { + const saveOrUpdate = async (field: any, index: number) => { if (field.id) { await $api.dbViewColumn.update(view?.value?.id as string, field.id, field) } else { if (fields.value) fields.value[index] = (await $api.dbViewColumn.create(view?.value?.id as string, field)) as any } + reloadData?.() } - return { fields, loadViewColumns, filteredFieldList, filterQuery, showAll, hideAll, sync } + return { fields, loadViewColumns, filteredFieldList, filterQuery, showAll, hideAll, saveOrUpdate } }