From: Daniel Kutyła Date: Tue, 28 Jul 2020 21:32:20 +0000 (+0200) Subject: 16627: Added refresh button to main contet bar X-Git-Tag: 2.1.0~18^2~1 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/cdd2d0222b4a0d7d2b6e0cf27ca3951d7d89a8c1 16627: Added refresh button to main contet bar Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- diff --git a/src/components/refresh-button/refresh-button.test.tsx b/src/components/refresh-button/refresh-button.test.tsx new file mode 100644 index 00000000..f6372e5c --- /dev/null +++ b/src/components/refresh-button/refresh-button.test.tsx @@ -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('', () => { + let props; + + beforeEach(() => { + props = { + history: { + push: jest.fn(), + }, + classes: {}, + }; + }); + + it('should render without issues', () => { + // when + const wrapper = shallow(); + + // then + expect(wrapper.html()).toContain('button'); + }); + + it('should pass window location to router', () => { + // setup + const wrapper = shallow(); + + // 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 index 00000000..f34a0213 --- /dev/null +++ b/src/components/refresh-button/refresh-button.tsx @@ -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 = theme => ({ + button: { + boxShadow: 'none', + padding: '2px 10px 2px 5px', + fontSize: '0.75rem' + }, + buttonRight: { + marginLeft: 'auto', + }, +}); + +export const RefreshButton = ({ history, classes }: RouteComponentProps & WithStyles) => + ; + +export default withStyles(styles)(withRouter(RefreshButton)); \ No newline at end of file diff --git a/src/views-components/main-content-bar/main-content-bar.tsx b/src/views-components/main-content-bar/main-content-bar.tsx index c0014d00..c8565d62 100644 --- a/src/views-components/main-content-bar/main-content-bar.tsx +++ b/src/views-components/main-content-bar/main-content-bar.tsx @@ -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 = 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) => - - - - - - - {props.buttonVisible && - - - - } - - - ); +export const MainContentBar = + connect((state: RootState) => ({ + buttonVisible: isButtonVisible(state) + }), { + onDetailsPanelToggle: toggleDetailsPanel, + })( + withStyles(styles)( + (props: MainContentBarProps & WithStyles & any) => + + + + + + + + + + {props.buttonVisible && + + + + } + + + + ) + );