Skip to content

Commit

Permalink
useBaseLayoutHeader #1213
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadkitenge committed Jan 9, 2025
1 parent 7f7eccd commit 9fe5a77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 50 deletions.
16 changes: 14 additions & 2 deletions src/systems/systems.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
useMaterialReactTable,
} from 'material-react-table';
import React from 'react';
import { useParams } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';
import { System } from '../api/api.types';
import { useGetSystems } from '../api/systems';
import { usePreservedTableState } from '../common/preservedTableState.component';
Expand All @@ -49,7 +49,19 @@ import { DeleteSystemDialog } from './deleteSystemDialog.component';
import SystemDetails from './systemDetails.component';
import SystemDialog from './systemDialog.component';
import { SystemDirectoryDialog } from './systemDirectoryDialog.component';
import { useNavigateToSystem } from './systemsLayout.component';

/* Returns function that navigates to a specific system id (or to the root of all systems
if given null) */
export const useNavigateToSystem = () => {
const navigate = useNavigate();

return React.useCallback(
(newId: string | null) => {
navigate(`/systems${newId ? `/${newId}` : ''}`);
},
[navigate]
);
};

export type SystemMenuDialogType = 'edit' | 'duplicate' | 'delete';

Expand Down
56 changes: 8 additions & 48 deletions src/systems/systemsLayout.component.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,19 @@
import { Box, Grid } from '@mui/material';
import React from 'react';
import { Outlet, useNavigate, useParams } from 'react-router-dom';
import { Outlet, useParams } from 'react-router-dom';
import { useGetSystemsBreadcrumbs } from '../api/systems';
import Breadcrumbs from '../view/breadcrumbs.component';

/* Returns function that navigates to a specific system id (or to the root of all systems
if given null) */
export const useNavigateToSystem = () => {
const navigate = useNavigate();

return React.useCallback(
(newId: string | null) => {
navigate(`/systems${newId ? `/${newId}` : ''}`);
},
[navigate]
);
};
import BaseLayoutHeader from '../common/baseLayoutHeader.component';

function SystemsLayout() {
const { system_id: systemId } = useParams();
const navigateToSystem = useNavigateToSystem();

const { data: systemsBreadcrumbs } = useGetSystemsBreadcrumbs(systemId);

return (
<>
<Box height="100%">
<Grid
container
alignItems="center"
justifyContent="space-between"
sx={{
display: 'flex',
paddingLeft: '4px',
}}
>
<div
style={{
display: 'flex',
alignItems: 'center',
paddingTop: '20px',
paddingBottom: '20px',
}}
>
<Breadcrumbs
breadcrumbsInfo={systemsBreadcrumbs}
onChangeNode={navigateToSystem}
onChangeNavigateHome={() => navigateToSystem(null)}
homeLocation="Systems"
/>
</div>
</Grid>
<Outlet />
</Box>
</>
<BaseLayoutHeader
homeLocation="Systems"
breadcrumbsInfo={systemsBreadcrumbs}
>
<Outlet />
</BaseLayoutHeader>
);
}

Expand Down

0 comments on commit 9fe5a77

Please sign in to comment.