-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Group queues in Menu (#867)
* feat: add delimiter property to queue adapter and app queue interfaces This change enhances the flexibility of queue configurations by allowing the specification of a delimiter. * feat(Menu): implement hierarchical queue display and enhance styling - Introduced a new `QueueTree` component to render queues in a hierarchical structure based on a delimiter. - Updated the `Menu` component to utilize the new `QueueTree` for displaying queues. - Enhanced CSS styles for the menu, including padding adjustments and added margin for nested levels. * refactor(example.ts): update queue names and add delimiter support (hierarchy support) * feat(menu): added two queue examples to demonestrate grouping in the menu component * style(Menu): update CSS for improved layout and padding * fix(example.ts): added an example with a different delimiter * refactor: renamed variable * perf(Menu, toTree): improved toTree to use arrays instead of objects for improved performance --------- Co-authored-by: ahmad anwar <[email protected]>
- Loading branch information
Showing
7 changed files
with
125 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,49 @@ | ||
import { AppQueue } from '@bull-board/api/typings/app'; | ||
|
||
export interface AppQueueTreeNode { | ||
name: string; | ||
queue?: AppQueue; | ||
children: AppQueueTreeNode[]; | ||
} | ||
|
||
export function toTree(queues: AppQueue[]): AppQueueTreeNode { | ||
const root: AppQueueTreeNode = { | ||
name: 'root', | ||
children: [], | ||
}; | ||
|
||
queues.forEach((queue) => { | ||
if (!queue.delimiter) { | ||
// If no delimiter, add as direct child to root | ||
root.children.push({ | ||
name: queue.name, | ||
queue, | ||
children: [], | ||
}); | ||
return; | ||
} | ||
|
||
const parts = queue.name.split(queue.delimiter); | ||
let currentLevel = root.children; | ||
let currentPath = ''; | ||
|
||
parts.forEach((part, index) => { | ||
currentPath = currentPath ? `${currentPath}${queue.delimiter}${part}` : part; | ||
let node = currentLevel.find((n) => n.name === part); | ||
|
||
if (!node) { | ||
node = { | ||
name: part, | ||
children: [], | ||
// Only set queue data if we're at the leaf node | ||
...(index === parts.length - 1 ? { queue } : {}), | ||
}; | ||
currentLevel.push(node); | ||
} | ||
|
||
currentLevel = node.children; | ||
}); | ||
}); | ||
|
||
return root; | ||
} |