mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 12:57:40 -02:30
fix credential list page number after deleting
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation, useHistory } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { CredentialsAPI } from '@api';
|
import { CredentialsAPI } from '@api';
|
||||||
@@ -11,7 +11,12 @@ import PaginatedDataList, {
|
|||||||
ToolbarAddButton,
|
ToolbarAddButton,
|
||||||
ToolbarDeleteButton,
|
ToolbarDeleteButton,
|
||||||
} from '@components/PaginatedDataList';
|
} from '@components/PaginatedDataList';
|
||||||
import { getQSConfig, parseQueryString } from '@util/qs';
|
import {
|
||||||
|
getQSConfig,
|
||||||
|
parseQueryString,
|
||||||
|
removeParams,
|
||||||
|
encodeNonDefaultQueryString,
|
||||||
|
} from '@util/qs';
|
||||||
import { CredentialListItem } from '.';
|
import { CredentialListItem } from '.';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('credential', {
|
const QS_CONFIG = getQSConfig('credential', {
|
||||||
@@ -30,6 +35,7 @@ function CredentialList({ i18n }) {
|
|||||||
const [selected, setSelected] = useState([]);
|
const [selected, setSelected] = useState([]);
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const loadCredentials = async ({ search }) => {
|
const loadCredentials = async ({ search }) => {
|
||||||
const params = parseQueryString(QS_CONFIG, search);
|
const params = parseQueryString(QS_CONFIG, search);
|
||||||
@@ -92,20 +98,23 @@ function CredentialList({ i18n }) {
|
|||||||
setDeletionError(error);
|
setDeletionError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adjustPagination();
|
||||||
|
setSelected([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const adjustPagination = () => {
|
||||||
const params = parseQueryString(QS_CONFIG, location.search);
|
const params = parseQueryString(QS_CONFIG, location.search);
|
||||||
try {
|
if (params.page > 1 && selected.length === credentials.length) {
|
||||||
const {
|
const newParams = removeParams(QS_CONFIG, params, { page: params.page });
|
||||||
data: { count, results },
|
history.push(
|
||||||
} = await CredentialsAPI.read(params);
|
`${location.pathname}?${encodeNonDefaultQueryString(
|
||||||
|
QS_CONFIG,
|
||||||
setCredentials(results);
|
newParams
|
||||||
setCredentialCount(count);
|
)}`
|
||||||
setSelected([]);
|
);
|
||||||
} catch (error) {
|
} else {
|
||||||
setContentError(error);
|
loadCredentials(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
setHasContentLoading(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const canAdd =
|
const canAdd =
|
||||||
|
|||||||
@@ -96,8 +96,9 @@ function OrganizationsList({ i18n }) {
|
|||||||
newParams
|
newParams
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
await fetchOrganizations();
|
||||||
}
|
}
|
||||||
await fetchOrganizations();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasContentLoading = isDeleteLoading || isOrgsLoading;
|
const hasContentLoading = isDeleteLoading || isOrgsLoading;
|
||||||
|
|||||||
Reference in New Issue
Block a user