From 80fbad10582930fad68cb41cdc710d296938cb00 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 11 Aug 2022 18:40:29 +0800 Subject: [PATCH] feat(gui-v2): implement copy form view logic --- packages/nc-gui-v2/components/dlg/ViewCreate.vue | 5 +++++ .../components/smartsheet/sidebar/MenuTop.vue | 2 +- .../smartsheet/sidebar/RenameableMenuItem.vue | 2 +- .../components/smartsheet/sidebar/index.vue | 15 +++++++++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/nc-gui-v2/components/dlg/ViewCreate.vue b/packages/nc-gui-v2/components/dlg/ViewCreate.vue index f099498d31..4062fd1e45 100644 --- a/packages/nc-gui-v2/components/dlg/ViewCreate.vue +++ b/packages/nc-gui-v2/components/dlg/ViewCreate.vue @@ -14,6 +14,7 @@ interface Props { modelValue: boolean type: ViewTypes title?: string + selectedViewId?: string } interface Emits { @@ -86,6 +87,10 @@ watch( function init() { form.title = generateUniqueTitle(capitalize(ViewTypes[props.type].toLowerCase()), viewList?.value || [], 'title') + if (props.selectedViewId) { + form.copy_from_id = props.selectedViewId + } + nextTick(() => { const el = inputEl?.$el as HTMLInputElement diff --git a/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue b/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue index 0f6bdd0e9b..411dce49dc 100644 --- a/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue +++ b/packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue @@ -11,7 +11,7 @@ import { extractSdkResponseErrorMsg } from '~/utils' import { ActiveViewInj, ViewListInj } from '~/context' interface Emits { - (event: 'openModal', data: { type: ViewTypes; title?: string }): void + (event: 'openModal', data: { type: ViewTypes; title?: string; copyViewId?: string }): void (event: 'deleted'): void (event: 'sorted'): void } diff --git a/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue b/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue index 0435093b31..d28ad94026 100644 --- a/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue +++ b/packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue @@ -85,7 +85,7 @@ function focusInput(el: HTMLInputElement) { /** Duplicate a view */ // todo: This is not really a duplication, maybe we need to implement a true duplication? function onDuplicate() { - emits('openModal', { type: vModel.value.type, title: vModel.value.title }) + emits('openModal', { type: vModel.value.type, title: vModel.value.title, copyViewId: vModel.value.id }) $e('c:view:copy', { view: vModel.value.type }) } diff --git a/packages/nc-gui-v2/components/smartsheet/sidebar/index.vue b/packages/nc-gui-v2/components/smartsheet/sidebar/index.vue index cfb5847d01..778de0ce1d 100644 --- a/packages/nc-gui-v2/components/smartsheet/sidebar/index.vue +++ b/packages/nc-gui-v2/components/smartsheet/sidebar/index.vue @@ -29,6 +29,9 @@ let viewCreateType = $ref() /** View title to create from modal (when duplicating) */ let viewCreateTitle = $ref('') +/** selected view id for copying view meta */ +let selectedViewId = $ref('') + /** is view creation modal open */ let modalOpen = $ref(false) @@ -51,10 +54,11 @@ watch( ) /** Open view creation modal */ -function openModal({ type, title = '' }: { type: ViewTypes; title: string }) { +function openModal({ type, title = '', copyViewId }: { type: ViewTypes; title: string; copyViewId: string }) { modalOpen = true viewCreateType = type viewCreateTitle = title + selectedViewId = copyViewId } /** Handle view creation */ @@ -129,7 +133,14 @@ function onCreate(view: GridType | FormType | KanbanType | GalleryType) { - +