@red-hat-developer-hub/backstage-plugin-global-header 0.0.3 → 0.0.4
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.
- package/CHANGELOG.md +7 -0
- package/app-config.dynamic.yaml +62 -1
- package/dist/components/GlobalHeader.esm.js +75 -61
- package/dist/components/GlobalHeader.esm.js.map +1 -1
- package/dist/components/HeaderButtonComponent/HeaderButton.esm.js +17 -0
- package/dist/components/HeaderButtonComponent/HeaderButton.esm.js.map +1 -0
- package/dist/components/HeaderButtonComponent/LogoutButton.esm.js +15 -0
- package/dist/components/HeaderButtonComponent/LogoutButton.esm.js.map +1 -0
- package/dist/components/HeaderDropdownComponent/CreateDropdown.esm.js +61 -56
- package/dist/components/HeaderDropdownComponent/CreateDropdown.esm.js.map +1 -1
- package/dist/components/HeaderDropdownComponent/HeaderDropdownComponent.esm.js +2 -49
- package/dist/components/HeaderDropdownComponent/HeaderDropdownComponent.esm.js.map +1 -1
- package/dist/components/HeaderDropdownComponent/MenuSection.esm.js +11 -22
- package/dist/components/HeaderDropdownComponent/MenuSection.esm.js.map +1 -1
- package/dist/components/HeaderDropdownComponent/ProfileDropdown.esm.js +36 -42
- package/dist/components/HeaderDropdownComponent/ProfileDropdown.esm.js.map +1 -1
- package/dist/components/HeaderDropdownComponent/RegisterAComponentSection.esm.js +29 -0
- package/dist/components/HeaderDropdownComponent/RegisterAComponentSection.esm.js.map +1 -0
- package/dist/components/HeaderDropdownComponent/SoftwareTemplatesSection.esm.js +23 -0
- package/dist/components/HeaderDropdownComponent/SoftwareTemplatesSection.esm.js.map +1 -0
- package/dist/components/HeaderIconButtonComponent/HeaderIcon.esm.js +33 -0
- package/dist/components/HeaderIconButtonComponent/HeaderIcon.esm.js.map +1 -0
- package/dist/components/HeaderIconButtonComponent/HeaderIconButton.esm.js +25 -0
- package/dist/components/HeaderIconButtonComponent/HeaderIconButton.esm.js.map +1 -0
- package/dist/components/HeaderLinkComponent/HeaderItemContent.esm.js +19 -0
- package/dist/components/HeaderLinkComponent/HeaderItemContent.esm.js.map +1 -0
- package/dist/components/HeaderLinkComponent/HeaderLink.esm.js +29 -0
- package/dist/components/HeaderLinkComponent/HeaderLink.esm.js.map +1 -0
- package/dist/components/SearchComponent/SearchBar.esm.js +1 -1
- package/dist/components/SearchComponent/SearchBar.esm.js.map +1 -1
- package/dist/hooks/useCreateDropdownMountPoints.esm.js +10 -0
- package/dist/hooks/useCreateDropdownMountPoints.esm.js.map +1 -0
- package/dist/hooks/useGlobalHeaderMountPoints.esm.js +10 -0
- package/dist/hooks/useGlobalHeaderMountPoints.esm.js.map +1 -0
- package/dist/hooks/useProfileDropdownMountPoints.esm.js +10 -0
- package/dist/hooks/useProfileDropdownMountPoints.esm.js.map +1 -0
- package/dist/index.d.ts +129 -5
- package/dist/index.esm.js +1 -1
- package/dist/plugin.esm.js +75 -1
- package/dist/plugin.esm.js.map +1 -1
- package/dist/types.esm.js +17 -0
- package/dist/types.esm.js.map +1 -0
- package/package.json +26 -16
- package/dist/components/HeaderDropdownComponent/MenuItemContent.esm.js +0 -15
- package/dist/components/HeaderDropdownComponent/MenuItemContent.esm.js.map +0 -1
- package/dist/components/HeaderIconButton/HeaderIconButton.esm.js +0 -22
- package/dist/components/HeaderIconButton/HeaderIconButton.esm.js.map +0 -1
- package/dist/components/HeaderIconButton/SmallIconWrapper.esm.js +0 -11
- package/dist/components/HeaderIconButton/SmallIconWrapper.esm.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @red-hat-developer-hub/backstage-plugin-global-header
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a07a84a: Update dependencies to Backstage 1.35.0
|
|
8
|
+
- 02cd530: add new mountpoints for the search, create dropdown, profile dropdown, software templates, register a component, logout button, header link and header icon
|
|
9
|
+
|
|
3
10
|
## 0.0.3
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/app-config.dynamic.yaml
CHANGED
|
@@ -7,4 +7,65 @@ dynamicPlugins:
|
|
|
7
7
|
importName: GlobalHeader
|
|
8
8
|
config:
|
|
9
9
|
layout:
|
|
10
|
-
position: above-main-content
|
|
10
|
+
position: above-main-content # above-main-content | below-main-content
|
|
11
|
+
- mountPoint: global.header/component
|
|
12
|
+
importName: SearchComponent
|
|
13
|
+
config:
|
|
14
|
+
type: search
|
|
15
|
+
slot: header-start
|
|
16
|
+
priority: 100
|
|
17
|
+
- mountPoint: global.header/component
|
|
18
|
+
importName: CreateDropdown
|
|
19
|
+
config:
|
|
20
|
+
type: dropdown_button
|
|
21
|
+
key: create
|
|
22
|
+
slot: header-start
|
|
23
|
+
priority: 90
|
|
24
|
+
- mountPoint: global.header/create
|
|
25
|
+
importName: SoftwareTemplatesSection
|
|
26
|
+
config:
|
|
27
|
+
type: list
|
|
28
|
+
priority: 10
|
|
29
|
+
- mountPoint: global.header/create
|
|
30
|
+
importName: RegisterAComponentSection
|
|
31
|
+
config:
|
|
32
|
+
type: link
|
|
33
|
+
- mountPoint: global.header/component
|
|
34
|
+
importName: HeaderIconButton
|
|
35
|
+
config:
|
|
36
|
+
type: icon_button
|
|
37
|
+
slot: header-start
|
|
38
|
+
priority: 80
|
|
39
|
+
props:
|
|
40
|
+
icon: support
|
|
41
|
+
tooltip: 'Support'
|
|
42
|
+
- mountPoint: global.header/component
|
|
43
|
+
importName: HeaderIconButton
|
|
44
|
+
config:
|
|
45
|
+
type: icon_button
|
|
46
|
+
slot: header-start
|
|
47
|
+
priority: 70
|
|
48
|
+
props:
|
|
49
|
+
icon: notifications
|
|
50
|
+
tooltip: 'Notifications'
|
|
51
|
+
- mountPoint: global.header/component
|
|
52
|
+
importName: ProfileDropdown
|
|
53
|
+
config:
|
|
54
|
+
type: dropdown_button
|
|
55
|
+
key: profile
|
|
56
|
+
slot: header-end
|
|
57
|
+
priority: 0
|
|
58
|
+
- mountPoint: global.header/profile
|
|
59
|
+
importName: HeaderLink
|
|
60
|
+
config:
|
|
61
|
+
type: link
|
|
62
|
+
priority: 10
|
|
63
|
+
props:
|
|
64
|
+
title: Settings
|
|
65
|
+
link: /settings
|
|
66
|
+
icon: manageAccounts
|
|
67
|
+
- mountPoint: global.header/profile
|
|
68
|
+
importName: LogoutButton
|
|
69
|
+
config:
|
|
70
|
+
type: logout
|
|
71
|
+
priority: 0
|
|
@@ -1,51 +1,84 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
2
|
import AppBar from '@mui/material/AppBar';
|
|
3
3
|
import Toolbar from '@mui/material/Toolbar';
|
|
4
|
-
import { SearchComponent } from './SearchComponent/SearchComponent.esm.js';
|
|
5
|
-
import { HeaderIconButton } from './HeaderIconButton/HeaderIconButton.esm.js';
|
|
6
|
-
import CreateDropdown from './HeaderDropdownComponent/CreateDropdown.esm.js';
|
|
7
|
-
import ProfileDropdown from './HeaderDropdownComponent/ProfileDropdown.esm.js';
|
|
8
4
|
import Divider from '@mui/material/Divider';
|
|
9
|
-
import HelpOutlineOutlinedIcon from '@mui/icons-material/HelpOutlineRounded';
|
|
10
|
-
import NotificationsOutlinedIcon from '@mui/icons-material/NotificationsOutlined';
|
|
11
5
|
import { useDropdownManager } from '../hooks/useDropdownManager.esm.js';
|
|
6
|
+
import { useGlobalHeaderMountPoints } from '../hooks/useGlobalHeaderMountPoints.esm.js';
|
|
7
|
+
import { Slot, ComponentType } from '../types.esm.js';
|
|
8
|
+
import { ErrorBoundary } from '@backstage/core-components';
|
|
9
|
+
import { useApi, configApiRef } from '@backstage/core-plugin-api';
|
|
12
10
|
|
|
13
|
-
const iconButtons = [
|
|
14
|
-
{
|
|
15
|
-
key: "help",
|
|
16
|
-
Icon: HelpOutlineOutlinedIcon,
|
|
17
|
-
onClick: () => {
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
key: "notification",
|
|
22
|
-
Icon: NotificationsOutlinedIcon,
|
|
23
|
-
onClick: () => {
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
];
|
|
27
11
|
const GlobalHeader = () => {
|
|
12
|
+
const config = useApi(configApiRef);
|
|
13
|
+
const frontendConfig = config.getOptionalConfig("dynamicPlugins.frontend");
|
|
14
|
+
const frontendData = frontendConfig?.get();
|
|
15
|
+
const allGlobalHeaderMountPoints = useGlobalHeaderMountPoints();
|
|
16
|
+
const filteredAndSortedGlobalHeaderComponents = useMemo(() => {
|
|
17
|
+
if (!allGlobalHeaderMountPoints) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const filteredAndSorted = allGlobalHeaderMountPoints.filter(
|
|
21
|
+
(component) => (component.config?.priority ?? 0) > -1
|
|
22
|
+
);
|
|
23
|
+
filteredAndSorted.sort(
|
|
24
|
+
(a, b) => (b.config?.priority ?? 0) - (a.config?.priority ?? 0)
|
|
25
|
+
);
|
|
26
|
+
return filteredAndSorted;
|
|
27
|
+
}, [allGlobalHeaderMountPoints]);
|
|
28
|
+
const globalHeaderStartComponentsMountPoints = filteredAndSortedGlobalHeaderComponents.filter(
|
|
29
|
+
(component) => component.config?.slot === Slot.HEADER_START
|
|
30
|
+
);
|
|
31
|
+
const globalHeaderEndComponentsMountPoints = filteredAndSortedGlobalHeaderComponents.filter(
|
|
32
|
+
(component) => component.config?.slot === Slot.HEADER_END
|
|
33
|
+
);
|
|
28
34
|
const { menuStates, handleOpen, handleClose } = useDropdownManager();
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
const getDropdownButtonProps = (key) => ({
|
|
36
|
+
handleMenu: handleOpen(key),
|
|
37
|
+
anchorEl: menuStates[key],
|
|
38
|
+
setAnchorEl: handleClose(key)
|
|
39
|
+
});
|
|
40
|
+
const getIconButtonProps = (props) => ({
|
|
41
|
+
icon: props.icon ?? "",
|
|
42
|
+
tooltip: props.tooltip ?? "",
|
|
43
|
+
to: props.to ?? ""
|
|
44
|
+
});
|
|
45
|
+
const renderComponents = (mountPoints) => mountPoints.map((mp, index) => {
|
|
46
|
+
let displayHeaderIcon = false;
|
|
47
|
+
if (frontendData) {
|
|
48
|
+
for (const pluginData of Object.values(frontendData)) {
|
|
49
|
+
const dynamicRoutes = pluginData.dynamicRoutes ?? [];
|
|
50
|
+
if (dynamicRoutes.some(
|
|
51
|
+
(route) => route.path === mp.config?.props?.to
|
|
52
|
+
)) {
|
|
53
|
+
displayHeaderIcon = true;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
46
56
|
}
|
|
47
57
|
}
|
|
48
|
-
|
|
58
|
+
switch (mp.config?.type) {
|
|
59
|
+
case ComponentType.SEARCH:
|
|
60
|
+
return /* @__PURE__ */ React.createElement(ErrorBoundary, null, /* @__PURE__ */ React.createElement(mp.Component, { key: index }));
|
|
61
|
+
case ComponentType.DROPDOWN_BUTTON:
|
|
62
|
+
return /* @__PURE__ */ React.createElement(ErrorBoundary, null, /* @__PURE__ */ React.createElement(
|
|
63
|
+
mp.Component,
|
|
64
|
+
{
|
|
65
|
+
key: index,
|
|
66
|
+
...getDropdownButtonProps(mp.config?.key ?? index.toString()),
|
|
67
|
+
...mp.config?.props
|
|
68
|
+
}
|
|
69
|
+
));
|
|
70
|
+
case ComponentType.ICON_BUTTON:
|
|
71
|
+
return /* @__PURE__ */ React.createElement(ErrorBoundary, null, displayHeaderIcon && /* @__PURE__ */ React.createElement(
|
|
72
|
+
mp.Component,
|
|
73
|
+
{
|
|
74
|
+
key: index,
|
|
75
|
+
...getIconButtonProps(mp.config?.props ?? {})
|
|
76
|
+
}
|
|
77
|
+
));
|
|
78
|
+
default:
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
49
82
|
return /* @__PURE__ */ React.createElement(
|
|
50
83
|
AppBar,
|
|
51
84
|
{
|
|
@@ -53,33 +86,14 @@ const GlobalHeader = () => {
|
|
|
53
86
|
component: "nav",
|
|
54
87
|
sx: { backgroundColor: "#212427" }
|
|
55
88
|
},
|
|
56
|
-
/* @__PURE__ */ React.createElement(Toolbar, null,
|
|
57
|
-
CreateDropdown,
|
|
58
|
-
{
|
|
59
|
-
key: dropdownConfigs[0].key,
|
|
60
|
-
...dropdownConfigs[0].buttonProps
|
|
61
|
-
}
|
|
62
|
-
), iconButtons.map(({ key, Icon, onClick }) => /* @__PURE__ */ React.createElement(
|
|
63
|
-
HeaderIconButton,
|
|
64
|
-
{
|
|
65
|
-
key: `header-icon-button-${key}`,
|
|
66
|
-
Icon,
|
|
67
|
-
onClick
|
|
68
|
-
}
|
|
69
|
-
)), /* @__PURE__ */ React.createElement(
|
|
89
|
+
/* @__PURE__ */ React.createElement(Toolbar, null, renderComponents(globalHeaderStartComponentsMountPoints), globalHeaderStartComponentsMountPoints.length > 0 && globalHeaderEndComponentsMountPoints.length > 0 && /* @__PURE__ */ React.createElement(
|
|
70
90
|
Divider,
|
|
71
91
|
{
|
|
72
92
|
orientation: "vertical",
|
|
73
93
|
flexItem: true,
|
|
74
|
-
sx: { borderColor: "#
|
|
75
|
-
}
|
|
76
|
-
), /* @__PURE__ */ React.createElement(
|
|
77
|
-
ProfileDropdown,
|
|
78
|
-
{
|
|
79
|
-
key: dropdownConfigs[1].key,
|
|
80
|
-
...dropdownConfigs[1].buttonProps
|
|
94
|
+
sx: { borderColor: "#4F5255", marginX: 1 }
|
|
81
95
|
}
|
|
82
|
-
))
|
|
96
|
+
), renderComponents(globalHeaderEndComponentsMountPoints))
|
|
83
97
|
);
|
|
84
98
|
};
|
|
85
99
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalHeader.esm.js","sources":["../../src/components/GlobalHeader.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 React from 'react';\nimport AppBar from '@mui/material/AppBar';\nimport Toolbar from '@mui/material/Toolbar';\nimport
|
|
1
|
+
{"version":3,"file":"GlobalHeader.esm.js","sources":["../../src/components/GlobalHeader.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 React, { useMemo } from 'react';\nimport AppBar from '@mui/material/AppBar';\nimport Toolbar from '@mui/material/Toolbar';\nimport Divider from '@mui/material/Divider';\nimport { useDropdownManager } from '../hooks';\nimport { useGlobalHeaderMountPoints } from '../hooks/useGlobalHeaderMountPoints';\nimport { ComponentType, GlobalHeaderComponentMountPoint, Slot } from '../types';\nimport { ErrorBoundary } from '@backstage/core-components';\nimport { configApiRef, useApi } from '@backstage/core-plugin-api';\n\nexport const GlobalHeader = () => {\n const config = useApi(configApiRef);\n const frontendConfig = config.getOptionalConfig('dynamicPlugins.frontend');\n const frontendData = frontendConfig?.get();\n\n const allGlobalHeaderMountPoints = useGlobalHeaderMountPoints();\n\n const filteredAndSortedGlobalHeaderComponents = useMemo(() => {\n if (!allGlobalHeaderMountPoints) {\n return [];\n }\n\n const filteredAndSorted = allGlobalHeaderMountPoints.filter(\n component => (component.config?.priority ?? 0) > -1,\n );\n\n filteredAndSorted.sort(\n (a, b) => (b.config?.priority ?? 0) - (a.config?.priority ?? 0),\n );\n\n return filteredAndSorted;\n }, [allGlobalHeaderMountPoints]);\n\n const globalHeaderStartComponentsMountPoints =\n filteredAndSortedGlobalHeaderComponents.filter(\n component => component.config?.slot === Slot.HEADER_START,\n );\n\n const globalHeaderEndComponentsMountPoints =\n filteredAndSortedGlobalHeaderComponents.filter(\n component => component.config?.slot === Slot.HEADER_END,\n );\n\n const { menuStates, handleOpen, handleClose } = useDropdownManager();\n\n const getDropdownButtonProps = (key: string) => ({\n handleMenu: handleOpen(key),\n anchorEl: menuStates[key],\n setAnchorEl: handleClose(key),\n });\n\n const getIconButtonProps = (props: Record<string, any>) => ({\n icon: props.icon ?? '',\n tooltip: props.tooltip ?? '',\n to: props.to ?? '',\n });\n const renderComponents = (mountPoints: GlobalHeaderComponentMountPoint[]) =>\n mountPoints.map((mp, index) => {\n let displayHeaderIcon = false;\n if (frontendData) {\n for (const pluginData of Object.values(frontendData)) {\n const dynamicRoutes = pluginData.dynamicRoutes ?? [];\n if (\n dynamicRoutes.some(\n (route: { path: string }) => route.path === mp.config?.props?.to,\n )\n ) {\n displayHeaderIcon = true;\n break;\n }\n }\n }\n\n switch (mp.config?.type) {\n case ComponentType.SEARCH:\n return (\n <ErrorBoundary>\n {/* eslint-disable-next-line react/no-array-index-key */}\n <mp.Component key={index} />\n </ErrorBoundary>\n );\n case ComponentType.DROPDOWN_BUTTON:\n return (\n <ErrorBoundary>\n <mp.Component\n // eslint-disable-next-line react/no-array-index-key\n key={index}\n {...getDropdownButtonProps(mp.config?.key ?? index.toString())}\n {...mp.config?.props}\n />\n </ErrorBoundary>\n );\n case ComponentType.ICON_BUTTON:\n return (\n <ErrorBoundary>\n {displayHeaderIcon && (\n <mp.Component\n // eslint-disable-next-line react/no-array-index-key\n key={index}\n {...getIconButtonProps(mp.config?.props ?? {})}\n />\n )}\n </ErrorBoundary>\n );\n default:\n return null;\n }\n });\n\n return (\n <AppBar\n position=\"sticky\"\n component=\"nav\"\n sx={{ backgroundColor: '#212427' }}\n >\n <Toolbar>\n {renderComponents(globalHeaderStartComponentsMountPoints)}\n {globalHeaderStartComponentsMountPoints.length > 0 &&\n globalHeaderEndComponentsMountPoints.length > 0 && (\n <Divider\n orientation=\"vertical\"\n flexItem\n sx={{ borderColor: '#4F5255', marginX: 1 }}\n />\n )}\n {renderComponents(globalHeaderEndComponentsMountPoints)}\n </Toolbar>\n </AppBar>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;AA0BO,MAAM,eAAe,MAAM;AAChC,EAAM,MAAA,MAAA,GAAS,OAAO,YAAY,CAAA;AAClC,EAAM,MAAA,cAAA,GAAiB,MAAO,CAAA,iBAAA,CAAkB,yBAAyB,CAAA;AACzE,EAAM,MAAA,YAAA,GAAe,gBAAgB,GAAI,EAAA;AAEzC,EAAA,MAAM,6BAA6B,0BAA2B,EAAA;AAE9D,EAAM,MAAA,uCAAA,GAA0C,QAAQ,MAAM;AAC5D,IAAA,IAAI,CAAC,0BAA4B,EAAA;AAC/B,MAAA,OAAO,EAAC;AAAA;AAGV,IAAA,MAAM,oBAAoB,0BAA2B,CAAA,MAAA;AAAA,MACnD,CAAc,SAAA,KAAA,CAAA,SAAA,CAAU,MAAQ,EAAA,QAAA,IAAY,CAAK,IAAA,CAAA;AAAA,KACnD;AAEA,IAAkB,iBAAA,CAAA,IAAA;AAAA,MAChB,CAAC,GAAG,CAAO,KAAA,CAAA,CAAA,CAAE,QAAQ,QAAY,IAAA,CAAA,KAAM,CAAE,CAAA,MAAA,EAAQ,QAAY,IAAA,CAAA;AAAA,KAC/D;AAEA,IAAO,OAAA,iBAAA;AAAA,GACT,EAAG,CAAC,0BAA0B,CAAC,CAAA;AAE/B,EAAA,MAAM,yCACJ,uCAAwC,CAAA,MAAA;AAAA,IACtC,CAAa,SAAA,KAAA,SAAA,CAAU,MAAQ,EAA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A;AAAA,QACZ,QAAQ,EAAA,IAAA;AAAA,QACR,EAAI,EAAA,EAAE,WAAa,EAAA,SAAA,EAAW,SAAS,CAAE;AAAA;AAAA,KAC3C,EAEH,gBAAiB,CAAA,oCAAoC,CACxD;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Box from '@mui/material/Box';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import HeaderItemContent from '../HeaderLinkComponent/HeaderItemContent.esm.js';
|
|
4
|
+
|
|
5
|
+
const HeaderButton = ({ title, icon, onClick }) => {
|
|
6
|
+
return /* @__PURE__ */ React.createElement(
|
|
7
|
+
Box,
|
|
8
|
+
{
|
|
9
|
+
onClick,
|
|
10
|
+
sx: { cursor: "pointer", width: "100%", color: "inherit" }
|
|
11
|
+
},
|
|
12
|
+
/* @__PURE__ */ React.createElement(HeaderItemContent, { icon, label: title })
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { HeaderButton };
|
|
17
|
+
//# sourceMappingURL=HeaderButton.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeaderButton.esm.js","sources":["../../../src/components/HeaderButtonComponent/HeaderButton.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 Box from '@mui/material/Box';\nimport React from 'react';\nimport HeaderItemContent from '../HeaderLinkComponent/HeaderItemContent';\n\nexport type HeaderButtonProps = {\n title: string;\n icon: string;\n onClick?: () => void;\n};\n\nexport const HeaderButton = ({ title, icon, onClick }: HeaderButtonProps) => {\n return (\n <Box\n onClick={onClick}\n sx={{ cursor: 'pointer', width: '100%', color: 'inherit' }}\n >\n <HeaderItemContent icon={icon} label={title} />\n </Box>\n );\n};\n"],"names":[],"mappings":";;;;AA0BO,MAAM,eAAe,CAAC,EAAE,KAAO,EAAA,IAAA,EAAM,SAAiC,KAAA;AAC3E,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,GAAA;AAAA,IAAA;AAAA,MACC,OAAA;AAAA,MACA,IAAI,EAAE,MAAA,EAAQ,WAAW,KAAO,EAAA,MAAA,EAAQ,OAAO,SAAU;AAAA,KAAA;AAAA,oBAExD,KAAA,CAAA,aAAA,CAAA,iBAAA,EAAA,EAAkB,IAAY,EAAA,KAAA,EAAO,KAAO,EAAA;AAAA,GAC/C;AAEJ;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useApi, errorApiRef, identityApiRef } from '@backstage/core-plugin-api';
|
|
3
|
+
import { HeaderButton } from './HeaderButton.esm.js';
|
|
4
|
+
|
|
5
|
+
const LogoutButton = () => {
|
|
6
|
+
const errorApi = useApi(errorApiRef);
|
|
7
|
+
const identityApi = useApi(identityApiRef);
|
|
8
|
+
const handleLogout = () => {
|
|
9
|
+
identityApi.signOut().catch((error) => errorApi.post(error));
|
|
10
|
+
};
|
|
11
|
+
return /* @__PURE__ */ React.createElement(HeaderButton, { title: "Logout", icon: "logout", onClick: handleLogout });
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { LogoutButton };
|
|
15
|
+
//# sourceMappingURL=LogoutButton.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogoutButton.esm.js","sources":["../../../src/components/HeaderButtonComponent/LogoutButton.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 React from 'react';\nimport {\n errorApiRef,\n identityApiRef,\n useApi,\n} from '@backstage/core-plugin-api';\nimport { HeaderButton } from './HeaderButton';\n\nexport const LogoutButton = () => {\n const errorApi = useApi(errorApiRef);\n const identityApi = useApi(identityApiRef);\n\n const handleLogout = () => {\n identityApi.signOut().catch(error => errorApi.post(error));\n };\n\n return <HeaderButton title=\"Logout\" icon=\"logout\" onClick={handleLogout} />;\n};\n"],"names":[],"mappings":";;;;AAwBO,MAAM,eAAe,MAAM;AAChC,EAAM,MAAA,QAAA,GAAW,OAAO,WAAW,CAAA;AACnC,EAAM,MAAA,WAAA,GAAc,OAAO,cAAc,CAAA;AAEzC,EAAA,MAAM,eAAe,MAAM;AACzB,IAAA,WAAA,CAAY,SAAU,CAAA,KAAA,CAAM,WAAS,QAAS,CAAA,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,GAC3D;AAEA,EAAA,2CAAQ,YAAa,EAAA,EAAA,KAAA,EAAM,UAAS,IAAK,EAAA,QAAA,EAAS,SAAS,YAAc,EAAA,CAAA;AAC3E;;;;"}
|
|
@@ -1,69 +1,65 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import { catalogApiRef } from '@backstage/plugin-catalog-react';
|
|
2
3
|
import HeaderDropdownComponent from './HeaderDropdownComponent.esm.js';
|
|
3
4
|
import ArrowDropDownOutlinedIcon from '@mui/icons-material/ArrowDropDownOutlined';
|
|
4
|
-
import
|
|
5
|
+
import { useApi } from '@backstage/core-plugin-api';
|
|
6
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
|
7
|
+
import Box from '@mui/material/Box';
|
|
8
|
+
import Typography from '@mui/material/Typography';
|
|
9
|
+
import { ComponentType } from '../../types.esm.js';
|
|
10
|
+
import { HeaderLink } from '../HeaderLinkComponent/HeaderLink.esm.js';
|
|
11
|
+
import { useCreateDropdownMountPoints } from '../../hooks/useCreateDropdownMountPoints.esm.js';
|
|
5
12
|
|
|
6
|
-
const models = [
|
|
7
|
-
{
|
|
8
|
-
key: "key-1",
|
|
9
|
-
value: "argocd-template",
|
|
10
|
-
label: "Add ArgoCD to an existing project"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
key: "key-2",
|
|
14
|
-
value: "create-backend-plugin",
|
|
15
|
-
label: "Create Backend Plugin Template"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
key: "key-3",
|
|
19
|
-
value: "create-frontend-plugin",
|
|
20
|
-
label: "Create Frontend Plugin Template"
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
key: "key-4",
|
|
24
|
-
value: "create-react-app-template-test-annotator",
|
|
25
|
-
label: "Create React App Template with annotations"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
key: "key-5",
|
|
29
|
-
value: "define-ansible-job-template",
|
|
30
|
-
label: "Ansible Job Template"
|
|
31
|
-
}
|
|
32
|
-
];
|
|
33
|
-
const menuBottomItems = [
|
|
34
|
-
{
|
|
35
|
-
itemKey: "custom",
|
|
36
|
-
icon: CategoryOutlinedIcon,
|
|
37
|
-
label: "Register a component",
|
|
38
|
-
subLabel: "Import it to the catalog page",
|
|
39
|
-
link: "/catalog-import"
|
|
40
|
-
}
|
|
41
|
-
];
|
|
42
13
|
const CreateDropdown = ({
|
|
43
14
|
handleMenu,
|
|
44
15
|
anchorEl,
|
|
45
16
|
setAnchorEl
|
|
46
17
|
}) => {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
18
|
+
const catalogApi = useApi(catalogApiRef);
|
|
19
|
+
const [entities, setEntities] = useState([]);
|
|
20
|
+
const [loading, setLoading] = useState(true);
|
|
21
|
+
const [error, setError] = useState(null);
|
|
22
|
+
const createDropdownMountPoints = useCreateDropdownMountPoints();
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const fetchEntities = async () => {
|
|
25
|
+
try {
|
|
26
|
+
const response = await catalogApi.getEntities({
|
|
27
|
+
filter: { kind: ["Template"] }
|
|
28
|
+
});
|
|
29
|
+
setEntities(response.items);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
setError(err);
|
|
32
|
+
} finally {
|
|
33
|
+
setLoading(false);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
fetchEntities();
|
|
37
|
+
}, [catalogApi]);
|
|
38
|
+
const items = useMemo(() => {
|
|
39
|
+
return entities.filter((e) => e.kind === "Template").map((m) => ({
|
|
40
|
+
Component: HeaderLink,
|
|
41
|
+
type: ComponentType.LINK,
|
|
42
|
+
label: m.metadata.title ?? m.metadata.name,
|
|
43
|
+
link: `/create/templates/default/${m.metadata.name}`
|
|
44
|
+
}));
|
|
45
|
+
}, [entities]);
|
|
46
|
+
const menuSections = useMemo(() => {
|
|
47
|
+
return (createDropdownMountPoints ?? []).map((mp) => ({
|
|
48
|
+
Component: mp.Component,
|
|
49
|
+
type: mp.config?.type ?? ComponentType.LINK,
|
|
50
|
+
priority: mp.config?.priority ?? 0
|
|
51
|
+
})).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
52
|
+
}, [createDropdownMountPoints]);
|
|
53
|
+
if (loading) {
|
|
54
|
+
return /* @__PURE__ */ React.createElement(Box, { display: "flex", justifyContent: "center", alignItems: "center", p: 2 }, /* @__PURE__ */ React.createElement(CircularProgress, null), /* @__PURE__ */ React.createElement(Typography, { variant: "body1", sx: { ml: 2 } }, "Loading templates..."));
|
|
55
|
+
}
|
|
56
|
+
if (error) {
|
|
57
|
+
return /* @__PURE__ */ React.createElement(Box, { display: "flex", justifyContent: "center", alignItems: "center", p: 2 }, /* @__PURE__ */ React.createElement(Typography, { variant: "body1", color: "error" }, "Error fetching templates: ", error));
|
|
58
|
+
}
|
|
61
59
|
return /* @__PURE__ */ React.createElement(
|
|
62
60
|
HeaderDropdownComponent,
|
|
63
61
|
{
|
|
64
62
|
buttonContent: /* @__PURE__ */ React.createElement(React.Fragment, null, "Create ", /* @__PURE__ */ React.createElement(ArrowDropDownOutlinedIcon, { sx: { ml: 1 } })),
|
|
65
|
-
menuSections,
|
|
66
|
-
menuBottomItems,
|
|
67
63
|
buttonProps: {
|
|
68
64
|
color: "primary",
|
|
69
65
|
variant: "contained",
|
|
@@ -72,9 +68,18 @@ const CreateDropdown = ({
|
|
|
72
68
|
buttonClick: handleMenu,
|
|
73
69
|
anchorEl,
|
|
74
70
|
setAnchorEl
|
|
75
|
-
}
|
|
71
|
+
},
|
|
72
|
+
menuSections.map((section, index) => /* @__PURE__ */ React.createElement(
|
|
73
|
+
section.Component,
|
|
74
|
+
{
|
|
75
|
+
key: `menu-section-${index.toString()}`,
|
|
76
|
+
hideDivider: index === menuSections.length - 1,
|
|
77
|
+
handleClose: () => setAnchorEl(null),
|
|
78
|
+
...section.type === ComponentType.LIST ? { items } : {}
|
|
79
|
+
}
|
|
80
|
+
))
|
|
76
81
|
);
|
|
77
82
|
};
|
|
78
83
|
|
|
79
|
-
export { CreateDropdown
|
|
84
|
+
export { CreateDropdown };
|
|
80
85
|
//# sourceMappingURL=CreateDropdown.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateDropdown.esm.js","sources":["../../../src/components/HeaderDropdownComponent/CreateDropdown.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 React from 'react';\nimport HeaderDropdownComponent from './HeaderDropdownComponent';\nimport ArrowDropDownOutlinedIcon from '@mui/icons-material/ArrowDropDownOutlined';\nimport
|
|
1
|
+
{"version":3,"file":"CreateDropdown.esm.js","sources":["../../../src/components/HeaderDropdownComponent/CreateDropdown.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 React, { useEffect, useMemo, useState } from 'react';\nimport { catalogApiRef } from '@backstage/plugin-catalog-react';\nimport HeaderDropdownComponent from './HeaderDropdownComponent';\nimport ArrowDropDownOutlinedIcon from '@mui/icons-material/ArrowDropDownOutlined';\nimport { MenuItemConfig } from './MenuSection';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { Entity } from '@backstage/catalog-model';\nimport CircularProgress from '@mui/material/CircularProgress';\nimport Box from '@mui/material/Box';\nimport Typography from '@mui/material/Typography';\nimport { ComponentType } from '../../types';\nimport { HeaderLink } from '../HeaderLinkComponent/HeaderLink';\nimport { useCreateDropdownMountPoints } from '../../hooks/useCreateDropdownMountPoints';\n\n/**\n * @public\n * Create button properties\n */\nexport interface CreateButtonProps {\n handleMenu: (event: React.MouseEvent<HTMLElement>) => void;\n anchorEl: HTMLElement | null;\n setAnchorEl: React.Dispatch<React.SetStateAction<HTMLElement | null>>;\n}\n\n/**\n * @public\n * Props for each dropdown section component\n */\ninterface SectionComponentProps {\n handleClose: () => void;\n hideDivider: boolean;\n items?: MenuItemConfig[];\n}\n\nexport const CreateDropdown = ({\n handleMenu,\n anchorEl,\n setAnchorEl,\n}: CreateButtonProps) => {\n const catalogApi = useApi(catalogApiRef);\n const [entities, setEntities] = useState<Entity[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n const createDropdownMountPoints = useCreateDropdownMountPoints();\n\n useEffect(() => {\n const fetchEntities = async () => {\n try {\n const response = await catalogApi.getEntities({\n filter: { kind: ['Template'] },\n });\n setEntities(response.items);\n } catch (err) {\n setError(err);\n } finally {\n setLoading(false);\n }\n };\n\n fetchEntities();\n }, [catalogApi]);\n\n const items = useMemo(() => {\n return entities\n .filter(e => e.kind === 'Template')\n .map(m => ({\n Component: HeaderLink as React.ComponentType,\n type: ComponentType.LINK,\n label: m.metadata.title ?? m.metadata.name,\n link: `/create/templates/default/${m.metadata.name}`,\n }));\n }, [entities]);\n\n const menuSections = useMemo(() => {\n return (createDropdownMountPoints ?? [])\n .map(mp => ({\n Component: mp.Component as React.ComponentType<SectionComponentProps>,\n type: mp.config?.type ?? ComponentType.LINK,\n priority: mp.config?.priority ?? 0,\n }))\n .sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));\n }, [createDropdownMountPoints]);\n\n if (loading) {\n return (\n <Box display=\"flex\" justifyContent=\"center\" alignItems=\"center\" p={2}>\n <CircularProgress />\n <Typography variant=\"body1\" sx={{ ml: 2 }}>\n Loading templates...\n </Typography>\n </Box>\n );\n }\n\n if (error) {\n return (\n <Box display=\"flex\" justifyContent=\"center\" alignItems=\"center\" p={2}>\n <Typography variant=\"body1\" color=\"error\">\n Error fetching templates: {error}\n </Typography>\n </Box>\n );\n }\n\n return (\n <HeaderDropdownComponent\n buttonContent={\n <>\n Create <ArrowDropDownOutlinedIcon sx={{ ml: 1 }} />\n </>\n }\n buttonProps={{\n color: 'primary',\n variant: 'contained',\n sx: { mr: 2 },\n }}\n buttonClick={handleMenu}\n anchorEl={anchorEl}\n setAnchorEl={setAnchorEl}\n >\n {menuSections.map((section, index) => (\n <section.Component\n key={`menu-section-${index.toString()}`}\n hideDivider={index === menuSections.length - 1}\n handleClose={() => setAnchorEl(null)}\n {...(section.type === ComponentType.LIST ? { items } : {})}\n />\n ))}\n </HeaderDropdownComponent>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AAkDO,MAAM,iBAAiB,CAAC;AAAA,EAC7B,UAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAyB,KAAA;AACvB,EAAM,MAAA,UAAA,GAAa,OAAO,aAAa,CAAA;AACvC,EAAA,MAAM,CAAC,QAAU,EAAA,WAAW,CAAI,GAAA,QAAA,CAAmB,EAAE,CAAA;AACrD,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,IAAI,CAAA;AAC3C,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAS,IAAI,CAAA;AACvC,EAAA,MAAM,4BAA4B,4BAA6B,EAAA;AAE/D,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAM,gBAAgB,YAAY;AAChC,MAAI,IAAA;AACF,QAAM,MAAA,QAAA,GAAW,MAAM,UAAA,CAAW,WAAY,CAAA;AAAA,UAC5C,MAAQ,EAAA,EAAE,IAAM,EAAA,CAAC,UAAU,CAAE;AAAA,SAC9B,CAAA;AACD,QAAA,WAAA,CAAY,SAAS,KAAK,CAAA;AAAA,eACnB,GAAK,EAAA;AACZ,QAAA,QAAA,CAAS,GAAG,CAAA;AAAA,OACZ,SAAA;AACA,QAAA,UAAA,CAAW,KAAK,CAAA;AAAA;AAClB,KACF;AAEA,IAAc,aAAA,EAAA;AAAA,GAChB,EAAG,CAAC,UAAU,CAAC,CAAA;AAEf,EAAM,MAAA,KAAA,GAAQ,QAAQ,MAAM;AAC1B,IAAO,OAAA,QAAA,CACJ,OAAO,CAAK,CAAA,KAAA,CAAA,CAAE,SAAS,UAAU,CAAA,CAC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/Menu';
|
|
3
|
-
import MenuItem from '@mui/material/MenuItem';
|
|
4
3
|
import Button from '@mui/material/Button';
|
|
5
|
-
import Typography from '@mui/material/Typography';
|
|
6
|
-
import { Link } from '@backstage/core-components';
|
|
7
4
|
import { styled } from '@mui/material/styles';
|
|
8
5
|
import Box from '@mui/material/Box';
|
|
9
|
-
import MenuSection from './MenuSection.esm.js';
|
|
10
6
|
|
|
11
7
|
const Listbox = styled("ul")(
|
|
12
8
|
({ theme }) => `
|
|
@@ -29,14 +25,12 @@ const Listbox = styled("ul")(
|
|
|
29
25
|
);
|
|
30
26
|
const HeaderDropdownComponent = ({
|
|
31
27
|
buttonContent,
|
|
32
|
-
|
|
33
|
-
menuBottomItems = [],
|
|
28
|
+
children,
|
|
34
29
|
buttonProps,
|
|
35
30
|
buttonClick,
|
|
36
31
|
anchorEl,
|
|
37
32
|
setAnchorEl
|
|
38
33
|
}) => {
|
|
39
|
-
const shouldHideDivider = (index) => menuSections.length === 1 && index === menuSections.length - 1 && menuBottomItems.length === 0;
|
|
40
34
|
return /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(
|
|
41
35
|
Button,
|
|
42
36
|
{
|
|
@@ -68,48 +62,7 @@ const HeaderDropdownComponent = ({
|
|
|
68
62
|
}
|
|
69
63
|
}
|
|
70
64
|
},
|
|
71
|
-
/* @__PURE__ */ React.createElement(Listbox, { role: "menu" },
|
|
72
|
-
MenuSection,
|
|
73
|
-
{
|
|
74
|
-
key: `menu-section-${section.sectionKey}`,
|
|
75
|
-
...{ hideDivider: shouldHideDivider(index), ...section },
|
|
76
|
-
handleClose: section.handleClose
|
|
77
|
-
}
|
|
78
|
-
)), menuBottomItems.map(
|
|
79
|
-
({ itemKey, icon: Icon, label, subLabel, link }) => /* @__PURE__ */ React.createElement(
|
|
80
|
-
MenuItem,
|
|
81
|
-
{
|
|
82
|
-
key: `menu-item-${itemKey}`,
|
|
83
|
-
sx: { my: "8px", "&:hover": { background: "transparent" } },
|
|
84
|
-
onClick: () => setAnchorEl(null),
|
|
85
|
-
disableRipple: true
|
|
86
|
-
},
|
|
87
|
-
link && /* @__PURE__ */ React.createElement(
|
|
88
|
-
Link,
|
|
89
|
-
{
|
|
90
|
-
to: link,
|
|
91
|
-
style: {
|
|
92
|
-
display: "flex",
|
|
93
|
-
color: "inherit",
|
|
94
|
-
alignItems: "center",
|
|
95
|
-
textDecoration: "none"
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
Icon && /* @__PURE__ */ React.createElement(
|
|
99
|
-
Icon,
|
|
100
|
-
{
|
|
101
|
-
fontSize: "small",
|
|
102
|
-
style: {
|
|
103
|
-
marginRight: "0.5rem",
|
|
104
|
-
flexShrink: 0,
|
|
105
|
-
color: "slategray"
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
),
|
|
109
|
-
/* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Typography, { variant: "body2" }, label), subLabel && /* @__PURE__ */ React.createElement(Typography, { variant: "caption", color: "text.secondary" }, subLabel))
|
|
110
|
-
)
|
|
111
|
-
)
|
|
112
|
-
))
|
|
65
|
+
/* @__PURE__ */ React.createElement(Listbox, { role: "menu" }, children)
|
|
113
66
|
));
|
|
114
67
|
};
|
|
115
68
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeaderDropdownComponent.esm.js","sources":["../../../src/components/HeaderDropdownComponent/HeaderDropdownComponent.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 React from 'react';\nimport Menu from '@mui/material/Menu';\nimport
|
|
1
|
+
{"version":3,"file":"HeaderDropdownComponent.esm.js","sources":["../../../src/components/HeaderDropdownComponent/HeaderDropdownComponent.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 React from 'react';\nimport Menu from '@mui/material/Menu';\nimport Button from '@mui/material/Button';\nimport { styled } from '@mui/material/styles';\nimport Box from '@mui/material/Box';\nimport { MenuItemConfig, MenuSectionConfig } from './MenuSection';\n\ninterface HeaderDropdownProps {\n buttonContent: React.ReactNode;\n children: React.ReactNode;\n menuSections?: MenuSectionConfig[];\n menuBottomItems?: MenuItemConfig[];\n buttonProps?: React.ComponentProps<typeof Button>;\n buttonClick?: (event: React.MouseEvent<HTMLElement>) => void;\n anchorEl: HTMLElement | null;\n setAnchorEl: React.Dispatch<React.SetStateAction<HTMLElement | null>>;\n}\n\nconst Listbox = styled('ul')(\n ({ theme }) => `\n font-size: 0.875rem;\n box-sizing: border-box;\n padding: 0;\n margin: 0;\n min-width: 160px;\n border-radius: 3px;\n text-decoration: none;\n list-style: none;\n overflow: auto;\n outline: 1;\n background: ${\n theme.palette.mode === 'dark' ? theme.palette.background.default : '#fff'\n };\n border: 1px solid ${\n theme.palette.mode === 'dark'\n ? theme.palette.divider\n : theme.palette.background.default\n };\n color: ${\n theme.palette.mode === 'dark'\n ? theme.palette.text.disabled\n : theme.palette.text.primary\n };\n box-shadow: 0 4px 6px ${\n theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'\n };\n z-index: 1;\n `,\n);\n\nconst HeaderDropdownComponent: React.FC<HeaderDropdownProps> = ({\n buttonContent,\n children,\n buttonProps,\n buttonClick,\n anchorEl,\n setAnchorEl,\n}) => {\n return (\n <Box>\n <Button\n disableRipple\n disableTouchRipple\n {...buttonProps}\n onClick={buttonClick}\n >\n {buttonContent}\n </Button>\n <Menu\n id=\"menu-appbar\"\n anchorEl={anchorEl}\n keepMounted\n open={Boolean(anchorEl)}\n onClose={() => setAnchorEl(null)}\n anchorOrigin={{\n vertical: 'bottom',\n horizontal: 'center',\n }}\n transformOrigin={{\n vertical: 'top',\n horizontal: 'center',\n }}\n sx={{\n '& ul[class*=\"MuiMenu-list\"]': {\n py: 0,\n },\n }}\n >\n <Listbox role=\"menu\">{children}</Listbox>\n </Menu>\n </Box>\n );\n};\n\nexport default HeaderDropdownComponent;\n"],"names":[],"mappings":";;;;;;AAkCA,MAAM,OAAA,GAAU,OAAO,IAAI,CAAA;AAAA,EACzB,CAAC,EAAE,KAAA,EAAY,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAYb,EAAA,KAAA,CAAM,QAAQ,IAAS,KAAA,MAAA,GAAS,MAAM,OAAQ,CAAA,UAAA,CAAW,UAAU,MACrE,CAAA;AAAA,oBAEE,EAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,KAAS,MACnB,GAAA,KAAA,CAAM,QAAQ,OACd,GAAA,KAAA,CAAM,OAAQ,CAAA,UAAA,CAAW,OAC/B,CAAA;AAAA,SAEE,EAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,KAAS,MACnB,GAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,CAAK,QACnB,GAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,CAAK,OACzB,CAAA;AAAA,wBAAA,EAEE,KAAM,CAAA,OAAA,CAAQ,IAAS,KAAA,MAAA,GAAS,sBAAsB,mBACxD,CAAA;AAAA;AAAA,EAAA;AAGF,CAAA;AAEA,MAAM,0BAAyD,CAAC;A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