From a604a1cc9482d4602886d200bee4507f9f0bdd27 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Fri, 21 Feb 2025 15:48:07 +0500 Subject: [PATCH] Fix status order (#8067) Signed-off-by: Denis Bykhov --- plugins/task-resources/src/index.ts | 24 ++++++++++-------- plugins/tracker-resources/src/utils.ts | 35 ++++++++++++++++++++------ 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/plugins/task-resources/src/index.ts b/plugins/task-resources/src/index.ts index 078746c34b..11772bcc60 100644 --- a/plugins/task-resources/src/index.ts +++ b/plugins/task-resources/src/index.ts @@ -152,11 +152,16 @@ export async function getAllStates ( attr: Attribute, filterDone: boolean = true ): Promise { - const typeId = get(selectedTypeStore) + const joinedProjectsTypes = get(typesOfJoinedProjectsStore) ?? [] + const typeId = get(selectedTypeStore) ?? (joinedProjectsTypes.length === 1 ? joinedProjectsTypes[0] : undefined) const type = typeId !== undefined ? get(typeStore).get(typeId) : undefined - const taskTypeId = get(selectedTaskTypeStore) + const $taskType = get(taskTypeStore) + const joinedTaskTypes = Array.from($taskType.values()).filter((taskType) => + joinedProjectsTypes.includes(taskType.parent) + ) + const taskTypeId = get(selectedTaskTypeStore) ?? (joinedTaskTypes.length === 1 ? joinedTaskTypes[0]?._id : undefined) if (taskTypeId !== undefined) { - const taskType = get(taskTypeStore).get(taskTypeId) + const taskType = $taskType.get(taskTypeId) if (taskType === undefined) { return [] } @@ -209,17 +214,16 @@ export async function getAllStates ( return statuses.map((p) => p?._id) } } - const joinedProjectsTypes = get(typesOfJoinedProjectsStore) ?? [] - const includedStatuses = Array.from(get(taskTypeStore).values()) - .filter((taskType) => joinedProjectsTypes.includes(taskType.parent)) - .flatMap((taskType) => taskType.statuses) - const allStates = get(statusStore).array.filter((p) => p.ofAttribute === attr._id && includedStatuses.includes(p._id)) + const includedStatuses = new Set(joinedTaskTypes.flatMap((taskType) => taskType.statuses)) + const $statusStore = get(statusStore) + const allStates = [...includedStatuses].map((p) => $statusStore.byId.get(p)) + const states = allStates.filter((p) => p !== undefined && p.ofAttribute === attr._id) if (filterDone) { - return allStates + return states .filter((p) => p?.category !== task.statusCategory.Lost && p?.category !== task.statusCategory.Won) .map((p) => p?._id) } else { - return allStates.map((p) => p?._id) + return states.map((p) => p?._id) } } diff --git a/plugins/tracker-resources/src/utils.ts b/plugins/tracker-resources/src/utils.ts index 8edea08147..0a6dd1b358 100644 --- a/plugins/tracker-resources/src/utils.ts +++ b/plugins/tracker-resources/src/utils.ts @@ -37,8 +37,12 @@ import core, { } from '@hcengineering/core' import { type IntlString } from '@hcengineering/platform' import { createQuery, getClient, onClient } from '@hcengineering/presentation' -import task, { getStatusIndex, makeRank, type ProjectType } from '@hcengineering/task' -import { activeProjects as taskActiveProjects, taskTypeStore } from '@hcengineering/task-resources' +import task, { getStatusIndex, makeRank, type TaskType, type ProjectType } from '@hcengineering/task' +import { + activeProjects as taskActiveProjects, + taskTypeStore, + typesOfJoinedProjectsStore +} from '@hcengineering/task-resources' import { IssuePriority, MilestoneStatus, @@ -49,7 +53,7 @@ import { type Milestone, type Project } from '@hcengineering/tracker' -import { PaletteColorIndexes, areDatesEqual, isWeekend } from '@hcengineering/ui' +import { areDatesEqual, isWeekend, PaletteColorIndexes } from '@hcengineering/ui' import { type KeyFilter, type ViewletDescriptor } from '@hcengineering/view' import { CategoryQuery, ListSelectionProvider, statusStore, type SelectDirection } from '@hcengineering/view-resources' import { derived, get, writable } from 'svelte/store' @@ -124,6 +128,16 @@ export const listIssueKanbanStatusOrder = [ task.statusCategory.Lost ] as const +function getTaskTypesStatusIndex (joinedTaskTypes: TaskType[], status: Ref): number { + for (const taskType of joinedTaskTypes) { + const indexx = taskType.statuses.indexOf(status) + if (indexx >= 0) { + return indexx + } + } + return -1 +} + export async function issueStatusSort ( client: TxOperations, value: Array>, @@ -143,7 +157,12 @@ export async function issueStatusSort ( ) type = _space?.$lookup?.type } + const joinedProjectsTypes = get(typesOfJoinedProjectsStore) ?? [] const taskTypes = get(taskTypeStore) + const joinedTaskTypes = Array.from(taskTypes.values()).filter( + (taskType) => joinedProjectsTypes.includes(taskType.parent) && taskType.ofClass === tracker.class.Issue + ) + const statuses = get(statusStore).byId // TODO: How we track category updates. @@ -159,9 +178,10 @@ export async function issueStatusSort ( const aIndex = getStatusIndex(type, taskTypes, a) const bIndex = getStatusIndex(type, taskTypes, b) return aIndex - bIndex - } else { - return (aVal?.name ?? '').localeCompare(bVal?.name ?? '') } + const aIndex = getTaskTypesStatusIndex(joinedTaskTypes, a) + const bIndex = getTaskTypesStatusIndex(joinedTaskTypes, b) + return aIndex - bIndex } return res }) @@ -177,9 +197,10 @@ export async function issueStatusSort ( const aIndex = getStatusIndex(type, taskTypes, a) const bIndex = getStatusIndex(type, taskTypes, b) return aIndex - bIndex - } else if (aVal != null && bVal != null) { - return aVal.name.localeCompare(bVal.name) } + const aIndex = getTaskTypesStatusIndex(joinedTaskTypes, a) + const bIndex = getTaskTypesStatusIndex(joinedTaskTypes, b) + return aIndex - bIndex } return res })