Home.utils.ts26 lines · main
| 1 | export const DEFAULT_SECTION_ORDER = ['connect', 'usage', 'advisor', 'custom-report'] |
| 2 | |
| 3 | /** |
| 4 | * Reconciles a stored section order with the canonical list. |
| 5 | * Preserves user ordering for known sections, inserts missing |
| 6 | * sections at their default-relative position. |
| 7 | */ |
| 8 | export function mergeSectionOrder(stored: string[]): string[] { |
| 9 | const known = stored.filter((id) => DEFAULT_SECTION_ORDER.includes(id)) |
| 10 | const missing = DEFAULT_SECTION_ORDER.filter((id) => !known.includes(id)) |
| 11 | |
| 12 | if (missing.length === 0 && known.length === stored.length) return stored |
| 13 | |
| 14 | const merged = [...known] |
| 15 | for (const id of missing) { |
| 16 | const defaultIndex = DEFAULT_SECTION_ORDER.indexOf(id) |
| 17 | const nextKnown = DEFAULT_SECTION_ORDER.slice(defaultIndex + 1).find((c) => merged.includes(c)) |
| 18 | |
| 19 | if (!nextKnown) { |
| 20 | merged.push(id) |
| 21 | } else { |
| 22 | merged.splice(merged.indexOf(nextKnown), 0, id) |
| 23 | } |
| 24 | } |
| 25 | return merged |
| 26 | } |