From eef9ce0f723d471db89e66784a81ede0d2abbf2d Mon Sep 17 00:00:00 2001 From: Anbarasu Date: Mon, 4 Nov 2024 11:45:27 +0530 Subject: [PATCH] fix: reload row if the attachments are expired (#9739) * fix: reload row if the attachments are expired * fix: handle attachment url expiry * fix:build feat: image zoom * fix:attchment comments * fix: async issue --- .../components/cell/attachment/Carousel.vue | 35 +++- .../cell/attachment/Preview/Image.vue | 149 +++++++++++++++--- .../cell/attachment/Preview/MiscOffice.vue | 10 +- .../cell/attachment/Preview/Pdf.vue | 10 +- .../cell/attachment/Preview/Video.vue | 9 ++ packages/nc-gui/utils/attachmentUtils.ts | 24 +++ 6 files changed, 208 insertions(+), 29 deletions(-) diff --git a/packages/nc-gui/components/cell/attachment/Carousel.vue b/packages/nc-gui/components/cell/attachment/Carousel.vue index b96e847e23..c10989c7f8 100644 --- a/packages/nc-gui/components/cell/attachment/Carousel.vue +++ b/packages/nc-gui/components/cell/attachment/Carousel.vue @@ -10,10 +10,6 @@ const isExpandedFormOpen = inject(IsExpandedFormOpenInj, ref(false)) const { isSharedForm } = useSmartsheetStoreOrThrow() -/* -const openComments = ref(false) -*/ - const { isUIAllowed } = useRoles() const container = ref(null) @@ -107,6 +103,15 @@ watchOnce(emblaMainApi, async (emblaMainApi) => { }) }) +const { loadRow } = useSmartsheetRowStoreOrThrow() + +const isUpdated = ref(1) + +const triggerReload = async () => { + await loadRow() + isUpdated.value = isUpdated.value + 1 +} + onMounted(() => { document.addEventListener('keydown', onKeyDown) }) @@ -132,7 +137,10 @@ function onKeyDown(event: KeyboardEvent) { } } -/* const toggleComment = () => { +/* +const openComments = ref(false) + +const toggleComment = () => { openComments.value = !openComments.value } @@ -181,13 +189,15 @@ const initEmblaApi = (val: any) => { -
+
{ :mime-type="item.mimeType" :title="item.title" :src="getPossibleAttachmentSrc(item)" + @error="triggerReload" />
@@ -266,6 +279,7 @@ const initEmblaApi = (val: any) => { object-fit="contain" :alt="item.title" :srcs="getPossibleAttachmentSrc(item, 'tiny')" + @error="triggerReload" />
{
-
diff --git a/packages/nc-gui/components/cell/attachment/Preview/Image.vue b/packages/nc-gui/components/cell/attachment/Preview/Image.vue index 7c16f2b62b..42ed7b0c44 100644 --- a/packages/nc-gui/components/cell/attachment/Preview/Image.vue +++ b/packages/nc-gui/components/cell/attachment/Preview/Image.vue @@ -1,33 +1,146 @@ diff --git a/packages/nc-gui/components/cell/attachment/Preview/MiscOffice.vue b/packages/nc-gui/components/cell/attachment/Preview/MiscOffice.vue index d7ff14e017..0cf63dd5bd 100644 --- a/packages/nc-gui/components/cell/attachment/Preview/MiscOffice.vue +++ b/packages/nc-gui/components/cell/attachment/Preview/MiscOffice.vue @@ -6,13 +6,19 @@ interface Props { const props = defineProps() +const emits = defineEmits(['error']) + const currentIndex = ref(0) -const handleError = () => { +const handleError = async () => { if (currentIndex.value < props.src.length - 1) { currentIndex.value = currentIndex.value + 1 } else { - currentIndex.value = -1 + const isURLExp = await isURLExpired(props.src[0]) + if (isURLExp.isExpired) { + emits('error') + } + currentIndex.value = 0 } } diff --git a/packages/nc-gui/components/cell/attachment/Preview/Pdf.vue b/packages/nc-gui/components/cell/attachment/Preview/Pdf.vue index 53a95ca76c..82654c5870 100644 --- a/packages/nc-gui/components/cell/attachment/Preview/Pdf.vue +++ b/packages/nc-gui/components/cell/attachment/Preview/Pdf.vue @@ -6,13 +6,19 @@ interface Props { const props = defineProps() +const emits = defineEmits(['error']) + const currentIndex = ref(0) -const handleError = () => { +const handleError = async () => { if (currentIndex.value < props.src.length - 1) { currentIndex.value = currentIndex.value + 1 } else { - currentIndex.value = -1 + const isURLExp = await isURLExpired(props.src[0]) + if (isURLExp.isExpired) { + emits('error') + } + currentIndex.value = 0 } } diff --git a/packages/nc-gui/components/cell/attachment/Preview/Video.vue b/packages/nc-gui/components/cell/attachment/Preview/Video.vue index 080638ab0c..ed9c86d638 100644 --- a/packages/nc-gui/components/cell/attachment/Preview/Video.vue +++ b/packages/nc-gui/components/cell/attachment/Preview/Video.vue @@ -17,6 +17,7 @@ const emit = defineEmits() interface Emits { (event: 'init', player: any): void + (event: 'error'): void } const videoPlayer = ref() @@ -36,6 +37,13 @@ onBeforeUnmount(() => { player.value.destroy() } }) + +const handleError = async () => { + const isURLExp = await isURLExpired(props.src?.[0]) + if (isURLExp.isExpired) { + emit('error') + } +}