π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: refactor view states and redundant api calls
DarkPhoenix270455c4b1d96a24
diff --git a/packages/nc-gui/components/dlg/LockView.vue b/packages/nc-gui/components/dlg/LockView.vueindex 5b06205cb9..13bbaaeaf7 100644--- a/packages/nc-gui/components/dlg/LockView.vue+++ b/packages/nc-gui/components/dlg/LockView.vue@@ -16,15 +16,19 @@ const dialogShow = useVModel(props, 'modelValue', emits, { defaultValue: false }const isForm = inject(IsFormInj, ref(false))-const { $api, $e } = useNuxtApp()+const { $e } = useNuxtApp()const { isUIAllowed } = useRoles()const { user } = useGlobal()+const viewStore = useViewsStore()+const { idUserMap } = storeToRefs(useBase())-const { activeView } = storeToRefs(useViewsStore())+const { activeView } = storeToRefs(viewStore)++const { updateView } = viewStoreconst view = computed(() => props.view || activeView.value)@@ -49,7 +53,7 @@ const formRules = {const isLoading = ref(false)const changeLockType = async () => {- if (!view.value) return+ if (!view.value?.id) returnif (changeType.value === LockType.Locked) {const valid = await formValidator.value.validate()@@ -65,7 +69,7 @@ const changeLockType = async () => {isLoading.value = truetry {- await $api.dbView.update(view.value.id as string, {+ await updateView(view.value.id, {lock_type: changeType.value,meta: {...parseProp(view.value.meta),@@ -73,13 +77,6 @@ const changeLockType = async () => {},})- view.value.meta = {- ...parseProp(view.value.meta),- ...payload,- }-- view.value.lock_type = changeType.value-message.success(`Successfully Switched to ${view.value.lock_type} view`)$e(`a:${viewTypeAlias[view.value.type] || 'view'}:lock`, { lockType: view.value.lock_type, title: view.value.title })diff --git a/packages/nc-gui/components/dlg/View/Create.vue b/packages/nc-gui/components/dlg/View/Create.vueindex 3639383798..64b0540fb3 100644--- a/packages/nc-gui/components/dlg/View/Create.vue+++ b/packages/nc-gui/components/dlg/View/Create.vue@@ -89,7 +89,9 @@ const { baseId: activeBaseId } = storeToRefs(baseStore)const { blockCalendarRange, getPlanTitle } = useEeConfig()-const { viewsByTable } = storeToRefs(useViewsStore())+const viewStore = useViewsStore()++const { viewsByTable } = storeToRefs(viewStore)const { refreshCommandPalette } = useCommandPalette()@@ -109,8 +111,6 @@ const vModel = useVModel(props, 'modelValue', emits)const { t } = useI18n()-const { api } = useApi()-const isViewCreating = ref(false)const views = computed(() => viewsByTable.value.get(tableId.value) ?? [])@@ -254,22 +254,6 @@ const onAiEnter = async () => {}}-const getDefaultViewMetas = (viewType: ViewTypes) => {- switch (viewType) {- case ViewTypes.FORM:- return {- submit_another_form: false,- show_blank_form: false,- meta: {- hide_branding: false,- background_color: '#F9F9FA',- hide_banner: false,- },- }- }- return {}-}-async function onSubmit() {if (aiMode.value) {return onAiEnter()@@ -291,58 +275,22 @@ async function onSubmit() {if (!tableId.value) returntry {- let data: GridType | KanbanType | GalleryType | FormType | MapType | null = null-isViewCreating.value = true- switch (form.type) {- case ViewTypes.GRID:- data = await api.dbView.gridCreate(tableId.value, form)- break- case ViewTypes.GALLERY:- data = await api.dbView.galleryCreate(tableId.value, form)- break- case ViewTypes.FORM:- data = await api.dbView.formCreate(tableId.value, {- ...form,- ...getDefaultViewMetas(ViewTypes.FORM),- })- break- case ViewTypes.KANBAN:- data = await api.dbView.kanbanCreate(tableId.value, form)- break- case ViewTypes.MAP:- data = await api.dbView.mapCreate(tableId.value, form)- break- case ViewTypes.CALENDAR:- data = await api.dbView.calendarCreate(tableId.value, {- ...form,- calendar_range: form.calendar_range.map((range) => ({- fk_from_column_id: range.fk_from_column_id,- fk_to_column_id: range.fk_to_column_id,- })),- })- break- }+ const data = await viewStore.createView(tableId.value, form)if (data) {- // View created successfully- // message.success(t('msg.toast.createView'))-emits('created', data)}} catch (e: any) {console.error(e)- message.error(await extractSdkResponseErrorMsg(e))} finally {- await refreshCommandPalette()+ setTimeout(() => {+ isViewCreating.value = false+ }, 500)}vModel.value = false-- setTimeout(() => {- isViewCreating.value = false- }, 500)}}diff --git a/packages/nc-gui/components/dlg/View/Delete.vue b/packages/nc-gui/components/dlg/View/Delete.vueindex a17a750b49..9afedb0e47 100644--- a/packages/nc-gui/components/dlg/View/Delete.vue+++ b/packages/nc-gui/components/dlg/View/Delete.vue@@ -13,33 +13,17 @@ const props = defineProps<Props>()const emits = defineEmits<Emits>()-const { refreshCommandPalette } = useCommandPalette()-const { view } = propsconst vModel = useVModel(props, 'modelValue', emits)-const { api } = useApi()--const { $e } = useNuxtApp()+const viewsStore = useViewsStore()-/** Delete a view */async function onDelete() {if (!props.view) return- try {- await api.dbView.delete(props.view.id)-- vModel.value = false- emits('deleted')- $e('a:view:delete', { view: props.view.type })- } catch (e: any) {- message.error(await extractSdkResponseErrorMsg(e))- } finally {- refreshCommandPalette()- }-- // telemetry event+ await viewsStore.deleteView(props.view)+ vModel.value = false}</script>diff --git a/packages/nc-gui/components/dlg/View/DescriptionUpdate.vue b/packages/nc-gui/components/dlg/View/DescriptionUpdate.vueindex 3ec3fb0a80..2c246eab92 100644--- a/packages/nc-gui/components/dlg/View/DescriptionUpdate.vue+++ b/packages/nc-gui/components/dlg/View/DescriptionUpdate.vue@@ -12,11 +12,11 @@ const { view, ...props } = defineProps<Props>()const emit = defineEmits(['update:modelValue', 'updated'])-const { $e, $api } = useNuxtApp()+const { $e } = useNuxtApp()const dialogShow = useVModel(props, 'modelValue', emit)-const { loadViews } = useViewsStore()+const { updateView } = useViewsStore()const { addUndo, defineProjectScope } = useUndoRedo()@@ -63,7 +63,7 @@ watchEffect()const updateDescription = async (undo = false) => {- if (!view) return+ if (!view?.id) returnif (formState.description) {formState.description = formState.description.trim()@@ -71,7 +71,7 @@ const updateDescription = async (undo = false) => {loading.value = truetry {- await $api.dbView.update(view.id as string, {+ await updateView(view.id, {description: formState.description,})@@ -97,8 +97,6 @@ const updateDescription = async (undo = false) => {})}- await loadViews({ tableId: view.fk_model_id, ignoreLoading: true, force: true })-$e('a:view:description:update')dialogShow.value = falsediff --git a/packages/nc-gui/components/smartsheet/toolbar/OpenedViewAction.vue b/packages/nc-gui/components/smartsheet/toolbar/OpenedViewAction.vueindex e77c384d31..369e5b2f80 100644--- a/packages/nc-gui/components/smartsheet/toolbar/OpenedViewAction.vue+++ b/packages/nc-gui/components/smartsheet/toolbar/OpenedViewAction.vue@@ -9,12 +9,14 @@ const { sharedView } = useSharedView()const { t } = useI18n()-const { $api, $e } = useNuxtApp()+const { $e } = useNuxtApp()const { refreshCommandPalette } = useCommandPalette()-const { activeView, views } = storeToRefs(useViewsStore())-const { loadViews, removeFromRecentViews } = useViewsStore()+const viewStore = useViewsStore()++const { activeView, views } = storeToRefs(viewStore)+const { loadViews, removeFromRecentViews, updateView } = viewStoreconst { navigateToTable } = useTablesStore()@@ -72,7 +74,7 @@ const onRenameBlur = async () => {isRenaming.value = falseerror.value = undefined- await $api.dbView.update(activeView.value!.id!, {+ await updateView(activeView.value!.id, {title: viewRenameTitle.value,})} else {diff --git a/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vueindex ca28807347..2cc2aa2066 100644--- a/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue+++ b/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue@@ -28,7 +28,7 @@ const view = computed(() => props.view)const table = computed(() => props.table)-const { loadViews, navigateToView, duplicateView } = useViewsStore()+const { navigateToView, duplicateView, updateView } = useViewsStore()const { user } = useGlobal()@@ -117,10 +117,10 @@ async function changeLockType(type: LockType) {try {view.value.lock_type = type- await $api.dbView.update(view.value.id as string, {++ await updateView(view.value?.id, {lock_type: type,})-message.success(`Successfully Switched to ${type} view`)} catch (e: any) {message.error(await extractSdkResponseErrorMsg(e))@@ -139,11 +139,6 @@ async function onDuplicate() {refreshCommandPalette()- await loadViews({- force: true,- tableId: table.value!.id!,- })-if (duplicatedView) {navigateToView({view: duplicatedView,diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.tsindex 9749b66de5..54594117ce 100644--- a/packages/nc-gui/lib/types.ts+++ b/packages/nc-gui/lib/types.ts@@ -887,6 +887,22 @@ type NcDropdownPlacement =| 'bottomCenter'| 'right'+interface CreateViewForm {+ title: string+ type: ViewTypes+ description?: string+ copy_from_id: string | null+ // for kanban view only+ fk_grp_col_id: string | null+ fk_geo_data_col_id: string | null+ // for calendar view only+ calendar_range: Array<{+ fk_from_column_id: string+ fk_to_column_id: string | null // for ee only+ }>+ fk_cover_image_col_id: string | null | undefined+}+export type {User,ProjectMetaInfo,@@ -951,4 +967,5 @@ export type {RawValueType,NcDropdownPlacement,MakeCellEditableFn,+ CreateViewForm,}diff --git a/packages/nc-gui/store/views.ts b/packages/nc-gui/store/views.tsindex b0dd16e0bd..9d94d1d6d5 100644--- a/packages/nc-gui/store/views.ts+++ b/packages/nc-gui/store/views.ts@@ -1,60 +1,80 @@-import type {- CalendarType,- FilterType,- GalleryType,- KanbanType,- MapType,- RowColoringInfo,- SortType,- ViewType,- ViewTypes,-} from 'nocodb-sdk'-import { ViewTypes as _ViewTypes } from 'nocodb-sdk'+import type { CalendarType, FilterType, GalleryType, KanbanType, MapType, RowColoringInfo, SortType, ViewType } from 'nocodb-sdk'+import { ViewTypes, ViewTypes as _ViewTypes } from 'nocodb-sdk'import { acceptHMRUpdate, defineStore } from 'pinia'import { useTitle } from '@vueuse/core'import type { ViewPageType } from '~/lib/types'import { getFormattedViewTabTitle } from '~/helpers/parsers/parserHelpers'import { DlgViewCreate } from '#components'+// Types and Interfaces+interface RecentView {+ viewName: string+ viewId: string | undefined+ viewType: ViewTypes+ tableID: string+ isDefault: boolean+ baseName: string+ tableName: string+ workspaceId: string+ baseId: string+}+export const useViewsStore = defineStore('viewsStore', () => {- const { $api } = useNuxtApp()- interface RecentView {- viewName: string- viewId: string | undefined- viewType: ViewTypes- tableID: string- isDefault: boolean- baseName: string- tableName: string- workspaceId: string- baseId: string- }+ const { $api, $e } = useNuxtApp()- const { isUIAllowed } = useRoles()+ const { ncNavigateTo } = useGlobal()const router = useRouter()- // Store recent views from all Workspaces- const allRecentViews = ref<RecentView[]>([])- const route = router.currentRoute++ const { meta: metaKey, control } = useMagicKeys()++ const bases = useBases()++ const tablesStore = useTablesStore()++ const workspaceStore = useWorkspace()const { refreshCommandPalette } = useCommandPalette()- const { $e } = useNuxtApp()+ const { isUIAllowed } = useRoles()++ const { sharedView } = useSharedView()- const bases = useBases()const { openedProject } = storeToRefs(bases)- const tablesStore = useTablesStore()+ const { activeWorkspaceId } = storeToRefs(workspaceStore)- const { activeWorkspaceId } = storeToRefs(useWorkspace())+ const { activeTable } = storeToRefs(tablesStore)- const { meta: metaKey, control } = useMagicKeys()+ const route = router.currentRoute++ const allRecentViews = ref<RecentView[]>([])++ const viewsByTable = ref<Map<string, ViewType[]>>(new Map())++ const activeSorts = ref<SortType[]>([])++ const activeNestedFilters = ref<FilterType[]>([])++ const isViewsLoading = ref(true)++ const isViewDataLoading = ref(true)++ const isPaginationLoading = ref(false)++ const lastOpenedViewId = ref<string | undefined>(undefined)++ const preFillFormSearchParams = ref('')++ const activeViewRowColorInfo = ref<RowColoringInfo>(defaultRowColorInfo)++ // Computed properties+ const isPublic = computed(() => route.value.meta?.public)const recentViews = computed<RecentView[]>(() =>allRecentViews.value.filter((f) => f.workspaceId === activeWorkspaceId.value).splice(0, 10),)- const viewsByTable = ref<Map<string, ViewType[]>>(new Map())const views = computed({get: () => (tablesStore.activeTableId ? viewsByTable.value.get(tablesStore.activeTableId) : []) ?? [],set: (value) => {@@ -65,20 +85,6 @@ export const useViewsStore = defineStore('viewsStore', () => {},})- // Both are synced with `useSmartsheetStore` state- // Sort of active view- const activeSorts = ref<SortType[]>([])- // Filters of active view (used for local filters)- const activeNestedFilters = ref<FilterType[]>([])-- const isViewsLoading = ref(true)- const isViewDataLoading = ref(true)- const isPublic = computed(() => route.value.meta?.public)-- const { activeTable } = storeToRefs(useTablesStore())-- const lastOpenedViewId = ref<string | undefined>(undefined)-const activeViewTitleOrId = computed(() => {if (!route.value.params.viewTitle?.length) {// find the default view and navigate to it, if not found navigate to the first one@@ -90,7 +96,6 @@ export const useViewsStore = defineStore('viewsStore', () => {return route.value.params.viewTitle})- // Get view page type acc to route which will be used to open the view pageconst openedViewsTab = computed<ViewPageType>(() => {// For types in ViewPageType typeif (!route.value.params?.slugs || route.value.params.slugs?.length === 0) return 'view'@@ -102,8 +107,6 @@ export const useViewsStore = defineStore('viewsStore', () => {return 'view'})- const { sharedView } = useSharedView()-const activeView = computed<ViewType | undefined>({get() {if (sharedView.value) return sharedView.value@@ -136,17 +139,10 @@ export const useViewsStore = defineStore('viewsStore', () => {})const isActiveViewLocked = computed(() => activeView.value?.lock_type === 'locked')-- // Used for Grid View Pagination- // TODO: Disable by default when group by is enabled- const isPaginationLoading = ref(false)-- const preFillFormSearchParams = ref('')+ const isLockedView = computed(() => activeView.value?.lock_type === 'locked')const refreshViewTabTitle = createEventHook<void>()- const activeViewRowColorInfo = ref<RowColoringInfo>(defaultRowColorInfo)-const loadViews = async ({tableId,ignoreLoading,@@ -177,67 +173,6 @@ export const useViewsStore = defineStore('viewsStore', () => {}}- const onViewsTabChange = (page: ViewPageType) => {- router.push({- name: 'index-typeOrId-baseId-index-index-viewId-viewTitle-slugs',- params: {- typeOrId: route.value.params.typeOrId,- baseId: route.value.params.baseId,- viewId: route.value.params.viewId,- viewTitle: activeViewTitleOrId.value,- slugs: [page],- },- })- }-- const changeView = async ({ viewId, tableId, baseId }: { viewId: string | null; tableId: string; baseId: string }) => {- const routeName = 'index-typeOrId-baseId-index-index-viewId-viewTitle'- await router.push({ name: routeName, params: { viewTitle: viewId || '', viewId: tableId, baseId } })- }-- const removeFromRecentViews = ({- viewId,- tableId,- baseId,- }: {- viewId?: string | undefined- tableId: string- baseId?: string- }) => {- if (baseId && !viewId && !tableId) {- allRecentViews.value = allRecentViews.value.filter((f) => f.baseId !== baseId)- } else if (baseId && tableId && !viewId) {- allRecentViews.value = allRecentViews.value.filter((f) => f.baseId !== baseId || f.tableID !== tableId)- } else if (tableId && viewId) {- allRecentViews.value = allRecentViews.value.filter((f) => f.viewId !== viewId || f.tableID !== tableId)- }- }- watch(- () => tablesStore.activeTableId,- async (newId, oldId) => {- if (newId === oldId) return- if (isPublic.value) {- isViewsLoading.value = false- return- }-- isViewDataLoading.value = true-- try {- if (tablesStore.activeTable) tablesStore.activeTable.isViewsLoading = true-- await loadViews()- } catch (e) {- console.error(e)- } finally {- if (tablesStore.activeTable) tablesStore.activeTable.isViewsLoading = false- }- },- { immediate: true },- )-- const isLockedView = computed(() => activeView.value?.lock_type === 'locked')-const navigateToView = async ({view,baseId,@@ -352,28 +287,293 @@ export const useViewsStore = defineStore('viewsStore', () => {}}- watch(activeView, (view) => {- if (!view) return- if (!view.base_id) return+ const createView = async (tableId: string, form: CreateViewForm): Promise<ViewType | null> => {+ if (!tableId) return null- const tableName = tablesStore.baseTables.get(view.base_id)?.find((t) => t.id === view.fk_model_id)?.title+ try {+ let data: ViewType | null = null++ switch (form.type) {+ case ViewTypes.GRID:+ data = await $api.dbView.gridCreate(tableId, form)+ break+ case ViewTypes.GALLERY:+ data = await $api.dbView.galleryCreate(tableId, form)+ break+ case ViewTypes.FORM:+ data = await $api.dbView.formCreate(tableId, {+ ...form,+ ...getDefaultViewMetas(ViewTypes.FORM),+ })+ break+ case ViewTypes.KANBAN:+ data = await $api.dbView.kanbanCreate(tableId, form)+ break+ case ViewTypes.MAP:+ data = await $api.dbView.mapCreate(tableId, form)+ break+ case ViewTypes.CALENDAR:+ data = await $api.dbView.calendarCreate(tableId, {+ ...form,+ calendar_range: form.calendar_range.map((range) => ({+ fk_from_column_id: range.fk_from_column_id,+ fk_to_column_id: range.fk_to_column_id,+ })),+ })+ break+ }- const baseName = bases.basesList.find((p) => p.id === view.base_id)?.title- allRecentViews.value = [- {+ if (data) {+ // Add the new view to the store+ const tableViews = viewsByTable.value.get(tableId) || []+ viewsByTable.value.set(tableId, [...tableViews, data])++ // Refresh command palette+ refreshCommandPalette()++ // Telemetry event+ $e(form.copy_from_id ? 'a:view:duplicate' : 'a:view:create', { view: data.type })++ return data+ }++ return null+ } catch (e: any) {+ console.error(e)+ message.error(await extractSdkResponseErrorMsg(e))+ throw e+ }+ }++ const duplicateView = async (view: ViewType): Promise<ViewType | null> => {+ if (!view?.id) return null++ const views = viewsByTable.value.get(view.fk_model_id) || []+ const uniqueTitle = generateUniqueTitle(`${view.title} copy`, views, 'title', '_', true)++ const getViewSpecificProps = (sourceView: ViewType) => {+ const baseProps = {+ fk_grp_col_id: null,+ fk_geo_data_col_id: null,+ fk_cover_image_col_id: null,+ calendar_range: [] as Array<{+ fk_from_column_id: string+ fk_to_column_id: string | null+ }>,+ }++ switch (sourceView.type) {+ case ViewTypes.GALLERY:+ return {+ ...baseProps,+ fk_cover_image_col_id: (sourceView.view as GalleryType)?.fk_cover_image_col_id || null,+ }+ case ViewTypes.KANBAN:+ return {+ ...baseProps,+ fk_cover_image_col_id: (sourceView.view as KanbanType)?.fk_cover_image_col_id || null,+ fk_grp_col_id: (sourceView.view as KanbanType)?.fk_grp_col_id || null,+ }+ case ViewTypes.MAP:+ return {+ ...baseProps,+ fk_geo_data_col_id: (sourceView.view as MapType)?.fk_geo_data_col_id || null,+ }+ case ViewTypes.CALENDAR:+ return {+ ...baseProps,+ calendar_range:+ (sourceView.view as CalendarType)?.calendar_range?.map((range) => ({+ fk_from_column_id: range.fk_from_column_id as string,+ fk_to_column_id: range.fk_to_column_id as string,+ })) || [],+ }+ default:+ return baseProps+ }+ }++ const viewSpecificProps = getViewSpecificProps(view)++ const duplicateForm: CreateViewForm = {+ title: uniqueTitle,+ type: view.type,+ description: view.description || '',+ copy_from_id: view.id!,+ row_coloring_mode: view.row_coloring_mode!,+ meta: parseProp(view.meta)?.rowColoringInfo ? { rowColoringInfo: parseProp(view.meta).rowColoringInfo } : undefined,+ ...viewSpecificProps,+ }++ return await createView(view.fk_model_id, duplicateForm)+ }++ const deleteView = async (view: ViewType) => {+ if (!view?.id) return++ const activeViewId = activeView.value?.id++ try {+ await $api.dbView.delete(view.id)++ // Remove view from the viewsByTable map+ const tableViews = viewsByTable.value.get(view.fk_model_id) || []+ const updatedViews = tableViews.filter((v) => v.id !== view.id)+ viewsByTable.value.set(view.fk_model_id, updatedViews)++ // Remove from recent views+ removeFromRecentViews({viewId: view.id,- baseId: view.base_id as string,- tableID: view.fk_model_id,- isDefault: !!view.is_default,- viewName: view.is_default ? (tableName as string) : view.title,- viewType: view.type,- workspaceId: activeWorkspaceId.value,- tableName: tableName as string,- baseName: baseName as string,+ tableId: view.fk_model_id,+ baseId: view.base_id,+ })++ // Refresh command palette+ refreshCommandPalette()++ // Telemetry event+ $e('a:view:delete', { view: view.type })++ // If we deleted the active view, navigate to default or first view+ if (activeViewId === view.id) {+ const remainingViews = viewsByTable.value.get(view.fk_model_id) || []+ const defaultView = remainingViews.find((v) => v.is_default) || remainingViews[0]++ if (defaultView && activeTable.value) {+ await navigateToView({+ view: defaultView,+ baseId: activeTable.value.base_id!,+ tableId: view.fk_model_id,+ })+ } else {+ await ncNavigateTo({+ workspaceId: activeWorkspaceId.value,+ baseId: view.base_id,+ })+ }+ }++ return true+ } catch (e: any) {+ console.error(e)+ message.error(await extractSdkResponseErrorMsg(e))+ throw e+ }+ }++ const updateView = async (viewId: string, updates: Partial<ViewType>): Promise<ViewType | null> => {+ try {+ const updatedView = await $api.dbView.update(viewId, updates)++ // Find the table and update the view in the store+ const tableId = activeView.value?.fk_model_id+ if (tableId) {+ const tableViews = viewsByTable.value.get(tableId) || []+ const viewIndex = tableViews.findIndex((v) => v.id === viewId)++ if (viewIndex !== -1) {+ // Replace with the response from API+ tableViews[viewIndex] = updatedView+ viewsByTable.value.set(tableId, [...tableViews])++ // Update recent views if title changed+ if (updatedView.title) {+ allRecentViews.value = allRecentViews.value.map((rv) => {+ if (rv.viewId === viewId && rv.tableID === tableId) {+ rv.viewName = updatedView.title+ }+ return rv+ })+ }++ refreshCommandPalette()++ return updatedView+ }+ }++ return updatedView+ } catch (e: any) {+ console.error(e)+ throw e+ }+ }++ const updateViewMeta = async (viewId: string, viewType: ViewTypes, updates: Record<string, any>): Promise<ViewType | null> => {+ try {+ let updatedView: ViewType++ switch (viewType) {+ case ViewTypes.GRID:+ updatedView = await $api.dbView.gridUpdate(viewId, updates)+ break+ case ViewTypes.GALLERY:+ updatedView = await $api.dbView.galleryUpdate(viewId, updates)+ break+ case ViewTypes.KANBAN:+ updatedView = await $api.dbView.kanbanUpdate(viewId, updates)+ break+ case ViewTypes.MAP:+ updatedView = await $api.dbView.mapUpdate(viewId, updates)+ break+ case ViewTypes.CALENDAR:+ updatedView = await $api.dbView.calendarUpdate(viewId, updates)+ break+ case ViewTypes.FORM:+ updatedView = await $api.dbView.formUpdate(viewId, updates)+ break+ default:+ throw new Error(`Unsupported view type for meta update: ${viewType}`)+ }++ // Find the table and update the view in the store+ const tableId = activeView.value?.fk_model_id+ if (tableId) {+ const tableViews = viewsByTable.value.get(tableId) || []+ const viewIndex = tableViews.findIndex((v) => v.id === viewId)++ if (viewIndex !== -1) {+ tableViews[viewIndex] = updatedView+ viewsByTable.value.set(tableId, [...tableViews])+ }+ }++ refreshCommandPalette()++ return updatedView+ } catch (e: any) {+ console.error(e)+ throw e+ }+ }++ const onViewsTabChange = (page: ViewPageType) => {+ router.push({+ name: 'index-typeOrId-baseId-index-index-viewId-viewTitle-slugs',+ params: {+ typeOrId: route.value.params.typeOrId,+ baseId: route.value.params.baseId,+ viewId: route.value.params.viewId,+ viewTitle: activeViewTitleOrId.value,+ slugs: [page],},- ...allRecentViews.value.filter((f) => f.viewId !== view.id || f.tableID !== view.fk_model_id),- ]- })+ })+ }++ const changeView = async ({ viewId, tableId, baseId }: { viewId: string | null; tableId: string; baseId: string }) => {+ const routeName = 'index-typeOrId-baseId-index-index-viewId-viewTitle'+ await router.push({ name: routeName, params: { viewTitle: viewId || '', viewId: tableId, baseId } })+ }++ function removeFromRecentViews({ viewId, tableId, baseId }: { viewId?: string | undefined; tableId: string; baseId?: string }) {+ if (baseId && !viewId && !tableId) {+ allRecentViews.value = allRecentViews.value.filter((f) => f.baseId !== baseId)+ } else if (baseId && tableId && !viewId) {+ allRecentViews.value = allRecentViews.value.filter((f) => f.baseId !== baseId || f.tableID !== tableId)+ } else if (tableId && viewId) {+ allRecentViews.value = allRecentViews.value.filter((f) => f.viewId !== viewId || f.tableID !== tableId)+ }+ }const updateTabTitle = () => {if (!activeView.value || !activeView.value.base_id) {@@ -435,82 +635,6 @@ export const useViewsStore = defineStore('viewsStore', () => {)}- const duplicateView = async (view: ViewType) => {- if (!view?.id) return-- const views = viewsByTable.value.get(view.fk_model_id) || []-- const uniqueTitle = generateUniqueTitle(`${view.title} copy`, views, 'title', '_', true)-- const payload: {- title: string- type: ViewTypes- description?: string- copy_from_id: string | null- // for kanban view only- fk_grp_col_id: string | null- fk_geo_data_col_id: string | null- row_coloring_mode: string | null- meta?: any-- // for calendar view only- calendar_range: Array<{- fk_from_column_id: string- fk_to_column_id: string | null // for ee only- }>- fk_cover_image_col_id: string | null- } = {- title: uniqueTitle,- type: view.type,- description: view.description || '',- copy_from_id: view.id!,- row_coloring_mode: view.row_coloring_mode!,- meta: parseProp(view.meta)?.rowColoringInfo ? { rowColoringInfo: parseProp(view.meta).rowColoringInfo } : undefined,- fk_grp_col_id: null,- fk_geo_data_col_id: null,- fk_cover_image_col_id: null,- calendar_range: [],- }-- try {- switch (payload.type) {- case _ViewTypes.GRID:- return await $api.dbView.gridCreate(view.fk_model_id, payload)-- case _ViewTypes.GALLERY:- payload.fk_cover_image_col_id = (view.view as GalleryType)?.fk_cover_image_col_id || null-- return await $api.dbView.galleryCreate(view.fk_model_id, payload)-- case _ViewTypes.FORM:- return await $api.dbView.formCreate(view.fk_model_id, payload)-- case _ViewTypes.KANBAN:- payload.fk_cover_image_col_id = (view.view as KanbanType)?.fk_cover_image_col_id || null- payload.fk_grp_col_id = (view.view as KanbanType)?.fk_grp_col_id || null-- return await $api.dbView.kanbanCreate(view.fk_model_id, payload)-- case _ViewTypes.MAP:- payload.fk_geo_data_col_id = (view.view as MapType)?.fk_geo_data_col_id || null-- return await $api.dbView.mapCreate(view.fk_model_id, payload)-- case _ViewTypes.CALENDAR:- payload.calendar_range =- (view.view as CalendarType)?.calendar_range?.map((range) => ({- fk_from_column_id: range.fk_from_column_id as string,- fk_to_column_id: range.fk_to_column_id as string,- })) || []-- return await $api.dbView.calendarCreate(view.fk_model_id, payload)- }- } catch (e: any) {- console.error(e)- message.error(await extractSdkResponseErrorMsg(e))- }- }-const setCurrentViewExpandedFormMode = async (viewId: string, mode: 'field' | 'attachment', columnId?: string) => {/*** Update value only if it is EeUI and active view@@ -519,13 +643,11 @@ export const useViewsStore = defineStore('viewsStore', () => {try {if (isUIAllowed('viewCreateOrEdit')) {- await $api.dbView.update(viewId, {+ await updateView(viewId, {expanded_record_mode: mode,attachment_mode_column_id: columnId,})}-- Object.assign(activeView.value, { expanded_record_mode: mode, attachment_mode_column_id: columnId })} catch (e: any) {console.error(e)message.error(await extractSdkResponseErrorMsg(e))@@ -540,7 +662,7 @@ export const useViewsStore = defineStore('viewsStore', () => {try {if (isUIAllowed('viewCreateOrEdit')) {- await $api.dbView.update(viewId, {+ await updateView(viewId, {attachment_mode_column_id: columnId,})}@@ -597,11 +719,6 @@ export const useViewsStore = defineStore('viewsStore', () => {refreshCommandPalette()- await loadViews({- tableId,- force: true,- })-if (view) {navigateToView({view,@@ -622,8 +739,51 @@ export const useViewsStore = defineStore('viewsStore', () => {}}- refreshViewTabTitle.on(() => {- updateTabTitle()+ watch(+ () => tablesStore.activeTableId,+ async (newId, oldId) => {+ if (newId === oldId) return+ if (isPublic.value) {+ isViewsLoading.value = false+ return+ }++ isViewDataLoading.value = true++ try {+ if (tablesStore.activeTable) tablesStore.activeTable.isViewsLoading = true++ await loadViews()+ } catch (e) {+ console.error(e)+ } finally {+ if (tablesStore.activeTable) tablesStore.activeTable.isViewsLoading = false+ }+ },+ { immediate: true },+ )++ watch(activeView, (view) => {+ if (!view) return+ if (!view.base_id) return++ const tableName = tablesStore.baseTables.get(view.base_id)?.find((t) => t.id === view.fk_model_id)?.title++ const baseName = bases.basesList.find((p) => p.id === view.base_id)?.title+ allRecentViews.value = [+ {+ viewId: view.id,+ baseId: view.base_id as string,+ tableID: view.fk_model_id,+ isDefault: !!view.is_default,+ viewName: view.is_default ? (tableName as string) : view.title,+ viewType: view.type,+ workspaceId: activeWorkspaceId.value,+ tableName: tableName as string,+ baseName: baseName as string,+ },+ ...allRecentViews.value.filter((f) => f.viewId !== view.id || f.tableID !== view.fk_model_id),+ ]})watch(@@ -636,36 +796,47 @@ export const useViewsStore = defineStore('viewsStore', () => {},)+ refreshViewTabTitle.on(() => {+ updateTabTitle()+ })+return {+ // StateisLockedView,isViewsLoading,isViewDataLoading,isPaginationLoading,- loadViews,recentViews,allRecentViews,views,activeView,openedViewsTab,- onViewsTabChange,- sharedView,viewsByTable,activeViewTitleOrId,- navigateToView,- changeView,- removeFromRecentViews,activeSorts,activeNestedFilters,isActiveViewLocked,preFillFormSearchParams,+ lastOpenedViewId,+ activeViewRowColorInfo,+ sharedView,++ // Methods+ createView,+ updateView,+ updateViewMeta,+ deleteView,+ loadViews,+ onViewsTabChange,+ navigateToView,+ changeView,+ removeFromRecentViews,refreshViewTabTitle: refreshViewTabTitle.trigger,updateViewCoverImageColumnId,duplicateView,setCurrentViewExpandedFormMode,setCurrentViewExpandedFormAttachmentColumn,onOpenViewCreateModal,- lastOpenedViewId,- activeViewRowColorInfo,}})diff --git a/packages/nc-gui/utils/viewUtils.ts b/packages/nc-gui/utils/viewUtils.tsindex 2ece663dbd..845ceef0bf 100644--- a/packages/nc-gui/utils/viewUtils.ts+++ b/packages/nc-gui/utils/viewUtils.ts@@ -63,3 +63,19 @@ export const defaultRowColorInfo: RowColoringInfo = {color: null,is_set_as_background: null,}++const getDefaultViewMetas = (viewType: ViewTypes) => {+ switch (viewType) {+ case ViewTypes.FORM:+ return {+ submit_another_form: false,+ show_blank_form: false,+ meta: {+ hide_branding: false,+ background_color: '#F9F9FA',+ hide_banner: false,+ },+ }+ }+ return {}+}diff --git a/packages/nocodb/src/services/calendars.service.ts b/packages/nocodb/src/services/calendars.service.tsindex 0b9f6d358d..56e6b0c821 100644--- a/packages/nocodb/src/services/calendars.service.ts+++ b/packages/nocodb/src/services/calendars.service.ts@@ -150,6 +150,9 @@ export class CalendarsService {context,owner,});++ await view.getView(context);+return res;}}diff --git a/packages/nocodb/src/services/forms.service.ts b/packages/nocodb/src/services/forms.service.tsindex 0688b516e0..259fe19fbb 100644--- a/packages/nocodb/src/services/forms.service.ts+++ b/packages/nocodb/src/services/forms.service.ts@@ -1,11 +1,11 @@import { Injectable } from '@nestjs/common';import { AppEvents, EventType, ViewTypes } from 'nocodb-sdk';-import type { MetaService } from '~/meta/meta.service';import type {FormUpdateReqType,UserType,ViewCreateReqType,} from 'nocodb-sdk';+import type { MetaService } from '~/meta/meta.service';import type { NcContext, NcRequest } from '~/interface/config';import { AppHooksService } from '~/services/app-hooks/app-hooks.service';import { validatePayload } from '~/helpers';@@ -20,8 +20,7 @@ export class FormsService {constructor(private readonly appHooksService: AppHooksService) {}async formViewGet(context: NcContext, param: { formViewId: string }) {- const formViewData = await FormView.getWithInfo(context, param.formViewId);- return formViewData;+ return await FormView.getWithInfo(context, param.formViewId);}async formViewCreate(@@ -96,6 +95,8 @@ export class FormsService {context,});+ await view.getView(context);+NocoSocket.broadcastEvent(context,{@@ -154,6 +155,8 @@ export class FormsService {owner,});+ await view.getView(context);+return res;}}diff --git a/packages/nocodb/src/services/galleries.service.ts b/packages/nocodb/src/services/galleries.service.tsindex 9e330a7f66..00e67751c0 100644--- a/packages/nocodb/src/services/galleries.service.ts+++ b/packages/nocodb/src/services/galleries.service.ts@@ -150,6 +150,8 @@ export class GalleriesService {owner,});+ await view.getView(context);+return res;}}diff --git a/packages/nocodb/src/services/grids.service.ts b/packages/nocodb/src/services/grids.service.tsindex 4d468e4b2c..3f937538c7 100644--- a/packages/nocodb/src/services/grids.service.ts+++ b/packages/nocodb/src/services/grids.service.ts@@ -71,6 +71,8 @@ export class GridsService {context,});+ await view.getView(context);+NocoSocket.broadcastEvent(context,{@@ -129,6 +131,8 @@ export class GridsService {context,});+ await view.getView(context);+NocoSocket.broadcastEvent(context,{