From 2b72b64df5fcd14912a79cb3501c4d5c547cbcad Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Tue, 11 Apr 2023 16:07:44 +0600 Subject: [PATCH] Fix create draft issue duplicate id (#2935) Signed-off-by: Denis Bykhov --- .../src/components/AttachmentStyledBox.svelte | 6 ++-- .../src/components/CreateCandidate.svelte | 13 +++---- .../src/components/CreateIssue.svelte | 18 +++++----- .../src/components/SubIssues.svelte | 11 +++--- .../issues/edit/CreateSubIssue.svelte | 9 ++--- .../components/issues/edit/EditIssue.svelte | 36 ++++++++++--------- server/core/src/storage.ts | 1 + 7 files changed, 49 insertions(+), 45 deletions(-) diff --git a/plugins/attachment-resources/src/components/AttachmentStyledBox.svelte b/plugins/attachment-resources/src/components/AttachmentStyledBox.svelte index c2844968e0..a381f0599b 100644 --- a/plugins/attachment-resources/src/components/AttachmentStyledBox.svelte +++ b/plugins/attachment-resources/src/components/AttachmentStyledBox.svelte @@ -144,7 +144,7 @@ } } - async function saveAttachment (doc: Attachment): Promise { + async function saveAttachment (doc: Attachment, objectId: Ref | undefined): Promise { if (space === undefined || objectId === undefined || _class === undefined) return await client.addCollection(attachment.class.Attachment, space, objectId, _class, 'attachments', doc, doc._id) } @@ -218,7 +218,7 @@ } } - export async function createAttachments (): Promise { + export async function createAttachments (_id: Ref | undefined = objectId): Promise { if (saved) { return } @@ -227,7 +227,7 @@ newAttachments.forEach((p) => { const attachment = attachments.get(p) if (attachment !== undefined) { - promises.push(saveAttachment(attachment)) + promises.push(saveAttachment(attachment, _id)) } }) removedAttachments.forEach((p) => { diff --git a/plugins/recruit-resources/src/components/CreateCandidate.svelte b/plugins/recruit-resources/src/components/CreateCandidate.svelte index f740d875b9..63af0912f0 100644 --- a/plugins/recruit-resources/src/components/CreateCandidate.svelte +++ b/plugins/recruit-resources/src/components/CreateCandidate.svelte @@ -157,6 +157,7 @@ }) async function createCandidate () { + const _id: Ref = generateId() const candidate: Data = { name: combineName(object.firstName ?? '', object.lastName ?? ''), city: object.city, @@ -190,11 +191,11 @@ } } - const applyOps = client.apply(object._id) + const applyOps = client.apply(_id) - await applyOps.createDoc(contact.class.Person, contact.space.Contacts, candidate, object._id) + await applyOps.createDoc(contact.class.Person, contact.space.Contacts, candidate, _id) await applyOps.createMixin( - object._id, + _id, contact.class.Person, contact.space.Contacts, recruit.mixin.Candidate, @@ -206,7 +207,7 @@ applyOps.addCollection( attachment.class.Attachment, contact.space.Contacts, - object._id, + _id, contact.class.Person, 'attachments', { @@ -222,7 +223,7 @@ await applyOps.addCollection( contact.class.Channel, contact.space.Contacts, - object._id, + _id, contact.class.Person, 'channels', { @@ -248,7 +249,7 @@ category: findTagCategory(skill.title, categories) }) } - await applyOps.addCollection(skill._class, skill.space, object._id, recruit.mixin.Candidate, 'skills', { + await applyOps.addCollection(skill._class, skill.space, _id, recruit.mixin.Candidate, 'skills', { title: skill.title, color: skill.color, tag: skill.tag, diff --git a/plugins/tracker-resources/src/components/CreateIssue.svelte b/plugins/tracker-resources/src/components/CreateIssue.svelte index 65f77b4a16..f9d099d22e 100644 --- a/plugins/tracker-resources/src/components/CreateIssue.svelte +++ b/plugins/tracker-resources/src/components/CreateIssue.svelte @@ -304,6 +304,7 @@ } async function createIssue () { + const _id: Ref = generateId() if (!canSave || object.status === undefined) { return } @@ -350,19 +351,19 @@ parentIssue?._class ?? tracker.class.Issue, 'subIssues', value, - object._id + _id ) for (const label of object.labels) { - await client.addCollection(label._class, label.space, object._id, tracker.class.Issue, 'labels', { + await client.addCollection(label._class, label.space, _id, tracker.class.Issue, 'labels', { title: label.title, color: label.color, tag: label.tag }) } - await descriptionBox.createAttachments() + await descriptionBox.createAttachments(_id) if (relatedTo !== undefined) { - const doc = await client.findOne(tracker.class.Issue, { _id: object._id }) + const doc = await client.findOne(tracker.class.Issue, { _id }) if (doc !== undefined) { if (client.getHierarchy().isDerived(relatedTo._class, tracker.class.Issue)) { await updateIssueRelation(client, relatedTo as Issue, doc, 'relations', '$push') @@ -374,14 +375,14 @@ } const parents = parentIssue ? [ - { parentId: object._id, parentTitle: value.title }, + { parentId: _id, parentTitle: value.title }, { parentId: parentIssue._id, parentTitle: parentIssue.title }, ...parentIssue.parents ] - : [{ parentId: object._id, parentTitle: value.title }] - await subIssuesComponent.save(parents) + : [{ parentId: _id, parentTitle: value.title }] + await subIssuesComponent.save(parents, _id) addNotification(await translate(tracker.string.IssueCreated, {}), getTitle(object.title), IssueNotification, { - issueId: object._id, + issueId: _id, subTitlePostfix: (await translate(tracker.string.Created, { value: 1 })).toLowerCase(), issueUrl: currentProject && generateIssueShortLink(getIssueId(currentProject, value as Issue)) }) @@ -598,7 +599,6 @@ import attachment, { Attachment } from '@hcengineering/attachment' import { deleteFile } from '@hcengineering/attachment-resources/src/utils' - import core, { AttachedData, Ref, SortingOrder } from '@hcengineering/core' + import core, { AttachedData, Doc, Ref, SortingOrder } from '@hcengineering/core' import { DraftController, draftsStore, getClient } from '@hcengineering/presentation' import tags from '@hcengineering/tags' - import { calcRank, Component, Issue, IssueDraft, IssueParentInfo, Project, Sprint } from '@hcengineering/tracker' - import { Button, closeTooltip, ExpandCollapse, IconAdd, Scroller } from '@hcengineering/ui' + import { Component, Issue, IssueDraft, IssueParentInfo, Project, Sprint, calcRank } from '@hcengineering/tracker' + import { Button, ExpandCollapse, IconAdd, Scroller, closeTooltip } from '@hcengineering/ui' import { onDestroy } from 'svelte' import tracker from '../plugin' import Collapsed from './icons/Collapsed.svelte' @@ -27,7 +27,6 @@ import DraftIssueChildEditor from './templates/DraftIssueChildEditor.svelte' import DraftIssueChildList from './templates/DraftIssueChildList.svelte' - export let parent: Ref export let projectId: Ref export let project: Project | undefined export let sprint: Ref | null = null @@ -63,7 +62,7 @@ const client = getClient() - export async function save (parents: IssueParentInfo[]) { + export async function save (parents: IssueParentInfo[], _id: Ref) { if (project === undefined) return saved = true @@ -104,7 +103,7 @@ await client.addCollection( tracker.class.Issue, project._id, - parent, + _id, tracker.class.Issue, 'subIssues', cvalue, diff --git a/plugins/tracker-resources/src/components/issues/edit/CreateSubIssue.svelte b/plugins/tracker-resources/src/components/issues/edit/CreateSubIssue.svelte index 1d6cbc3720..3bbe0c1324 100644 --- a/plugins/tracker-resources/src/components/issues/edit/CreateSubIssue.svelte +++ b/plugins/tracker-resources/src/components/issues/edit/CreateSubIssue.svelte @@ -100,6 +100,7 @@ if (!canSave) { return } + const _id: Ref = generateId() loading = true try { const space = currentProject._id @@ -135,13 +136,13 @@ parentIssue._class, 'subIssues', value, - object._id + _id ) - await descriptionBox.createAttachments() + await descriptionBox.createAttachments(_id) for (const label of object.labels) { - await client.addCollection(label._class, label.space, object._id, tracker.class.Issue, 'labels', { + await client.addCollection(label._class, label.space, _id, tracker.class.Issue, 'labels', { title: label.title, color: label.color, tag: label.tag @@ -149,7 +150,7 @@ } addNotification(await translate(tracker.string.IssueCreated, {}), getTitle(object.title), IssueNotification, { - issueId: object._id, + issueId: _id, subTitlePostfix: (await translate(tracker.string.Created, { value: 1 })).toLowerCase() }) draftController.remove() diff --git a/plugins/tracker-resources/src/components/issues/edit/EditIssue.svelte b/plugins/tracker-resources/src/components/issues/edit/EditIssue.svelte index 9a0bc30028..00dffe54ce 100644 --- a/plugins/tracker-resources/src/components/issues/edit/EditIssue.svelte +++ b/plugins/tracker-resources/src/components/issues/edit/EditIssue.svelte @@ -177,23 +177,25 @@ {/if}
- + {#key _id} + + {/key}
diff --git a/server/core/src/storage.ts b/server/core/src/storage.ts index 3f58bdfa6d..875d77bb6d 100644 --- a/server/core/src/storage.ts +++ b/server/core/src/storage.ts @@ -698,6 +698,7 @@ class TServerStorage implements ServerStorage { } } catch (err: any) { console.log(err) + throw err } finally { onEnd() }