fix: report invalid content errors to analytics (#6699)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2024-09-24 13:49:30 +07:00 committed by GitHub
parent ba5a7525d3
commit daf4247b07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 2 deletions

View File

@ -42,6 +42,7 @@
"@hcengineering/platform": "^0.6.11", "@hcengineering/platform": "^0.6.11",
"svelte": "^4.2.12", "svelte": "^4.2.12",
"@hcengineering/ui": "^0.6.15", "@hcengineering/ui": "^0.6.15",
"@hcengineering/analytics": "^0.6.0",
"@hcengineering/presentation": "^0.6.3", "@hcengineering/presentation": "^0.6.3",
"@hcengineering/core": "^0.6.32", "@hcengineering/core": "^0.6.32",
"@hcengineering/view": "^0.6.13", "@hcengineering/view": "^0.6.13",

View File

@ -15,6 +15,7 @@
// //
--> -->
<script lang="ts"> <script lang="ts">
import { Analytics } from '@hcengineering/analytics'
import { type Space, type Class, type CollaborativeDoc, type Doc, type Ref } from '@hcengineering/core' import { type Space, type Class, type CollaborativeDoc, type Doc, type Ref } from '@hcengineering/core'
import { IntlString, translate } from '@hcengineering/platform' import { IntlString, translate } from '@hcengineering/platform'
import { getFileUrl, getImageSize, imageSizeToRatio } from '@hcengineering/presentation' import { getFileUrl, getImageSize, imageSizeToRatio } from '@hcengineering/presentation'
@ -116,11 +117,12 @@
objectAttr objectAttr
}) })
let contentError = false
let localSynced = false let localSynced = false
let remoteSynced = false let remoteSynced = false
$: loading = !localSynced && !remoteSynced $: loading = !localSynced && !remoteSynced
$: editable = !readonly && remoteSynced $: editable = !readonly && !contentError && remoteSynced
void localProvider.loaded.then(() => (localSynced = true)) void localProvider.loaded.then(() => (localSynced = true))
void remoteProvider.loaded.then(() => (remoteSynced = true)) void remoteProvider.loaded.then(() => (remoteSynced = true))
@ -218,7 +220,10 @@
} }
$: if (editor !== undefined) { $: if (editor !== undefined) {
editor.setEditable(editable, true) // When the content is invalid, we don't want to emit an update
// Preventing synchronization of the invalid content
const emitUpdate = !contentError
editor.setEditable(editable, emitUpdate)
} }
// TODO: should be inside the editor // TODO: should be inside the editor
@ -364,6 +369,7 @@
await ph await ph
editor = new Editor({ editor = new Editor({
enableContentCheck: true,
element, element,
editorProps: { attributes: mergeAttributes(defaultEditorAttributes, editorAttributes, { class: 'flex-grow' }) }, editorProps: { attributes: mergeAttributes(defaultEditorAttributes, editorAttributes, { class: 'flex-grow' }) },
extensions: [ extensions: [
@ -432,6 +438,11 @@
throttle.call(updateLastUpdateTime) throttle.call(updateLastUpdateTime)
dispatch('update') dispatch('update')
},
onContentError: ({ error, disableCollaboration }) => {
disableCollaboration()
contentError = true
Analytics.handleError(error)
} }
}) })
}) })

View File

@ -14,6 +14,7 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import { Analytics } from '@hcengineering/analytics'
import { Markup } from '@hcengineering/core' import { Markup } from '@hcengineering/core'
import { IntlString, translate } from '@hcengineering/platform' import { IntlString, translate } from '@hcengineering/platform'
import { EmptyMarkup, getMarkup, markupToJSON } from '@hcengineering/text' import { EmptyMarkup, getMarkup, markupToJSON } from '@hcengineering/text'
@ -150,6 +151,7 @@
onMount(() => { onMount(() => {
void ph.then(async () => { void ph.then(async () => {
editor = new Editor({ editor = new Editor({
enableContentCheck: true,
element, element,
editorProps: { editorProps: {
attributes: mergeAttributes(defaultEditorAttributes, editorAttributes), attributes: mergeAttributes(defaultEditorAttributes, editorAttributes),
@ -197,6 +199,9 @@
content = getContent() content = getContent()
dispatch('value', content) dispatch('value', content)
dispatch('update', content) dispatch('update', content)
},
onContentError: ({ error }) => {
Analytics.handleError(error)
} }
}) })
}) })