Skip to content

Commit 1bb8c3c

Browse files
authored
DONT MERGE: 1727 Allow adding more version info to hover modal (#1733)
* Add icon, gql query, sub context menu * Add orchestrator-ui-components npm pkg version to popover * Change icon * Add changeset * Add translations * Break up nested ternary; address PR comments * Small change to gql query for version endpoint
1 parent 88ffba4 commit 1bb8c3c

File tree

7 files changed

+138
-7
lines changed

7 files changed

+138
-7
lines changed

.changeset/spotty-cheetahs-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@orchestrator-ui/orchestrator-ui-components': minor
3+
---
4+
5+
Added support for displaying software versions in hamburger menu

packages/orchestrator-ui-components/src/components/WfoPageTemplate/WfoPageHeader/WfoHamburgerMenu.tsx

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ import { useTranslations } from 'next-intl';
55

66
import { EuiButtonIcon, EuiContextMenu, EuiPopover } from '@elastic/eui';
77
import type { EuiContextMenuPanelDescriptor } from '@elastic/eui';
8+
import { EmotionJSX } from '@emotion/react/types/jsx-namespace';
89

10+
import { WfoLoading } from '@/components/WfoLoading';
11+
import { ORCHESTRATOR_UI_LIBRARY_VERSION } from '@/configuration';
912
import { useGetOrchestratorConfig, useOrchestratorTheme } from '@/hooks';
10-
import { WfoLogoutIcon } from '@/icons';
13+
import { WfoLogoutIcon, WfoSquareStack3dStack, WfoXCircleFill } from '@/icons';
1114
import { WfoQuestionCircle } from '@/icons/WfoQuestionCircle';
15+
import { useGetVersionsQuery } from '@/rtk/endpoints/versions';
1216
import { toOptionalArrayEntry } from '@/utils';
1317

1418
export const WfoHamburgerMenu = ({}) => {
15-
const t = useTranslations('main');
19+
const t = useTranslations('hamburgerMenu');
1620
const [isPopoverOpen, setPopoverIsOpen] = useState(false);
1721
const { theme, isDarkThemeActive } = useOrchestratorTheme();
1822
const { enableSupportMenuItem, supportMenuItemUrl } =
@@ -23,9 +27,50 @@ export const WfoHamburgerMenu = ({}) => {
2327
const handleOpenSupport = async (): Promise<undefined> => {
2428
window.open(supportMenuItemUrl, '_blank');
2529
};
30+
const {
31+
data,
32+
isFetching,
33+
error: versionFetchError,
34+
} = useGetVersionsQuery();
35+
36+
const getVersionItems = () => {
37+
if (versionFetchError) {
38+
console.error(versionFetchError);
39+
return [
40+
{
41+
name: 'Error fetching application version data',
42+
icon: <WfoXCircleFill color={theme.colors.danger} />,
43+
},
44+
];
45+
}
46+
if (isFetching) {
47+
return [{ name: '', icon: <WfoLoading /> }];
48+
}
49+
// initial array contains orchestrator-ui-components library version
50+
const versionsArr: [{ name: string; icon: EmotionJSX.Element }] = [
51+
{
52+
name: `orchestrator-ui-components: ${ORCHESTRATOR_UI_LIBRARY_VERSION}`,
53+
icon: <WfoSquareStack3dStack />,
54+
},
55+
];
56+
57+
if (data === undefined) {
58+
return versionsArr;
59+
}
60+
61+
const orchApiVersions = data.version.applicationVersions.map((item) => {
62+
return {
63+
name: item,
64+
icon: <WfoSquareStack3dStack />,
65+
};
66+
});
67+
68+
// orchestrator-ui-components library version + versions returned from orchestrator api
69+
return versionsArr.concat(orchApiVersions);
70+
};
2671

2772
const logoutItem = {
28-
name: 'Logout',
73+
name: t('logout'),
2974
icon: (
3075
<WfoLogoutIcon
3176
color={
@@ -37,7 +82,7 @@ export const WfoHamburgerMenu = ({}) => {
3782
};
3883

3984
const supportItem = {
40-
name: 'Support',
85+
name: t('support'),
4186
icon: (
4287
<WfoQuestionCircle
4388
color={
@@ -48,8 +93,15 @@ export const WfoHamburgerMenu = ({}) => {
4893
onClick: handleOpenSupport,
4994
};
5095

96+
const versionItem = {
97+
name: t('softwareVersions'),
98+
icon: <WfoSquareStack3dStack width={24} height={24} />,
99+
panel: 1,
100+
};
101+
51102
const panelItems = [
52103
...toOptionalArrayEntry(supportItem, enableSupportMenuItem),
104+
versionItem,
53105
{ ...logoutItem },
54106
];
55107

@@ -58,6 +110,11 @@ export const WfoHamburgerMenu = ({}) => {
58110
id: 0,
59111
items: panelItems,
60112
},
113+
{
114+
id: 1,
115+
title: t('softwareVersions'),
116+
items: getVersionItems(),
117+
},
61118
];
62119

63120
return (
@@ -77,7 +134,11 @@ export const WfoHamburgerMenu = ({}) => {
77134
panelPaddingSize="none"
78135
anchorPosition="downLeft"
79136
>
80-
<EuiContextMenu initialPanelId={0} panels={panels} />
137+
<EuiContextMenu
138+
initialPanelId={0}
139+
panels={panels}
140+
css={{ width: theme.base * 25 }}
141+
/>
81142
</EuiPopover>
82143
);
83144
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { FC } from 'react';
2+
3+
import { WfoIconProps } from '@/icons';
4+
5+
import { withWfoHeroIconsWrapper } from './WfoHeroIconsWrapper';
6+
7+
const WfoSquareStack3dStackSvg: FC<WfoIconProps> = ({
8+
width = 20,
9+
height = 20,
10+
color = 'currentColor',
11+
}) => (
12+
<svg
13+
width={width}
14+
height={height}
15+
xmlns="http://www.w3.org/2000/svg"
16+
viewBox="0 0 24 24"
17+
fill={color}
18+
>
19+
<path d="M11.644 1.59a.75.75 0 0 1 .712 0l9.75 5.25a.75.75 0 0 1 0 1.32l-9.75 5.25a.75.75 0 0 1-.712 0l-9.75-5.25a.75.75 0 0 1 0-1.32l9.75-5.25Z" />
20+
<path d="m3.265 10.602 7.668 4.129a2.25 2.25 0 0 0 2.134 0l7.668-4.13 1.37.739a.75.75 0 0 1 0 1.32l-9.75 5.25a.75.75 0 0 1-.71 0l-9.75-5.25a.75.75 0 0 1 0-1.32l1.37-.738Z" />
21+
<path d="m10.933 19.231-7.668-4.13-1.37.739a.75.75 0 0 0 0 1.32l9.75 5.25c.221.12.489.12.71 0l9.75-5.25a.75.75 0 0 0 0-1.32l-1.37-.738-7.668 4.13a2.25 2.25 0 0 1-2.134-.001Z" />
22+
</svg>
23+
);
24+
25+
export const WfoSquareStack3dStack = withWfoHeroIconsWrapper(
26+
WfoSquareStack3dStackSvg,
27+
);

packages/orchestrator-ui-components/src/icons/heroicons/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './WfoArrowDown';
44
export * from './WfoArrowsUpDown';
55
export * from './WfoArrowUp';
66
export * from './WfoWrench';
7+
export * from './WfoSquareStack3dStack';

packages/orchestrator-ui-components/src/messages/en-GB.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"resetToDefault": "Reset to default",
2525
"savePreferences": "Save preferences",
2626
"numberOfRows": "Number of rows",
27-
"tableSettings": "Table settings",
28-
"openMenu": "Open menu"
27+
"tableSettings": "Table settings"
2928
},
3029
"common": {
3130
"product": "Product",
@@ -428,5 +427,11 @@
428427
"headerTitle": "Total number of products",
429428
"listTitle": "Total number of product instances"
430429
}
430+
},
431+
"hamburgerMenu": {
432+
"openMenu": "Open menu",
433+
"support": "Support",
434+
"softwareVersions": "Software Versions",
435+
"logout": "Logout"
431436
}
432437
}

packages/orchestrator-ui-components/src/messages/nl-NL.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,5 +428,10 @@
428428
"headerTitle": "Totaal aantal producten",
429429
"listTitle": "Totaal aantal productinstanties"
430430
}
431+
},
432+
"hamburgerMenu": {
433+
"support": "Support",
434+
"softwareVersions": "Software Versies",
435+
"logout": "Logout"
431436
}
432437
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { orchestratorApi } from '../api';
2+
3+
const versionsQuery = `
4+
query Versions {
5+
version {
6+
applicationVersions
7+
}
8+
}
9+
`;
10+
11+
export type VersionsResponse = {
12+
version: {
13+
applicationVersions: [string];
14+
};
15+
};
16+
17+
const versionsApi = orchestratorApi.injectEndpoints({
18+
endpoints: (build) => ({
19+
getVersions: build.query<VersionsResponse, void>({
20+
query: () => ({
21+
document: versionsQuery,
22+
}),
23+
}),
24+
}),
25+
});
26+
27+
export const { useGetVersionsQuery } = versionsApi;

0 commit comments

Comments
 (0)