Browse Source

feat: undo/redo for cover image change

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5332/head
mertmit 2 years ago
parent
commit
829f83145c
  1. 51
      packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue
  2. 4
      packages/nocodb-sdk/src/lib/Api.ts
  3. 4
      packages/nocodb/src/schema/swagger.json

51
packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue

@ -146,6 +146,27 @@ const coverOptions = computed<SelectProps['options']>(() => {
return [{ value: null, label: 'No Image' }, ...filterFields]
})
const updateCoverImage = async (val?: string | null) => {
if (
(activeView.value?.type === ViewTypes.GALLERY || activeView.value?.type === ViewTypes.KANBAN) &&
activeView.value?.id &&
activeView.value?.view
) {
if (activeView.value?.type === ViewTypes.GALLERY) {
await $api.dbView.galleryUpdate(activeView.value?.id, {
fk_cover_image_col_id: val,
})
;(activeView.value.view as GalleryType).fk_cover_image_col_id = val
} else if (activeView.value?.type === ViewTypes.KANBAN) {
await $api.dbView.kanbanUpdate(activeView.value?.id, {
fk_cover_image_col_id: val,
})
;(activeView.value.view as KanbanType).fk_cover_image_col_id = val
}
reloadViewMetaHook?.trigger()
}
}
const coverImageColumnId = computed({
get: () => {
const fk_cover_image_col_id =
@ -159,23 +180,19 @@ const coverImageColumnId = computed({
return null
},
set: async (val) => {
if (
(activeView.value?.type === ViewTypes.GALLERY || activeView.value?.type === ViewTypes.KANBAN) &&
activeView.value?.id &&
activeView.value?.view
) {
if (activeView.value?.type === ViewTypes.GALLERY) {
await $api.dbView.galleryUpdate(activeView.value?.id, {
fk_cover_image_col_id: val,
})
;(activeView.value.view as GalleryType).fk_cover_image_col_id = val
} else if (activeView.value?.type === ViewTypes.KANBAN) {
await $api.dbView.kanbanUpdate(activeView.value?.id, {
fk_cover_image_col_id: val,
})
;(activeView.value.view as KanbanType).fk_cover_image_col_id = val
}
reloadViewMetaHook?.trigger()
if (val !== coverImageColumnId.value) {
addUndo({
undo: {
fn: await updateCoverImage,
args: [coverImageColumnId.value],
},
redo: {
fn: await updateCoverImage,
args: [val],
},
})
await updateCoverImage(val)
}
},
})

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

@ -902,7 +902,7 @@ export interface GalleryType {
/** Model for Bool */
deleted?: BoolType;
/** Foreign Key to Cover Image Column */
fk_cover_image_col_id?: string;
fk_cover_image_col_id?: StringOrNullType;
/** Foreign Key to Model */
fk_model_id?: string;
/** Foreign Key to View */
@ -1229,7 +1229,7 @@ export interface KanbanType {
/** View ID */
fk_view_id?: IdType;
/** Cover Image Column ID */
fk_cover_image_col_id?: IdType;
fk_cover_image_col_id?: StringOrNullType;
/** Kanban Columns */
columns?: KanbanColumnType[];
/** Meta Info for Kanban */

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

@ -15629,7 +15629,7 @@
"$ref": "#/components/schemas/Bool"
},
"fk_cover_image_col_id": {
"type": "string",
"$ref": "#/components/schemas/StringOrNull",
"description": "Foreign Key to Cover Image Column"
},
"fk_model_id": {
@ -16498,7 +16498,7 @@
"description": "View ID"
},
"fk_cover_image_col_id": {
"$ref": "#/components/schemas/Id",
"$ref": "#/components/schemas/StringOrNull",
"description": "Cover Image Column ID"
},
"columns": {

Loading…
Cancel
Save