mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
create updateUrlAfterDelete util
This commit is contained in:
@@ -12,12 +12,8 @@ import PaginatedDataList, {
|
|||||||
ToolbarDeleteButton,
|
ToolbarDeleteButton,
|
||||||
} from '@components/PaginatedDataList';
|
} from '@components/PaginatedDataList';
|
||||||
import useRequest from '@util/useRequest';
|
import useRequest from '@util/useRequest';
|
||||||
import {
|
import updateUrlAfterDelete from '@util/updateUrlAfterDelete';
|
||||||
getQSConfig,
|
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||||
parseQueryString,
|
|
||||||
replaceParams,
|
|
||||||
encodeNonDefaultQueryString,
|
|
||||||
} from '@util/qs';
|
|
||||||
import { CredentialListItem } from '.';
|
import { CredentialListItem } from '.';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('credential', {
|
const QS_CONFIG = getQSConfig('credential', {
|
||||||
@@ -80,21 +76,18 @@ function CredentialList({ i18n }) {
|
|||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
await deleteCredentials();
|
await deleteCredentials();
|
||||||
adjustPagination();
|
const url = updateUrlAfterDelete(
|
||||||
setSelected([]);
|
QS_CONFIG,
|
||||||
};
|
location,
|
||||||
|
credentials,
|
||||||
const adjustPagination = () => {
|
selected
|
||||||
const params = parseQueryString(QS_CONFIG, location.search);
|
);
|
||||||
if (params.page > 1 && selected.length === credentials.length) {
|
if (url) {
|
||||||
const newParams = encodeNonDefaultQueryString(
|
history.push(url);
|
||||||
QS_CONFIG,
|
|
||||||
replaceParams(params, { page: params.page - 1 })
|
|
||||||
);
|
|
||||||
history.push(`${location.pathname}?${newParams}`);
|
|
||||||
} else {
|
} else {
|
||||||
fetchCredentials();
|
fetchCredentials();
|
||||||
}
|
}
|
||||||
|
setSelected([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectAll = isSelected => {
|
const handleSelectAll = isSelected => {
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ import { getQSConfig, parseQueryString } from '@util/qs';
|
|||||||
import AddDropDownButton from '@components/AddDropDownButton';
|
import AddDropDownButton from '@components/AddDropDownButton';
|
||||||
import InventoryListItem from './InventoryListItem';
|
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', {
|
const QS_CONFIG = getQSConfig('inventory', {
|
||||||
page: 1,
|
page: 1,
|
||||||
page_size: 20,
|
page_size: 20,
|
||||||
|
|||||||
@@ -13,13 +13,8 @@ import PaginatedDataList, {
|
|||||||
ToolbarAddButton,
|
ToolbarAddButton,
|
||||||
ToolbarDeleteButton,
|
ToolbarDeleteButton,
|
||||||
} from '@components/PaginatedDataList';
|
} from '@components/PaginatedDataList';
|
||||||
import {
|
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||||
getQSConfig,
|
import updateUrlAfterDelete from '@util/updateUrlAfterDelete';
|
||||||
parseQueryString,
|
|
||||||
replaceParams,
|
|
||||||
encodeNonDefaultQueryString,
|
|
||||||
} from '@util/qs';
|
|
||||||
|
|
||||||
import OrganizationListItem from './OrganizationListItem';
|
import OrganizationListItem from './OrganizationListItem';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('organization', {
|
const QS_CONFIG = getQSConfig('organization', {
|
||||||
@@ -87,21 +82,18 @@ function OrganizationsList({ i18n }) {
|
|||||||
|
|
||||||
const handleOrgDelete = async () => {
|
const handleOrgDelete = async () => {
|
||||||
await deleteOrganizations();
|
await deleteOrganizations();
|
||||||
await adjustPagination();
|
const url = updateUrlAfterDelete(
|
||||||
setSelected([]);
|
QS_CONFIG,
|
||||||
};
|
location,
|
||||||
|
organizations,
|
||||||
const adjustPagination = () => {
|
selected
|
||||||
const params = parseQueryString(QS_CONFIG, location.search);
|
);
|
||||||
if (params.page > 1 && selected.length === organizations.length) {
|
if (url) {
|
||||||
const newParams = encodeNonDefaultQueryString(
|
history.push(url);
|
||||||
QS_CONFIG,
|
|
||||||
replaceParams(params, { page: params.page - 1 })
|
|
||||||
);
|
|
||||||
history.push(`${location.pathname}?${newParams}`);
|
|
||||||
} else {
|
} else {
|
||||||
fetchOrganizations();
|
fetchOrganizations();
|
||||||
}
|
}
|
||||||
|
setSelected([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasContentLoading = isDeleteLoading || isOrgsLoading;
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user