@red-hat-developer-hub/backstage-plugin-global-header 1.20.2 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +92 -8
  3. package/config.d.ts +75 -33
  4. package/dist/alpha/components/ApplicationLauncherDropdown.esm.js +35 -0
  5. package/dist/alpha/components/ApplicationLauncherDropdown.esm.js.map +1 -0
  6. package/dist/alpha/components/GlobalHeader.esm.js +23 -0
  7. package/dist/alpha/components/GlobalHeader.esm.js.map +1 -0
  8. package/dist/alpha/components/GlobalHeaderDropdown.esm.js +59 -0
  9. package/dist/alpha/components/GlobalHeaderDropdown.esm.js.map +1 -0
  10. package/dist/alpha/components/GlobalHeaderDropdownContent.esm.js +52 -0
  11. package/dist/alpha/components/GlobalHeaderDropdownContent.esm.js.map +1 -0
  12. package/dist/alpha/components/GlobalHeaderMenuItem.esm.js +41 -0
  13. package/dist/alpha/components/GlobalHeaderMenuItem.esm.js.map +1 -0
  14. package/dist/alpha/components/HelpDropdown.esm.js +32 -0
  15. package/dist/alpha/components/HelpDropdown.esm.js.map +1 -0
  16. package/dist/alpha/components/MyProfileMenuItem.esm.js +58 -0
  17. package/dist/alpha/components/MyProfileMenuItem.esm.js.map +1 -0
  18. package/dist/alpha/components/ProfileDropdown.esm.js +97 -0
  19. package/dist/alpha/components/ProfileDropdown.esm.js.map +1 -0
  20. package/dist/alpha/defaults/index.esm.js +26 -0
  21. package/dist/alpha/defaults/index.esm.js.map +1 -0
  22. package/dist/alpha/defaults/menuItemExtensions.esm.js +67 -0
  23. package/dist/alpha/defaults/menuItemExtensions.esm.js.map +1 -0
  24. package/dist/alpha/defaults/rhdhLogo.esm.js +7 -0
  25. package/dist/alpha/defaults/rhdhLogo.esm.js.map +1 -0
  26. package/dist/alpha/defaults/toolbarExtensions.esm.js +74 -0
  27. package/dist/alpha/defaults/toolbarExtensions.esm.js.map +1 -0
  28. package/dist/alpha/extensions/GlobalHeaderContext.esm.js +31 -0
  29. package/dist/alpha/extensions/GlobalHeaderContext.esm.js.map +1 -0
  30. package/dist/alpha/extensions/blueprints.esm.js +112 -0
  31. package/dist/alpha/extensions/blueprints.esm.js.map +1 -0
  32. package/dist/alpha/extensions/dataRefs.esm.js +11 -0
  33. package/dist/alpha/extensions/dataRefs.esm.js.map +1 -0
  34. package/dist/alpha/extensions/globalHeaderModule.esm.js +72 -0
  35. package/dist/alpha/extensions/globalHeaderModule.esm.js.map +1 -0
  36. package/dist/alpha/plugin.esm.js +28 -0
  37. package/dist/alpha/plugin.esm.js.map +1 -0
  38. package/dist/alpha/utils/menuItemGrouping.esm.js +52 -0
  39. package/dist/alpha/utils/menuItemGrouping.esm.js.map +1 -0
  40. package/dist/alpha/utils/readConfigComponents.esm.js +29 -0
  41. package/dist/alpha/utils/readConfigComponents.esm.js.map +1 -0
  42. package/dist/alpha/utils/readConfigMenuItems.esm.js +19 -0
  43. package/dist/alpha/utils/readConfigMenuItems.esm.js.map +1 -0
  44. package/dist/alpha.d.ts +1255 -0
  45. package/dist/alpha.esm.js +28 -0
  46. package/dist/alpha.esm.js.map +1 -0
  47. package/dist/components/HeaderDropdownComponent/HeaderDropdownComponent.esm.js +23 -15
  48. package/dist/components/HeaderDropdownComponent/HeaderDropdownComponent.esm.js.map +1 -1
  49. package/dist/components/HeaderDropdownComponent/MenuSection.esm.js +15 -3
  50. package/dist/components/HeaderDropdownComponent/MenuSection.esm.js.map +1 -1
  51. package/dist/components/HeaderIcon/HeaderIcon.esm.js +5 -1
  52. package/dist/components/HeaderIcon/HeaderIcon.esm.js.map +1 -1
  53. package/dist/components/HeaderIconButton/HeaderIconButton.esm.js +3 -5
  54. package/dist/components/HeaderIconButton/HeaderIconButton.esm.js.map +1 -1
  55. package/dist/components/LogoutButton/LogoutButton.esm.js +4 -2
  56. package/dist/components/LogoutButton/LogoutButton.esm.js.map +1 -1
  57. package/dist/components/MenuItemLink/MenuItemLink.esm.js.map +1 -1
  58. package/dist/defaultMountPoints/defaultMountPoints.esm.js +7 -10
  59. package/dist/defaultMountPoints/defaultMountPoints.esm.js.map +1 -1
  60. package/dist/hooks/useDropdownManager.esm.js +10 -5
  61. package/dist/hooks/useDropdownManager.esm.js.map +1 -1
  62. package/dist/index.d.ts +7 -66
  63. package/dist/index.esm.js.map +1 -1
  64. package/dist/plugin.esm.js +6 -7
  65. package/dist/plugin.esm.js.map +1 -1
  66. package/dist/translations/de.esm.js +8 -1
  67. package/dist/translations/de.esm.js.map +1 -1
  68. package/dist/translations/es.esm.js +8 -1
  69. package/dist/translations/es.esm.js.map +1 -1
  70. package/dist/types/index.d-CdKdPbQ2.d.ts +67 -0
  71. package/package.json +57 -37
@@ -0,0 +1,72 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { useMemo } from 'react';
3
+ import { createExtensionInput, createFrontendModule } from '@backstage/frontend-plugin-api';
4
+ import { AppRootWrapperBlueprint } from '@backstage/plugin-app-react';
5
+ import { useApi, configApiRef } from '@backstage/core-plugin-api';
6
+ import { GlobalHeaderProvider } from './GlobalHeaderContext.esm.js';
7
+ import { GlobalHeader } from '../components/GlobalHeader.esm.js';
8
+ import { globalHeaderComponentDataRef, globalHeaderMenuItemDataRef } from './dataRefs.esm.js';
9
+ import { readConfigMenuItems } from '../utils/readConfigMenuItems.esm.js';
10
+ import { readConfigComponents } from '../utils/readConfigComponents.esm.js';
11
+
12
+ function GlobalHeaderWrapper({
13
+ extensionComponents,
14
+ extensionMenuItems,
15
+ children
16
+ }) {
17
+ const configApi = useApi(configApiRef);
18
+ const configComponents = useMemo(
19
+ () => readConfigComponents(configApi),
20
+ [configApi]
21
+ );
22
+ const allComponents = useMemo(
23
+ () => [...extensionComponents, ...configComponents].sort(
24
+ (a, b) => (b.priority ?? 0) - (a.priority ?? 0)
25
+ ),
26
+ [extensionComponents, configComponents]
27
+ );
28
+ const configMenuItems = useMemo(
29
+ () => readConfigMenuItems(configApi),
30
+ [configApi]
31
+ );
32
+ const allMenuItems = useMemo(
33
+ () => [...extensionMenuItems, ...configMenuItems].sort(
34
+ (a, b) => (b.priority ?? 0) - (a.priority ?? 0)
35
+ ),
36
+ [extensionMenuItems, configMenuItems]
37
+ );
38
+ return /* @__PURE__ */ jsxs(GlobalHeaderProvider, { components: allComponents, menuItems: allMenuItems, children: [
39
+ /* @__PURE__ */ jsx(GlobalHeader, {}),
40
+ children
41
+ ] });
42
+ }
43
+ const globalHeaderExtension = AppRootWrapperBlueprint.makeWithOverrides({
44
+ name: "global-header",
45
+ inputs: {
46
+ components: createExtensionInput([globalHeaderComponentDataRef]),
47
+ menuItems: createExtensionInput([globalHeaderMenuItemDataRef])
48
+ },
49
+ factory(originalFactory, { inputs }) {
50
+ const extensionComponents = inputs.components.map((c) => c.get(globalHeaderComponentDataRef)).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
51
+ const extensionMenuItems = inputs.menuItems.map(
52
+ (m) => m.get(globalHeaderMenuItemDataRef)
53
+ );
54
+ return originalFactory({
55
+ component: ({ children }) => /* @__PURE__ */ jsx(
56
+ GlobalHeaderWrapper,
57
+ {
58
+ extensionComponents,
59
+ extensionMenuItems,
60
+ children
61
+ }
62
+ )
63
+ });
64
+ }
65
+ });
66
+ const globalHeaderModule = createFrontendModule({
67
+ pluginId: "app",
68
+ extensions: [globalHeaderExtension]
69
+ });
70
+
71
+ export { globalHeaderModule };
72
+ //# sourceMappingURL=globalHeaderModule.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalHeaderModule.esm.js","sources":["../../../src/alpha/extensions/globalHeaderModule.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useMemo } from 'react';\nimport type { PropsWithChildren } from 'react';\n\nimport {\n createExtensionInput,\n createFrontendModule,\n} from '@backstage/frontend-plugin-api';\nimport { AppRootWrapperBlueprint } from '@backstage/plugin-app-react';\nimport { configApiRef, useApi } from '@backstage/core-plugin-api';\n\nimport { GlobalHeaderProvider } from './GlobalHeaderContext';\nimport { GlobalHeader } from '../components/GlobalHeader';\nimport {\n globalHeaderComponentDataRef,\n globalHeaderMenuItemDataRef,\n} from './dataRefs';\nimport type {\n GlobalHeaderComponentData,\n GlobalHeaderMenuItemData,\n} from '../types';\nimport { readConfigMenuItems } from '../utils/readConfigMenuItems';\nimport { readConfigComponents } from '../utils/readConfigComponents';\n\nfunction GlobalHeaderWrapper({\n extensionComponents,\n extensionMenuItems,\n children,\n}: PropsWithChildren<{\n extensionComponents: GlobalHeaderComponentData[];\n extensionMenuItems: GlobalHeaderMenuItemData[];\n}>) {\n const configApi = useApi(configApiRef);\n const configComponents = useMemo(\n () => readConfigComponents(configApi),\n [configApi],\n );\n const allComponents = useMemo(\n () =>\n [...extensionComponents, ...configComponents].sort(\n (a, b) => (b.priority ?? 0) - (a.priority ?? 0),\n ),\n [extensionComponents, configComponents],\n );\n const configMenuItems = useMemo(\n () => readConfigMenuItems(configApi),\n [configApi],\n );\n const allMenuItems = useMemo(\n () =>\n [...extensionMenuItems, ...configMenuItems].sort(\n (a, b) => (b.priority ?? 0) - (a.priority ?? 0),\n ),\n [extensionMenuItems, configMenuItems],\n );\n return (\n <GlobalHeaderProvider components={allComponents} menuItems={allMenuItems}>\n <GlobalHeader />\n {children}\n </GlobalHeaderProvider>\n );\n}\n\n/**\n * Wrapper extension that collects header component and menu item extensions,\n * merges config-driven items from `globalHeader.components` and\n * `globalHeader.menuItems`, and renders them in a global header bar at the\n * top of the app.\n */\nconst globalHeaderExtension = AppRootWrapperBlueprint.makeWithOverrides({\n name: 'global-header',\n inputs: {\n components: createExtensionInput([globalHeaderComponentDataRef]),\n menuItems: createExtensionInput([globalHeaderMenuItemDataRef]),\n },\n factory(originalFactory, { inputs }) {\n const extensionComponents = inputs.components\n .map(c => c.get(globalHeaderComponentDataRef))\n .sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));\n\n const extensionMenuItems = inputs.menuItems.map(m =>\n m.get(globalHeaderMenuItemDataRef),\n );\n\n return originalFactory({\n component: ({ children }) => (\n <GlobalHeaderWrapper\n extensionComponents={extensionComponents}\n extensionMenuItems={extensionMenuItems}\n >\n {children}\n </GlobalHeaderWrapper>\n ),\n });\n },\n});\n\n/**\n * Frontend module that provides the global header system.\n * Registers a wrapper extension with input slots for toolbar components\n * and dropdown menu items.\n *\n * Uses `pluginId: 'app'` because the `wrappers` input on `app/root` is\n * marked `internal: true`, restricting attachments to extensions from the\n * `app` plugin.\n *\n * @alpha\n */\nexport const globalHeaderModule = createFrontendModule({\n pluginId: 'app',\n extensions: [globalHeaderExtension],\n});\n"],"names":[],"mappings":";;;;;;;;;;;AAuCA,SAAS,mBAAoB,CAAA;AAAA,EAC3B,mBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAGI,EAAA;AACF,EAAM,MAAA,SAAA,GAAY,OAAO,YAAY,CAAA;AACrC,EAAA,MAAM,gBAAmB,GAAA,OAAA;AAAA,IACvB,MAAM,qBAAqB,SAAS,CAAA;AAAA,IACpC,CAAC,SAAS;AAAA,GACZ;AACA,EAAA,MAAM,aAAgB,GAAA,OAAA;AAAA,IACpB,MACE,CAAC,GAAG,mBAAqB,EAAA,GAAG,gBAAgB,CAAE,CAAA,IAAA;AAAA,MAC5C,CAAC,CAAG,EAAA,CAAA,KAAA,CAAO,EAAE,QAAY,IAAA,CAAA,KAAM,EAAE,QAAY,IAAA,CAAA;AAAA,KAC/C;AAAA,IACF,CAAC,qBAAqB,gBAAgB;AAAA,GACxC;AACA,EAAA,MAAM,eAAkB,GAAA,OAAA;AAAA,IACtB,MAAM,oBAAoB,SAAS,CAAA;AAAA,IACnC,CAAC,SAAS;AAAA,GACZ;AACA,EAAA,MAAM,YAAe,GAAA,OAAA;AAAA,IACnB,MACE,CAAC,GAAG,kBAAoB,EAAA,GAAG,eAAe,CAAE,CAAA,IAAA;AAAA,MAC1C,CAAC,CAAG,EAAA,CAAA,KAAA,CAAO,EAAE,QAAY,IAAA,CAAA,KAAM,EAAE,QAAY,IAAA,CAAA;AAAA,KAC/C;AAAA,IACF,CAAC,oBAAoB,eAAe;AAAA,GACtC;AACA,EAAA,uBACG,IAAA,CAAA,oBAAA,EAAA,EAAqB,UAAY,EAAA,aAAA,EAAe,WAAW,YAC1D,EAAA,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,YAAa,EAAA,EAAA,CAAA;AAAA,IACb;AAAA,GACH,EAAA,CAAA;AAEJ;AAQA,MAAM,qBAAA,GAAwB,wBAAwB,iBAAkB,CAAA;AAAA,EACtE,IAAM,EAAA,eAAA;AAAA,EACN,MAAQ,EAAA;AAAA,IACN,UAAY,EAAA,oBAAA,CAAqB,CAAC,4BAA4B,CAAC,CAAA;AAAA,IAC/D,SAAW,EAAA,oBAAA,CAAqB,CAAC,2BAA2B,CAAC;AAAA,GAC/D;AAAA,EACA,OAAQ,CAAA,eAAA,EAAiB,EAAE,MAAA,EAAU,EAAA;AACnC,IAAA,MAAM,sBAAsB,MAAO,CAAA,UAAA,CAChC,IAAI,CAAK,CAAA,KAAA,CAAA,CAAE,IAAI,4BAA4B,CAAC,EAC5C,IAAK,CAAA,CAAC,GAAG,CAAO,KAAA,CAAA,CAAA,CAAE,YAAY,CAAM,KAAA,CAAA,CAAE,YAAY,CAAE,CAAA,CAAA;AAEvD,IAAM,MAAA,kBAAA,GAAqB,OAAO,SAAU,CAAA,GAAA;AAAA,MAAI,CAAA,CAAA,KAC9C,CAAE,CAAA,GAAA,CAAI,2BAA2B;AAAA,KACnC;AAEA,IAAA,OAAO,eAAgB,CAAA;AAAA,MACrB,SAAW,EAAA,CAAC,EAAE,QAAA,EACZ,qBAAA,GAAA;AAAA,QAAC,mBAAA;AAAA,QAAA;AAAA,UACC,mBAAA;AAAA,UACA,kBAAA;AAAA,UAEC;AAAA;AAAA;AACH,KAEH,CAAA;AAAA;AAEL,CAAC,CAAA;AAaM,MAAM,qBAAqB,oBAAqB,CAAA;AAAA,EACrD,QAAU,EAAA,KAAA;AAAA,EACV,UAAA,EAAY,CAAC,qBAAqB;AACpC,CAAC;;;;"}
@@ -0,0 +1,28 @@
1
+ import { createFrontendPlugin } from '@backstage/frontend-plugin-api';
2
+ import { companyLogoExtension, searchExtension, spacerExtension, selfServiceButtonExtension, starredDropdownExtension, applicationLauncherDropdownExtension, helpDropdownExtension, notificationButtonExtension, dividerExtension, profileDropdownExtension } from './defaults/toolbarExtensions.esm.js';
3
+ import { settingsMenuItemExtension, myProfileMenuItemExtension, logoutMenuItemExtension, supportButtonMenuItemExtension, appLauncherDevHubMenuItemExtension, appLauncherRhdhLocalMenuItemExtension } from './defaults/menuItemExtensions.esm.js';
4
+
5
+ const globalHeaderPlugin = createFrontendPlugin({
6
+ pluginId: "global-header",
7
+ extensions: [
8
+ companyLogoExtension,
9
+ searchExtension,
10
+ spacerExtension,
11
+ selfServiceButtonExtension,
12
+ starredDropdownExtension,
13
+ applicationLauncherDropdownExtension,
14
+ helpDropdownExtension,
15
+ notificationButtonExtension,
16
+ dividerExtension,
17
+ profileDropdownExtension,
18
+ settingsMenuItemExtension,
19
+ myProfileMenuItemExtension,
20
+ logoutMenuItemExtension,
21
+ supportButtonMenuItemExtension,
22
+ appLauncherDevHubMenuItemExtension,
23
+ appLauncherRhdhLocalMenuItemExtension
24
+ ]
25
+ });
26
+
27
+ export { globalHeaderPlugin as default };
28
+ //# sourceMappingURL=plugin.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.esm.js","sources":["../../src/alpha/plugin.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFrontendPlugin } from '@backstage/frontend-plugin-api';\n\nimport {\n companyLogoExtension,\n searchExtension,\n spacerExtension,\n selfServiceButtonExtension,\n starredDropdownExtension,\n applicationLauncherDropdownExtension,\n helpDropdownExtension,\n notificationButtonExtension,\n dividerExtension,\n profileDropdownExtension,\n settingsMenuItemExtension,\n myProfileMenuItemExtension,\n logoutMenuItemExtension,\n supportButtonMenuItemExtension,\n appLauncherDevHubMenuItemExtension,\n appLauncherRhdhLocalMenuItemExtension,\n} from './defaults';\n\n/**\n * Plugin providing the default global header toolbar items and\n * dropdown menu items.\n *\n * @alpha\n */\nconst globalHeaderPlugin = createFrontendPlugin({\n pluginId: 'global-header',\n extensions: [\n companyLogoExtension,\n searchExtension,\n spacerExtension,\n selfServiceButtonExtension,\n starredDropdownExtension,\n applicationLauncherDropdownExtension,\n helpDropdownExtension,\n notificationButtonExtension,\n dividerExtension,\n profileDropdownExtension,\n settingsMenuItemExtension,\n myProfileMenuItemExtension,\n logoutMenuItemExtension,\n supportButtonMenuItemExtension,\n appLauncherDevHubMenuItemExtension,\n appLauncherRhdhLocalMenuItemExtension,\n ],\n});\n\nexport default globalHeaderPlugin;\n"],"names":[],"mappings":";;;;AA2CA,MAAM,qBAAqB,oBAAqB,CAAA;AAAA,EAC9C,QAAU,EAAA,eAAA;AAAA,EACV,UAAY,EAAA;AAAA,IACV,oBAAA;AAAA,IACA,eAAA;AAAA,IACA,eAAA;AAAA,IACA,0BAAA;AAAA,IACA,wBAAA;AAAA,IACA,oCAAA;AAAA,IACA,qBAAA;AAAA,IACA,2BAAA;AAAA,IACA,gBAAA;AAAA,IACA,wBAAA;AAAA,IACA,yBAAA;AAAA,IACA,0BAAA;AAAA,IACA,uBAAA;AAAA,IACA,8BAAA;AAAA,IACA,kCAAA;AAAA,IACA;AAAA;AAEJ,CAAC;;;;"}
@@ -0,0 +1,52 @@
1
+ import { MenuItemLink } from '../../components/MenuItemLink/MenuItemLink.esm.js';
2
+
3
+ function groupBySection(items) {
4
+ const groups = /* @__PURE__ */ new Map();
5
+ for (const item of items) {
6
+ const key = item.sectionLabel ?? "";
7
+ let group = groups.get(key);
8
+ if (!group) {
9
+ group = {
10
+ sectionLabel: key,
11
+ sectionLink: item.sectionLink,
12
+ sectionLinkLabel: item.sectionLinkLabel,
13
+ items: [],
14
+ priority: item.priority ?? 0
15
+ };
16
+ groups.set(key, group);
17
+ }
18
+ group.priority = Math.max(group.priority, item.priority ?? 0);
19
+ group.items.push({
20
+ Component: item.component ?? MenuItemLink,
21
+ label: item.title ?? "",
22
+ labelKey: item.titleKey,
23
+ icon: item.icon,
24
+ subLabel: item.subTitle,
25
+ subLabelKey: item.subTitleKey,
26
+ link: item.link,
27
+ onClick: item.onClick
28
+ });
29
+ }
30
+ return Array.from(groups.values());
31
+ }
32
+ function buildDropdownEntries(menuItems) {
33
+ const custom = menuItems.filter((i) => i.type === "component");
34
+ const data = menuItems.filter((i) => i.type === "data");
35
+ const sections = groupBySection(data);
36
+ const entries = [
37
+ ...custom.map((item) => ({
38
+ type: "component",
39
+ item,
40
+ priority: item.priority ?? 0
41
+ })),
42
+ ...sections.map((group) => ({
43
+ type: "section",
44
+ group,
45
+ priority: group.priority
46
+ }))
47
+ ];
48
+ return entries.sort((a, b) => b.priority - a.priority);
49
+ }
50
+
51
+ export { buildDropdownEntries, groupBySection };
52
+ //# sourceMappingURL=menuItemGrouping.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menuItemGrouping.esm.js","sources":["../../../src/alpha/utils/menuItemGrouping.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { MenuItemLink } from '../../components/MenuItemLink/MenuItemLink';\nimport type { GlobalHeaderMenuItemData } from '../types';\nimport type { MenuItemConfig } from '../../components/HeaderDropdownComponent/MenuSection';\n\n/** A group of data-driven menu items sharing the same `sectionLabel` value. */\nexport interface SectionGroup {\n sectionLabel: string;\n sectionLink?: string;\n sectionLinkLabel?: string;\n items: MenuItemConfig[];\n priority: number;\n}\n\n/**\n * Groups data-driven menu items by their `sectionLabel` string.\n * Items without a `sectionLabel` default to `''` (rendered without a header).\n * Section metadata (`sectionLink`, `sectionLinkLabel`) is taken from\n * the first item encountered in each group.\n */\nexport function groupBySection(\n items: GlobalHeaderMenuItemData[],\n): SectionGroup[] {\n const groups = new Map<string, SectionGroup>();\n for (const item of items) {\n const key = item.sectionLabel ?? '';\n let group = groups.get(key);\n if (!group) {\n group = {\n sectionLabel: key,\n sectionLink: item.sectionLink,\n sectionLinkLabel: item.sectionLinkLabel,\n items: [],\n priority: item.priority ?? 0,\n };\n groups.set(key, group);\n }\n group.priority = Math.max(group.priority, item.priority ?? 0);\n group.items.push({\n Component: (item.component ??\n MenuItemLink) as MenuItemConfig['Component'],\n label: item.title ?? '',\n labelKey: item.titleKey,\n icon: item.icon,\n subLabel: item.subTitle,\n subLabelKey: item.subTitleKey,\n link: item.link,\n onClick: item.onClick,\n });\n }\n return Array.from(groups.values());\n}\n\n/** A single element in the priority-sorted dropdown content list. */\nexport type DropdownEntry =\n | { type: 'component'; item: GlobalHeaderMenuItemData; priority: number }\n | { type: 'section'; group: SectionGroup; priority: number };\n\n/**\n * Builds the final dropdown entry list by splitting items into standalone\n * components and data-driven section groups, then sorting by priority.\n */\nexport function buildDropdownEntries(\n menuItems: GlobalHeaderMenuItemData[],\n): DropdownEntry[] {\n const custom = menuItems.filter(i => i.type === 'component');\n const data = menuItems.filter(i => i.type === 'data');\n const sections = groupBySection(data);\n\n const entries: DropdownEntry[] = [\n ...custom.map(item => ({\n type: 'component' as const,\n item,\n priority: item.priority ?? 0,\n })),\n ...sections.map(group => ({\n type: 'section' as const,\n group,\n priority: group.priority,\n })),\n ];\n\n return entries.sort((a, b) => b.priority - a.priority);\n}\n"],"names":[],"mappings":";;AAmCO,SAAS,eACd,KACgB,EAAA;AAChB,EAAM,MAAA,MAAA,uBAAa,GAA0B,EAAA;AAC7C,EAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,IAAM,MAAA,GAAA,GAAM,KAAK,YAAgB,IAAA,EAAA;AACjC,IAAI,IAAA,KAAA,GAAQ,MAAO,CAAA,GAAA,CAAI,GAAG,CAAA;AAC1B,IAAA,IAAI,CAAC,KAAO,EAAA;AACV,MAAQ,KAAA,GAAA;AAAA,QACN,YAAc,EAAA,GAAA;AAAA,QACd,aAAa,IAAK,CAAA,WAAA;AAAA,QAClB,kBAAkB,IAAK,CAAA,gBAAA;AAAA,QACvB,OAAO,EAAC;AAAA,QACR,QAAA,EAAU,KAAK,QAAY,IAAA;AAAA,OAC7B;AACA,MAAO,MAAA,CAAA,GAAA,CAAI,KAAK,KAAK,CAAA;AAAA;AAEvB,IAAA,KAAA,CAAM,WAAW,IAAK,CAAA,GAAA,CAAI,MAAM,QAAU,EAAA,IAAA,CAAK,YAAY,CAAC,CAAA;AAC5D,IAAA,KAAA,CAAM,MAAM,IAAK,CAAA;AAAA,MACf,SAAA,EAAY,KAAK,SACf,IAAA,YAAA;AAAA,MACF,KAAA,EAAO,KAAK,KAAS,IAAA,EAAA;AAAA,MACrB,UAAU,IAAK,CAAA,QAAA;AAAA,MACf,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,UAAU,IAAK,CAAA,QAAA;AAAA,MACf,aAAa,IAAK,CAAA,WAAA;AAAA,MAClB,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,SAAS,IAAK,CAAA;AAAA,KACf,CAAA;AAAA;AAEH,EAAA,OAAO,KAAM,CAAA,IAAA,CAAK,MAAO,CAAA,MAAA,EAAQ,CAAA;AACnC;AAWO,SAAS,qBACd,SACiB,EAAA;AACjB,EAAA,MAAM,SAAS,SAAU,CAAA,MAAA,CAAO,CAAK,CAAA,KAAA,CAAA,CAAE,SAAS,WAAW,CAAA;AAC3D,EAAA,MAAM,OAAO,SAAU,CAAA,MAAA,CAAO,CAAK,CAAA,KAAA,CAAA,CAAE,SAAS,MAAM,CAAA;AACpD,EAAM,MAAA,QAAA,GAAW,eAAe,IAAI,CAAA;AAEpC,EAAA,MAAM,OAA2B,GAAA;AAAA,IAC/B,GAAG,MAAO,CAAA,GAAA,CAAI,CAAS,IAAA,MAAA;AAAA,MACrB,IAAM,EAAA,WAAA;AAAA,MACN,IAAA;AAAA,MACA,QAAA,EAAU,KAAK,QAAY,IAAA;AAAA,KAC3B,CAAA,CAAA;AAAA,IACF,GAAG,QAAS,CAAA,GAAA,CAAI,CAAU,KAAA,MAAA;AAAA,MACxB,IAAM,EAAA,SAAA;AAAA,MACN,KAAA;AAAA,MACA,UAAU,KAAM,CAAA;AAAA,KAChB,CAAA;AAAA,GACJ;AAEA,EAAO,OAAA,OAAA,CAAQ,KAAK,CAAC,CAAA,EAAG,MAAM,CAAE,CAAA,QAAA,GAAW,EAAE,QAAQ,CAAA;AACvD;;;;"}
@@ -0,0 +1,29 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { HeaderIconButton } from '../../components/HeaderIconButton/HeaderIconButton.esm.js';
3
+
4
+ function readConfigComponents(configApi) {
5
+ const items = configApi.getOptionalConfigArray("globalHeader.components");
6
+ if (!items) return [];
7
+ return items.map((item) => {
8
+ const title = item.getString("title");
9
+ const titleKey = item.getOptionalString("titleKey");
10
+ const icon = item.getString("icon");
11
+ const link = item.getString("link");
12
+ const tooltip = item.getOptionalString("tooltip");
13
+ const priority = item.getOptionalNumber("priority");
14
+ const ConfigComponent = () => /* @__PURE__ */ jsx(
15
+ HeaderIconButton,
16
+ {
17
+ title,
18
+ titleKey,
19
+ icon,
20
+ tooltip,
21
+ to: link
22
+ }
23
+ );
24
+ return { component: ConfigComponent, priority };
25
+ });
26
+ }
27
+
28
+ export { readConfigComponents };
29
+ //# sourceMappingURL=readConfigComponents.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readConfigComponents.esm.js","sources":["../../../src/alpha/utils/readConfigComponents.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Config } from '@backstage/config';\n\nimport { HeaderIconButton } from '../../components/HeaderIconButton/HeaderIconButton';\nimport type { GlobalHeaderComponentData } from '../types';\n\n/**\n * Reads `globalHeader.components` from the app config and maps\n * each entry into a {@link GlobalHeaderComponentData}.\n *\n * Config-driven components are always rendered as a `HeaderIconButton`\n * (icon + link), matching the data-driven tier of\n * `GlobalHeaderComponentBlueprint`.\n */\nexport function readConfigComponents(\n configApi: Config,\n): GlobalHeaderComponentData[] {\n const items = configApi.getOptionalConfigArray('globalHeader.components');\n if (!items) return [];\n\n return items.map(item => {\n const title = item.getString('title');\n const titleKey = item.getOptionalString('titleKey');\n const icon = item.getString('icon');\n const link = item.getString('link');\n const tooltip = item.getOptionalString('tooltip');\n const priority = item.getOptionalNumber('priority');\n\n const ConfigComponent = () => (\n <HeaderIconButton\n title={title}\n titleKey={titleKey}\n icon={icon}\n tooltip={tooltip}\n to={link}\n />\n );\n\n return { component: ConfigComponent, priority };\n });\n}\n"],"names":[],"mappings":";;;AA6BO,SAAS,qBACd,SAC6B,EAAA;AAC7B,EAAM,MAAA,KAAA,GAAQ,SAAU,CAAA,sBAAA,CAAuB,yBAAyB,CAAA;AACxE,EAAI,IAAA,CAAC,KAAO,EAAA,OAAO,EAAC;AAEpB,EAAO,OAAA,KAAA,CAAM,IAAI,CAAQ,IAAA,KAAA;AACvB,IAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,SAAA,CAAU,OAAO,CAAA;AACpC,IAAM,MAAA,QAAA,GAAW,IAAK,CAAA,iBAAA,CAAkB,UAAU,CAAA;AAClD,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,SAAA,CAAU,MAAM,CAAA;AAClC,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,SAAA,CAAU,MAAM,CAAA;AAClC,IAAM,MAAA,OAAA,GAAU,IAAK,CAAA,iBAAA,CAAkB,SAAS,CAAA;AAChD,IAAM,MAAA,QAAA,GAAW,IAAK,CAAA,iBAAA,CAAkB,UAAU,CAAA;AAElD,IAAA,MAAM,kBAAkB,sBACtB,GAAA;AAAA,MAAC,gBAAA;AAAA,MAAA;AAAA,QACC,KAAA;AAAA,QACA,QAAA;AAAA,QACA,IAAA;AAAA,QACA,OAAA;AAAA,QACA,EAAI,EAAA;AAAA;AAAA,KACN;AAGF,IAAO,OAAA,EAAE,SAAW,EAAA,eAAA,EAAiB,QAAS,EAAA;AAAA,GAC/C,CAAA;AACH;;;;"}
@@ -0,0 +1,19 @@
1
+ function readConfigMenuItems(configApi) {
2
+ const items = configApi.getOptionalConfigArray("globalHeader.menuItems");
3
+ if (!items) return [];
4
+ return items.map((item) => ({
5
+ target: item.getString("target"),
6
+ type: "data",
7
+ title: item.getString("title"),
8
+ titleKey: item.getOptionalString("titleKey"),
9
+ icon: item.getOptionalString("icon"),
10
+ link: item.getString("link"),
11
+ sectionLabel: item.getOptionalString("sectionLabel"),
12
+ sectionLink: item.getOptionalString("sectionLink"),
13
+ sectionLinkLabel: item.getOptionalString("sectionLinkLabel"),
14
+ priority: item.getOptionalNumber("priority")
15
+ }));
16
+ }
17
+
18
+ export { readConfigMenuItems };
19
+ //# sourceMappingURL=readConfigMenuItems.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readConfigMenuItems.esm.js","sources":["../../../src/alpha/utils/readConfigMenuItems.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Config } from '@backstage/config';\n\nimport type { GlobalHeaderMenuItemData } from '../types';\n\n/**\n * Reads `globalHeader.menuItems` from the app config and maps\n * each entry into a {@link GlobalHeaderMenuItemData}.\n * Config-driven items are always `type: 'data'` (the default).\n */\nexport function readConfigMenuItems(\n configApi: Config,\n): GlobalHeaderMenuItemData[] {\n const items = configApi.getOptionalConfigArray('globalHeader.menuItems');\n if (!items) return [];\n\n return items.map(item => ({\n target: item.getString('target'),\n type: 'data' as const,\n title: item.getString('title'),\n titleKey: item.getOptionalString('titleKey'),\n icon: item.getOptionalString('icon'),\n link: item.getString('link'),\n sectionLabel: item.getOptionalString('sectionLabel'),\n sectionLink: item.getOptionalString('sectionLink'),\n sectionLinkLabel: item.getOptionalString('sectionLinkLabel'),\n priority: item.getOptionalNumber('priority'),\n }));\n}\n"],"names":[],"mappings":"AAyBO,SAAS,oBACd,SAC4B,EAAA;AAC5B,EAAM,MAAA,KAAA,GAAQ,SAAU,CAAA,sBAAA,CAAuB,wBAAwB,CAAA;AACvE,EAAI,IAAA,CAAC,KAAO,EAAA,OAAO,EAAC;AAEpB,EAAO,OAAA,KAAA,CAAM,IAAI,CAAS,IAAA,MAAA;AAAA,IACxB,MAAA,EAAQ,IAAK,CAAA,SAAA,CAAU,QAAQ,CAAA;AAAA,IAC/B,IAAM,EAAA,MAAA;AAAA,IACN,KAAA,EAAO,IAAK,CAAA,SAAA,CAAU,OAAO,CAAA;AAAA,IAC7B,QAAA,EAAU,IAAK,CAAA,iBAAA,CAAkB,UAAU,CAAA;AAAA,IAC3C,IAAA,EAAM,IAAK,CAAA,iBAAA,CAAkB,MAAM,CAAA;AAAA,IACnC,IAAA,EAAM,IAAK,CAAA,SAAA,CAAU,MAAM,CAAA;AAAA,IAC3B,YAAA,EAAc,IAAK,CAAA,iBAAA,CAAkB,cAAc,CAAA;AAAA,IACnD,WAAA,EAAa,IAAK,CAAA,iBAAA,CAAkB,aAAa,CAAA;AAAA,IACjD,gBAAA,EAAkB,IAAK,CAAA,iBAAA,CAAkB,kBAAkB,CAAA;AAAA,IAC3D,QAAA,EAAU,IAAK,CAAA,iBAAA,CAAkB,UAAU;AAAA,GAC3C,CAAA,CAAA;AACJ;;;;"}