mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-25 04:25:13 +03:00
Board: Fix card members update (#1620)
Signed-off-by: Dvinyanin Alexandr <dvinyanin.alexandr@gmail.com>
This commit is contained in:
parent
e7138eadf9
commit
0cec2cb1d1
@ -15,7 +15,7 @@
|
||||
//
|
||||
|
||||
import type { Doc, PropertyType } from './classes'
|
||||
import type { Position } from './tx'
|
||||
import type { Position, PullArray } from './tx'
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -43,8 +43,13 @@ function $pull (document: Doc, keyval: Record<string, PropertyType>): void {
|
||||
const doc = document as any
|
||||
for (const key in keyval) {
|
||||
const arr = doc[key] as Array<any>
|
||||
if (typeof keyval[key] === 'object') {
|
||||
const { $in } = keyval[key] as PullArray<PropertyType>
|
||||
doc[key] = arr.filter((val) => !$in.includes(val))
|
||||
} else {
|
||||
doc[key] = arr.filter((val) => val !== keyval[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function $move (document: Doc, keyval: Record<string, PropertyType>): void {
|
||||
|
@ -108,6 +108,13 @@ export interface Position<X extends PropertyType> {
|
||||
$position: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface PullArray<X extends PropertyType> {
|
||||
$in: X[]
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
|
@ -63,8 +63,7 @@
|
||||
return false
|
||||
}
|
||||
const checkSelected = (person: Person): void => {
|
||||
if (isSelected(person)) selectedUsers = selectedUsers.filter((p) => p !== person._id)
|
||||
else selectedUsers.push(person._id)
|
||||
selectedUsers = isSelected(person) ? selectedUsers.filter((p) => p !== person._id) : [...selectedUsers, person._id]
|
||||
objects = objects
|
||||
dispatch('update', selectedUsers)
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
import CardInlineActions from './editor/CardInlineActions.svelte'
|
||||
import CardLabels from './editor/CardLabels.svelte'
|
||||
import DatePresenter from './presenters/DatePresenter.svelte'
|
||||
import { hasDate, openCardPanel, updateCard } from '../utils/CardUtils'
|
||||
import { hasDate, openCardPanel, updateCard, updateCardMembers } from '../utils/CardUtils'
|
||||
import { getElementPopupAlignment } from '../utils/PopupUtils'
|
||||
|
||||
export let object: WithLookup<Card>
|
||||
@ -61,7 +61,7 @@
|
||||
}
|
||||
|
||||
function updateMembers (e: CustomEvent<Ref<Employee>[]>) {
|
||||
client.update(object, { members: e.detail })
|
||||
updateCardMembers(object, client, e.detail)
|
||||
}
|
||||
|
||||
function updateDate (e: CustomEvent<CardDate>) {
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
import board from '../../plugin'
|
||||
import { getCardActions } from '../../utils/CardActionUtils'
|
||||
import { hasDate } from '../../utils/CardUtils'
|
||||
import { hasDate, updateCardMembers } from '../../utils/CardUtils'
|
||||
import DatePresenter from '../presenters/DatePresenter.svelte'
|
||||
import MemberPresenter from '../presenters/MemberPresenter.svelte'
|
||||
import CardLabels from './CardLabels.svelte'
|
||||
@ -49,7 +49,7 @@
|
||||
title: board.string.RemoveFromCard,
|
||||
handler: () => {
|
||||
const newMembers = membersIds.filter((m) => m !== member._id)
|
||||
client.update(value, { members: newMembers })
|
||||
updateCardMembers(value, client, newMembers)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -47,7 +47,8 @@ import {
|
||||
isArchived,
|
||||
isUnarchived,
|
||||
archiveCard,
|
||||
unarchiveCard
|
||||
unarchiveCard,
|
||||
updateCardMembers
|
||||
} from './utils/CardUtils'
|
||||
import { getPopupAlignment } from './utils/PopupUtils'
|
||||
|
||||
@ -84,7 +85,7 @@ async function showEditMembersPopup (object: Card, client: Client, e?: Event): P
|
||||
getPopupAlignment(e),
|
||||
undefined,
|
||||
(result: Array<Ref<Employee>>) => {
|
||||
void client.update(object, { members: result })
|
||||
updateCardMembers(object, client, result)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Card } from '@anticrm/board'
|
||||
import { EmployeeAccount } from '@anticrm/contact'
|
||||
import { TxOperations as Client, TxResult, getCurrentAccount } from '@anticrm/core'
|
||||
import { Employee, EmployeeAccount } from '@anticrm/contact'
|
||||
import { TxOperations as Client, TxResult, getCurrentAccount, Ref } from '@anticrm/core'
|
||||
import { showPanel } from '@anticrm/ui'
|
||||
|
||||
import board from '../plugin'
|
||||
@ -67,3 +67,12 @@ export function archiveCard (card: Card, client: Client): Promise<TxResult> | un
|
||||
export function unarchiveCard (card: Card, client: Client): Promise<TxResult> | undefined {
|
||||
return updateCard(client, card, 'isArchived', false)
|
||||
}
|
||||
|
||||
export function updateCardMembers (card: Card, client: Client, users: Array<Ref<Employee>>): void {
|
||||
if (card?.members == null) return
|
||||
const { members } = card
|
||||
const membersToPull = members.filter((member) => !users.includes(member))
|
||||
const usersToPush = users.filter((member) => !members.includes(member))
|
||||
if (membersToPull.length > 0) void updateCard(client, card, '$pull', { members: { $in: membersToPull } })
|
||||
if (usersToPush.length > 0) void updateCard(client, card, '$push', { members: { $each: usersToPush, $position: 0 } })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user