From b8fbcc695e0e868120528f346695115fe440dc6f Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Fri, 6 Oct 2023 16:29:25 +0600 Subject: [PATCH] UBER-1000 (#3801) Signed-off-by: Denis Bykhov --- plugins/contact-assets/lang/en.json | 2 - plugins/contact-assets/lang/ru.json | 2 - plugins/contact-resources/src/assignee.ts | 35 ++------ .../src/components/AssigneeBox.svelte | 11 +-- .../src/components/AssigneePopup.svelte | 86 +++++++++--------- plugins/contact-resources/src/plugin.ts | 2 - plugins/notification-resources/src/utils.ts | 3 +- plugins/tracker-assets/lang/en.json | 1 + plugins/tracker-assets/lang/ru.json | 1 + .../components/issues/AssigneeEditor.svelte | 87 ++++++++++--------- plugins/tracker-resources/src/plugin.ts | 3 +- plugins/tracker-resources/src/utils.ts | 64 ++++++++------ plugins/view-resources/src/actions.ts | 38 ++++---- .../src/components/Workbench.svelte | 17 +--- 14 files changed, 169 insertions(+), 183 deletions(-) diff --git a/plugins/contact-assets/lang/en.json b/plugins/contact-assets/lang/en.json index 8185683a40..1eb262a5f6 100644 --- a/plugins/contact-assets/lang/en.json +++ b/plugins/contact-assets/lang/en.json @@ -90,8 +90,6 @@ "AddMembersHeader": "Add members to {value}:", "Assigned": "Assigned", "Unassigned": "Unassigned", - "CategoryPreviousAssigned": "Previously assigned", - "CategoryComponentLead": "Component lead", "CategoryCurrentUser": "Current user", "CategoryOther": "Other", "NumberMembers": "{count, plural, =0 {no members} =1 {1 member} other {# members}}", diff --git a/plugins/contact-assets/lang/ru.json b/plugins/contact-assets/lang/ru.json index 2b1332923c..630ac97851 100644 --- a/plugins/contact-assets/lang/ru.json +++ b/plugins/contact-assets/lang/ru.json @@ -92,8 +92,6 @@ "Assigned": "Назначен", "Unassigned": "Не назначен", "CategoryCurrentUser": "Текущий пользователь", - "CategoryPreviousAssigned": "Ранее назначенные", - "CategoryComponentLead": "Ответственный за компонент", "CategoryOther": "Прочие", "Position": "Должность", "ConfigLabel": "Контакты", diff --git a/plugins/contact-resources/src/assignee.ts b/plugins/contact-resources/src/assignee.ts index 7eefb560db..cd245c96da 100644 --- a/plugins/contact-resources/src/assignee.ts +++ b/plugins/contact-resources/src/assignee.ts @@ -1,36 +1,11 @@ +import { Person } from '@hcengineering/contact' +import { Ref } from '@hcengineering/core' import { IntlString } from '@hcengineering/platform' -import contact from './plugin' /** * @public */ -export type AssigneeCategory = 'CurrentUser' | 'Assigned' | 'PreviouslyAssigned' | 'ComponentLead' | 'Members' | 'Other' - -const assigneeCategoryTitleMap: Record = Object.freeze({ - CurrentUser: contact.string.CategoryCurrentUser, - Assigned: contact.string.Assigned, - PreviouslyAssigned: contact.string.CategoryPreviousAssigned, - ComponentLead: contact.string.CategoryComponentLead, - Members: contact.string.Members, - Other: contact.string.CategoryOther -}) - -/** - * @public - */ -export const assigneeCategoryOrder: AssigneeCategory[] = [ - 'CurrentUser', - 'Assigned', - 'PreviouslyAssigned', - 'ComponentLead', - 'Members', - 'Other' -] - -/** - * @public - */ -export function getCategoryTitle (category: AssigneeCategory | undefined): IntlString { - const cat: AssigneeCategory = category ?? 'Other' - return assigneeCategoryTitleMap[cat] +export interface AssigneeCategory { + label: IntlString + func: (val: Array>) => Promise>> } diff --git a/plugins/contact-resources/src/components/AssigneeBox.svelte b/plugins/contact-resources/src/components/AssigneeBox.svelte index d77b08374b..172c40db3a 100644 --- a/plugins/contact-resources/src/components/AssigneeBox.svelte +++ b/plugins/contact-resources/src/components/AssigneeBox.svelte @@ -39,6 +39,7 @@ import EmployeePresenter from './EmployeePresenter.svelte' import UserInfo from './UserInfo.svelte' import IconPerson from './icons/Person.svelte' + import { AssigneeCategory } from '../assignee' export let _class: Ref> = contact.mixin.Employee export let excluded: Ref[] | undefined = undefined @@ -49,9 +50,7 @@ export let label: IntlString export let placeholder: IntlString = presentation.string.Search export let value: Ref | null | undefined - export let prevAssigned: Ref[] | undefined = [] - export let componentLead: Ref | undefined = undefined - export let members: Ref[] | undefined = [] + export let categories: AssigneeCategory[] | undefined = undefined export let allowDeselect = true export let titleDeselect: IntlString | undefined = undefined export let readonly = false @@ -87,7 +86,7 @@ const mgr = getFocusManager() - const _click = (ev: MouseEvent): void => { + function _click (ev: MouseEvent): void { if (!readonly) { ev.preventDefault() ev.stopPropagation() @@ -98,9 +97,7 @@ _class, options, docQuery, - prevAssigned, - componentLead, - members, + categories, ignoreUsers: excluded ?? [], icon, selected: value, diff --git a/plugins/contact-resources/src/components/AssigneePopup.svelte b/plugins/contact-resources/src/components/AssigneePopup.svelte index 549eb7a933..d22679ffa0 100644 --- a/plugins/contact-resources/src/components/AssigneePopup.svelte +++ b/plugins/contact-resources/src/components/AssigneePopup.svelte @@ -13,34 +13,33 @@ // limitations under the License. --> {#if object} @@ -94,9 +105,7 @@ label={tracker.string.Assignee} placeholder={tracker.string.Assignee} value={object.assignee} - {prevAssigned} - {componentLead} - {members} + {categories} titleDeselect={tracker.string.Unassigned} {size} {kind} diff --git a/plugins/tracker-resources/src/plugin.ts b/plugins/tracker-resources/src/plugin.ts index fcbea42014..d4a6a51bbb 100644 --- a/plugins/tracker-resources/src/plugin.ts +++ b/plugins/tracker-resources/src/plugin.ts @@ -300,7 +300,8 @@ export default mergeIds(trackerId, tracker, { NoStatusFound: '' as IntlString, CreateMissingStatus: '' as IntlString, - UnsetParent: '' as IntlString + UnsetParent: '' as IntlString, + PreviousAssigned: '' as IntlString }, component: { NopeComponent: '' as AnyComponent, diff --git a/plugins/tracker-resources/src/utils.ts b/plugins/tracker-resources/src/utils.ts index 53528e8c9f..8b7ef0c1cb 100644 --- a/plugins/tracker-resources/src/utils.ts +++ b/plugins/tracker-resources/src/utils.ts @@ -13,7 +13,7 @@ // limitations under the License. // -import { Employee } from '@hcengineering/contact' +import { Contact } from '@hcengineering/contact' import core, { ApplyOperations, AttachedData, @@ -29,23 +29,24 @@ import core, { Space, Status, StatusCategory, - toIdMap, TxCollectionCUD, + TxCreateDoc, TxOperations, TxResult, - TxUpdateDoc + TxUpdateDoc, + toIdMap } from '@hcengineering/core' import { Asset, IntlString } from '@hcengineering/platform' -import { createQuery } from '@hcengineering/presentation' +import { createQuery, getClient } from '@hcengineering/presentation' import { calcRank } from '@hcengineering/task' import { Component, Issue, IssuePriority, + IssueStatus, IssuesDateModificationPeriod, IssuesGrouping, IssuesOrdering, - IssueStatus, Milestone, MilestoneStatus, Project, @@ -54,18 +55,18 @@ import { import { AnyComponent, AnySvelteComponent, + MILLISECONDS_IN_WEEK, + PaletteColorIndexes, areDatesEqual, getMillisecondsInMonth, - isWeekend, - MILLISECONDS_IN_WEEK, - PaletteColorIndexes + isWeekend } from '@hcengineering/ui' import { KeyFilter, ViewletDescriptor } from '@hcengineering/view' import { CategoryQuery, - groupBy, ListSelectionProvider, SelectDirection, + groupBy, statusStore } from '@hcengineering/view-resources' import { get } from 'svelte/store' @@ -497,24 +498,33 @@ export function subIssueListProvider (subIssues: Issue[], target: Ref): v } } -export async function getPreviousAssignees (objectId: Ref): Promise>> { - return await new Promise((resolve) => { - const query = createQuery(true) - query.query( - core.class.Tx, - { - 'tx.objectId': objectId, - 'tx.operations.assignee': { $exists: true } - }, - (res) => { - const prevAssignee = res - .map((t) => ((t as TxCollectionCUD).tx as TxUpdateDoc).operations.assignee) - .filter((p) => !(p == null)) as Array> - resolve(prevAssignee) - query.unsubscribe() - } - ) - }) +export async function getPreviousAssignees (objectId: Ref | undefined): Promise>> { + if (objectId === undefined) { + return [] + } + const client = getClient() + const createTx = ( + await client.findAll>(core.class.TxCollectionCUD, { + 'tx.objectId': objectId, + 'tx._class': core.class.TxCreateDoc + }) + )[0] + const updateTxes = await client.findAll>( + core.class.TxCollectionCUD, + { 'tx.objectId': objectId, 'tx._class': core.class.TxUpdateDoc, 'tx.operations.assignee': { $exists: true } }, + { sort: { modifiedOn: -1 } } + ) + const set: Set> = new Set() + const createAssignee = (createTx.tx as TxCreateDoc).attributes.assignee + for (const tx of updateTxes) { + const assignee = (tx.tx as TxUpdateDoc).operations.assignee + if (assignee == null) continue + set.add(assignee) + } + if (createAssignee != null) { + set.add(createAssignee) + } + return Array.from(set) } async function updateIssuesOnMove ( diff --git a/plugins/view-resources/src/actions.ts b/plugins/view-resources/src/actions.ts index 17225e651e..d950cd6ba1 100644 --- a/plugins/view-resources/src/actions.ts +++ b/plugins/view-resources/src/actions.ts @@ -56,14 +56,31 @@ export async function getActions ( derived: Ref> = core.class.Doc, mode: ViewContextType = 'context' ): Promise { - const actions: Action[] = await client.findAll(view.class.Action, { + let actions: Action[] = await client.findAll(view.class.Action, { 'context.mode': mode }) const categories: Partial> = { top: 1, tools: 50, other: 100, remove: 200 } - let filteredActions: Action[] = [] + if (Array.isArray(doc)) { + for (const d of doc) { + actions = filterActions(client, d, actions, derived) + } + } else { + actions = filterActions(client, doc, actions, derived) + } + const inputVal: ViewActionInput[] = ['none'] + if (!Array.isArray(doc) || doc.length === 1) { + inputVal.push('focus') + inputVal.push('any') + } + if (Array.isArray(doc) && doc.length > 0) { + inputVal.push('selection') + inputVal.push('any') + } + actions = actions.filter((it) => inputVal.includes(it.input)) + const filteredActions: Action[] = [] for (const action of actions) { if (action.visibilityTester == null) { filteredActions.push(action) @@ -75,23 +92,6 @@ export async function getActions ( } } } - if (Array.isArray(doc)) { - for (const d of doc) { - filteredActions = filterActions(client, d, filteredActions, derived) - } - } else { - filteredActions = filterActions(client, doc, filteredActions, derived) - } - const inputVal: ViewActionInput[] = ['none'] - if (!Array.isArray(doc) || doc.length === 1) { - inputVal.push('focus') - inputVal.push('any') - } - if (Array.isArray(doc) && doc.length > 0) { - inputVal.push('selection') - inputVal.push('any') - } - filteredActions = filteredActions.filter((it) => inputVal.includes(it.input)) filteredActions.sort((a, b) => { const aTarget = categories[a.context.group ?? 'top'] ?? 0 const bTarget = categories[b.context.group ?? 'top'] ?? 0 diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index d717500141..043d81ed44 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -102,7 +102,6 @@ const excludedApps = getMetadata(workbench.metadata.ExcludedApplications) ?? [] const client = getClient() - NotificationClientImpl.createClient() let apps: Application[] | Promise = client .findAll(workbench.class.Application, { hidden: false, _id: { $nin: excludedApps } }) @@ -162,18 +161,10 @@ ) let hasNotification = false - const notificationQuery = createQuery() - - notificationQuery.query( - notification.class.DocUpdates, - { - user: accountId, - hidden: false - }, - (res) => { - hasNotification = res.some((p) => p.txes.some((p) => p.isNew)) - } - ) + const noficicationClient = NotificationClientImpl.getClient() + noficicationClient.docUpdates.subscribe((res) => { + hasNotification = res.some((p) => !p.hidden && p.txes.some((p) => p.isNew)) + }) const workspaceId = $location.path[1]