mirror of
https://github.com/ansible/awx.git
synced 2026-01-24 07:51:23 -03:30
Fix Org list returning a 404 by redirecting user to current page.
- Update itemCount after an org has been successfully deleted. - Update PaginatedDataList to get current page when the number of items has changed.
This commit is contained in:
parent
7178c1d9e0
commit
58444a75b9
@ -38,7 +38,15 @@ class PaginatedDataList extends React.Component {
|
||||
this.handleSort = this.handleSort.bind(this);
|
||||
}
|
||||
|
||||
getSortOrder() {
|
||||
componentDidUpdate(prevProps) {
|
||||
const { itemCount: prevItemCount } = prevProps;
|
||||
const { itemCount } = this.props
|
||||
if (prevItemCount !== itemCount) {
|
||||
this.getCurrPage(itemCount);
|
||||
}
|
||||
}
|
||||
|
||||
getSortOrder () {
|
||||
const { qsConfig, location } = this.props;
|
||||
const queryParams = parseNamespacedQueryString(qsConfig, location.search);
|
||||
if (queryParams.order_by && queryParams.order_by.startsWith('-')) {
|
||||
@ -47,7 +55,20 @@ class PaginatedDataList extends React.Component {
|
||||
return [queryParams.order_by, 'ascending'];
|
||||
}
|
||||
|
||||
handleSetPage(event, pageNumber) {
|
||||
getCurrPage (itemCount) {
|
||||
if (itemCount < 0) {
|
||||
return;
|
||||
}
|
||||
const { qsConfig, location } = this.props;
|
||||
const queryParams = parseNamespacedQueryString(qsConfig, location.search);
|
||||
const maxPages = Math.ceil(itemCount / queryParams.page_size);
|
||||
const currPage = queryParams.page;
|
||||
if (currPage > maxPages) {
|
||||
this.pushHistoryState({ page: (currPage + (maxPages - currPage)) || 1 })
|
||||
}
|
||||
}
|
||||
|
||||
handleSetPage (event, pageNumber) {
|
||||
this.pushHistoryState({ page: pageNumber });
|
||||
}
|
||||
|
||||
|
||||
@ -75,12 +75,13 @@ class OrganizationsList extends Component {
|
||||
this.setState({ deletionError: null });
|
||||
}
|
||||
|
||||
async handleOrgDelete() {
|
||||
const { selected } = this.state;
|
||||
async handleOrgDelete () {
|
||||
const { selected, itemCount } = this.state;
|
||||
|
||||
this.setState({ hasContentLoading: true });
|
||||
try {
|
||||
await Promise.all(selected.map(org => OrganizationsAPI.destroy(org.id)));
|
||||
await Promise.all(selected.map((org) => OrganizationsAPI.destroy(org.id)));
|
||||
this.setState({ itemCount: itemCount - selected.length });
|
||||
} catch (err) {
|
||||
this.setState({ deletionError: err });
|
||||
} finally {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user