From ebdcf504b5762e9108a8f64def3f99e6d2d0d721 Mon Sep 17 00:00:00 2001 From: Melvin Chia Date: Tue, 28 Oct 2025 10:42:48 +0800 Subject: [PATCH] feat(client): add dynamic module category sequence loading from configuration file Former-commit-id: e886c6b794fb1e39de28d096ff2527ed255db076 [formerly 82e16d38e321d46c3b6549b9f7f26acf5b5a8102] [formerly 8cf1c7b45c2cabc43b53f372f3274d8f32a3ab41 [formerly 3fed1b24e80f3663bb28a20f357e5a4424c8e033]] Former-commit-id: 90903ae136215dab15d6aa25da6b3c221083882a [formerly 3c6404d13024155c4dabecf6b15d91f068020c1f] Former-commit-id: 760e4ec67b53e863dd3cf9064458b39c57308418 --- apps/cat.config.json | 1 + client/src/routes/index.tsx | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 apps/cat.config.json diff --git a/apps/cat.config.json b/apps/cat.config.json new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/apps/cat.config.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/client/src/routes/index.tsx b/client/src/routes/index.tsx index db6f42f35..87f000314 100644 --- a/client/src/routes/index.tsx +++ b/client/src/routes/index.tsx @@ -2,6 +2,20 @@ import type { ModuleCategory, ModuleConfig } from 'shared' let ROUTES: ModuleCategory[] = [] +const categoryFile = import.meta.glob('../../../apps/cat.config.json', { + eager: true +}) + +let categoriesSeq: string[] = [] + +console.log(categoryFile) + +if (categoryFile['../../../apps/cat.config.json']) { + categoriesSeq = ( + categoryFile['../../../apps/cat.config.json'] as { default: string[] } + ).default +} + await Promise.all( Object.entries( import.meta.glob(['../apps/**/manifest.ts', '../../../apps/**/manifest.ts']) @@ -49,7 +63,28 @@ ROUTES = ROUTES.sort((a, b) => { if (bIndex >= 1) return -1 // Settings, SSO, go last } - // Both are regular categories - alphabetical + if (categoriesSeq.length > 0) { + const aCatIndex = categoriesSeq.indexOf(a.title) + + const bCatIndex = categoriesSeq.indexOf(b.title) + + // Both found in sequence + if (aCatIndex !== -1 && bCatIndex !== -1) { + return aCatIndex - bCatIndex + } + + // Only a found in sequence + if (aCatIndex !== -1) { + return -1 + } + + // Only b found in sequence + if (bCatIndex !== -1) { + return 1 + } + } + + // Default to alphabetical return a.title.localeCompare(b.title) }).map(cat => ({ title: ['', ''].includes(cat.title) ? '' : cat.title,