Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.

Commit 71e4902

Browse files
authored
Merge pull request #545 from aws-samples/fix-logout
Fix sign out not working when a cluster is selected
2 parents 9235b52 + 7de2ebc commit 71e4902

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

frontend/locales/en/strings.json

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
"users": "Users",
1010
"viewLicense": "View License"
1111
},
12+
"topBar": {
13+
"signOut": "Sign out",
14+
"logoAltText": "$t(global.projectName} logo",
15+
"regionSelector": {
16+
"defaultRegionText": "Region",
17+
"ariaLabel": "Region"
18+
},
19+
"overflowMenuTitleText": "All",
20+
"overflowMenuTriggerText": "More"
21+
},
1222
"docs": {
1323
"title": "$t(global.projectName) documentation",
1424
"link": "https://pcluster.cloud/"

frontend/src/components/TopBar.tsx

+23-20
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
// or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
99
// OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
1010
// limitations under the License.
11-
12-
import * as React from 'react'
11+
import React, {useMemo} from 'react'
1312

1413
import {useState, setState} from '../store'
1514
import {LoadInitialState} from '../model'
@@ -18,6 +17,8 @@ import {LoadInitialState} from '../model'
1817
import TopNavigation from '@cloudscape-design/components/top-navigation'
1918
import {useQueryClient} from 'react-query'
2019
import {NavigateFunction, useNavigate} from 'react-router-dom'
20+
import {ButtonDropdownProps} from '@cloudscape-design/components'
21+
import {useTranslation} from 'react-i18next'
2122

2223
export function regions(selected: string) {
2324
const supportedRegions = [
@@ -103,18 +104,16 @@ export const clearClusterOnRegionChange = (
103104
}
104105

105106
export default function Topbar() {
107+
const {t} = useTranslation()
106108
let username = useState(['identity', 'attributes', 'email'])
107109
const queryClient = useQueryClient()
108110
const navigate = useNavigate()
109111

110-
const defaultRegion = useState(['aws', 'region']) || 'DEFAULT'
112+
const defaultRegionText = t('global.topBar.regionSelector.defaultRegionText')
113+
const defaultRegion = useState(['aws', 'region']) || defaultRegionText
111114
const selectedRegion = useState(['app', 'selectedRegion']) || defaultRegion
112115
const displayedRegions = regions(selectedRegion)
113116

114-
const handleLogout = () => {
115-
window.location.href = 'logout'
116-
}
117-
118117
const selectRegion = (region: any) => {
119118
let newRegion = region.detail.id
120119
setState(['app', 'selectedRegion'], newRegion)
@@ -123,17 +122,26 @@ export default function Topbar() {
123122
queryClient.invalidateQueries()
124123
}
125124

126-
const profileActions = [{type: 'button', id: 'signout', text: 'Sign out'}]
125+
const profileActions: ButtonDropdownProps.Items = useMemo(
126+
() => [
127+
{
128+
id: 'signout',
129+
text: t('global.topBar.signOut'),
130+
href: '/logout',
131+
},
132+
],
133+
[t],
134+
)
127135

128136
return (
129137
<div id="top-bar">
130138
<TopNavigation
131139
identity={{
132-
title: 'AWS ParallelCluster UI',
140+
title: t('global.projectName'),
133141
href: '/',
134142
logo: {
135143
src: '/img/pcluster.svg',
136-
alt: 'AWS ParallelCluster UI Logo',
144+
alt: t('global.topBar.logoAltText'),
137145
},
138146
}}
139147
utilities={[
@@ -143,34 +151,29 @@ export default function Topbar() {
143151
type: 'menu-dropdown',
144152
text: username || 'user',
145153
iconName: 'user-profile',
146-
onItemClick: handleLogout,
147154
items: profileActions,
148155
}
149156
: {
150157
type: 'button',
151-
text: 'loading...',
158+
text: t('global.loading'),
152159
},
153160
],
154161
...[
155162
selectedRegion && {
156163
type: 'menu-dropdown',
157-
ariaLabel: 'Region',
164+
ariaLabel: t('global.topBar.regionSelector.ariaLabel'),
158165
disableUtilityCollapse: true,
159166
text: (
160-
<span style={{fontWeight: 'normal'}}>
161-
{selectedRegion || 'region'}
162-
</span>
167+
<span style={{fontWeight: 'normal'}}>{selectedRegion}</span>
163168
),
164169
onItemClick: selectRegion,
165170
items: regionsToDropdownItems(displayedRegions, selectedRegion),
166171
},
167172
],
168173
]}
169-
// @ts-expect-error TS(2741) FIXME: Property 'overflowMenuTitleText' is missing in typ... Remove this comment to see the full error message
170174
i18nStrings={{
171-
searchIconAriaLabel: 'Search',
172-
searchDismissIconAriaLabel: 'Close search',
173-
overflowMenuTriggerText: 'More',
175+
overflowMenuTitleText: t('global.topBar.overflowMenuTitleText'),
176+
overflowMenuTriggerText: t('global.topBar.overflowMenuTriggerText'),
174177
}}
175178
/>
176179
</div>

0 commit comments

Comments
 (0)