Skip to content

Commit 1f42de5

Browse files
committed
add onChange prop to AppNavigation.tsx, so that caller can reset actions on nav change
1 parent f2a553d commit 1f42de5

File tree

4 files changed

+59
-135
lines changed

4 files changed

+59
-135
lines changed

redisinsight/ui/src/components/base/layout/flex/flex.styles.ts

Lines changed: 53 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { HTMLAttributes, PropsWithChildren, ReactNode } from 'react'
22

33
import styled, { css } from 'styled-components'
4-
import { useTheme } from '@redis-ui/styles'
5-
import { CommonProps } from 'uiSrc/components/base/theme/types'
4+
import { CommonProps, Theme } from 'uiSrc/components/base/theme/types'
65

76
export const gapSizes = ['none', 'xs', 's', 'm', 'l', 'xl', 'xxl'] as const
87
export type GapSizeType = (typeof gapSizes)[number]
@@ -18,22 +17,12 @@ export type GridProps = HTMLAttributes<HTMLDivElement> & {
1817
responsive?: boolean
1918
}
2019

21-
type ThemeType = ReturnType<typeof useTheme>
22-
2320
const flexGridStyles = {
2421
columns: {
25-
1: css`
26-
grid-template-columns: repeat(1, max-content);
27-
`,
28-
2: css`
29-
grid-template-columns: repeat(2, max-content);
30-
`,
31-
3: css`
32-
grid-template-columns: repeat(3, max-content);
33-
`,
34-
4: css`
35-
grid-template-columns: repeat(4, max-content);
36-
`,
22+
1: 'repeat(1, max-content)',
23+
2: 'repeat(2, max-content)',
24+
3: 'repeat(3, max-content)',
25+
4: 'repeat(4, max-content)',
3726
},
3827
responsive: css`
3928
@media screen and (max-width: 767px) {
@@ -48,9 +37,9 @@ const flexGridStyles = {
4837

4938
export const StyledGrid = styled.div<GridProps>`
5039
display: grid;
51-
${({ columns = 1 }) =>
52-
columns ? flexGridStyles.columns[columns] : flexGridStyles.columns['1']}
53-
${({ gap = 'none' }) => (gap ? flexGroupStyles.gapSizes[gap] : '')}
40+
grid-template-columns: ${({ columns = 1 }) =>
41+
flexGridStyles.columns[columns] ?? flexGridStyles.columns['1']};
42+
gap: ${({ gap = 'none' }) => flexGroupStyles.gapSizes[gap] ?? '0'};
5443
${({ centered = false }) => (centered ? flexGroupStyles.centered : '')}
5544
${({ responsive = false }) => (responsive ? flexGridStyles.responsive : '')}
5645
`
@@ -81,87 +70,51 @@ const flexGroupStyles = {
8170
wrap: css`
8271
flex-wrap: wrap;
8372
`,
84-
grow: css`
85-
flex-grow: 1;
86-
`,
87-
noGrow: css`
88-
flex-grow: 0;
89-
`,
9073
centered: css`
9174
justify-content: center;
9275
align-items: center;
9376
`,
9477
gapSizes: {
9578
none: css``,
9679
xs: css`
97-
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space025};
80+
${({ theme }: { theme: Theme }) => theme.core.space.space025};
9881
`,
9982
s: css`
100-
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space050};
83+
${({ theme }: { theme: Theme }) => theme.core.space.space050};
10184
`,
10285
m: css`
103-
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space100};
86+
${({ theme }: { theme: Theme }) => theme.core.space.space100};
10487
`,
10588
l: css`
106-
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space150};
89+
${({ theme }: { theme: Theme }) => theme.core.space.space150};
10790
`,
10891
xl: css`
109-
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space250};
92+
${({ theme }: { theme: Theme }) => theme.core.space.space250};
11093
`,
11194
xxl: css`
112-
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space300};
95+
${({ theme }: { theme: Theme }) => theme.core.space.space300};
11396
`,
11497
},
11598
justify: {
116-
center: css`
117-
justify-content: center;
118-
`,
119-
start: css`
120-
justify-content: flex-start;
121-
`,
122-
end: css`
123-
justify-content: flex-end;
124-
`,
125-
between: css`
126-
justify-content: space-between;
127-
`,
128-
around: css`
129-
justify-content: space-around;
130-
`,
131-
evenly: css`
132-
justify-content: space-evenly;
133-
`,
99+
center: 'center',
100+
start: 'flex-start',
101+
end: 'flex-end',
102+
between: 'space-between',
103+
around: 'space-around',
104+
evenly: 'space-evenly',
134105
},
135106
align: {
136-
center: css`
137-
align-items: center;
138-
`,
139-
stretch: css`
140-
align-items: stretch;
141-
`,
142-
baseline: css`
143-
align-items: baseline;
144-
`,
145-
start: css`
146-
align-items: flex-start;
147-
`,
148-
end: css`
149-
align-items: flex-end;
150-
`,
107+
center: 'center',
108+
stretch: 'stretch',
109+
baseline: 'baseline',
110+
start: 'flex-start',
111+
end: 'flex-end',
151112
},
152113
direction: {
153-
row: css`
154-
flex-direction: row;
155-
`,
156-
rowReverse: css`
157-
flex-direction: row-reverse;
158-
`,
159-
column: css`
160-
flex-direction: column;
161-
`,
162-
columnReverse: css`
163-
flex-direction: column-reverse;
164-
`,
114+
row: 'row',
115+
rowReverse: 'row-reverse',
116+
column: 'column',
117+
columnReverse: 'column-reverse',
165118
},
166119
responsive: css`
167120
@media screen and (max-width: 767px) {
@@ -208,15 +161,14 @@ type StyledFlexProps = Omit<
208161
}
209162
export const StyledFlex = styled.div<StyledFlexProps>`
210163
display: flex;
211-
align-items: stretch;
212-
${({ $grow = true }) =>
213-
$grow ? flexGroupStyles.grow : flexGroupStyles.noGrow}
214-
${({ $gap = 'none' }) => ($gap ? flexGroupStyles.gapSizes[$gap] : '')}
215-
${({ $align = 'stretch' }) => ($align ? flexGroupStyles.align[$align] : '')}
216-
${({ $direction = 'row' }) =>
217-
$direction ? flexGroupStyles.direction[$direction] : ''}
218-
${({ $justify = 'start' }) =>
219-
$justify ? flexGroupStyles.justify[$justify] : ''}
164+
flex-grow: ${({ $grow = true }) => ($grow ? 1 : 0)};
165+
gap: ${({ $gap = 'none' }) => flexGroupStyles.gapSizes[$gap] ?? '0'};
166+
align-items: ${({ $align = 'stretch' }) =>
167+
flexGroupStyles.align[$align] ?? 'stretch'};
168+
flex-direction: ${({ $direction = 'row' }) =>
169+
flexGroupStyles.direction[$direction] ?? 'row'};
170+
justify-content: ${({ $justify = 'start' }) =>
171+
flexGroupStyles.justify[$justify] ?? 'flex-start'};
220172
${({ $centered = false }) => ($centered ? flexGroupStyles.centered : '')}
221173
${({ $responsive = false }) =>
222174
$responsive ? flexGroupStyles.responsive : ''}
@@ -270,60 +222,46 @@ export const flexItemStyles = {
270222
},
271223
padding: {
272224
'0': css`
273-
padding: ${({ theme }: { theme: ThemeType }) =>
274-
theme.core.space.space000};
225+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space000};
275226
`,
276227
'1': css`
277-
padding: ${({ theme }: { theme: ThemeType }) =>
278-
theme.core.space.space010};
228+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space010};
279229
`,
280230
'2': css`
281-
padding: ${({ theme }: { theme: ThemeType }) =>
282-
theme.core.space.space025};
231+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space025};
283232
`,
284233
'3': css`
285-
padding: ${({ theme }: { theme: ThemeType }) =>
286-
theme.core.space.space050};
234+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space050};
287235
`,
288236
'4': css`
289-
padding: ${({ theme }: { theme: ThemeType }) =>
290-
theme.core.space.space100};
237+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space100};
291238
`,
292239
'5': css`
293-
padding: ${({ theme }: { theme: ThemeType }) =>
294-
theme.core.space.space150};
240+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space150};
295241
`,
296242
'6': css`
297-
padding: ${({ theme }: { theme: ThemeType }) =>
298-
theme.core.space.space200};
243+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space200};
299244
`,
300245
'7': css`
301-
padding: ${({ theme }: { theme: ThemeType }) =>
302-
theme.core.space.space250};
246+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space250};
303247
`,
304248
'8': css`
305-
padding: ${({ theme }: { theme: ThemeType }) =>
306-
theme.core.space.space300};
249+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space300};
307250
`,
308251
'9': css`
309-
padding: ${({ theme }: { theme: ThemeType }) =>
310-
theme.core.space.space400};
252+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space400};
311253
`,
312254
'10': css`
313-
padding: ${({ theme }: { theme: ThemeType }) =>
314-
theme.core.space.space500};
255+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space500};
315256
`,
316257
'11': css`
317-
padding: ${({ theme }: { theme: ThemeType }) =>
318-
theme.core.space.space550};
258+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space550};
319259
`,
320260
'12': css`
321-
padding: ${({ theme }: { theme: ThemeType }) =>
322-
theme.core.space.space600};
261+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space600};
323262
`,
324263
'13': css`
325-
padding: ${({ theme }: { theme: ThemeType }) =>
326-
theme.core.space.space800};
264+
padding: ${({ theme }: { theme: Theme }) => theme.core.space.space800};
327265
`,
328266
},
329267
}
@@ -377,22 +315,8 @@ export type FlexItemProps = React.HTMLAttributes<HTMLDivElement> &
377315

378316
export const StyledFlexItem = styled.div<FlexItemProps>`
379317
display: flex;
380-
flex-direction: ${({ $direction = 'column' }) => {
381-
if (!dirValues.includes($direction)) {
382-
return 'column'
383-
}
384-
switch ($direction) {
385-
case 'row':
386-
return 'row'
387-
case 'rowReverse':
388-
return 'row-reverse'
389-
case 'column':
390-
return 'column'
391-
case 'columnReverse':
392-
default:
393-
return 'column-reverse'
394-
}
395-
}};
318+
flex-direction: ${({ $direction = 'column' }) =>
319+
flexGroupStyles.direction[$direction] ?? 'column'};
396320
${({ grow }) => {
397321
if (!grow) {
398322
return flexItemStyles.growZero

redisinsight/ui/src/components/navigation-menu/app-navigation/AppNavigation.styles.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type NavContainerProps = React.ComponentProps<typeof Row> & {
2020
export const StyledAppNavigationContainer = styled(Row)<NavContainerProps>`
2121
height: 100%;
2222
width: auto;
23-
max-width: 35%;
23+
max-width: 50%;
2424
&:first-child {
2525
padding-inline-start: ${({ theme }) => theme.components.appBar.group.gap};
2626
}
@@ -29,9 +29,7 @@ export const StyledAppNavigationContainer = styled(Row)<NavContainerProps>`
2929
}
3030
3131
border-bottom: ${({ theme, $borderLess }) =>
32-
$borderLess
33-
? 'none'
34-
: theme.components.tabs.variants.default.tabsLine.size}
32+
$borderLess ? '0' : theme.components.tabs.variants.default.tabsLine.size}
3533
solid
3634
${({ theme }) => theme.components.tabs.variants.default.tabsLine.color};
3735
`

redisinsight/ui/src/components/navigation-menu/app-navigation/AppNavigation.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ const AppNavigationContainer = ({
3939

4040
export type AppNavigationProps = {
4141
actions?: ReactNode
42+
onChange?: (tabValue: string) => void
4243
}
4344

44-
const AppNavigation = ({ actions }: AppNavigationProps) => {
45+
const AppNavigation = ({ actions, onChange }: AppNavigationProps) => {
4546
const { privateRoutes } = useNavigation()
4647
const activeTab = privateRoutes.find((route) => route.isActivePage)
4748
const navTabs: TabInfo[] = privateRoutes.map((route) => ({
@@ -62,6 +63,7 @@ const AppNavigation = ({ actions }: AppNavigationProps) => {
6263
(route) => route.pageName === tabValue,
6364
)
6465
if (tabNavItem) {
66+
onChange?.(tabNavItem.pageName) // remove actions before navigation, displayed page, should set their own actions
6567
tabNavItem.onClick()
6668
}
6769
}}

redisinsight/ui/src/templates/instance-page-template/InstancePageTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const InstancePageTemplate = (props: Props) => {
9999
return (
100100
<>
101101
<InstanceHeader />
102-
<AppNavigation actions={actions} />
102+
<AppNavigation actions={actions} onChange={() => setActions(null)} />
103103
<ResizableContainer
104104
ref={ref}
105105
direction="vertical"

0 commit comments

Comments
 (0)