From 1ad7e663a1f54e7184d62451b52b7e4f25475e1e Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Tue, 11 Feb 2020 10:11:17 -0800 Subject: [PATCH] fix org list page on delete --- .../OrganizationList/OrganizationList.jsx | 20 +++++++++++++++++-- awx/ui_next/src/util/qs.js | 1 - 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx b/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx index 3051861a05..2b278d2585 100644 --- a/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx +++ b/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.jsx @@ -1,5 +1,5 @@ import React, { useState, useEffect, useCallback } from 'react'; -import { useLocation, useRouteMatch } from 'react-router-dom'; +import { useLocation, useHistory, useRouteMatch } from 'react-router-dom'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; import { Card, PageSection } from '@patternfly/react-core'; @@ -13,7 +13,12 @@ import PaginatedDataList, { ToolbarAddButton, ToolbarDeleteButton, } from '@components/PaginatedDataList'; -import { getQSConfig, parseQueryString } from '@util/qs'; +import { + getQSConfig, + parseQueryString, + removeParams, + encodeNonDefaultQueryString, +} from '@util/qs'; import OrganizationListItem from './OrganizationListItem'; @@ -25,6 +30,7 @@ const QS_CONFIG = getQSConfig('organization', { function OrganizationsList({ i18n }) { const location = useLocation(); + const history = useHistory(); const match = useRouteMatch(); const [selected, setSelected] = useState([]); @@ -81,6 +87,16 @@ function OrganizationsList({ i18n }) { const handleOrgDelete = async () => { await deleteOrganizations(); + const params = parseQueryString(QS_CONFIG, location.search); + if (params.page > 1 && selected.length === organizations.length) { + const newParams = removeParams(QS_CONFIG, params, { page: params.page }); + history.push( + `${location.pathname}?${encodeNonDefaultQueryString( + QS_CONFIG, + newParams + )}` + ); + } await fetchOrganizations(); }; diff --git a/awx/ui_next/src/util/qs.js b/awx/ui_next/src/util/qs.js index c31e0061e9..8cdc9cc56d 100644 --- a/awx/ui_next/src/util/qs.js +++ b/awx/ui_next/src/util/qs.js @@ -90,7 +90,6 @@ export { addDefaultsToObject as _addDefaultsToObject }; /** * Convert query param object to url query string * Used to encode params for interacting with the api - * @param {object} qs config object for namespacing params, filtering defaults * @param {object} query param object * @return {string} url query string */