Skip to content

Commit 39ac6d6

Browse files
committed
Merge branch '451-collapse-expand-for-the-right-side-panel' into 'master'
feat(ui): Collapse/expand for the right-side panel in DLE UI (#451) Closes #451 See merge request postgres-ai/database-lab!677
2 parents e1f64af + fe0b5fe commit 39ac6d6

File tree

9 files changed

+137
-11
lines changed

9 files changed

+137
-11
lines changed

ui/packages/ce/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@monaco-editor/react": "^4.4.5",
1414
"@mui/material": "^5.10.12",
1515
"@postgres.ai/shared": "link:../shared",
16+
"@postgres.ai/ce": "link:../ce",
1617
"@types/node": "^12.20.33",
1718
"@types/react": "^17.0.30",
1819
"@types/react-dom": "^17.0.10",

ui/packages/ce/src/App/Menu/styles.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
@include touch-transition(width);
1616

17+
@media screen and (max-width: '600px') {
18+
width: 100vw;
19+
}
20+
1721
&.collapsed {
1822
width: 64px;
1923
}

ui/packages/ce/src/components/PageContainer/styles.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
flex: 1 1 100%;
44
display: flex;
55
flex-direction: column;
6+
7+
@media screen and (max-width: '600px') {
8+
padding: 24px 12px 24px 12px;
9+
}
610
}

ui/packages/shared/components/Button2/styles.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
}
2727

2828
&.md {
29-
height: 26px;
29+
min-height: 26px;
3030
font-size: 14px;
3131
}
3232

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useEffect, useState } from 'react'
2+
3+
export const useWindowDimensions = () => {
4+
const [windowDimensions, setWindowDimensions] = useState(window.innerWidth)
5+
6+
useEffect(() => {
7+
const handleResize = () => {
8+
setWindowDimensions(window.innerWidth)
9+
}
10+
11+
window.addEventListener('resize', handleResize)
12+
return () => window.removeEventListener('resize', handleResize)
13+
}, [])
14+
15+
return windowDimensions
16+
}

ui/packages/shared/pages/Instance/Info/components/Property/styles.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
.name {
88
flex: 0 0 134px;
99
margin-right: 14px;
10+
11+
@media screen and (max-width: '600px') {
12+
flex: 1 1 100%;
13+
margin-right: 7px;
14+
}
1015
}
1116

1217
.content {

ui/packages/shared/pages/Instance/Info/index.tsx

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,119 @@
55
*--------------------------------------------------------------------------
66
*/
77

8+
import cn from 'classnames'
9+
import { useEffect, useState } from 'react'
810
import { makeStyles } from '@material-ui/core'
911

12+
import { Button } from '@postgres.ai/ce/src/App/Menu/components/Button'
13+
import { useWindowDimensions } from '@postgres.ai/shared/hooks/useWindowDimensions'
14+
import { ReactComponent as ArrowRightIcon } from '@postgres.ai/ce/src/App/Menu/icons/arrow-right.svg'
15+
import { ReactComponent as ArrowLeftIcon } from '@postgres.ai/ce/src/App/Menu/icons/arrow-left.svg'
16+
1017
import { Status } from './Status'
1118
import { Retrieval } from './Retrieval'
1219
import { Connection } from './Connection'
1320
import { Disks } from './Disks'
1421
import { Snapshots } from './Snapshots'
1522

23+
import styles from './styles.module.scss'
24+
25+
const SIDEBAR_COLLAPSED_PARAM = 'overviewSidebarCollapsed'
26+
const SMALL_BREAKPOINT_PX = 937
27+
1628
const useStyles = makeStyles(
1729
(theme) => ({
1830
root: {
19-
flex: '0 0 437px',
20-
minWidth: 0,
31+
flex: '0 0 auto',
2132

2233
[theme.breakpoints.down('md')]: {
23-
flexBasis: '300px',
34+
width: '300px',
2435
},
2536

2637
[theme.breakpoints.down('sm')]: {
27-
flex: '1 1 100%',
38+
flex: '0 0 auto',
39+
width: '100%',
2840
marginTop: '20px',
2941
},
3042
},
43+
collapseBtn: {
44+
background: '#f9f9f9',
45+
margin: '20px 0 10px 0',
46+
fontWeight: 500,
47+
48+
'& svg': {
49+
marginRight: '5px',
50+
},
51+
52+
'&:hover': {
53+
background: '#f1f1f1',
54+
},
55+
},
56+
arrowImage: {
57+
width: '16px',
58+
height: '16px',
59+
60+
'& path': {
61+
fill: '#000',
62+
},
63+
},
3164
}),
3265
{ index: 1 },
3366
)
3467

3568
export const Info = () => {
3669
const classes = useStyles()
70+
const width = useWindowDimensions()
71+
const isMobileScreen = width <= SMALL_BREAKPOINT_PX
72+
73+
const [isCollapsed, setIsCollapsed] = useState(
74+
() => localStorage.getItem(SIDEBAR_COLLAPSED_PARAM) === '1',
75+
)
76+
77+
const handleClick = () => {
78+
setIsCollapsed(!isCollapsed)
79+
localStorage.setItem(SIDEBAR_COLLAPSED_PARAM, isCollapsed ? '0' : '1')
80+
}
81+
82+
useEffect(() => {
83+
if (isMobileScreen) {
84+
setIsCollapsed(false)
85+
}
86+
}, [width])
3787

3888
return (
39-
<div className={classes.root}>
40-
<Status />
41-
<Retrieval />
42-
<Connection />
43-
<Disks />
44-
<Snapshots />
89+
<div
90+
className={cn(
91+
styles.root,
92+
!isCollapsed ? classes.root : styles.collapsed,
93+
)}
94+
>
95+
{!isMobileScreen && (
96+
<Button
97+
className={classes.collapseBtn}
98+
onClick={handleClick}
99+
isCollapsed={isCollapsed}
100+
icon={
101+
isCollapsed ? (
102+
<ArrowLeftIcon className={classes.arrowImage} />
103+
) : (
104+
<ArrowRightIcon className={classes.arrowImage} />
105+
)
106+
}
107+
>
108+
Collapse
109+
</Button>
110+
)}
111+
112+
{!isCollapsed && (
113+
<div>
114+
<Status />
115+
<Retrieval />
116+
<Connection />
117+
<Disks />
118+
<Snapshots />
119+
</div>
120+
)}
45121
</div>
46122
)
47123
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@import '@postgres.ai/shared/styles/mixins';
2+
3+
.root {
4+
min-height: 0;
5+
min-width: 0;
6+
width: 437px;
7+
8+
@media screen and (max-width: '600px') {
9+
width: 100%;
10+
}
11+
12+
@include touch-transition(width);
13+
14+
&.collapsed {
15+
height: 100%;
16+
width: 64px;
17+
}
18+
}

ui/pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)