mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 11:50:56 +00:00
Board: Handle labels when move card to another board (#1538)
Signed-off-by: Sergey Semenov <lvfx@ya.ru>
This commit is contained in:
parent
6d6f1fb48a
commit
ff3b12f282
@ -12,6 +12,7 @@
|
||||
import type { TxOperations } from '@anticrm/core'
|
||||
import { generateId, AttachedData } from '@anticrm/core'
|
||||
import task from '@anticrm/task'
|
||||
import { createMissingLabels } from '../../utils/BoardUtils';
|
||||
|
||||
export let object: Card
|
||||
export let client: TxOperations
|
||||
@ -38,6 +39,10 @@
|
||||
|
||||
const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true)
|
||||
|
||||
const labels = object.space !== selected.space
|
||||
? await createMissingLabels(client, object, selected.space)
|
||||
: object.labels
|
||||
|
||||
const value: AttachedData<Card> = {
|
||||
state: selected.state,
|
||||
doneState: null,
|
||||
@ -47,7 +52,8 @@
|
||||
assignee: null,
|
||||
description: '',
|
||||
members: [],
|
||||
location: ''
|
||||
location: '',
|
||||
labels
|
||||
}
|
||||
|
||||
await client.addCollection(
|
||||
|
@ -10,6 +10,7 @@
|
||||
import SpaceSelect from '../selectors/SpaceSelect.svelte'
|
||||
import StateSelect from '../selectors/StateSelect.svelte'
|
||||
import RankSelect from '../selectors/RankSelect.svelte'
|
||||
import { createMissingLabels } from '../../utils/BoardUtils'
|
||||
|
||||
export let object: Card
|
||||
|
||||
@ -23,9 +24,14 @@
|
||||
rank: object.rank
|
||||
}
|
||||
|
||||
function move () {
|
||||
async function move(): Promise<void> {
|
||||
const update: DocumentUpdate<Card> = {}
|
||||
if (selected.space !== object.space) update.space = selected.space
|
||||
|
||||
if (selected.space !== object.space) {
|
||||
update.labels = await createMissingLabels(client, object, selected.space)
|
||||
update.space = selected.space
|
||||
}
|
||||
|
||||
if (selected.state !== object.state) update.state = selected.state
|
||||
if (selected.rank !== object.rank) update.rank = selected.rank
|
||||
client.update(object, update)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import board, { Board, CardLabel } from '@anticrm/board'
|
||||
import core, { Ref, TxOperations } from '@anticrm/core'
|
||||
import board, { Board, CardLabel, Card } from '@anticrm/board'
|
||||
import core, { Ref, TxOperations, Space } from '@anticrm/core'
|
||||
import type { KanbanTemplate } from '@anticrm/task'
|
||||
import { createKanban } from '@anticrm/task'
|
||||
import {
|
||||
@ -16,7 +16,7 @@ import {
|
||||
SeagullColor
|
||||
} from '@anticrm/ui'
|
||||
|
||||
export async function createBoard (
|
||||
export async function createBoard(
|
||||
client: TxOperations,
|
||||
name: string,
|
||||
description: string,
|
||||
@ -79,3 +79,41 @@ export async function createCardLabel (
|
||||
isHidden: isHidden ?? false
|
||||
})
|
||||
}
|
||||
|
||||
const isEqualLabel = (l1: CardLabel, l2: CardLabel): boolean =>
|
||||
l1.title === l2.title && l1.color === l2.color && (l1.isHidden ?? false) === (l2.isHidden ?? false)
|
||||
|
||||
export async function createMissingLabels (
|
||||
client: TxOperations,
|
||||
object: Card,
|
||||
targetBoard: Ref<Space>
|
||||
): Promise<Array<Ref<CardLabel>> | undefined> {
|
||||
const sourceBoardLabels = await getBoardLabels(client, object.space)
|
||||
const targetBoardLabels = await getBoardLabels(client, targetBoard)
|
||||
|
||||
const missingLabels = sourceBoardLabels.filter((srcLabel) => {
|
||||
if (object.labels?.includes(srcLabel._id) === false) return false
|
||||
|
||||
return targetBoardLabels.findIndex((targetLabel) => isEqualLabel(targetLabel, srcLabel)) === -1
|
||||
})
|
||||
|
||||
await Promise.all(missingLabels.map((l) => createCardLabel(client, targetBoard, l.color, l.title, l.isHidden)))
|
||||
|
||||
const updatedTargetBoardLabels = await getBoardLabels(client, targetBoard)
|
||||
|
||||
const labelsUpdate = object.labels
|
||||
?.map((srcLabelId) => {
|
||||
const srcLabel = sourceBoardLabels.find((l) => l._id === srcLabelId)
|
||||
|
||||
if (srcLabel === undefined) return null
|
||||
|
||||
const targetLabel = updatedTargetBoardLabels.find((l) => isEqualLabel(l, srcLabel))
|
||||
|
||||
if (targetLabel === undefined) return null
|
||||
|
||||
return targetLabel._id
|
||||
})
|
||||
.filter((l) => l !== null) as Array<Ref<CardLabel>> | undefined
|
||||
|
||||
return labelsUpdate
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user