From 96de2f914010bc65d1c7fd4ff4bc793ee7c43c6f Mon Sep 17 00:00:00 2001 From: Maxim Karmatskikh Date: Thu, 9 Nov 2023 07:44:30 +0100 Subject: [PATCH 1/4] UBERF-4229: Fix createAttachments runtime error Signed-off-by: Maxim Karmatskikh --- .../src/components/AttachmentStyleBoxEditor.svelte | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte b/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte index fa88fa6e80..4883bae5f9 100644 --- a/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte +++ b/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte @@ -1,14 +1,14 @@ @@ -86,7 +86,12 @@ haveUnsavedChanges = false } - await descriptionBox.createAttachments() + /* + Delayed save can be invoked after dismount. In this case descriptionBox would be null + */ + if (descriptionBox !== undefined && descriptionBox !== null) { + await descriptionBox.createAttachments() + } } let saveTrigger: any From b249336a5753cfef5000520317e4058be73fff61 Mon Sep 17 00:00:00 2001 From: Maxim Karmatskikh Date: Thu, 9 Nov 2023 15:59:24 +0100 Subject: [PATCH 2/4] UBERF-4229: Fix codestyle Signed-off-by: Maxim Karmatskikh --- .../src/components/AttachmentStyleBoxEditor.svelte | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte b/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte index 4883bae5f9..7f5d10b6ef 100644 --- a/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte +++ b/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte @@ -89,9 +89,7 @@ /* Delayed save can be invoked after dismount. In this case descriptionBox would be null */ - if (descriptionBox !== undefined && descriptionBox !== null) { - await descriptionBox.createAttachments() - } + await descriptionBox?.createAttachments() } let saveTrigger: any From 615d3d98b8655b57f8efd7a9fb995415c8ebdf5f Mon Sep 17 00:00:00 2001 From: Maxim Karmatskikh Date: Thu, 16 Nov 2023 06:55:23 +0100 Subject: [PATCH 3/4] UBERF-4229: Add more save attachment calls Signed-off-by: Maxim Karmatskikh --- .../src/components/AttachmentStyleBoxEditor.svelte | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte b/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte index 7f5d10b6ef..7610c41fdb 100644 --- a/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte +++ b/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte @@ -20,7 +20,7 @@ import { navigate } from '@hcengineering/ui' import view from '@hcengineering/view' import { getObjectLinkFragment } from '@hcengineering/view-resources' - import { createEventDispatcher } from 'svelte' + import { createEventDispatcher, onDestroy } from 'svelte' import AttachmentStyledBox from './AttachmentStyledBox.svelte' export let object: Doc @@ -105,6 +105,17 @@ saveTrigger = setTimeout(() => save(saveObject, saveDescription), 2500) } + onDestroy(async () => { + // If change text and use mention link inside TextArea + // there is a case when createAttachments wouldn't be called + // because descriptionBox could be destroyed while + // we are doing await updateAttribute + // In that case it's better to call it from here, although + // I didn't find a way to loose any data. + // Check if no change is inside + await descriptionBox?.createAttachments() + }) + export function isFocused (): boolean { return descriptionBox.isFocused() } From 419a81a6c43d0de81fcf3ab63dc47ce68336181e Mon Sep 17 00:00:00 2001 From: Maxim Karmatskikh Date: Fri, 17 Nov 2023 17:13:54 +0100 Subject: [PATCH 4/4] UBERF-4229: Save attachment cleaner way Signed-off-by: Maxim Karmatskikh --- .../AttachmentStyleBoxEditor.svelte | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte b/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte index 7610c41fdb..7117cdd6d2 100644 --- a/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte +++ b/plugins/attachment-resources/src/components/AttachmentStyleBoxEditor.svelte @@ -20,7 +20,7 @@ import { navigate } from '@hcengineering/ui' import view from '@hcengineering/view' import { getObjectLinkFragment } from '@hcengineering/view-resources' - import { createEventDispatcher, onDestroy } from 'svelte' + import { createEventDispatcher } from 'svelte' import AttachmentStyledBox from './AttachmentStyledBox.svelte' export let object: Doc @@ -74,6 +74,8 @@ return } + descriptionBox.createAttachments() + const old = getAttribute(client, object, key) if (description !== old) { await updateAttribute(client, object, object._class, key, description) @@ -85,11 +87,6 @@ } else { haveUnsavedChanges = false } - - /* - Delayed save can be invoked after dismount. In this case descriptionBox would be null - */ - await descriptionBox?.createAttachments() } let saveTrigger: any @@ -105,17 +102,6 @@ saveTrigger = setTimeout(() => save(saveObject, saveDescription), 2500) } - onDestroy(async () => { - // If change text and use mention link inside TextArea - // there is a case when createAttachments wouldn't be called - // because descriptionBox could be destroyed while - // we are doing await updateAttribute - // In that case it's better to call it from here, although - // I didn't find a way to loose any data. - // Check if no change is inside - await descriptionBox?.createAttachments() - }) - export function isFocused (): boolean { return descriptionBox.isFocused() }