Fix create draft issue duplicate id (#2935)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-04-11 16:07:44 +06:00 committed by GitHub
parent 9c79f20aa4
commit 2b72b64df5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 45 deletions

View File

@ -144,7 +144,7 @@
}
}
async function saveAttachment (doc: Attachment): Promise<void> {
async function saveAttachment (doc: Attachment, objectId: Ref<Doc> | undefined): Promise<void> {
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<void> {
export async function createAttachments (_id: Ref<Doc> | undefined = objectId): Promise<void> {
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) => {

View File

@ -157,6 +157,7 @@
})
async function createCandidate () {
const _id: Ref<Person> = generateId()
const candidate: Data<Person> = {
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,

View File

@ -304,6 +304,7 @@
}
async function createIssue () {
const _id: Ref<Issue> = 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 @@
<SubIssues
bind:this={subIssuesComponent}
projectId={_space}
parent={object._id}
project={currentProject}
sprint={object.sprint}
component={object.component}

View File

@ -15,11 +15,11 @@
<script lang="ts">
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<Issue>
export let projectId: Ref<Project>
export let project: Project | undefined
export let sprint: Ref<Sprint> | null = null
@ -63,7 +62,7 @@
const client = getClient()
export async function save (parents: IssueParentInfo[]) {
export async function save (parents: IssueParentInfo[], _id: Ref<Doc>) {
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,

View File

@ -100,6 +100,7 @@
if (!canSave) {
return
}
const _id: Ref<Issue> = 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()

View File

@ -177,6 +177,7 @@
{/if}
<EditBox bind:value={title} placeholder={tracker.string.IssueTitlePlaceholder} kind="large-style" on:blur={save} />
<div class="w-full mt-6">
{#key _id}
<AttachmentStyledBox
bind:this={descriptionBox}
useAttachmentPreview={true}
@ -194,6 +195,7 @@
bind:content={description}
placeholder={tracker.string.IssueDescriptionPlaceholder}
/>
{/key}
</div>
<div class="mt-6">

View File

@ -698,6 +698,7 @@ class TServerStorage implements ServerStorage {
}
} catch (err: any) {
console.log(err)
throw err
} finally {
onEnd()
}