From 6a098aec17fffb7cff999054e3d2b3fcbc70b470 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 24 Jan 2023 17:51:33 +0530 Subject: [PATCH] fix(gui): apply attachment validation in shared form view Signed-off-by: Pranav C --- .../components/cell/attachment/utils.ts | 78 ++-- .../nc-gui/components/smartsheet/Grid.vue | 336 +++++++++--------- 2 files changed, 206 insertions(+), 208 deletions(-) diff --git a/packages/nc-gui/components/cell/attachment/utils.ts b/packages/nc-gui/components/cell/attachment/utils.ts index f5d472def7..9fdc6af4ac 100644 --- a/packages/nc-gui/components/cell/attachment/utils.ts +++ b/packages/nc-gui/components/cell/attachment/utils.ts @@ -96,50 +96,13 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( async function onFileSelect(selectedFiles: FileList | File[]) { if (!selectedFiles.length) return - if (isPublic.value && isForm.value) { - const newFiles = await Promise.all( - Array.from(selectedFiles).map( - (file) => - new Promise((resolve) => { - const res: { file: File; title: string; mimetype: string; data?: any } = { - ...file, - file, - title: file.name, - mimetype: file.type, - } - - if (isImage(file.name, (file).mimetype ?? file.type)) { - const reader = new FileReader() - - reader.onload = (e) => { - res.data = e.target?.result - - resolve(res) - } - - reader.onerror = () => { - resolve(res) - } - - reader.readAsDataURL(file) - } else { - resolve(res) - } - }), - ), - ) - attachments.value = [...attachments.value, ...newFiles] - - return updateModelValue(attachments.value) - } - - const newAttachments = [] - const attachmentMeta = { ...defaultAttachmentMeta, ...(typeof column.value?.meta === 'string' ? JSON.parse(column.value.meta) : column.value?.meta), } + const newAttachments = [] + const files: File[] = [] for (const file of selectedFiles) { @@ -173,6 +136,43 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( files.push(file) } + if (isPublic.value && isForm.value) { + const newFiles = await Promise.all( + Array.from(files).map( + (file) => + new Promise((resolve) => { + const res: { file: File; title: string; mimetype: string; data?: any } = { + ...file, + file, + title: file.name, + mimetype: file.type, + } + + if (isImage(file.name, (file).mimetype ?? file.type)) { + const reader = new FileReader() + + reader.onload = (e) => { + res.data = e.target?.result + + resolve(res) + } + + reader.onerror = () => { + resolve(res) + } + + reader.readAsDataURL(file) + } else { + resolve(res) + } + }), + ), + ) + attachments.value = [...attachments.value, ...newFiles] + + return updateModelValue(attachments.value) + } + try { const data = await api.storage.upload( { diff --git a/packages/nc-gui/components/smartsheet/Grid.vue b/packages/nc-gui/components/smartsheet/Grid.vue index 09a9dd5b36..a13cd74a40 100644 --- a/packages/nc-gui/components/smartsheet/Grid.vue +++ b/packages/nc-gui/components/smartsheet/Grid.vue @@ -156,8 +156,8 @@ const getContainerScrollForElement = ( relativePos.right + (offset?.right || 0) > 0 ? container.scrollLeft + relativePos.right + (offset?.right || 0) : relativePos.left - (offset?.left || 0) < 0 - ? container.scrollLeft + relativePos.left - (offset?.left || 0) - : container.scrollLeft + ? container.scrollLeft + relativePos.left - (offset?.left || 0) + : container.scrollLeft /* * If the element is below the container, scroll down (positive) @@ -167,8 +167,8 @@ const getContainerScrollForElement = ( relativePos.bottom + (offset?.bottom || 0) > 0 ? container.scrollTop + relativePos.bottom + (offset?.bottom || 0) : relativePos.top - (offset?.top || 0) < 0 - ? container.scrollTop + relativePos.top - (offset?.top || 0) - : container.scrollTop + ? container.scrollTop + relativePos.top - (offset?.top || 0) + : container.scrollTop return scroll } @@ -672,105 +672,104 @@ const closeAddColumnDropdown = () => { @contextmenu="showContextMenu" > - - -
- - -
- - -
- + + +
+ + +
+ + -
- +
+ + +
+ + + +
+ +
- -
- - + + + + - - + + + + +
+ - + {{ $t('activity.addRow') }} -
- - +
+ + @@ -897,8 +896,7 @@ const closeAddColumnDropdown = () => {
- +
{{ $t('general.copy') }}