index.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { NavigationMenuCategory } from '#desktop/components/NavigationMenu/types.ts'
  3. import type { PersonalSettingPlugin } from './types.ts'
  4. const plugins = import.meta.glob<PersonalSettingPlugin>(
  5. ['./**/*.ts', '!./**/index.ts', '!./types.ts', '!./__tests__/**/*.ts'],
  6. {
  7. eager: true,
  8. import: 'default',
  9. },
  10. )
  11. const categories: NavigationMenuCategory[] = []
  12. const categorizedItems: Record<string, PersonalSettingPlugin[]> = {}
  13. Object.values(plugins).forEach((plugin) => {
  14. if (
  15. !categories.find((category) => category.label === plugin.category.label)
  16. ) {
  17. categories.push(plugin.category)
  18. }
  19. return categories.sort((c1, c2) => c1.order - c2.order)
  20. })
  21. Object.values(plugins).forEach((plugin) => {
  22. const categoryLabel = plugin.category.label
  23. if (!categorizedItems[categoryLabel]) {
  24. categorizedItems[categoryLabel] = []
  25. }
  26. categorizedItems[categoryLabel].push(plugin)
  27. categorizedItems[categoryLabel].sort((p1, p2) => p1.order - p2.order)
  28. return categorizedItems
  29. })
  30. export const personalSettingCategories = categories
  31. export const personalSettingItems = categorizedItems
  32. export const personalSettingRoutes = Object.values(plugins).map(
  33. (plugin) => plugin.route,
  34. )