Home.utils.ts 917 B

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