Browse Source

feat: undo/redo column width

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5332/head
mertmit 2 years ago
parent
commit
8bb9a3d20c
  1. 37
      packages/nc-gui/composables/useGridViewColumnWidth.ts
  2. 2
      packages/nocodb-sdk/src/lib/Api.ts
  3. 4
      packages/nocodb/src/schema/swagger.json

37
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 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<GridType | undefined>) { export function useGridViewColumnWidth(view: Ref<ViewType | undefined>) {
const { css, load: loadCss, unload: unloadCss } = useStyleTag('') const { css, load: loadCss, unload: unloadCss } = useStyleTag('')
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()
@ -11,12 +22,14 @@ export function useGridViewColumnWidth(view: Ref<GridType | undefined>) {
const { metas } = useMetas() const { metas } = useMetas()
const { addUndo } = useUndoRedo()
const gridViewCols = ref<Record<string, GridColumnType>>({}) const gridViewCols = ref<Record<string, GridColumnType>>({})
const resizingCol = ref('') const resizingCol = ref('')
const resizingColWidth = ref('200px') const resizingColWidth = ref('200px')
const isPublic = inject(IsPublicInj, ref(false)) const isPublic = inject(IsPublicInj, ref(false))
const columns = computed<ColumnType[]>(() => metas.value?.[(view.value as ViewType)?.fk_model_id as string]?.columns || []) const columns = computed<ColumnType[]>(() => metas.value?.[view.value?.fk_model_id as string]?.columns || [])
watch( watch(
[gridViewCols, resizingCol, resizingColWidth], [gridViewCols, resizingCol, resizingColWidth],
@ -54,7 +67,21 @@ export function useGridViewColumnWidth(view: Ref<GridType | undefined>) {
* or when view changes reload columns width */ * or when view changes reload columns width */
watch([() => columns.value?.length, () => view?.value?.id], loadGridViewColumns) 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]) { if (gridViewCols?.value?.[id]) {
gridViewCols.value[id].width = width gridViewCols.value[id].width = width
} }

2
packages/nocodb-sdk/src/lib/Api.ts

@ -2203,6 +2203,8 @@ export interface ViewType {
show: BoolType; show: BoolType;
/** Should show system fields in this view? */ /** Should show system fields in this view? */
show_system_fields?: BoolType; show_system_fields?: BoolType;
/** Is this view default view for the model? */
is_default?: BoolType;
/** View Title */ /** View Title */
title: string; title: string;
/** View Type */ /** View Type */

4
packages/nocodb/src/schema/swagger.json

@ -19505,6 +19505,10 @@
"$ref": "#/components/schemas/Bool", "$ref": "#/components/schemas/Bool",
"description": "Should show system fields in this view?" "description": "Should show system fields in this view?"
}, },
"is_default": {
"$ref": "#/components/schemas/Bool",
"description": "Is this view default view for the model?"
},
"title": { "title": {
"description": "View Title", "description": "View Title",
"type": "string" "type": "string"

Loading…
Cancel
Save