Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugins/task-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"build": "compile ui",
"build:docs": "api-extractor run --local",
"format": "format src",
"test": "jest --passWithNoTests --silent",
"svelte-check": "do-svelte-check",
"_phase:svelte-check": "do-svelte-check",
"build:watch": "compile ui",
"_phase:build": "compile ui",
"_phase:format": "format src",
"_phase:validate": "compile validate"
"_phase:validate": "compile validate",
"_phase:test": "jest --passWithNoTests --silent"
},
"devDependencies": {
"svelte-loader": "^3.2.0",
Expand Down
57 changes: 57 additions & 0 deletions plugins/task-resources/src/__tests__/statusProjectType.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Copyright © 2026 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

import type { IdMap, Ref, Status } from '@hcengineering/core'
import type { ProjectStatus, ProjectType, TaskType } from '@hcengineering/task'
import { getStatusProjectType } from '../statusProjectType'

const status = 'status-a' as Ref<Status>
const other = 'status-b' as Ref<Status>

function projectType (id: string, statuses: Array<Partial<ProjectStatus>>): ProjectType {
return {
_id: id as Ref<ProjectType>,
statuses: statuses.map((it) => ({ taskType: 'tt' as Ref<TaskType>, ...it }))
} as unknown as ProjectType
}

function typesMap (...types: ProjectType[]): IdMap<ProjectType> {
return new Map(types.map((it) => [it._id, it]))
}

describe('getStatusProjectType', () => {
const plain = projectType('plain', [{ _id: status }])
const colored = projectType('colored', [{ _id: status, color: 5 }])
const unrelated = projectType('unrelated', [{ _id: other, color: 3 }])
const types = typesMap(plain, colored, unrelated)

it('uses the selected project type when present', () => {
expect(getStatusProjectType(status, unrelated._id, types, [plain._id, colored._id])).toBe(unrelated._id)
})

it('prefers a joined project type that configures the status color', () => {
expect(getStatusProjectType(status, undefined, types, [unrelated._id, plain._id, colored._id])).toBe(colored._id)
})

it('falls back to the first joined project type containing the status', () => {
expect(getStatusProjectType(status, undefined, types, [unrelated._id, plain._id])).toBe(plain._id)
})

it('returns undefined when no joined project type contains the status', () => {
expect(getStatusProjectType(status, undefined, types, [unrelated._id, 'missing' as Ref<ProjectType>])).toBe(
undefined
)
})
})
15 changes: 15 additions & 0 deletions plugins/task-resources/src/components/StatusFilter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import { buildConfigLookup, getPresenter } from '@hcengineering/view-resources/src/utils'
import { createEventDispatcher } from 'svelte'
import { typesOfJoinedProjectsStore, selectedTaskTypeStore, selectedTypeStore, taskTypeStore, typeStore } from '..'
import { getStatusProjectType } from '../statusProjectType'

export let filter: Filter
export let space: Ref<Space> | undefined = undefined
Expand Down Expand Up @@ -183,6 +184,19 @@
}, FILTER_DEBOUNCE_MS)
}

// Without a space (e.g. All Issues) pick a project type per status, so its own color is shown, not the category one.
$: getPresenterProps = (status: Status): Record<string, any> =>
space === undefined
? {
projectType: getStatusProjectType(
status._id,
$selectedTypeStore,
$typeStore,
$typesOfJoinedProjectsStore ?? []
)
}
: {}

let search: string = ''

const dispatch = createEventDispatcher()
Expand Down Expand Up @@ -237,6 +251,7 @@
{value}
{...attribute.props}
{space}
{...getPresenterProps(value)}
disabled
oneLine
/>
Expand Down
41 changes: 41 additions & 0 deletions plugins/task-resources/src/statusProjectType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright © 2026 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

import type { IdMap, Ref, Status } from '@hcengineering/core'
import type { ProjectType } from '@hcengineering/task'

/**
* Resolve the project type used to present a status when no space is known (e.g. All Issues).
* The selected project type wins; otherwise a joined project type that configures a color or icon
* for the status is preferred, falling back to the first joined project type that contains it.
*
* @public
*/
export function getStatusProjectType (
status: Ref<Status>,
selectedProjectType: Ref<ProjectType> | undefined,
projectTypes: IdMap<ProjectType>,
joinedProjectTypes: Array<Ref<ProjectType>>
): Ref<ProjectType> | undefined {
if (selectedProjectType !== undefined) return selectedProjectType
let fallback: Ref<ProjectType> | undefined
for (const typeId of joinedProjectTypes) {
const projectStatus = projectTypes.get(typeId)?.statuses?.find((it) => it._id === status)
if (projectStatus === undefined) continue
if (projectStatus.color !== undefined || projectStatus.icon !== undefined) return typeId
fallback = fallback ?? typeId
}
return fallback
}
Loading