Empty title subissue, backreferences fix (#2280)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2022-10-04 21:48:14 +06:00 committed by GitHub
parent 6e4474494d
commit 9290942a56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 84 deletions

View File

@ -24,7 +24,7 @@ import chunter, {
Backlink Backlink
} from '@hcengineering/chunter' } from '@hcengineering/chunter'
import { NotificationClientImpl } from '@hcengineering/notification-resources' import { NotificationClientImpl } from '@hcengineering/notification-resources'
import { Resources } from '@hcengineering/platform' import { IntlString, Resources, translate } from '@hcengineering/platform'
import preference from '@hcengineering/preference' import preference from '@hcengineering/preference'
import { getClient, MessageBox } from '@hcengineering/presentation' import { getClient, MessageBox } from '@hcengineering/presentation'
import { getCurrentLocation, navigate, showPopup } from '@hcengineering/ui' import { getCurrentLocation, navigate, showPopup } from '@hcengineering/ui'
@ -190,13 +190,14 @@ export function chunterBrowserVisible (spaces: Space[]): boolean {
return false return false
} }
async function update (source: Doc, key: string, target: RelatedDocument[], msg: string): Promise<void> { async function update (source: Doc, key: string, target: RelatedDocument[], msg: IntlString): Promise<void> {
const message = await translate(msg, {})
const backlinks: Array<Data<Backlink>> = target.map((it) => ({ const backlinks: Array<Data<Backlink>> = target.map((it) => ({
backlinkId: source._id, backlinkId: source._id,
backlinkClass: source._class, backlinkClass: source._class,
attachedTo: it._id, attachedTo: it._id,
attachedToClass: it._class, attachedToClass: it._class,
message: msg, message,
collection: key collection: key
})) }))

View File

@ -161,6 +161,6 @@ export default plugin(chunterId, {
}, },
backreference: { backreference: {
// Update list of back references // Update list of back references
Update: '' as Resource<(source: Doc, key: string, target: RelatedDocument[], label: IntlString) => void> Update: '' as Resource<(source: Doc, key: string, target: RelatedDocument[], label: IntlString) => Promise<void>>
} }
}) })

View File

@ -17,7 +17,7 @@
import chunter from '@hcengineering/chunter' import chunter from '@hcengineering/chunter'
import { Employee } from '@hcengineering/contact' import { Employee } from '@hcengineering/contact'
import core, { Account, AttachedData, Doc, generateId, Ref, SortingOrder, WithLookup } from '@hcengineering/core' import core, { Account, AttachedData, Doc, generateId, Ref, SortingOrder, WithLookup } from '@hcengineering/core'
import { getResource, translate } from '@hcengineering/platform' import { getResource } from '@hcengineering/platform'
import { Card, createQuery, getClient, KeyedAttribute, SpaceSelector } from '@hcengineering/presentation' import { Card, createQuery, getClient, KeyedAttribute, SpaceSelector } from '@hcengineering/presentation'
import tags, { TagElement, TagReference } from '@hcengineering/tags' import tags, { TagElement, TagReference } from '@hcengineering/tags'
import { calcRank, Issue, IssuePriority, IssueStatus, Project, Sprint, Team } from '@hcengineering/tracker' import { calcRank, Issue, IssuePriority, IssueStatus, Project, Sprint, Team } from '@hcengineering/tracker'
@ -190,7 +190,9 @@
const update = await getResource(chunter.backreference.Update) const update = await getResource(chunter.backreference.Update)
if (relatedTo !== undefined) { if (relatedTo !== undefined) {
const doc = await client.findOne(tracker.class.Issue, { _id: objectId }) const doc = await client.findOne(tracker.class.Issue, { _id: objectId })
await update(doc, 'relations', [relatedTo], await translate(tracker.string.AddedReference, {})) if (doc !== undefined) {
await update(doc, 'relations', [relatedTo], tracker.string.AddedReference)
}
} }
objectId = generateId() objectId = generateId()

View File

@ -1,13 +1,13 @@
<script lang="ts"> <script lang="ts">
import { createEventDispatcher, afterUpdate } from 'svelte' import chunter from '@hcengineering/chunter'
import { Class, Doc, Ref, RelatedDocument } from '@hcengineering/core' import { Class, Doc, Ref, RelatedDocument } from '@hcengineering/core'
import { getResource, IntlString, translate } from '@hcengineering/platform' import { getResource, IntlString } from '@hcengineering/platform'
import { createQuery, getClient, ObjectSearchPopup, ObjectSearchResult } from '@hcengineering/presentation' import { createQuery, getClient, ObjectSearchPopup, ObjectSearchResult } from '@hcengineering/presentation'
import { Issue } from '@hcengineering/tracker' import { Issue } from '@hcengineering/tracker'
import { Action, closePopup, Menu, showPopup } from '@hcengineering/ui' import { Action, closePopup, Menu, showPopup } from '@hcengineering/ui'
import { afterUpdate, createEventDispatcher } from 'svelte'
import { updateIssueRelation } from '../issues' import { updateIssueRelation } from '../issues'
import tracker from '../plugin' import tracker from '../plugin'
import chunter from '@hcengineering/chunter'
export let value: Issue export let value: Issue
@ -65,7 +65,7 @@
if (operation === '$pull' && pos !== -1) { if (operation === '$pull' && pos !== -1) {
docs.splice(pos, 1) docs.splice(pos, 1)
} }
await update(value, type, docs, await translate(label, {})) await update(value, type, docs, label)
} }
const makeAddAction = (type: keyof typeof relations, placeholder: IntlString) => async (props: any, evt: Event) => { const makeAddAction = (type: keyof typeof relations, placeholder: IntlString) => async (props: any, evt: Event) => {

View File

@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import chunter from '@hcengineering/chunter' import chunter from '@hcengineering/chunter'
import { Class, Doc, Ref, RelatedDocument, WithLookup } from '@hcengineering/core' import { Class, Doc, Ref, RelatedDocument, WithLookup } from '@hcengineering/core'
import { getResource, IntlString, translate } from '@hcengineering/platform' import { getResource, IntlString } from '@hcengineering/platform'
import { createQuery, getClient } from '@hcengineering/presentation' import { createQuery, getClient } from '@hcengineering/presentation'
import { Issue } from '@hcengineering/tracker' import { Issue } from '@hcengineering/tracker'
import { Component, Icon, IconClose } from '@hcengineering/ui' import { Component, Icon, IconClose } from '@hcengineering/ui'
@ -68,7 +68,7 @@
if (pos !== -1) { if (pos !== -1) {
docs.splice(pos, 1) docs.splice(pos, 1)
} }
await update(value, type, docs, await translate(label, {})) await update(value, type, docs, label)
} }
const asIssue = (x: Doc) => x as WithLookup<Issue> const asIssue = (x: Doc) => x as WithLookup<Issue>
</script> </script>

View File

@ -82,46 +82,50 @@
if (!canSave) { if (!canSave) {
return return
} }
loading = true
try {
const space = currentTeam._id
const lastOne = await client.findOne<Issue>(
tracker.class.Issue,
{ space },
{ sort: { rank: SortingOrder.Descending } }
)
const incResult = await client.updateDoc(
tracker.class.Team,
core.space.Space,
space,
{ $inc: { sequence: 1 } },
true
)
const space = currentTeam._id const value: AttachedData<Issue> = {
const lastOne = await client.findOne<Issue>( ...newIssue,
tracker.class.Issue, title: getTitle(newIssue.title),
{ space }, number: (incResult as any).object.sequence,
{ sort: { rank: SortingOrder.Descending } } rank: calcRank(lastOne, undefined),
) project: parentIssue.project,
const incResult = await client.updateDoc( parents: [{ parentId: parentIssue._id, parentTitle: parentIssue.title }, ...parentIssue.parents]
tracker.class.Team, }
core.space.Space,
space,
{ $inc: { sequence: 1 } },
true
)
const value: AttachedData<Issue> = { const objectId = await client.addCollection(
...newIssue, tracker.class.Issue,
title: getTitle(newIssue.title), space,
number: (incResult as any).object.sequence, parentIssue._id,
rank: calcRank(lastOne, undefined), parentIssue._class,
project: parentIssue.project, 'subIssues',
parents: [{ parentId: parentIssue._id, parentTitle: parentIssue.title }, ...parentIssue.parents] value
)
for (const label of labels) {
await client.addCollection(label._class, label.space, objectId, tracker.class.Issue, 'labels', {
title: label.title,
color: label.color,
tag: label.tag
})
}
} finally {
resetToDefaults()
loading = false
} }
const objectId = await client.addCollection(
tracker.class.Issue,
space,
parentIssue._id,
parentIssue._class,
'subIssues',
value
)
for (const label of labels) {
await client.addCollection(label._class, label.space, objectId, tracker.class.Issue, 'labels', {
title: label.title,
color: label.color,
tag: label.tag
})
}
resetToDefaults()
} }
function addTagRef (tag: TagElement): void { function addTagRef (tag: TagElement): void {
@ -143,6 +147,8 @@
] ]
} }
let loading = false
$: thisRef && thisRef.scrollIntoView({ behavior: 'smooth' }) $: thisRef && thisRef.scrollIntoView({ behavior: 'smooth' })
$: canSave = getTitle(newIssue.title ?? '').length > 0 $: canSave = getTitle(newIssue.title ?? '').length > 0
$: if (!newIssue.status && currentTeam?.defaultIssueStatus) { $: if (!newIssue.status && currentTeam?.defaultIssueStatus) {
@ -222,6 +228,7 @@
<div class="buttons-group small-gap"> <div class="buttons-group small-gap">
<Button label={presentation.string.Cancel} size="small" kind="transparent" on:click={close} /> <Button label={presentation.string.Cancel} size="small" kind="transparent" on:click={close} />
<Button <Button
{loading}
disabled={!canSave} disabled={!canSave}
label={presentation.string.Save} label={presentation.string.Save}
size="small" size="small"

View File

@ -89,44 +89,49 @@
if (!canSave) { if (!canSave) {
return return
} }
loading = true
const lastOne = await client.findOne<Issue>( try {
tracker.class.Issue, const lastOne = await client.findOne<Issue>(
{ space: currentTeam }, tracker.class.Issue,
{ sort: { rank: SortingOrder.Descending } } { space: currentTeam },
) { sort: { rank: SortingOrder.Descending } }
const incResult = await client.updateDoc( )
tracker.class.Team, const incResult = await client.updateDoc(
core.space.Space, tracker.class.Team,
currentTeam, core.space.Space,
{ $inc: { sequence: 1 } }, currentTeam,
true { $inc: { sequence: 1 } },
) true
)
const value: AttachedData<Issue> = { const value: AttachedData<Issue> = {
...newIssue, ...newIssue,
title: getTitle(newIssue.title), title: getTitle(newIssue.title),
number: (incResult as any).object.sequence, number: (incResult as any).object.sequence,
rank: calcRank(lastOne, undefined), rank: calcRank(lastOne, undefined),
parents: [{ parentId: tracker.ids.NoParent, parentTitle: '' }] parents: [{ parentId: tracker.ids.NoParent, parentTitle: '' }]
}
const objectId = await client.addCollection(
tracker.class.Issue,
currentTeam,
tracker.ids.NoParent,
tracker.class.Issue,
'subIssues',
value
)
for (const label of labels) {
await client.addCollection(label._class, label.space, objectId, tracker.class.Issue, 'labels', {
title: label.title,
color: label.color,
tag: label.tag
})
}
} finally {
resetToDefaults()
loading = false
} }
const objectId = await client.addCollection(
tracker.class.Issue,
currentTeam,
tracker.ids.NoParent,
tracker.class.Issue,
'subIssues',
value
)
for (const label of labels) {
await client.addCollection(label._class, label.space, objectId, tracker.class.Issue, 'labels', {
title: label.title,
color: label.color,
tag: label.tag
})
}
resetToDefaults()
} }
function addTagRef (tag: TagElement): void { function addTagRef (tag: TagElement): void {
@ -148,6 +153,7 @@
] ]
} }
let loading = false
$: thisRef && thisRef.scrollIntoView({ behavior: 'smooth' }) $: thisRef && thisRef.scrollIntoView({ behavior: 'smooth' })
$: canSave = getTitle(newIssue.title ?? '').length > 0 $: canSave = getTitle(newIssue.title ?? '').length > 0
$: if (!newIssue.status) { $: if (!newIssue.status) {
@ -230,6 +236,7 @@
<div class="buttons-group small-gap"> <div class="buttons-group small-gap">
<Button label={presentation.string.Cancel} size="small" kind="transparent" on:click={close} /> <Button label={presentation.string.Cancel} size="small" kind="transparent" on:click={close} />
<Button <Button
{loading}
disabled={!canSave} disabled={!canSave}
label={presentation.string.Save} label={presentation.string.Save}
size="small" size="small"