diff --git a/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue b/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue index 55cc86b8e9..abd0573159 100644 --- a/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue +++ b/packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue @@ -21,7 +21,7 @@ const { showAll, hideAll, saveOrUpdate, -} = useViewColumns(activeView, meta, false, () => reloadDataHook.trigger()) +} = useViewColumns(activeView, meta, () => reloadDataHook.trigger()) watch( () => (activeView.value as any)?.id, diff --git a/packages/nc-gui-v2/components/smartsheet/Grid.vue b/packages/nc-gui-v2/components/smartsheet/Grid.vue index cd90ac9fe6..26e159418e 100644 --- a/packages/nc-gui-v2/components/smartsheet/Grid.vue +++ b/packages/nc-gui-v2/components/smartsheet/Grid.vue @@ -100,8 +100,10 @@ provide(ChangePageInj, changePage) provide(ReadonlyInj, !isUIAllowed('xcDatatableEditable')) reloadViewDataHook?.on(async () => { + if (!isPublicView) { + loadAggCommentsCount() + } await loadData() - loadAggCommentsCount() }) const selectCell = (row: number, col: number) => { diff --git a/packages/nc-gui-v2/components/smartsheet/Toolbar.vue b/packages/nc-gui-v2/components/smartsheet/Toolbar.vue index d4d9bfb4ca..f817b260b4 100644 --- a/packages/nc-gui-v2/components/smartsheet/Toolbar.vue +++ b/packages/nc-gui-v2/components/smartsheet/Toolbar.vue @@ -1,18 +1,20 @@ - + - + - + diff --git a/packages/nc-gui-v2/composables/useSharedView.ts b/packages/nc-gui-v2/composables/useSharedView.ts index 7200acdd23..5bd73019b9 100644 --- a/packages/nc-gui-v2/composables/useSharedView.ts +++ b/packages/nc-gui-v2/composables/useSharedView.ts @@ -3,8 +3,8 @@ import { useNuxtApp } from '#app' export function useSharedView(viewId: string) { const sharedView = ref() - const meta = computed(() => sharedView.value.model) - const columns = computed(() => sharedView.value?.model?.columns ?? []) + const meta = ref(() => sharedView.value.model) + const columns = ref(() => sharedView.value?.model?.columns ?? []) const { $api } = useNuxtApp() const { setMeta } = useMetas() @@ -12,6 +12,9 @@ export function useSharedView(viewId: string) { const loadSharedView = async () => { const viewMeta = await $api.public.sharedViewMetaGet(viewId) sharedView.value = viewMeta + meta.value = sharedView.value.model + columns.value = sharedView.value.model.columns + setMeta(viewMeta.model) const relatedMetas = { ...viewMeta.relatedMetas } diff --git a/packages/nc-gui-v2/composables/useViewColumns.ts b/packages/nc-gui-v2/composables/useViewColumns.ts index 7c7b9bc191..6cc390ef37 100644 --- a/packages/nc-gui-v2/composables/useViewColumns.ts +++ b/packages/nc-gui-v2/composables/useViewColumns.ts @@ -3,13 +3,10 @@ import type { ColumnType, TableType, ViewType } from 'nocodb-sdk' import { watch } from 'vue' import type { ComputedRef, Ref } from 'vue' import { useNuxtApp } from '#app' +import { IsPublicInj } from '~/context' -export function useViewColumns( - view: Ref | undefined, - meta: ComputedRef, - isPublic = false, - reloadData?: () => void, -) { +export function useViewColumns(view: Ref | undefined, meta: ComputedRef, reloadData?: () => void) { + const isPublic = inject(IsPublicInj, ref(false)) const fields = ref< { order: number @@ -31,7 +28,7 @@ export function useViewColumns( let order = 1 if (view.value?.id) { - const data = (await $api.dbViewColumn.list(view.value.id)) as any[] + const data = (isPublic.value ? meta.value?.columns : await $api.dbViewColumn.list(view.value.id)) as any[] const fieldById = data.reduce>((acc, curr) => { curr.show = !!curr.show @@ -54,8 +51,6 @@ export function useViewColumns( } }) .sort((a, b) => a.order - b.order) - } else if (isPublic) { - fields.value = meta.value.columns as any } } @@ -89,6 +84,22 @@ export function useViewColumns( } const saveOrUpdate = async (field: any, index: number) => { + if (isPublic && fields.value) { + fields.value[index] = field + meta.value.columns = meta.value?.columns?.map((column) => { + if (column.id === field.fk_column_id) { + return { + ...column, + ...field, + } + } + return column + }) + + reloadData?.() + return + } + if (isUIAllowed('fieldsSync')) { if (field.id && view?.value?.id) { await $api.dbViewColumn.update(view.value.id, field.id, field) @@ -118,11 +129,13 @@ export function useViewColumns( }, set(v: boolean) { if (view?.value?.id) { - $api.dbView - .update(view.value.id, { - show_system_fields: v, - }) - .finally(() => reloadData?.()) + if (!isPublic.value) { + $api.dbView + .update(view.value.id, { + show_system_fields: v, + }) + .finally(() => reloadData?.()) + } ;(view.value as any).show_system_fields = v } }, diff --git a/packages/nc-gui-v2/pages/[projectType]/view/[viewId].vue b/packages/nc-gui-v2/pages/[projectType]/view/[viewId].vue index 44f27701c5..f891d7b423 100644 --- a/packages/nc-gui-v2/pages/[projectType]/view/[viewId].vue +++ b/packages/nc-gui-v2/pages/[projectType]/view/[viewId].vue @@ -17,7 +17,7 @@ await loadSharedView() provide(ReloadViewDataHookInj, reloadEventHook) provide(MetaInj, meta) provide(ActiveViewInj, sharedView) -provide(FieldsInj, ref(columns)) +provide(FieldsInj, columns) provide(IsPublicInj, ref(true)) const { isGrid } = useProvideSmartsheetStore(sharedView as Ref, meta) @@ -25,6 +25,7 @@ const { isGrid } = useProvideSmartsheetStore(sharedView as Ref, meta) +