16627: Added refresh button to main contet bar
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Tue, 28 Jul 2020 21:32:20 +0000 (23:32 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Tue, 28 Jul 2020 21:32:20 +0000 (23:32 +0200)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

src/components/refresh-button/refresh-button.test.tsx [new file with mode: 0644]
src/components/refresh-button/refresh-button.tsx [new file with mode: 0644]
src/views-components/main-content-bar/main-content-bar.tsx

diff --git a/src/components/refresh-button/refresh-button.test.tsx b/src/components/refresh-button/refresh-button.test.tsx
new file mode 100644 (file)
index 0000000..f6372e5
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from "react";
+import { Button } from "@material-ui/core";
+import { shallow, configure } from "enzyme";
+import * as Adapter from "enzyme-adapter-react-16";
+import { RefreshButton } from './refresh-button';
+
+configure({ adapter: new Adapter() });
+
+describe('<RefreshButton />', () => {
+    let props;
+
+    beforeEach(() => {
+        props = {
+            history: {
+                push: jest.fn(),
+            },
+            classes: {},
+        };
+    });
+
+    it('should render without issues', () => {
+        // when
+        const wrapper = shallow(<RefreshButton {...props} />);
+
+        // then
+        expect(wrapper.html()).toContain('button');
+    });
+
+    it('should pass window location to router', () => {
+        // setup
+        const wrapper = shallow(<RefreshButton {...props} />);
+
+        // when
+        wrapper.find(Button).simulate('click');
+
+        // then
+        expect(props.history.push).toHaveBeenCalledWith('/');
+    });
+});
diff --git a/src/components/refresh-button/refresh-button.tsx b/src/components/refresh-button/refresh-button.tsx
new file mode 100644 (file)
index 0000000..f34a021
--- /dev/null
@@ -0,0 +1,38 @@
+
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import * as classNames from 'classnames';
+import { withRouter, RouteComponentProps } from 'react-router';
+import { StyleRulesCallback, Button, WithStyles, withStyles } from "@material-ui/core";
+import { ReRunProcessIcon } from '~/components/icon/icon';
+
+type CssRules = 'button' | 'buttonRight';
+
+const styles: StyleRulesCallback<CssRules> = theme => ({
+    button: {
+        boxShadow: 'none',
+        padding: '2px 10px 2px 5px',
+        fontSize: '0.75rem'
+    },
+    buttonRight: {
+        marginLeft: 'auto',
+    },
+});
+
+export const RefreshButton = ({ history, classes }: RouteComponentProps & WithStyles<CssRules>) =>
+    <Button
+        color="primary"
+        size="small"
+        variant="contained"
+        onClick={() => {
+            history.push(window.location.pathname);
+        }}
+        className={classNames(classes.buttonRight, classes.button)}>
+        <ReRunProcessIcon />
+        Refresh
+    </Button>;
+
+export default withStyles(styles)(withRouter(RefreshButton));
\ No newline at end of file
index c0014d005134bc52a706dc4c770baf00ae4907dc..c8565d62b1844c70e3c0eec7459b02e497dc9a28 100644 (file)
@@ -3,15 +3,27 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
-import { Toolbar, IconButton, Tooltip, Grid } from "@material-ui/core";
+
+import { Toolbar, StyleRulesCallback, IconButton, Tooltip, Grid, WithStyles, withStyles } from "@material-ui/core";
 import { DetailsIcon } from "~/components/icon/icon";
 import { Breadcrumbs } from "~/views-components/breadcrumbs/breadcrumbs";
 import { connect } from 'react-redux';
 import { RootState } from '~/store/store';
 import * as Routes from '~/routes/routes';
 import { toggleDetailsPanel } from '~/store/details-panel/details-panel-action';
+import RefreshButton from "~/components/refresh-button/refresh-button";
+
+type CssRules = "infoTooltip";
+
+const styles: StyleRulesCallback<CssRules> = theme => ({
+    infoTooltip: {
+        marginTop: '-10px',
+        marginLeft: '10px',
+    }
+});
 
 interface MainContentBarProps {
+    onRefreshPage: () => void;
     onDetailsPanelToggle: () => void;
     buttonVisible: boolean;
 }
@@ -27,22 +39,30 @@ const isButtonVisible = ({ router }: RootState) => {
         !Routes.matchMyAccountRoute(pathname) && !Routes.matchLinksRoute(pathname);
 };
 
-export const MainContentBar = connect((state: RootState) => ({
-    buttonVisible: isButtonVisible(state)
-}), {
-        onDetailsPanelToggle: toggleDetailsPanel
-    })((props: MainContentBarProps) =>
-        <Toolbar>
-            <Grid container>
-                <Grid container item xs alignItems="center">
-                    <Breadcrumbs />
-                </Grid>
-                <Grid item>
-                    {props.buttonVisible && <Tooltip title="Additional Info">
-                        <IconButton color="inherit" onClick={props.onDetailsPanelToggle}>
-                            <DetailsIcon />
-                        </IconButton>
-                    </Tooltip>}
-                </Grid>
-            </Grid>
-        </Toolbar>);
+export const MainContentBar =
+    connect((state: RootState) => ({
+        buttonVisible: isButtonVisible(state)
+    }), {
+        onDetailsPanelToggle: toggleDetailsPanel,
+    })(
+        withStyles(styles)(
+            (props: MainContentBarProps & WithStyles<CssRules> & any) =>
+                <Toolbar>
+                    <Grid container>
+                        <Grid item xs alignItems="center">
+                            <Breadcrumbs />
+                        </Grid>
+                        <Grid item>
+                            <RefreshButton />
+                        </Grid>
+                        <Grid item>
+                            {props.buttonVisible && <Tooltip title="Additional Info">
+                                <IconButton color="inherit" className={props.classes.infoTooltip} onClick={props.onDetailsPanelToggle}>
+                                    <DetailsIcon />
+                                </IconButton>
+                            </Tooltip>}
+                        </Grid>
+                    </Grid>
+                </Toolbar>
+        )
+    );