Skip to content

Commit e9788b4

Browse files
authored
Merge branch 'main' into issue/h2oai#2047
2 parents bd12dad + af8b8b3 commit e9788b4

File tree

2 files changed

+62
-43
lines changed

2 files changed

+62
-43
lines changed

ui/src/nav.test.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ describe('Nav.tsx', () => {
107107
expect(pushMock).toHaveBeenCalledTimes(0)
108108
})
109109

110+
it('Does not set args and calls sync when link is opened in a new window', () => {
111+
const pushMock = jest.fn()
112+
const { getByTitle } = render(<View {...navProps} />)
113+
114+
wave.push = pushMock
115+
116+
fireEvent.click(getByTitle('Nav 1'), { ctrlKey: true, metaKey: true })
117+
118+
expect(wave.args['nav1']).toBeUndefined()
119+
expect(pushMock).not.toHaveBeenCalled()
120+
})
121+
110122
it('Sets window location hash when name starts with hash', () => {
111123
const { getByTitle } = render(<View {...navPropsHash} />)
112124
fireEvent.click(getByTitle('Nav 1'))

ui/src/nav.tsx

+50-43
Original file line numberDiff line numberDiff line change
@@ -72,49 +72,54 @@ export interface State {
7272
color?: 'card' | 'primary'
7373
}
7474

75-
const css = stylesheet({
76-
card: {
77-
display: 'flex',
78-
flexDirection: 'column'
79-
},
80-
title: {
81-
color: cssVar('$themePrimary')
82-
},
83-
icon: {
84-
fontSize: 56,
85-
display: 'flex',
86-
justifyContent: 'center'
87-
},
88-
header: {
89-
padding: padding(24, 24, 0),
90-
textAlign: 'center'
91-
},
92-
img: {
93-
maxHeight: 100
94-
},
95-
brand: {
96-
marginBottom: 10
97-
},
98-
secondaryItems: {
99-
padding: 24,
100-
},
101-
persona: {
102-
$nest: {
103-
'.ms-Persona': {
104-
flexDirection: 'column',
105-
height: 'auto',
106-
},
107-
'.ms-Persona-details': {
108-
alignItems: 'center',
109-
padding: 0
75+
const
76+
css = stylesheet({
77+
card: {
78+
display: 'flex',
79+
flexDirection: 'column'
80+
},
81+
title: {
82+
color: cssVar('$themePrimary')
83+
},
84+
icon: {
85+
fontSize: 56,
86+
display: 'flex',
87+
justifyContent: 'center'
88+
},
89+
header: {
90+
padding: padding(24, 24, 0),
91+
textAlign: 'center'
92+
},
93+
img: {
94+
maxHeight: 100
95+
},
96+
brand: {
97+
marginBottom: 10
98+
},
99+
secondaryItems: {
100+
padding: 24,
101+
},
102+
persona: {
103+
$nest: {
104+
'.ms-Persona': {
105+
flexDirection: 'column',
106+
height: 'auto',
107+
},
108+
'.ms-Persona-details': {
109+
alignItems: 'center',
110+
padding: 0
111+
},
112+
'.ms-Persona-primaryText': {
113+
fontWeight: 500,
114+
marginTop: 12,
115+
}
110116
},
111-
'.ms-Persona-primaryText': {
112-
fontWeight: 500,
113-
marginTop: 12,
114-
}
115117
},
116-
},
117-
})
118+
}),
119+
getUrl = (name: S) => {
120+
const { origin, pathname } = window.location
121+
return name.startsWith('#') ? origin + pathname + name : ''
122+
}
118123

119124
export const
120125
XNav = ({ items, hideNav, linksOnly = false, valueB }: State & { hideNav?: () => void, linksOnly?: B, valueB: Box<S | undefined> }) => {
@@ -131,8 +136,10 @@ export const
131136
opacity: disabled ? 0.7 : undefined,
132137
marginTop: !linksOnly && idx === 0 && !g.label ? 30 : undefined
133138
},
134-
url: '',
135-
onClick: () => {
139+
url: path || getUrl(name),
140+
onClick: (ev) => {
141+
ev?.preventDefault()
142+
if (ev?.ctrlKey || ev?.metaKey) return
136143
valueB(name)
137144
if (hideNav) hideNav()
138145
if (path) window.open(path, "_blank")

0 commit comments

Comments
 (0)