Skip to content

Commit a0e1b4f

Browse files
committed
categorized taskbar
1 parent 5b414a6 commit a0e1b4f

File tree

1 file changed

+76
-29
lines changed

1 file changed

+76
-29
lines changed

libs/app-canvas/src/app/components/node-sidebar-menu.tsx

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,55 @@ export class NodeSidebarMenuComponent extends Component<
145145
this.rootElement.append(this.element);
146146
let taskbar: HTMLElement | null = null;
147147
let taskbarContainer: HTMLElement | null = null;
148+
149+
const categorizedNodeTasks = new Map<
150+
string,
151+
{ label: string; nodeType: string }[]
152+
>();
153+
const nodeTasks = getNodeFactoryNames();
154+
nodeTasks.forEach((nodeTask) => {
155+
const factory = this.getNodeFactory(nodeTask);
156+
let categoryName = 'Default';
157+
if (factory) {
158+
const node = factory(this.props.canvasUpdated);
159+
categoryName = node.category || 'uncategorized';
160+
}
161+
const label = canvasNodeTaskRegistryLabels[nodeTask] || nodeTask;
162+
const category = categorizedNodeTasks.get(categoryName);
163+
if (category) {
164+
category.push({
165+
label,
166+
nodeType: nodeTask,
167+
});
168+
} else {
169+
categorizedNodeTasks.set(categoryName, [
170+
{
171+
label,
172+
nodeType: nodeTask,
173+
},
174+
]);
175+
}
176+
});
177+
// sort the categories case-insensitive
178+
const sortedCategories = Array.from(categorizedNodeTasks.keys()).sort(
179+
(a, b) => {
180+
return a.localeCompare(b);
181+
}
182+
);
183+
184+
// sort the tasks within the categories
185+
sortedCategories.forEach((categoryName) => {
186+
const category = categorizedNodeTasks.get(categoryName);
187+
if (category) {
188+
category.sort((a, b) => {
189+
return a.label.localeCompare(b.label);
190+
});
191+
}
192+
});
193+
148194
renderElement(
149195
<div
150-
class={`taskbar-container transition-transform z-[1050] flex flex-col absolute left-0 top-[58px] max-h-[calc(100vh-108px)] bg-slate-700 p-[4px] rounded-l-lg overflow-y-scroll`}
196+
class={`taskbar-container transition-transform z-[1050] flex flex-col absolute left-0 top-[58px] max-h-[calc(100vh-108px)] bg-slate-700 p-4 rounded-l-lg overflow-y-scroll`}
151197
getElement={(element: HTMLElement) => {
152198
taskbarContainer = element;
153199
}}
@@ -156,37 +202,38 @@ export class NodeSidebarMenuComponent extends Component<
156202
class={`overflow-visible flex flex-col `}
157203
getElement={(element: HTMLElement) => {
158204
taskbar = element;
159-
160-
const nodeTasks = getNodeFactoryNames();
161-
nodeTasks.forEach((nodeTask) => {
162-
//const factory = this.getNodeFactory(nodeTask);
163-
//let categoryName = 'Default';
164-
// if (factory) {
165-
// const node = factory(canvasUpdated);
166-
// if (allowedNodeTasks.indexOf(node.name) < 0) {
167-
// return;
168-
// }
169-
// categoryName = node.category || 'uncategorized';
170-
// }
171-
const label =
172-
canvasNodeTaskRegistryLabels[nodeTask] || nodeTask;
173-
205+
sortedCategories.forEach((categoryName) => {
206+
const category = categorizedNodeTasks.get(categoryName);
207+
if (categoryName === 'deprecated') {
208+
return;
209+
}
174210
renderElement(
175-
<div
176-
class={`cursor-pointer border border-white border-solid rounded px-4 py-2 text-white`}
177-
pointerdown={(event: PointerEvent) => {
178-
this.startDragNode(
179-
event,
180-
taskbar,
181-
taskbarContainer,
182-
nodeTask
183-
);
184-
}}
185-
>
186-
{label}
187-
</div>,
211+
<h2 class={`text-white py-2`}>{categoryName}</h2>,
188212
taskbar
189213
);
214+
215+
category?.forEach((nodeTask) => {
216+
const label =
217+
canvasNodeTaskRegistryLabels[nodeTask.nodeType] ||
218+
nodeTask.nodeType;
219+
220+
renderElement(
221+
<div
222+
class={`cursor-pointer border border-white border-solid rounded px-4 py-2 mb-2 text-white`}
223+
pointerdown={(event: PointerEvent) => {
224+
this.startDragNode(
225+
event,
226+
taskbar,
227+
taskbarContainer,
228+
nodeTask.nodeType
229+
);
230+
}}
231+
>
232+
{label}
233+
</div>,
234+
taskbar
235+
);
236+
});
190237
});
191238
}}
192239
></div>

0 commit comments

Comments
 (0)