diff --git a/packages/nc-gui/composables/useGridViewColumnWidth.ts b/packages/nc-gui/composables/useGridViewColumnWidth.ts index 27f3855298..e03c0db292 100644 --- a/packages/nc-gui/composables/useGridViewColumnWidth.ts +++ b/packages/nc-gui/composables/useGridViewColumnWidth.ts @@ -1,8 +1,19 @@ -import type { ColumnType, GridColumnType, GridType, ViewType } from 'nocodb-sdk' +import type { ColumnType, GridColumnType, ViewType } from 'nocodb-sdk' import type { Ref } from 'vue' -import { IsPublicInj, computed, inject, ref, useMetas, useNuxtApp, useStyleTag, useUIPermission, watch } from '#imports' +import { + IsPublicInj, + computed, + inject, + ref, + useMetas, + useNuxtApp, + useStyleTag, + useUIPermission, + useUndoRedo, + watch, +} from '#imports' -export function useGridViewColumnWidth(view: Ref) { +export function useGridViewColumnWidth(view: Ref) { const { css, load: loadCss, unload: unloadCss } = useStyleTag('') const { isUIAllowed } = useUIPermission() @@ -11,12 +22,14 @@ export function useGridViewColumnWidth(view: Ref) { const { metas } = useMetas() + const { addUndo } = useUndoRedo() + const gridViewCols = ref>({}) const resizingCol = ref('') const resizingColWidth = ref('200px') const isPublic = inject(IsPublicInj, ref(false)) - const columns = computed(() => metas.value?.[(view.value as ViewType)?.fk_model_id as string]?.columns || []) + const columns = computed(() => metas.value?.[view.value?.fk_model_id as string]?.columns || []) watch( [gridViewCols, resizingCol, resizingColWidth], @@ -54,7 +67,21 @@ export function useGridViewColumnWidth(view: Ref) { * or when view changes reload columns width */ watch([() => columns.value?.length, () => view?.value?.id], loadGridViewColumns) - const updateWidth = async (id: string, width: string) => { + const updateWidth = async (id: string, width: string, undo = false) => { + if (!undo) { + addUndo({ + redo: { + fn: (w: string) => updateWidth(id, w, true), + args: [width], + }, + undo: { + fn: (w: string) => updateWidth(id, w, true), + args: [gridViewCols.value[id].width], + }, + scope: view.value?.is_default ? [view.value.fk_model_id, view.value.title] : view.value?.title, + }) + } + if (gridViewCols?.value?.[id]) { gridViewCols.value[id].width = width } diff --git a/packages/nocodb-sdk/src/lib/Api.ts b/packages/nocodb-sdk/src/lib/Api.ts index be2fca8810..3069409962 100644 --- a/packages/nocodb-sdk/src/lib/Api.ts +++ b/packages/nocodb-sdk/src/lib/Api.ts @@ -2203,6 +2203,8 @@ export interface ViewType { show: BoolType; /** Should show system fields in this view? */ show_system_fields?: BoolType; + /** Is this view default view for the model? */ + is_default?: BoolType; /** View Title */ title: string; /** View Type */ diff --git a/packages/nocodb/src/schema/swagger.json b/packages/nocodb/src/schema/swagger.json index 60fc44bfff..57bf94c867 100644 --- a/packages/nocodb/src/schema/swagger.json +++ b/packages/nocodb/src/schema/swagger.json @@ -19505,6 +19505,10 @@ "$ref": "#/components/schemas/Bool", "description": "Should show system fields in this view?" }, + "is_default": { + "$ref": "#/components/schemas/Bool", + "description": "Is this view default view for the model?" + }, "title": { "description": "View Title", "type": "string"