8
8
// or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
9
9
// OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
10
10
// limitations under the License.
11
-
12
- import * as React from 'react'
11
+ import React , { useMemo } from 'react'
13
12
14
13
import { useState , setState } from '../store'
15
14
import { LoadInitialState } from '../model'
@@ -18,6 +17,8 @@ import {LoadInitialState} from '../model'
18
17
import TopNavigation from '@cloudscape-design/components/top-navigation'
19
18
import { useQueryClient } from 'react-query'
20
19
import { NavigateFunction , useNavigate } from 'react-router-dom'
20
+ import { ButtonDropdownProps } from '@cloudscape-design/components'
21
+ import { useTranslation } from 'react-i18next'
21
22
22
23
export function regions ( selected : string ) {
23
24
const supportedRegions = [
@@ -103,18 +104,16 @@ export const clearClusterOnRegionChange = (
103
104
}
104
105
105
106
export default function Topbar ( ) {
107
+ const { t} = useTranslation ( )
106
108
let username = useState ( [ 'identity' , 'attributes' , 'email' ] )
107
109
const queryClient = useQueryClient ( )
108
110
const navigate = useNavigate ( )
109
111
110
- const defaultRegion = useState ( [ 'aws' , 'region' ] ) || 'DEFAULT'
112
+ const defaultRegionText = t ( 'global.topBar.regionSelector.defaultRegionText' )
113
+ const defaultRegion = useState ( [ 'aws' , 'region' ] ) || defaultRegionText
111
114
const selectedRegion = useState ( [ 'app' , 'selectedRegion' ] ) || defaultRegion
112
115
const displayedRegions = regions ( selectedRegion )
113
116
114
- const handleLogout = ( ) => {
115
- window . location . href = 'logout'
116
- }
117
-
118
117
const selectRegion = ( region : any ) => {
119
118
let newRegion = region . detail . id
120
119
setState ( [ 'app' , 'selectedRegion' ] , newRegion )
@@ -123,17 +122,26 @@ export default function Topbar() {
123
122
queryClient . invalidateQueries ( )
124
123
}
125
124
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
+ )
127
135
128
136
return (
129
137
< div id = "top-bar" >
130
138
< TopNavigation
131
139
identity = { {
132
- title : 'AWS ParallelCluster UI' ,
140
+ title : t ( 'global.projectName' ) ,
133
141
href : '/' ,
134
142
logo : {
135
143
src : '/img/pcluster.svg' ,
136
- alt : 'AWS ParallelCluster UI Logo' ,
144
+ alt : t ( 'global.topBar.logoAltText' ) ,
137
145
} ,
138
146
} }
139
147
utilities = { [
@@ -143,34 +151,29 @@ export default function Topbar() {
143
151
type : 'menu-dropdown' ,
144
152
text : username || 'user' ,
145
153
iconName : 'user-profile' ,
146
- onItemClick : handleLogout ,
147
154
items : profileActions ,
148
155
}
149
156
: {
150
157
type : 'button' ,
151
- text : 'loading...' ,
158
+ text : t ( 'global.loading' ) ,
152
159
} ,
153
160
] ,
154
161
...[
155
162
selectedRegion && {
156
163
type : 'menu-dropdown' ,
157
- ariaLabel : 'Region' ,
164
+ ariaLabel : t ( 'global.topBar.regionSelector.ariaLabel' ) ,
158
165
disableUtilityCollapse : true ,
159
166
text : (
160
- < span style = { { fontWeight : 'normal' } } >
161
- { selectedRegion || 'region' }
162
- </ span >
167
+ < span style = { { fontWeight : 'normal' } } > { selectedRegion } </ span >
163
168
) ,
164
169
onItemClick : selectRegion ,
165
170
items : regionsToDropdownItems ( displayedRegions , selectedRegion ) ,
166
171
} ,
167
172
] ,
168
173
] }
169
- // @ts -expect-error TS(2741) FIXME: Property 'overflowMenuTitleText' is missing in typ... Remove this comment to see the full error message
170
174
i18nStrings = { {
171
- searchIconAriaLabel : 'Search' ,
172
- searchDismissIconAriaLabel : 'Close search' ,
173
- overflowMenuTriggerText : 'More' ,
175
+ overflowMenuTitleText : t ( 'global.topBar.overflowMenuTitleText' ) ,
176
+ overflowMenuTriggerText : t ( 'global.topBar.overflowMenuTriggerText' ) ,
174
177
} }
175
178
/>
176
179
</ div >
0 commit comments