-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathPlatformMasthead.tsx
More file actions
151 lines (147 loc) · 5.68 KB
/
PlatformMasthead.tsx
File metadata and controls
151 lines (147 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import {
PageMasthead,
PageNotificationsIcon,
useBreakpoint,
usePageDialog,
usePageNavigate,
} from '@ansible/ansible-ui-framework';
import { PageMastheadDropdown } from '@ansible/ansible-ui-framework/PageMasthead/PageMastheadDropdown';
import { PageThemeSwitcher } from '@ansible/ansible-ui-framework/PageMasthead/PageThemeSwitcher';
import { useAwxActiveUser } from '@ansible/awx-ui/common/useAwxActiveUser';
import { useAwxNotifications } from '@ansible/awx-ui/main/AwxMasthead';
import { ChatbotToolbarItem } from '@ansible/chatbot/ChatbotToolbarItem';
import { postRequest } from '@ansible/common-ui/crud/Data';
import { PageRefreshIcon } from '@ansible/common-ui/PageRefreshIcon';
import { useDocsVersion } from '@ansible/common-ui/utils/useDocsVersion';
import { useEdaActiveUser } from '@ansible/eda-ui/common/useEdaActiveUser';
import { useHubActiveUser } from '@ansible/hub-ui/common/useHubActiveUser';
import { useHubNotifications } from '@ansible/hub-ui/main/HubMasthead';
import { DropdownItem, ToolbarGroup, ToolbarItem } from '@patternfly/react-core';
import { QuestionCircleIcon, UserCircleIcon } from '@patternfly/react-icons';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import PlatformLogo from '../assets/platform-logo.svg?react';
import PlatformIcon from '../assets/platform-icon.svg?react';
import { useRssNotifications } from '../notifications/useRssNotifications';
import { useQuickStarts } from '../overview/quickstarts/useQuickStarts';
import { gatewayAPI } from '../utils/gateway-api-utils';
import { useIsManagedCloudInstall } from './GatewayUIAuth';
import { PlatformAbout } from './PlatformAbout';
import { usePlatformActiveUser } from './PlatformActiveUserProvider';
import { PlatformRoute } from './PlatformRoutes';
export function PlatformMasthead() {
const { t } = useTranslation();
const { version: platformVersion } = useDocsVersion();
const pageNavigate = usePageNavigate();
useAwxNotifications();
useHubNotifications();
useRssNotifications();
const isSmOrLarger = useBreakpoint('sm');
const [_dialog, setDialog] = usePageDialog();
const { activePlatformUser, refreshActivePlatformUser } = usePlatformActiveUser();
const { refreshActiveAwxUser } = useAwxActiveUser();
const { refreshActiveEdaUser } = useEdaActiveUser();
const { refreshActiveHubUser } = useHubActiveUser();
const managedCloudInstall = useIsManagedCloudInstall() ?? false;
const quickStarts = useQuickStarts();
const logout = useCallback(async () => {
try {
await postRequest(gatewayAPI`/logout/`, {});
} catch {
// do nothing
}
void refreshActiveAwxUser?.();
void refreshActiveEdaUser?.();
void refreshActiveHubUser?.();
void refreshActivePlatformUser?.();
pageNavigate(PlatformRoute.Login);
}, [
pageNavigate,
refreshActiveEdaUser,
refreshActiveAwxUser,
refreshActiveHubUser,
refreshActivePlatformUser,
]);
return (
<PageMasthead
brand={
<div style={{ marginTop: -6 }}>
<PlatformLogo style={{ height: 48 }} />
</div>
}
>
<ToolbarItem style={{ flexGrow: 1 }}>
{!isSmOrLarger && <PlatformIcon style={{ height: 38, width: 38 }} />}
</ToolbarItem>
<ToolbarGroup
variant="action-group-plain"
// This fixes displaying the toolbar items on the right side of the masthead
// on small screens with the platform logo
style={{ marginLeft: -24 }}
>
<ToolbarItem>
<PageRefreshIcon />
</ToolbarItem>
<ToolbarItem visibility={{ default: 'hidden', lg: 'visible' }}>
<PageThemeSwitcher />
</ToolbarItem>
<ToolbarItem>
<PageNotificationsIcon />
</ToolbarItem>
<ChatbotToolbarItem />
<ToolbarItem>
<PageMastheadDropdown id="help-menu" icon={<QuestionCircleIcon />}>
<DropdownItem
id="documentation"
isExternalLink
component="a"
to={`https://access.redhat.com/documentation/en-us/red_hat_ansible_automation_platform`}
data-cy="masthead-documentation"
data-testid="masthead-documentation"
>
{t('Documentation')}
</DropdownItem>
{!managedCloudInstall && quickStarts.length > 0 ? (
<DropdownItem
id="quickstarts"
onClick={() => pageNavigate(PlatformRoute.QuickStarts)}
data-cy="masthead-quickstarts"
data-testid="masthead-quickstarts"
>
{t('Quick starts')}
</DropdownItem>
) : null}
<DropdownItem
id="about"
onClick={() => setDialog(<PlatformAbout platformVersion={platformVersion} />)}
data-cy="masthead-about"
data-testid="masthead-about"
>
{t('About')}
</DropdownItem>
</PageMastheadDropdown>
</ToolbarItem>
<ToolbarItem>
<PageMastheadDropdown
id="account-menu"
icon={<UserCircleIcon />}
label={activePlatformUser?.username}
>
<DropdownItem
id="user-details"
label={t('User details')}
onClick={() =>
pageNavigate(PlatformRoute.UserPage, { params: { id: activePlatformUser?.id } })
}
>
{t('User details')}
</DropdownItem>
<DropdownItem id="logout" label={t('Logout')} onClick={() => void logout()}>
{t('Logout')}
</DropdownItem>
</PageMastheadDropdown>
</ToolbarItem>
</ToolbarGroup>
</PageMasthead>
);
}