Skip to content

Commit db9d502

Browse files
committed
fix: prevent 'New category' crash when QualityDocuments space is missing #10772
Signed-off-by: Learnobug <gunjanaggarwal12345@gmail.com>
1 parent 3d469f0 commit db9d502

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

plugins/controlled-documents-resources/src/components/Categories.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
const _class: Ref<Class<DocumentCategory>> = document.class.DocumentCategory
4040
4141
function showCreateDialog (): void {
42-
showPopup(CreateDocumentCategory, {}, 'top')
42+
showPopup(CreateDocumentCategory, { space }, 'top')
4343
}
4444
</script>
4545

plugins/controlled-documents-resources/src/components/CreateDocumentCategory.svelte

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
//
1616
-->
1717
<script lang="ts">
18-
import { createEventDispatcher } from 'svelte'
18+
import { createEventDispatcher, onMount } from 'svelte'
1919
import { Attachment } from '@hcengineering/attachment'
2020
import { AttachmentPresenter, AttachmentStyledBox } from '@hcengineering/attachment-resources'
2121
import { generateId, Ref, Space } from '@hcengineering/core'
2222
import { Card, getClient } from '@hcengineering/presentation'
2323
import { Button, EditBox, IconAttachment, tooltip } from '@hcengineering/ui'
24-
import { DocumentCategory } from '@hcengineering/controlled-documents'
24+
import { DocumentCategory, DocumentSpace } from '@hcengineering/controlled-documents'
2525
2626
import IconWarning from './icons/IconWarning.svelte'
2727
import documents from '../plugin'
@@ -37,9 +37,18 @@
3737
const dispatch = createEventDispatcher()
3838
const client = getClient()
3939
let descriptionBox: AttachmentStyledBox
40+
let spaceExists = true
41+
42+
onMount(async () => {
43+
const spaceDoc = await client.findOne(documents.class.DocumentSpace, { _id: space as Ref<DocumentSpace> })
44+
spaceExists = spaceDoc !== undefined
45+
if (!spaceExists) {
46+
console.error(`Document space ${space} not found. Category cannot be created.`)
47+
}
48+
})
4049
4150
async function handleOkAction (): Promise<void> {
42-
if (isCodeWrong || isTitleWrong) {
51+
if (isCodeWrong || isTitleWrong || !spaceExists) {
4352
return
4453
}
4554
const op = client.apply()
@@ -61,7 +70,7 @@
6170
6271
let existingCategories: string[] = []
6372
let existingCodes: string[] = []
64-
$: void client.findAll(documents.class.DocumentCategory, {}).then((cats) => {
73+
$: void client.findAll(documents.class.DocumentCategory, { space }).then((cats) => {
6574
existingCategories = cats.map((cat) => cat.title)
6675
existingCodes = cats.map((cat) => cat.code)
6776
})
@@ -82,7 +91,7 @@
8291
<Card
8392
label={documents.string.CreateDocumentCategory}
8493
okAction={handleOkAction}
85-
canSave={!isCodeWrong && !isTitleWrong}
94+
canSave={!isCodeWrong && !isTitleWrong && spaceExists}
8695
hideAttachments={attachments.size === 0}
8796
on:close={() => {
8897
dispatch('close')

0 commit comments

Comments
 (0)