From 85f4be117bfa3ab6ac0bf9195959e485b5878d4f Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 17 Aug 2022 01:58:09 +0530 Subject: [PATCH] feat(gui-v2): integrate attachment cell Signed-off-by: Pranav C --- .../components/cell/attachment/index.vue | 14 ++++- .../components/cell/attachment/utils.ts | 52 ++++++++++++++----- .../nc-gui-v2/components/shared-view/Form.vue | 2 +- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/packages/nc-gui-v2/components/cell/attachment/index.vue b/packages/nc-gui-v2/components/cell/attachment/index.vue index 33db7c7b83..28912f4314 100644 --- a/packages/nc-gui-v2/components/cell/attachment/index.vue +++ b/packages/nc-gui-v2/components/cell/attachment/index.vue @@ -4,7 +4,7 @@ import { useProvideAttachmentCell } from './utils' import { useSortable } from './sort' import Modal from './Modal.vue' import Carousel from './Carousel.vue' -import { computed, isImage, openLink, ref, useDropZone, useSmartsheetStoreOrThrow, watch } from '#imports' +import { computed, isImage, openLink, ref, useDropZone, useSmartsheetStoreOrThrow, watch, useSmartsheetRowStoreOrThrow } from '#imports' interface Props { modelValue: string | Record[] | null @@ -23,13 +23,15 @@ const sortableRef = ref() const { cellRefs } = useSmartsheetStoreOrThrow()! -const { column, modalVisible, attachments, visibleItems, onDrop, isLoading, open, FileIcon, selectedImage, isReadonly } = +const { column, modalVisible, attachments, visibleItems, onDrop, isLoading, open, FileIcon, selectedImage, isReadonly, storedFilesRefs, } = useProvideAttachmentCell(updateModelValue) const currentCellRef = computed(() => cellRefs.value.find((cell) => cell.dataset.key === `${rowIndex}${column.value.id}`)) const { dragging } = useSortable(sortableRef, visibleItems, updateModelValue, isReadonly) +const { state: rowState } = useSmartsheetRowStoreOrThrow() + const { isOverDropZone } = useDropZone(currentCellRef, onDrop) /** on new value, reparse our stored attachments */ @@ -53,6 +55,14 @@ onKeyDown('Escape', () => { modalVisible.value = false isOverDropZone.value = false }) + +/** sync storedFilesRefs state with row state */ +watch( + () => storedFilesRefs?.value?.length || 0, + () => { + rowState.value[column.value.title!] = storedFilesRefs?.value + }, +)