Merge remote-tracking branch 'origin/main' into 18207-Workbench2-is-not-clearing...
[arvados-workbench2.git] / 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 { StyleRulesCallback, Button, WithStyles, withStyles } from "@material-ui/core";
10 import { ReRunProcessIcon } from 'components/icon/icon';
11
12 type CssRules = 'button' | 'buttonRight';
13
14 const styles: StyleRulesCallback<CssRules> = theme => ({
15     button: {
16         boxShadow: 'none',
17         padding: '2px 10px 2px 5px',
18         fontSize: '0.75rem'
19     },
20     buttonRight: {
21         marginLeft: 'auto',
22     },
23 });
24
25 interface RefreshButtonProps {
26     onClick?: () => void;
27 }
28
29 export const RefreshButton = ({ history, classes, onClick }: RouteComponentProps & WithStyles<CssRules> & RefreshButtonProps) =>
30     <Button
31         color="primary"
32         size="small"
33         variant="contained"
34         onClick={() => {
35             history.replace(window.location.pathname);
36             if (onClick) {
37                 onClick();
38             }
39         }}
40         className={classNames(classes.buttonRight, classes.button)}>
41         <ReRunProcessIcon />
42         Refresh
43     </Button>;
44
45 export default withStyles(styles)(withRouter(RefreshButton));