|
15 | 15 | // |
16 | 16 | --> |
17 | 17 | <script lang="ts"> |
18 | | - import { createEventDispatcher } from 'svelte' |
| 18 | + import { createEventDispatcher, onMount } from 'svelte' |
19 | 19 | import { Attachment } from '@hcengineering/attachment' |
20 | 20 | import { AttachmentPresenter, AttachmentStyledBox } from '@hcengineering/attachment-resources' |
21 | 21 | import { generateId, Ref, Space } from '@hcengineering/core' |
22 | 22 | import { Card, getClient } from '@hcengineering/presentation' |
23 | 23 | import { Button, EditBox, IconAttachment, tooltip } from '@hcengineering/ui' |
24 | | - import { DocumentCategory } from '@hcengineering/controlled-documents' |
| 24 | + import { DocumentCategory, DocumentSpace } from '@hcengineering/controlled-documents' |
25 | 25 |
|
26 | 26 | import IconWarning from './icons/IconWarning.svelte' |
27 | 27 | import documents from '../plugin' |
|
37 | 37 | const dispatch = createEventDispatcher() |
38 | 38 | const client = getClient() |
39 | 39 | 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 | + }) |
40 | 49 |
|
41 | 50 | async function handleOkAction (): Promise<void> { |
42 | | - if (isCodeWrong || isTitleWrong) { |
| 51 | + if (isCodeWrong || isTitleWrong || !spaceExists) { |
43 | 52 | return |
44 | 53 | } |
45 | 54 | const op = client.apply() |
|
61 | 70 |
|
62 | 71 | let existingCategories: string[] = [] |
63 | 72 | let existingCodes: string[] = [] |
64 | | - $: void client.findAll(documents.class.DocumentCategory, {}).then((cats) => { |
| 73 | + $: void client.findAll(documents.class.DocumentCategory, { space }).then((cats) => { |
65 | 74 | existingCategories = cats.map((cat) => cat.title) |
66 | 75 | existingCodes = cats.map((cat) => cat.code) |
67 | 76 | }) |
|
82 | 91 | <Card |
83 | 92 | label={documents.string.CreateDocumentCategory} |
84 | 93 | okAction={handleOkAction} |
85 | | - canSave={!isCodeWrong && !isTitleWrong} |
| 94 | + canSave={!isCodeWrong && !isTitleWrong && spaceExists} |
86 | 95 | hideAttachments={attachments.size === 0} |
87 | 96 | on:close={() => { |
88 | 97 | dispatch('close') |
|
0 commit comments