From ee864b2df318c50b74acc7b67b9496fef60d12ce Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Thu, 12 Sep 2019 14:11:49 -0700 Subject: [PATCH] clear Lookup query params when lookup is closed --- awx/ui_next/src/components/Lookup/Lookup.jsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/awx/ui_next/src/components/Lookup/Lookup.jsx b/awx/ui_next/src/components/Lookup/Lookup.jsx index 5d2dab89ba..a90ff851ae 100644 --- a/awx/ui_next/src/components/Lookup/Lookup.jsx +++ b/awx/ui_next/src/components/Lookup/Lookup.jsx @@ -64,7 +64,7 @@ class Lookup extends React.Component { count: 0, error: null, }; - this.qsConfig = getQSConfig('lookup', { + this.qsConfig = getQSConfig(props.qsNamespace, { page: 1, page_size: 5, order_by: props.sortedColumnKey, @@ -73,6 +73,7 @@ class Lookup extends React.Component { this.toggleSelected = this.toggleSelected.bind(this); this.saveModal = this.saveModal.bind(this); this.getData = this.getData.bind(this); + this.clearQSParams = this.clearQSParams.bind(this); } componentDidMount() { @@ -163,6 +164,8 @@ class Lookup extends React.Component { lookupSelectedItems = multiple ? [...value] : [value]; } this.setState({ lookupSelectedItems }); + } else { + this.clearQSParams(); } this.setState(prevState => ({ isModalOpen: !prevState.isModalOpen, @@ -179,6 +182,14 @@ class Lookup extends React.Component { this.handleModalToggle(); } + clearQSParams() { + const { history } = this.props; + const parts = history.location.search.replace(/^\?/, '').split('&'); + const ns = this.qsConfig.namespace; + const otherParts = parts.filter(param => !param.startsWith(`${ns}.`)) + history.push(`${history.location.pathname}?${otherParts.join('&')}`); + } + render() { const { isModalOpen, @@ -303,6 +314,7 @@ Lookup.propTypes = { sortedColumnKey: string.isRequired, multiple: bool, required: bool, + qsNamespace: string, }; Lookup.defaultProps = { @@ -312,6 +324,7 @@ Lookup.defaultProps = { value: null, multiple: false, required: false, + qsNamespace: 'lookup', }; export { Lookup as _Lookup };