From 04d9b08f5539b97204680015ef2dae61cbf15c96 Mon Sep 17 00:00:00 2001 From: Daniel Spaude Date: Fri, 3 Feb 2023 18:15:20 +0100 Subject: [PATCH 1/6] add delete and duplicate row buttons to expanded form and grid view --- .../nc-gui/components/smartsheet/Gallery.vue | 191 +++++++++++------- .../smartsheet/expanded-form/Header.vue | 50 ++++- .../smartsheet/expanded-form/index.vue | 29 ++- packages/nc-gui/composables/useViewData.ts | 1 + packages/nc-gui/lang/en.json | 2 + 5 files changed, 201 insertions(+), 72 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Gallery.vue b/packages/nc-gui/components/smartsheet/Gallery.vue index 0128997248..0af5bdc9d9 100644 --- a/packages/nc-gui/components/smartsheet/Gallery.vue +++ b/packages/nc-gui/components/smartsheet/Gallery.vue @@ -49,6 +49,7 @@ const { galleryData, changePage, addEmptyRow, + deleteRow, navigateToSiblingRow, } = useViewData(meta, view) @@ -81,6 +82,9 @@ const isRowEmpty = (record: any, col: any) => { return Array.isArray(val) && val.length === 0 } +// const { xWhere, isPkAvail, isSqlView, eventBus } = useSmartsheetStoreOrThrow() +const { isSqlView } = useSmartsheetStoreOrThrow() + const attachments = (record: any): Attachment[] => { try { if (coverImageColumn?.title && record.row[coverImageColumn.title]) { @@ -168,85 +172,134 @@ watch(view, async (nextView) => { await loadGalleryData() } }) + +const { isUIAllowed } = useUIPermission() +const hasEditPermission = $computed(() => isUIAllowed('xcDatatableEditable')) +// TODO: extract this code (which is duplicated in grid and gallery) into a separate component +const _contextMenu = ref(false) +const contextMenu = computed({ + get: () => _contextMenu.value, + set: (val) => { + if (hasEditPermission) { + _contextMenu.value = val + } + }, +}) +const contextMenuTarget = ref<{ row: number } | null>(null) + +const showContextMenu = (e: MouseEvent, target?: { row: number }) => { + if (isSqlView.value) return + e.preventDefault() + if (target) { + contextMenuTarget.value = target + } +} + +