Skip to content
Open
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
1 change: 1 addition & 0 deletions frontend/src/lib/api/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const search = {

// Text search
if (params.query) searchParams.append('q', params.query);
if (params.ql) searchParams.append('ql', params.ql);

// Multiple workspace IDs
if (params.workspaceIds && params.workspaceIds.length > 0) {
Expand Down
115 changes: 105 additions & 10 deletions frontend/src/lib/dialogs/CreateModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import { workspacePermissions } from '../stores/workspacePermissions.svelte.js';
import { packs as packsApi } from '../api/packs.js';
import { workspaces } from '../api/workspaces.js';
import { attachments } from '../api/misc.js';
import { attachments, search } from '../api/misc.js';
import { items } from '../api/items.js';
import ItemTypeIcon from '../components/ItemTypeIcon.svelte';
import ItemKey from '../components/ItemKey.svelte';
import { childItemTypesForParent, canHaveChildren } from '../utils/hierarchy.js';
import { collections } from '../api/collections.js';
import X from '@lucide/svelte/icons/x';
import Target from '@lucide/svelte/icons/target';
Expand Down Expand Up @@ -130,6 +133,69 @@
let collectionCategoryId = $state(null);
let submitting = $state(false);

// Parent chosen from the header picker (as opposed to a pre-set parent context).
const NO_PARENT = '__none__';
let parentPickedHere = $state(false);
let parentSearchResults = $state([]);
let parentSearchTimer;
let parentSearchController;
let pickedParent = $state(null);
let parentItems = $derived([
{ id: NO_PARENT, title: t('createModal.noParentOption') },
...(pickedParent && !parentSearchResults.some((r) => r.id === pickedParent.id) ? [pickedParent] : []),
...parentSearchResults
]);

function resetParentSearch() {
clearTimeout(parentSearchTimer);
parentSearchController?.abort();
parentSearchResults = [];
}

function onParentSearchChange(query) {
resetParentSearch();
const workspaceId = workItemFormStore.formData.workspace_id;
// Read synchronously so the picker re-queries once item types finish loading.
const types = workItemFormStore.itemTypes;
if (!workspaceId || !types.length) return;
// Short or empty input browses the workspace's open items instead of searching.
const browsing = query.trim().length < 2;
const params = browsing ? { ql: 'statusCompleted = false', limit: 50 } : { query, limit: 20 };
parentSearchTimer = setTimeout(async () => {
const controller = new AbortController();
parentSearchController = controller;
try {
const results = await search.items({ ...params, workspaceIds: [workspaceId], signal: controller.signal });
if (controller.signal.aborted) return;
parentSearchResults = (results || [])
.filter((r) => canHaveChildren(types, types.find((ty) => ty.id === r.item_type_id)))
.slice(0, browsing ? 50 : 10);
} catch (error) {
if (!controller.signal.aborted) errorToast(error?.message || String(error));
}
}, 300);
}

function selectParent(item) {
if (item.id === NO_PARENT) {
clearPickedParent();
return;
}
const type = workItemFormStore.itemTypes.find((ty) => ty.id === item.item_type_id);
pickedParent = item;
parentPickedHere = true;
workItemFormStore.setParentItem(
{ id: item.id, title: item.title },
childItemTypesForParent(workItemFormStore.itemTypes, type)
);
}

function clearPickedParent() {
pickedParent = null;
parentPickedHere = false;
workItemFormStore.setParentItem(null, null);
}

// The work-item create endpoint requires item.create in the target
// workspace (denied with 404), so the picker must only offer workspaces
// where creation is allowed. Mirrors CollectionBoard's quick-add filter;
Expand Down Expand Up @@ -174,6 +240,9 @@
isOpen = false;
selectedType = initialType;
recoverableItemId = null;
parentPickedHere = false;
pickedParent = null;
resetParentSearch();

// Reset work item form store
workItemFormStore.resetForm();
Expand Down Expand Up @@ -541,7 +610,7 @@
<CreateFormFrame dataTestid="create-modal">
{#snippet header()}
<!-- Type Selector FIRST (independent of workspace) -->
{#if !workItemFormStore.parentItem && !compactMode}
{#if (!workItemFormStore.parentItem || parentPickedHere) && !compactMode}
<ChipPicker
value={selectedType}
items={typeOptions}
Expand All @@ -561,7 +630,7 @@
{/if}

<!-- Workspace Selector (only for work-items) -->
{#if selectedType === 'work-item' && !workItemFormStore.parentItem}
{#if selectedType === 'work-item' && (!workItemFormStore.parentItem || parentPickedHere)}
<ChipPicker
value={workItemFormStore.formData.workspace_id}
items={creatableWorkspaces}
Expand All @@ -574,6 +643,7 @@
testId="create-workspace-chip"
onSelect={(workspace) => {
if (workspace) {
if (parentPickedHere && workspace.id !== workItemFormStore.formData.workspace_id) clearPickedParent();
workItemFormStore.setWorkspace(workspace);
}
}}
Expand Down Expand Up @@ -607,13 +677,38 @@
<ChevronRight size={14} style="color: var(--ds-text-subtle);" />
{/if}

<span data-testid="create-modal-heading" class="font-medium" style="color: var(--ds-text);">
{#if workItemFormStore.parentItem}
{t('createModal.newChildItem')}
{:else}
{t('createModal.new')} {currentTypeName}
{/if}
</span>
{#if selectedType === 'work-item' && (!workItemFormStore.parentItem || parentPickedHere)}
<ChipPicker
value={pickedParent?.id ?? null}
items={parentItems}
getValue={(p) => p.id}
getLabel={(p) => p.id === NO_PARENT ? '' : p.title}
placeholder={`${t('createModal.new')} ${currentTypeName}`}
searchable={true}
testId="create-parent-chip"
onSearchChange={onParentSearchChange}
onSelect={selectParent}
>
{#snippet itemSnippet({ item })}
{#if item.id === NO_PARENT}
<span class="font-medium">{item.title}</span>
{:else}
{@const itemType = workItemFormStore.itemTypes.find((ty) => ty.id === item.item_type_id)}
{#if itemType}<ItemTypeIcon {itemType} />{/if}
<ItemKey {item} workspace={{ key: item.workspace_key }} clickable={false} />
<span class="text-sm truncate">{item.title}</span>
{/if}
{/snippet}
</ChipPicker>
{:else}
<span data-testid="create-modal-heading" class="font-medium" style="color: var(--ds-text);">
{#if workItemFormStore.parentItem}
{t('createModal.newChildItem')}
{:else}
{t('createModal.new')} {currentTypeName}
{/if}
</span>
{/if}

<button
data-testid="create-modal-close"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/de/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ export default {
completeSetupEnter: 'Einrichtung abschließen (Enter)',
},
createModal: {
noParentOption: 'Neuer Vorgang (ohne übergeordneten Vorgang)',
workItem: 'Vorgang',
milestone: 'Meilenstein',
workspace: 'Arbeitsbereich',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/en/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ export default {
},

createModal: {
noParentOption: 'New work item (no parent)',
// Type labels
workItem: 'Work Item',
team: 'Team',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/fa/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ export default {
"completeSetupEnter": "راه اندازی کامل (Enter)"
},
"createModal": {
"noParentOption": "مورد کار جدید (بدون والد)",
"workItem": "مورد کار",
"team": "تیم",
"milestone": "نقطه عطف",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/fr/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ export default {
},

createModal: {
noParentOption: 'Nouvel élément de travail (sans parent)',
// Type labels
workItem: 'Élément de travail',
milestone: 'Jalon',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/it/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ export default {
},

createModal: {
noParentOption: 'Nuovo elemento di lavoro (senza padre)',
// Type labels
workItem: 'Elemento di lavoro',
team: 'Team',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/nl/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ export default {
},

createModal: {
noParentOption: 'Nieuw werkitem (zonder bovenliggend item)',
// Type labels
workItem: 'Werkitem',
team: 'Team',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/pl/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ export default {
},

createModal: {
noParentOption: 'Nowy element pracy (bez elementu nadrzędnego)',
// Etykiety typów
workItem: 'Element pracy',
team: 'Zespół',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/locales/ru/misc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/lib/locales/zh-CN/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ export default {
},

createModal: {
noParentOption: '新建工作项(无父项)',
workItem: '工作项',
milestone: '里程碑',
workspace: '工作区',
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/lib/pickers/ChipPicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
triggerSnippet = null,
itemSnippet = null,
onSelect = () => {},
onSearchChange = null,
testId = null
} = $props();

Expand Down Expand Up @@ -67,7 +68,7 @@

// Filter items when searchable
let filteredItems = $derived.by(() => {
if (!searchable || !searchTerm.trim()) return items;
if (onSearchChange || !searchable || !searchTerm.trim()) return items;
const term = searchTerm.toLowerCase();
return items.filter(item =>
searchFields.some(field => {
Expand All @@ -86,6 +87,10 @@
revealedCount = maxVisibleOptions;
});

$effect(() => {
onSearchChange?.(searchTerm);
});

// Focus input when popover opens, reset state
$effect(() => {
if ($open) {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lib/utils/hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export function childItemTypesForParent(itemTypes, parentType) {
return (itemTypes || []).filter((type) => canItemTypeBeChildOf(type, parentType));
}

export function canHaveChildren(itemTypes, parentType) {
return childItemTypesForParent(itemTypes, parentType).length > 0;
}

/**
* Child types for a parent whose own type is unknown (for example a level-0
* item whose type is not bound to the workspace configuration set). The parent
Expand Down
Loading