-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(task): add baseMixin support in TaskTypes #10495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
luisrosasx
wants to merge
7
commits into
hcengineering:develop
Choose a base branch
from
luisrosasx:feature/tasktype-basemixin
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
54ce6fb
feat(task): add baseMixin support in TaskTypes
luisrosasx c5450c4
feat(task): integrate MixinSelector into CreateTaskType UI
luisrosasx 6fa4c2c
feat(task): query existing TaskTypes for inheritance selector
luisrosasx 04d1c91
feat(task): add Clone Existing TaskTypes feature
luisrosasx a33d3f5
feat(task): add hierarchical class/mixin selector for TaskType inheri…
luisrosasx 035eb08
fix(task): use TaskType names for readable labels in ClassMixinSelector
luisrosasx 7dc247e
fix(task): improve ClassMixinSelector with tree hierarchy formatting
luisrosasx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,14 @@ | |
| "StatusChange": "Status changed", | ||
| "TaskCreated": "Task created", | ||
| "TaskType": "Task type", | ||
| "BaseMixin": "Inherit from", | ||
| "BaseMixinDescription": "Inherit attributes from an existing task type", | ||
| "NoBaseMixin": "None (create new)", | ||
| "CreateNew": "Create new", | ||
| "CloneExisting": "Clone existing", | ||
| "CloneTaskTypes": "Clone", | ||
| "SelectTaskTypesToClone": "Select task types to clone", | ||
| "NoTaskTypesAvailable": "No task types available to clone", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add translations for other languages as well? |
||
| "ManageProjects": "Project types", | ||
| "Export": "Export", | ||
| "CreateProjectType": "Create project type", | ||
|
|
||
145 changes: 145 additions & 0 deletions
145
plugins/task-resources/src/components/taskTypes/ClassMixinSelector.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| <script lang="ts"> | ||
| import { Class, Mixin, Ref, SortingOrder } from '@hcengineering/core' | ||
| import task, { Task, TaskType } from '@hcengineering/task' | ||
| import { ButtonMenu, Label } from '@hcengineering/ui' | ||
| import { createEventDispatcher } from 'svelte' | ||
| import { createQuery, getClient } from '@hcengineering/presentation' | ||
| import plugin from '../../plugin' | ||
|
|
||
| export let baseClass: Ref<Class<Task>> | ||
| export let value: Ref<Mixin<Task>> | undefined = undefined | ||
| export let readonly = false | ||
| export let buttonKind: 'primary' | 'secondary' | 'tertiary' | 'negative' = 'secondary' | ||
| export let buttonSize: 'large' | 'medium' | 'small' = 'large' | ||
|
|
||
| const dispatch = createEventDispatcher() | ||
| const client = getClient() | ||
| const hierarchy = client.getHierarchy() | ||
|
|
||
| interface MixinItem { | ||
| id: string | ||
| label: string | ||
| targetClass: Ref<Mixin<Task>> | ||
| parentMixin: Ref<Mixin<Task>> | undefined | ||
| } | ||
|
|
||
| let allTaskTypes: TaskType[] = [] | ||
|
|
||
| // Query all TaskTypes to get their names and targetClass mixins | ||
| const taskTypeQuery = createQuery() | ||
| $: { | ||
| const compatibleClasses = hierarchy.getDescendants(baseClass) | ||
| taskTypeQuery.query( | ||
| task.class.TaskType, | ||
| { ofClass: { $in: compatibleClasses } }, | ||
| (res) => { | ||
| allTaskTypes = res | ||
| }, | ||
| { sort: { name: SortingOrder.Ascending } } | ||
| ) | ||
| } | ||
|
|
||
| // Build hierarchical items from TaskTypes using recursive tree structure | ||
| function buildItems (taskTypes: TaskType[]): MixinItem[] { | ||
| const result: MixinItem[] = [] | ||
|
|
||
| // Create a map of targetClass -> TaskType for lookup | ||
| const targetClassToTaskType = new Map<string, TaskType>() | ||
| for (const tt of taskTypes) { | ||
| targetClassToTaskType.set(tt.targetClass as string, tt) | ||
| } | ||
|
|
||
| // Find children of a given targetClass | ||
| function getChildren (parentTargetClass: Ref<Mixin<Task>> | undefined): TaskType[] { | ||
| return taskTypes.filter((tt) => tt.baseMixin === parentTargetClass) | ||
| } | ||
|
|
||
| // Get root TaskTypes (those without baseMixin or with baseMixin not in our set) | ||
| function getRoots (): TaskType[] { | ||
| return taskTypes.filter((tt) => { | ||
| if (tt.baseMixin === undefined) return true | ||
| return !targetClassToTaskType.has(tt.baseMixin as string) | ||
| }) | ||
| } | ||
|
|
||
| // Recursively add items with proper indentation | ||
| function addItems (parent: Ref<Mixin<Task>> | undefined, level: number, prefix: string): void { | ||
| const children = parent === undefined ? getRoots() : getChildren(parent) | ||
|
|
||
| for (let i = 0; i < children.length; i++) { | ||
| const tt = children[i] | ||
| const isLast = i === children.length - 1 | ||
| const connector = level === 0 ? '' : (isLast ? '└─ ' : '├─ ') | ||
| const nextPrefix = level === 0 ? '' : (isLast ? ' ' : '│ ') | ||
|
|
||
| result.push({ | ||
| id: tt.targetClass as string, | ||
| label: prefix + connector + tt.name, | ||
| targetClass: tt.targetClass, | ||
| parentMixin: tt.baseMixin | ||
| }) | ||
|
|
||
| addItems(tt.targetClass, level + 1, prefix + nextPrefix) | ||
| } | ||
| } | ||
|
|
||
| addItems(undefined, 0, '') | ||
| return result | ||
| } | ||
|
|
||
| $: mixinItems = buildItems(allTaskTypes) | ||
|
|
||
| // Build items for ButtonMenu | ||
| $: items = [ | ||
| { id: '', label: 'None (create new)' }, | ||
| ...mixinItems.map((m) => ({ | ||
| id: m.id, | ||
| label: m.label | ||
| })) | ||
| ] | ||
|
|
||
| $: selected = items.find((it) => it.id === (value ?? '')) | ||
|
|
||
| function handleSelect (evt: CustomEvent<string>): void { | ||
| if (evt.detail !== undefined) { | ||
| value = evt.detail === '' ? undefined : (evt.detail as Ref<Mixin<Task>>) | ||
| dispatch('change', value) | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| <div class="mixin-selector"> | ||
| <span class="label"> | ||
| <Label label={plugin.string.BaseMixin} /> | ||
| </span> | ||
| {#if readonly} | ||
| {#if selected} | ||
| <span class="selected-value">{selected.label}</span> | ||
| {/if} | ||
| {:else} | ||
| <ButtonMenu | ||
| selected={value ?? ''} | ||
| {items} | ||
| label={selected?.label ?? plugin.string.NoBaseMixin} | ||
| kind={buttonKind} | ||
| size={buttonSize} | ||
| on:selected={handleSelect} | ||
| /> | ||
| {/if} | ||
| </div> | ||
|
|
||
| <style lang="scss"> | ||
| .mixin-selector { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 0.5rem; | ||
| } | ||
|
|
||
| .selected-value { | ||
| color: var(--theme-content-color); | ||
| } | ||
|
|
||
| .label { | ||
| color: var(--theme-halfcontent-color); | ||
| } | ||
| </style> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please fix validation errors here?
You can verify it locally by running
rushx _phase:validatein the directory/models/task/.