Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ui): Reduce code duplication
- Loading branch information
Showing
10 changed files
with
184 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import {Divider, Grid, IconButton, styled, Typography} from "@mui/material"; | ||
import React, {FunctionComponent} from "react"; | ||
import { | ||
Help as HelpIcon, | ||
Refresh as RefreshIcon, | ||
} from "@mui/icons-material"; | ||
import {LoadingButton} from "@mui/lab"; | ||
import HelpDialog from "./HelpDialog"; | ||
|
||
const TopRightRefreshButton = styled(LoadingButton)(({theme}) => { | ||
return { | ||
minWidth: 0 | ||
}; | ||
}); | ||
|
||
interface DetailPageHeaderRowProps { | ||
title: string; | ||
icon: JSX.Element; | ||
helpText?: string, | ||
onRefreshClick?: () => void, | ||
isRefreshing?: boolean | ||
} | ||
|
||
const DetailPageHeaderRow: FunctionComponent<DetailPageHeaderRowProps> = ({ | ||
title, | ||
icon, | ||
helpText, | ||
onRefreshClick, | ||
isRefreshing | ||
}): JSX.Element => { | ||
const [helpDialogOpen, setHelpDialogOpen] = React.useState(false); | ||
|
||
return ( | ||
<> | ||
<Grid item container alignItems="center" spacing={1} justifyContent="space-between"> | ||
<Grid item style={{display:"flex"}}> | ||
<Grid item style={{paddingRight: "8px"}}> | ||
{icon} | ||
</Grid> | ||
<Grid item> | ||
<Typography>{title}</Typography> | ||
</Grid> | ||
</Grid> | ||
<Grid item> | ||
<Grid container> | ||
{ | ||
helpText !== undefined && | ||
<> | ||
<Grid | ||
item | ||
style={{marginTop:"-0.125rem"}} //:( | ||
> | ||
<IconButton | ||
onClick={() => { | ||
return setHelpDialogOpen(true); | ||
}} | ||
title="Help" | ||
> | ||
<HelpIcon/> | ||
</IconButton> | ||
</Grid> | ||
|
||
<HelpDialog | ||
dialogOpen={helpDialogOpen} | ||
setDialogOpen={(open: boolean) => { | ||
setHelpDialogOpen(open); | ||
}} | ||
helpText={helpText} | ||
/> | ||
</> | ||
} | ||
|
||
{ | ||
onRefreshClick !== undefined && | ||
<Grid item> | ||
<TopRightRefreshButton | ||
loading={isRefreshing ?? false} | ||
onClick={onRefreshClick} | ||
title="Refresh" | ||
> | ||
<RefreshIcon/> | ||
</TopRightRefreshButton> | ||
</Grid> | ||
} | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
<Divider sx={{mt: 1}}/> | ||
</> | ||
); | ||
}; | ||
|
||
export default DetailPageHeaderRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.