From eee50fda735574397ad9e1dffd481dd0e332b9e9 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sun, 10 Jul 2022 17:39:01 +0530 Subject: [PATCH] feat(gui-v2): add fields show/hide option Signed-off-by: Pranav C --- packages/nc-gui-v2/components/index.ts | 1 + .../smartsheet-toolbar/FieldsMenu.vue | 81 +- .../nc-gui-v2/components/smartsheet/Form.vue | 1156 +++++++---------- .../nc-gui-v2/components/smartsheet/Grid.vue | 15 +- .../components/smartsheet/Toolbar.vue | 2 +- .../nc-gui-v2/composables/useViewColumns.ts | 62 + 6 files changed, 646 insertions(+), 671 deletions(-) create mode 100644 packages/nc-gui-v2/composables/useViewColumns.ts diff --git a/packages/nc-gui-v2/components/index.ts b/packages/nc-gui-v2/components/index.ts index c5a44ba1fd..3cbe799406 100644 --- a/packages/nc-gui-v2/components/index.ts +++ b/packages/nc-gui-v2/components/index.ts @@ -13,3 +13,4 @@ export const IsGridInj: InjectionKey = Symbol('is-grid-injection') export const ValueInj: InjectionKey = Symbol('value-injection') export const ActiveViewInj: InjectionKey = Symbol('active-view-injection') export const ReadonlyInj: InjectionKey = Symbol('readonly-injection') +export const ReloadViewDataInj: InjectionKey = Symbol('reload-view-data-injection') diff --git a/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue b/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue index 84ad292e86..d345fdae6f 100644 --- a/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue +++ b/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue @@ -1,6 +1,7 @@ + + diff --git a/packages/nc-gui-v2/components/smartsheet/Grid.vue b/packages/nc-gui-v2/components/smartsheet/Grid.vue index 694c43ed6e..3f05058362 100644 --- a/packages/nc-gui-v2/components/smartsheet/Grid.vue +++ b/packages/nc-gui-v2/components/smartsheet/Grid.vue @@ -1,7 +1,15 @@ diff --git a/packages/nc-gui-v2/composables/useViewColumns.ts b/packages/nc-gui-v2/composables/useViewColumns.ts new file mode 100644 index 0000000000..3c8ac42272 --- /dev/null +++ b/packages/nc-gui-v2/composables/useViewColumns.ts @@ -0,0 +1,62 @@ +import type { TableType } from 'nocodb-sdk' +import type { Ref } from 'vue' +import { useNuxtApp } from '#app' + +export default function () { + const fields = ref< + { + order?: number + show?: number + title: string + fk_column_id?: string + }[] + >() + let viewId: string + + const filterQuery = ref('') + const filteredFieldList = computed(() => { + return fields.value?.filter((field) => { + return !filterQuery?.value || field.title.toLowerCase().includes(filterQuery.value) + }) + }) + + const { $api } = useNuxtApp() + + const loadViewColumns = async (meta: Ref, _viewId: string, isPublic = false) => { + viewId = _viewId + let order = 1 + if (viewId) { + const data = await $api.dbViewColumn.list(viewId) + const fieldById: Record = data.reduce((o: Record, f: any) => { + f.show = !!f.show + return { + ...o, + [f.fk_column_id as string]: f, + } + }, {}) + fields.value = meta.value?.columns + ?.map((c) => ({ + title: c.title, + fk_column_id: c.id, + ...(fieldById[c.id as string] ? fieldById[c.id as string] : {}), + order: (fieldById[c.id as string] && fieldById[c.id as string].order) || order++, + })) + .sort((a, b) => a.order - b.order) + } else if (isPublic) { + fields.value = meta.value.columns as any + } + } + + const showAll = () => {} + const hideAll = () => {} + + const sync = async (field: any, index: number) => { + if (field.id) { + await $api.dbViewColumn.update(viewId, field.id, field) + } else { + if (fields.value) fields.value[index] = (await $api.dbViewColumn.create(viewId, field)) as any + } + } + + return { fields, loadViewColumns, filteredFieldList, filterQuery, showAll, hideAll, sync } +}