Skip to content

Commit a09f5ad

Browse files
committed
[85, 126] fix endpoints, layouts
1 parent a0e7328 commit a09f5ad

File tree

14 files changed

+158
-133
lines changed

14 files changed

+158
-133
lines changed

frontend/src/App.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ const App: React.FC = () => {
3030
</Routes>
3131
) : (
3232
<Routes>
33-
<Route path="/" element={<Dashboard />} />
34-
<Route path="/account" element={<Account />} />
33+
<Route path="/" element={<Navigate replace to="/console" />} />
3534
<Route path="/account-deleted" element={<AccountDelete />} />
3635
<Route path="/login" element={<Login />} />
3736
<Route path="/reset-password" element={<ResetPassword />} />
38-
<Route path="/workspaces">
37+
<Route path="/console" element={<Dashboard />} />
38+
<Route path="/console/account" element={<Account />} />
39+
<Route path="/console/workspaces">
3940
<Route path="" element={<Workspaces />} />
4041
<Route path=":workspaceId" element={<Workspace />} />
4142
</Route>
43+
<Route path="/console/*" element={<Navigate replace to="/console" />} />
4244
<Route path="*" element={<Navigate replace to="/" />} />
4345
</Routes>
4446
)}

frontend/src/components/Layout/Header.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Tooltips from 'components/Layout/Tooltips'
1212
import WorkspaceTabs from 'components/Workspace/WorkspaceTabs'
1313
import { IS_STANDALONE } from 'const/Mode'
1414
import Profile from './Profile'
15+
import { APP_BAR_HEIGHT } from 'const/Layout'
1516

1617
const Header: FC<{
1718
handleDrawerOpen: () => void
@@ -40,7 +41,7 @@ const StandaloneHeader: FC = () => {
4041
const MultiUserHeader: FC<{ handleDrawerOpen: () => void }> = ({
4142
handleDrawerOpen,
4243
}) => {
43-
const showTabsRegex = /^\/workspaces\/.+$/
44+
const showTabsRegex = /^\/console\/workspaces\/.+$/
4445
const location = useLocation()
4546

4647
return (
@@ -68,6 +69,7 @@ const StyledAppBar = styled(MuiAppBar)({
6869
position: 'fixed',
6970
backgroundColor: '#E1DEDB',
7071
color: '#000000',
72+
height: APP_BAR_HEIGHT,
7173
})
7274

7375
const TitleLogo = styled(Typography)({

frontend/src/components/Layout/LeftMenu.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import ListItem from '@mui/material/ListItem'
66
import ListItemButton from '@mui/material/ListItemButton'
77
import ListItemIcon from '@mui/material/ListItemIcon'
88
import ListItemText from '@mui/material/ListItemText'
9-
import HomeIcon from '@mui/icons-material/Home'
10-
import SourceIcon from '@mui/icons-material/Source'
9+
import DashboardIcon from '@mui/icons-material/Dashboard';
10+
import AnalyticsIcon from '@mui/icons-material/Analytics'
1111
import { DRAWER_WIDTH } from 'const/Layout'
1212
import { Box } from '@mui/material'
1313

@@ -19,12 +19,12 @@ const LeftMenu: FC<{ open: boolean; handleDrawerClose: () => void }> = ({
1919

2020
const onClickDashboard = () => {
2121
handleDrawerClose()
22-
navigate('/')
22+
navigate('/console')
2323
}
2424

2525
const onClickWorkspaces = () => {
2626
handleDrawerClose()
27-
navigate('/workspaces')
27+
navigate('/console/workspaces')
2828
}
2929

3030
return (
@@ -35,15 +35,15 @@ const LeftMenu: FC<{ open: boolean; handleDrawerClose: () => void }> = ({
3535
<ListItem key="dashboard" disablePadding>
3636
<ListItemButton onClick={onClickDashboard}>
3737
<ListItemIcon>
38-
<HomeIcon />
38+
<DashboardIcon />
3939
</ListItemIcon>
4040
<ListItemText primary="Dashboard" />
4141
</ListItemButton>
4242
</ListItem>
4343
<ListItem key="workspaces" disablePadding>
4444
<ListItemButton onClick={onClickWorkspaces}>
4545
<ListItemIcon>
46-
<SourceIcon />
46+
<AnalyticsIcon />
4747
</ListItemIcon>
4848
<ListItemText primary="Workspaces" />
4949
</ListItemButton>

frontend/src/components/Layout/Profile.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Profile: FC = () => {
2828

2929
const onClickAccount = () => {
3030
setAnchorEl(null)
31-
navigate('/account')
31+
navigate('/console/account')
3232
}
3333

3434
return (
+60-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, useEffect, useState } from 'react'
1+
import { FC, ReactNode, useEffect, useState } from 'react'
22
import { useSelector, useDispatch } from 'react-redux'
33
import { useLocation, useNavigate } from 'react-router-dom'
44
import { Box } from '@mui/material'
@@ -9,58 +9,83 @@ import { getMe } from 'store/slice/User/UserActions'
99
import Header from './Header'
1010
import LeftMenu from './LeftMenu'
1111
import { IS_STANDALONE } from 'const/Mode'
12+
import Loading from 'components/common/Loading'
13+
import { APP_BAR_HEIGHT } from 'const/Layout'
1214

13-
const ignorePaths = ['/login', '/account-delete', '/reset-password']
14-
const loginPaths = ['/login', '/reset-password']
15+
const authRequiredPathRegex = /^\/console\/?.*/
1516

16-
const Layout: FC = ({ children }) => {
17+
const Layout = ({ children }: { children?: ReactNode }) => {
1718
const user = useSelector(selectCurrentUser)
1819
const location = useLocation()
19-
const [open, setOpen] = useState(false)
2020
const navigate = useNavigate()
2121
const dispatch = useDispatch()
2222

23-
const handleDrawerOpen = () => {
24-
setOpen(true)
25-
}
26-
27-
const handleDrawerClose = () => {
28-
setOpen(false)
29-
}
23+
const [loading, setLoadingAuth] = useState(
24+
!IS_STANDALONE && authRequiredPathRegex.test(location.pathname),
25+
)
3026

3127
useEffect(() => {
32-
!IS_STANDALONE && checkAuth()
28+
!IS_STANDALONE &&
29+
authRequiredPathRegex.test(location.pathname) &&
30+
checkAuth()
3331
// eslint-disable-next-line react-hooks/exhaustive-deps
3432
}, [location.pathname, user])
3533

3634
const checkAuth = async () => {
37-
if (user) return
35+
if (user) {
36+
if (loading) setLoadingAuth(false)
37+
return
38+
}
3839
const token = getToken()
39-
const isPageLogin = loginPaths.includes(window.location.pathname)
40+
const isLogin = location.pathname === '/login'
4041

4142
try {
4243
if (token) {
43-
dispatch(getMe())
44-
if (isPageLogin) navigate('/')
44+
await dispatch(getMe())
45+
if (isLogin) navigate('/console')
4546
return
46-
} else if (!isPageLogin) throw new Error('fail auth')
47+
} else if (!isLogin) throw new Error('fail auth')
4748
} catch {
48-
navigate('/login')
49+
navigate('/login', { replace: true })
50+
} finally {
51+
if (loading) setLoadingAuth(false)
4952
}
5053
}
5154

55+
if (loading) return <Loading />
56+
57+
return IS_STANDALONE || authRequiredPathRegex.test(location.pathname) ? (
58+
<AuthedLayout>{children}</AuthedLayout>
59+
) : (
60+
<UnauthedLayout>{children}</UnauthedLayout>
61+
)
62+
}
63+
64+
const AuthedLayout: FC = ({ children }) => {
65+
const [open, setOpen] = useState(false)
66+
const handleDrawerOpen = () => {
67+
setOpen(true)
68+
}
69+
70+
const handleDrawerClose = () => {
71+
setOpen(false)
72+
}
73+
return (
74+
<LayoutWrapper>
75+
<Header handleDrawerOpen={handleDrawerOpen} />
76+
<ContentBodyWrapper>
77+
<LeftMenu open={open} handleDrawerClose={handleDrawerClose} />
78+
<ChildrenWrapper>{children}</ChildrenWrapper>
79+
</ContentBodyWrapper>
80+
</LayoutWrapper>
81+
)
82+
}
83+
84+
const UnauthedLayout: FC = ({ children }) => {
5285
return (
5386
<LayoutWrapper>
54-
{ignorePaths.includes(location.pathname) ? null : (
55-
<Header handleDrawerOpen={handleDrawerOpen} />
56-
)}
5787
<ContentBodyWrapper>
58-
{ignorePaths.includes(location.pathname) ? null : (
59-
<LeftMenu open={open} handleDrawerClose={handleDrawerClose} />
60-
)}
61-
<ChildrenWrapper open={open}>
62-
{children}
63-
</ChildrenWrapper>
88+
<ChildrenWrapper>{children}</ChildrenWrapper>
6489
</ContentBodyWrapper>
6590
</LayoutWrapper>
6691
)
@@ -74,28 +99,21 @@ const LayoutWrapper = styled(Box)({
7499
const ContentBodyWrapper = styled(Box)(() => ({
75100
backgroundColor: '#ffffff',
76101
display: 'flex',
77-
paddingTop: 48,
78-
height: 'calc(100% - 48px)',
102+
paddingTop: APP_BAR_HEIGHT,
103+
height: `calc(100% - ${APP_BAR_HEIGHT}px)`,
79104
paddingRight: 10,
80-
overflow: 'hidden',
105+
overflow: 'auto',
81106
}))
82107

83-
const ChildrenWrapper = styled('main', { shouldForwardProp: (prop) => prop !== 'open' })<{
84-
open?: boolean;
85-
}>(({ theme, open }) => ({
108+
const ChildrenWrapper = styled('main', {
109+
shouldForwardProp: (prop) => prop !== 'open',
110+
})<{}>(({ theme }) => ({
86111
flexGrow: 1,
87112
padding: theme.spacing(3),
88113
transition: theme.transitions.create('margin', {
89114
easing: theme.transitions.easing.sharp,
90115
duration: theme.transitions.duration.leavingScreen,
91116
}),
92-
...(open && {
93-
transition: theme.transitions.create('margin', {
94-
easing: theme.transitions.easing.easeOut,
95-
duration: theme.transitions.duration.enteringScreen,
96-
}),
97-
marginLeft: 0,
98-
}),
99-
}));
117+
}))
100118

101119
export default Layout

frontend/src/components/Workspace/Experiment/Experiment.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import { ExperimentTable } from './ExperimentTable'
3+
import { CONTENT_HEIGHT } from 'const/Layout'
34

45
const Experiment = React.memo(() => {
56
return (
@@ -9,8 +10,7 @@ const Experiment = React.memo(() => {
910
display: 'flex',
1011
flexDirection: 'column',
1112
flexGrow: 1,
12-
height: '100vh',
13-
padding: 16,
13+
minHeight: CONTENT_HEIGHT,
1414
}}
1515
>
1616
<ExperimentTable />

frontend/src/components/Workspace/FlowChart/FlowChart.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import RightDrawer from './RightDrawer'
1010
import { selectRightDrawerIsOpen } from 'store/slice/RightDrawer/RightDrawerSelectors'
1111
import { UseRunPipelineReturnType } from 'store/slice/Pipeline/PipelineHook'
1212
import { CurrentPipelineInfo } from 'components/common/CurrentPipelineInfo'
13-
import { DRAWER_WIDTH, RIGHT_DRAWER_WIDTH } from 'const/Layout'
13+
import { CONTENT_HEIGHT, DRAWER_WIDTH, RIGHT_DRAWER_WIDTH } from 'const/Layout'
1414
import { Box } from '@mui/material'
1515
import { grey } from '@mui/material/colors'
1616

@@ -53,7 +53,7 @@ const MainContents = styled('main')<{ open: boolean }>(
5353
({ theme }) => ({
5454
flexDirection: 'column',
5555
flexGrow: 1,
56-
height: '90vh',
56+
minHeight: CONTENT_HEIGHT,
5757
transition: theme.transitions.create('margin', {
5858
easing: theme.transitions.easing.sharp,
5959
duration: theme.transitions.duration.leavingScreen,

frontend/src/components/Workspace/ToolBar.tsx

+34-18
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,39 @@ import { UseRunPipelineReturnType } from 'store/slice/Pipeline/PipelineHook'
55
import { NWBSettingButton } from './FlowChart/NWB'
66
import { SnakemakeButton } from './FlowChart/Snakemake'
77
import { RunButtons } from './RunButtons'
8+
import { Button } from '@mui/material'
9+
import ArrowBackIosIcon from '@mui/icons-material/ArrowBackIos'
10+
import { useNavigate } from 'react-router-dom'
11+
import { IS_STANDALONE } from 'const/Mode'
812
import { ImportWorkflowConfigButton } from './FlowChart/ImportWorkflowConfigButton'
913

10-
export const ToolBar = React.memo<UseRunPipelineReturnType>((props) => (
11-
<Box
12-
style={{
13-
position: 'absolute',
14-
float: 'right',
15-
textAlign: 'right',
16-
top: -7,
17-
right: 10,
18-
zIndex: 4,
19-
textTransform: 'none',
20-
}}
21-
>
22-
<ImportWorkflowConfigButton />
23-
<SnakemakeButton />
24-
<NWBSettingButton />
25-
<RunButtons {...props} />
26-
</Box>
27-
))
14+
export const ToolBar = React.memo<UseRunPipelineReturnType>((props) => {
15+
const navigate = useNavigate()
16+
return (
17+
<Box
18+
style={{
19+
position: 'absolute',
20+
float: 'right',
21+
textAlign: 'right',
22+
top: -7,
23+
right: 10,
24+
zIndex: 4,
25+
textTransform: 'none',
26+
fontSize: '1rem',
27+
}}
28+
>
29+
{ !IS_STANDALONE &&
30+
(
31+
<Button onClick={() => navigate('/console/workspaces')}>
32+
<ArrowBackIosIcon />
33+
Workspaces
34+
</Button>
35+
)
36+
}
37+
<ImportWorkflowConfigButton />
38+
<SnakemakeButton />
39+
<NWBSettingButton />
40+
<RunButtons {...props} />
41+
</Box>
42+
)
43+
})

frontend/src/components/Workspace/Visualize/Visualize.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { styled } from '@mui/material/styles'
33
import { FlexItemList } from './FlexItemList'
44
import { VisualizeItemEditor } from './VisualizeItemEditor'
55
import { CurrentPipelineInfo } from 'components/common/CurrentPipelineInfo'
6-
import { DRAWER_WIDTH } from 'const/Layout'
6+
import { CONTENT_HEIGHT, DRAWER_WIDTH } from 'const/Layout'
77
import { Box } from '@mui/material'
88
import { grey } from '@mui/material/colors'
99

@@ -42,7 +42,7 @@ const MainContents = styled('main')({
4242
display: 'flex',
4343
flexDirection: 'column',
4444
flexGrow: 1,
45-
height: '100vh',
45+
minHeight: CONTENT_HEIGHT
4646
})
4747

4848
export default Visualize

frontend/src/const/Layout.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
export const APP_BAR_HEIGHT = 60
2+
export const CONTENT_HEIGHT = `calc(100vh - 48px - ${APP_BAR_HEIGHT}px)` // 48px: spacing(3)
13
export const DRAWER_WIDTH = 240
24
export const RIGHT_DRAWER_WIDTH = 320

0 commit comments

Comments
 (0)