Update sub-issue rank when attaching to another issue (#2055)

This commit is contained in:
Sergei Ogorelkov 2022-06-10 22:51:31 +07:00 committed by GitHub
parent 059bc3fdf8
commit dd804a079c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 34 deletions

View File

@ -154,7 +154,7 @@
action: async () => action: async () =>
showPopup( showPopup(
SetDueDateActionPopup, SetDueDateActionPopup,
{ value: object, shouldSaveOnChange: false }, { value: object },
'top', 'top',
undefined, undefined,
(newDueDate) => newDueDate !== undefined && (object.dueDate = newDueDate) (newDueDate) => newDueDate !== undefined && (object.dueDate = newDueDate)
@ -167,7 +167,7 @@
action: async () => action: async () =>
showPopup( showPopup(
SetParentIssueActionPopup, SetParentIssueActionPopup,
{ value: { ...object, space, attachedTo: parentIssue?._id }, shouldSaveOnChange: false }, { value: { ...object, space, attachedTo: parentIssue?._id } },
'top', 'top',
(selectedIssue) => selectedIssue !== undefined && (parentIssue = selectedIssue) (selectedIssue) => selectedIssue !== undefined && (parentIssue = selectedIssue)
) )

View File

@ -13,15 +13,15 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import { AttachedData } from '@anticrm/core'
import { DatePopup } from '@anticrm/ui' import { DatePopup } from '@anticrm/ui'
import { getClient } from '@anticrm/presentation' import { getClient } from '@anticrm/presentation'
import { Issue } from '@anticrm/tracker' import { Issue } from '@anticrm/tracker'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
export let value: Issue export let value: Issue | AttachedData<Issue>
export let mondayStart = true export let mondayStart = true
export let withTime = false export let withTime = false
export let shouldSaveOnChange = true
const client = getClient() const client = getClient()
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -29,16 +29,8 @@
async function onUpdate ({ detail }: CustomEvent<Date | null | undefined>) { async function onUpdate ({ detail }: CustomEvent<Date | null | undefined>) {
const newDueDate = detail && detail?.getTime() const newDueDate = detail && detail?.getTime()
if (shouldSaveOnChange && newDueDate !== undefined && newDueDate !== value.dueDate) { if ('_id' in value && newDueDate !== undefined && newDueDate !== value.dueDate) {
await client.updateCollection( await client.update(value, { dueDate: newDueDate })
value._class,
value.space,
value._id,
value.attachedTo,
value.attachedToClass,
value.collection,
{ dueDate: newDueDate }
)
} }
dispatch('update', newDueDate) dispatch('update', newDueDate)

View File

@ -13,8 +13,8 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import { FindOptions, SortingOrder } from '@anticrm/core' import { AttachedData, FindOptions, SortingOrder } from '@anticrm/core'
import { Issue, IssueStatusCategory, Team } from '@anticrm/tracker' import { Issue, IssueStatusCategory, Team, calcRank } from '@anticrm/tracker'
import { createQuery, getClient } from '@anticrm/presentation' import { createQuery, getClient } from '@anticrm/presentation'
import { Icon } from '@anticrm/ui' import { Icon } from '@anticrm/ui'
import ObjectPopup from '@anticrm/presentation/src/components/ObjectPopup.svelte' import ObjectPopup from '@anticrm/presentation/src/components/ObjectPopup.svelte'
@ -22,8 +22,7 @@
import tracker from '../plugin' import tracker from '../plugin'
import { getIssueId } from '../utils' import { getIssueId } from '../utils'
export let value: Issue export let value: Issue | AttachedData<Issue>
export let shouldSaveOnChange = true
const client = getClient() const client = getClient()
const spaceQuery = createQuery() const spaceQuery = createQuery()
@ -43,32 +42,38 @@
} }
async function onClose ({ detail: parentIssue }: CustomEvent<Issue | undefined | null>) { async function onClose ({ detail: parentIssue }: CustomEvent<Issue | undefined | null>) {
if (shouldSaveOnChange && parentIssue !== undefined && parentIssue?._id !== value.attachedTo) { if ('_id' in value && parentIssue !== undefined && parentIssue?._id !== value.attachedTo) {
await client.updateCollection( let rank: string | null = null
value._class,
value.space, if (parentIssue) {
value._id, const lastAttachedIssue = await client.findOne<Issue>(
value.attachedTo, tracker.class.Issue,
value.attachedToClass, { attachedTo: parentIssue._id },
'subIssues', { sort: { rank: SortingOrder.Descending } }
{ attachedTo: parentIssue === null ? tracker.ids.NoParent : parentIssue._id }
) )
rank = calcRank(lastAttachedIssue, undefined)
}
await client.update(value, {
attachedTo: parentIssue === null ? tracker.ids.NoParent : parentIssue._id,
...(rank ? { rank } : {})
})
} }
dispatch('close', parentIssue) dispatch('close', parentIssue)
} }
$: ignoreObjects = value._id ? [value._id] : [] $: selected = 'attachedTo' in value ? value.attachedTo : undefined
$: ignoreObjects = '_id' in value ? [value._id] : []
$: updateIssueStatusCategories() $: updateIssueStatusCategories()
$: if (value.space) { $: 'space' in value && spaceQuery.query(tracker.class.Team, { _id: value.space }, (res) => ([team] = res))
spaceQuery.query(tracker.class.Team, { _id: value.space }, (res) => ([team] = res))
}
</script> </script>
<ObjectPopup <ObjectPopup
_class={tracker.class.Issue} _class={tracker.class.Issue}
{options} {options}
selected={value.attachedTo} {selected}
multiSelect={false} multiSelect={false}
allowDeselect={true} allowDeselect={true}
placeholder={tracker.string.SetParent} placeholder={tracker.string.SetParent}

View File

@ -69,7 +69,11 @@
} }
const space = currentTeam._id const space = currentTeam._id
const lastOne = await client.findOne<Issue>(tracker.class.Issue, {}, { sort: { rank: SortingOrder.Descending } }) const lastOne = await client.findOne<Issue>(
tracker.class.Issue,
{ space },
{ sort: { rank: SortingOrder.Descending } }
)
const incResult = await client.updateDoc( const incResult = await client.updateDoc(
tracker.class.Team, tracker.class.Team,
core.space.Space, core.space.Space,