mirror of
https://github.com/ansible/awx.git
synced 2026-01-18 21:21:21 -03:30
create updateUrlAfterDelete util
This commit is contained in:
parent
c336c989e7
commit
c824f0d590
@ -12,12 +12,8 @@ import PaginatedDataList, {
|
||||
ToolbarDeleteButton,
|
||||
} from '@components/PaginatedDataList';
|
||||
import useRequest from '@util/useRequest';
|
||||
import {
|
||||
getQSConfig,
|
||||
parseQueryString,
|
||||
replaceParams,
|
||||
encodeNonDefaultQueryString,
|
||||
} from '@util/qs';
|
||||
import updateUrlAfterDelete from '@util/updateUrlAfterDelete';
|
||||
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||
import { CredentialListItem } from '.';
|
||||
|
||||
const QS_CONFIG = getQSConfig('credential', {
|
||||
@ -80,21 +76,18 @@ function CredentialList({ i18n }) {
|
||||
|
||||
const handleDelete = async () => {
|
||||
await deleteCredentials();
|
||||
adjustPagination();
|
||||
setSelected([]);
|
||||
};
|
||||
|
||||
const adjustPagination = () => {
|
||||
const params = parseQueryString(QS_CONFIG, location.search);
|
||||
if (params.page > 1 && selected.length === credentials.length) {
|
||||
const newParams = encodeNonDefaultQueryString(
|
||||
QS_CONFIG,
|
||||
replaceParams(params, { page: params.page - 1 })
|
||||
);
|
||||
history.push(`${location.pathname}?${newParams}`);
|
||||
const url = updateUrlAfterDelete(
|
||||
QS_CONFIG,
|
||||
location,
|
||||
credentials,
|
||||
selected
|
||||
);
|
||||
if (url) {
|
||||
history.push(url);
|
||||
} else {
|
||||
fetchCredentials();
|
||||
}
|
||||
setSelected([]);
|
||||
};
|
||||
|
||||
const handleSelectAll = isSelected => {
|
||||
|
||||
@ -17,8 +17,6 @@ import { getQSConfig, parseQueryString } from '@util/qs';
|
||||
import AddDropDownButton from '@components/AddDropDownButton';
|
||||
import InventoryListItem from './InventoryListItem';
|
||||
|
||||
// The type value in const QS_CONFIG below does not have a space between job_inventory and
|
||||
// workflow_job_inventory so the params sent to the API match what the api expects.
|
||||
const QS_CONFIG = getQSConfig('inventory', {
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
|
||||
@ -13,13 +13,8 @@ import PaginatedDataList, {
|
||||
ToolbarAddButton,
|
||||
ToolbarDeleteButton,
|
||||
} from '@components/PaginatedDataList';
|
||||
import {
|
||||
getQSConfig,
|
||||
parseQueryString,
|
||||
replaceParams,
|
||||
encodeNonDefaultQueryString,
|
||||
} from '@util/qs';
|
||||
|
||||
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||
import updateUrlAfterDelete from '@util/updateUrlAfterDelete';
|
||||
import OrganizationListItem from './OrganizationListItem';
|
||||
|
||||
const QS_CONFIG = getQSConfig('organization', {
|
||||
@ -87,21 +82,18 @@ function OrganizationsList({ i18n }) {
|
||||
|
||||
const handleOrgDelete = async () => {
|
||||
await deleteOrganizations();
|
||||
await adjustPagination();
|
||||
setSelected([]);
|
||||
};
|
||||
|
||||
const adjustPagination = () => {
|
||||
const params = parseQueryString(QS_CONFIG, location.search);
|
||||
if (params.page > 1 && selected.length === organizations.length) {
|
||||
const newParams = encodeNonDefaultQueryString(
|
||||
QS_CONFIG,
|
||||
replaceParams(params, { page: params.page - 1 })
|
||||
);
|
||||
history.push(`${location.pathname}?${newParams}`);
|
||||
const url = updateUrlAfterDelete(
|
||||
QS_CONFIG,
|
||||
location,
|
||||
organizations,
|
||||
selected
|
||||
);
|
||||
if (url) {
|
||||
history.push(url);
|
||||
} else {
|
||||
fetchOrganizations();
|
||||
}
|
||||
setSelected([]);
|
||||
};
|
||||
|
||||
const hasContentLoading = isDeleteLoading || isOrgsLoading;
|
||||
|
||||
22
awx/ui_next/src/util/updateUrlAfterDelete.js
Normal file
22
awx/ui_next/src/util/updateUrlAfterDelete.js
Normal file
@ -0,0 +1,22 @@
|
||||
import {
|
||||
parseQueryString,
|
||||
replaceParams,
|
||||
encodeNonDefaultQueryString,
|
||||
} from './qs';
|
||||
|
||||
export default function updateUrlAfterDelete(
|
||||
qsConfig,
|
||||
location,
|
||||
items,
|
||||
selectedItems
|
||||
) {
|
||||
const params = parseQueryString(qsConfig, location.search);
|
||||
if (params.page > 1 && selectedItems.length === items.length) {
|
||||
const newParams = encodeNonDefaultQueryString(
|
||||
qsConfig,
|
||||
replaceParams(params, { page: params.page - 1 })
|
||||
);
|
||||
return `${location.pathname}?${newParams}`;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user