21720:
[arvados.git] / services / workbench2 / src / components / refresh-button / refresh-button.tsx
1
2 // Copyright (C) The Arvados Authors. All rights reserved.
3 //
4 // SPDX-License-Identifier: AGPL-3.0
5
6 import React from 'react';
7 import classNames from 'classnames';
8 import { withRouter, RouteComponentProps } from 'react-router';
9 import { CustomStyleRulesCallback } from 'common/custom-theme';
10 import { Button } from "@mui/material";
11 import { WithStyles } from '@mui/styles';
12 import withStyles from '@mui/styles/withStyles';
13 import { ReRunProcessIcon } from 'components/icon/icon';
14
15 type CssRules = 'button' | 'buttonRight';
16
17 const styles: CustomStyleRulesCallback<CssRules> = theme => ({
18     button: {
19         boxShadow: 'none',
20         padding: '2px 10px 2px 5px',
21         fontSize: '0.75rem'
22     },
23     buttonRight: {
24         marginLeft: 'auto',
25     },
26 });
27
28 interface RefreshButtonProps {
29     onClick?: () => void;
30 }
31
32 export const LAST_REFRESH_TIMESTAMP = 'lastRefreshTimestamp';
33
34 export const RefreshButton = ({ history, classes, onClick }: RouteComponentProps & WithStyles<CssRules> & RefreshButtonProps) =>
35     <Button
36         color="primary"
37         size="small"
38         variant="contained"
39         onClick={() => {
40             // Notify interested parties that the refresh button was clicked.
41             const now = (new Date()).getTime();
42             localStorage.setItem(LAST_REFRESH_TIMESTAMP, now.toString());
43             history.replace(window.location.pathname);
44             if (onClick) {
45                 onClick();
46             }
47         }}
48         className={classNames(classes.buttonRight, classes.button)}>
49         <ReRunProcessIcon />
50         Refresh
51     </Button>;
52
53 export default withStyles(styles)(withRouter(RefreshButton));