From 3263f15e7742236185e2b8e5203d1becc8bfdcf1 Mon Sep 17 00:00:00 2001 From: Janicki Artur Date: Wed, 12 Sep 2018 13:54:27 +0200 Subject: [PATCH] show and hide button depends on url Feature #14137 Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- .../side-panel-button/side-panel-button.tsx | 29 ++++++++++++------- .../process-log-panel/process-log-panel.tsx | 1 - 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/views-components/side-panel-button/side-panel-button.tsx b/src/views-components/side-panel-button/side-panel-button.tsx index 2781d479..80b3163f 100644 --- a/src/views-components/side-panel-button/side-panel-button.tsx +++ b/src/views-components/side-panel-button/side-panel-button.tsx @@ -13,6 +13,7 @@ import { StyleRulesCallback, WithStyles, withStyles, Toolbar, Grid, Button, Menu import { AddIcon, CollectionIcon, ProcessIcon, ProjectIcon } from '~/components/icon/icon'; import { openProjectCreateDialog } from '~/store/projects/project-create-actions'; import { openCollectionCreateDialog } from '~/store/collections/collection-create-actions'; +import { matchProjectRoute } from '~/routes/routes'; type CssRules = 'button' | 'menuItem' | 'icon'; @@ -33,6 +34,7 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ interface SidePanelDataProps { currentItemId: string; + showButton: boolean; } interface SidePanelState { @@ -41,9 +43,21 @@ interface SidePanelState { type SidePanelProps = SidePanelDataProps & DispatchProp & WithStyles; +const transformOrigin: PopoverOrigin = { + vertical: -50, + horizontal: 45 +}; + +const checkButtonVisibility = ({ router }: RootState) => { + const pathname = router.location ? router.location.pathname : ''; + const match = matchProjectRoute(pathname); + return match ? true : false; +}; + export const SidePanelButton = withStyles(styles)( connect((state: RootState) => ({ - currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties) + currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties), + showButton: checkButtonVisibility(state) }))( class extends React.Component { @@ -51,16 +65,11 @@ export const SidePanelButton = withStyles(styles)( anchorEl: undefined }; - transformOrigin: PopoverOrigin = { - vertical: -50, - horizontal: 45 - }; - render() { - const { classes } = this.props; + const { classes, showButton } = this.props; const { anchorEl } = this.state; return - + {showButton &&