Browse Source

feat(gui-v2): implement copy form view logic

pull/3078/head
Wing-Kam Wong 2 years ago
parent
commit
80fbad1058
  1. 5
      packages/nc-gui-v2/components/dlg/ViewCreate.vue
  2. 2
      packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue
  3. 2
      packages/nc-gui-v2/components/smartsheet/sidebar/RenameableMenuItem.vue
  4. 15
      packages/nc-gui-v2/components/smartsheet/sidebar/index.vue

5
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

2
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
}

2
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 })
}

15
packages/nc-gui-v2/components/smartsheet/sidebar/index.vue

@ -29,6 +29,9 @@ let viewCreateType = $ref<ViewTypes>()
/** 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) {
<MenuBottom @open-modal="openModal" />
</div>
<dlg-view-create v-if="views" v-model="modalOpen" :title="viewCreateTitle" :type="viewCreateType" @created="onCreate" />
<dlg-view-create
v-if="views"
v-model="modalOpen"
:title="viewCreateTitle"
:type="viewCreateType"
:selected-view-id="selectedViewId"
@created="onCreate"
/>
</a-layout-sider>
</template>

Loading…
Cancel
Save