diff --git a/packages/nc-gui/components/cell/attachment/index.vue b/packages/nc-gui/components/cell/attachment/index.vue index c143fd1f45..dc7fb30b07 100644 --- a/packages/nc-gui/components/cell/attachment/index.vue +++ b/packages/nc-gui/components/cell/attachment/index.vue @@ -3,7 +3,6 @@ import { onKeyDown } from '@vueuse/core' import { useProvideAttachmentCell } from './utils' import { useSortable } from './sort' import { - IsFormInj, IsGalleryInj, inject, isImage, @@ -22,24 +21,26 @@ interface Props { } interface Emits { - (event: 'update:modelValue', value: string | Record): void + (event: 'update:modelValue', value: string | Record[]): void } const { modelValue, rowIndex } = defineProps() const emits = defineEmits() -const isForm = inject(IsFormInj, ref(false)) - const isGallery = inject(IsGalleryInj, ref(false)) const attachmentCellRef = ref() const sortableRef = ref() -const { cellRefs } = useSmartsheetStoreOrThrow()! +const currentCellRef = ref() + +const { cellRefs, isSharedForm } = useSmartsheetStoreOrThrow()! const { + isPublic, + isForm, column, modalVisible, attachments, @@ -53,8 +54,6 @@ const { storedFiles, } = useProvideAttachmentCell(updateModelValue) -const currentCellRef = ref() - watch( [() => rowIndex, isForm, attachmentCellRef], () => { @@ -91,10 +90,20 @@ watch( (nextModel) => { if (nextModel) { try { - attachments.value = ((typeof nextModel === 'string' ? JSON.parse(nextModel) : nextModel) || []).filter(Boolean) + const nextAttachments = ((typeof nextModel === 'string' ? JSON.parse(nextModel) : nextModel) || []).filter(Boolean) + + if (isPublic.value && isForm.value) { + storedFiles.value = nextAttachments + } else { + attachments.value = nextAttachments + } } catch (e) { console.error(e) - attachments.value = [] + if (isPublic.value && isForm.value) { + storedFiles.value = [] + } else { + attachments.value = [] + } } } }, @@ -102,8 +111,8 @@ watch( ) /** updates attachments array for autosave */ -function updateModelValue(data: string | Record) { - emits('update:modelValue', typeof data !== 'string' ? JSON.stringify(data) : data) +function updateModelValue(data: string | Record[]) { + emits('update:modelValue', data) } /** Close modal on escape press, disable dropzone as well */ @@ -119,8 +128,6 @@ watch( rowState.value[column.value!.title!] = storedFiles.value }, ) - -const { isSharedForm } = useSmartsheetStoreOrThrow()