Fix status order (#8067)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2025-02-21 15:48:07 +05:00 committed by GitHub
parent f137df66eb
commit a604a1cc94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 17 deletions

View File

@ -152,11 +152,16 @@ export async function getAllStates (
attr: Attribute<Status>,
filterDone: boolean = true
): Promise<any[]> {
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)
}
}

View File

@ -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<Status>): 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<Ref<IssueStatus>>,
@ -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
})