From 9a7b7869ca2f30b9591feb3cd934ad18962a6490 Mon Sep 17 00:00:00 2001 From: Noah Talerman Date: Wed, 14 Apr 2021 17:52:03 -0700 Subject: [PATCH 1/2] Cancel edit mode when a different label is clicked. Navigate back to correct label when cancel add new label --- .../hosts/ManageHostsPage/ManageHostsPage.jsx | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/frontend/pages/hosts/ManageHostsPage/ManageHostsPage.jsx b/frontend/pages/hosts/ManageHostsPage/ManageHostsPage.jsx index 18bdb84b4a66..820a1aaaccf3 100644 --- a/frontend/pages/hosts/ManageHostsPage/ManageHostsPage.jsx +++ b/frontend/pages/hosts/ManageHostsPage/ManageHostsPage.jsx @@ -25,6 +25,7 @@ import deepDifference from "utilities/deep_difference"; import HostContainer from "./components/HostContainer"; const NEW_LABEL_HASH = "#new_label"; +const EDIT_LABEL_HASH = "#edit_label"; const baseClass = "manage-hosts"; export class ManageHostsPage extends PureComponent { @@ -32,6 +33,7 @@ export class ManageHostsPage extends PureComponent { config: configInterface, dispatch: PropTypes.func, isAddLabel: PropTypes.bool, + isEditLabel: PropTypes.bool, labelErrors: PropTypes.shape({ base: PropTypes.string, }), @@ -52,7 +54,6 @@ export class ManageHostsPage extends PureComponent { super(props); this.state = { - isEditLabel: false, labelQueryText: "", pagedHosts: [], showAddHostModal: false, @@ -75,17 +76,34 @@ export class ManageHostsPage extends PureComponent { onAddLabelClick = (evt) => { evt.preventDefault(); - const { dispatch } = this.props; + const { dispatch, selectedFilter } = this.props; + dispatch(push(`${PATHS.MANAGE_HOSTS}/${selectedFilter}${NEW_LABEL_HASH}`)); - dispatch(push(`${PATHS.MANAGE_HOSTS}${NEW_LABEL_HASH}`)); + return false; + }; + + onEditLabelClick = (evt) => { + evt.preventDefault(); + + const { dispatch, selectedFilter } = this.props; + console.log(selectedFilter); + dispatch(push(`${PATHS.MANAGE_HOSTS}/${selectedFilter}${EDIT_LABEL_HASH}`)); return false; }; onCancelAddLabel = () => { - const { dispatch } = this.props; + const { dispatch, selectedFilter } = this.props; + + dispatch(push(`${PATHS.MANAGE_HOSTS}/${selectedFilter}`)); + + return false; + }; + + onCancelEditLabel = () => { + const { dispatch, selectedFilter } = this.props; - dispatch(push(PATHS.MANAGE_HOSTS)); + dispatch(push(`${PATHS.MANAGE_HOSTS}/${selectedFilter}`)); return false; }; @@ -100,12 +118,12 @@ export class ManageHostsPage extends PureComponent { }; onEditLabel = (formData) => { - const { dispatch, selectedLabel } = this.props; + const { dispatch, selectedLabel, selectedFilter } = this.props; const updateAttrs = deepDifference(formData, selectedLabel); return dispatch(labelActions.update(selectedLabel, updateAttrs)) .then(() => { - this.toggleEditLabel(); + dispatch(push(`${PATHS.MANAGE_HOSTS}/${selectedFilter}`)); return false; }) @@ -180,14 +198,6 @@ export class ManageHostsPage extends PureComponent { return false; }; - toggleEditLabel = () => { - const { isEditLabel } = this.state; - - this.setState({ isEditLabel: !isEditLabel }); - - return false; - }; - renderAddHostModal = () => { const { toggleAddHostModal } = this; const { showAddHostModal } = this.state; @@ -240,7 +250,7 @@ export class ManageHostsPage extends PureComponent { }; renderDeleteButton = () => { - const { toggleDeleteLabelModal, toggleEditLabel } = this; + const { toggleDeleteLabelModal, onEditLabelClick } = this; const { selectedLabel: { type }, } = this.props; @@ -251,7 +261,7 @@ export class ManageHostsPage extends PureComponent { return (
-