mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02: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:
@@ -38,7 +38,15 @@ class PaginatedDataList extends React.Component {
|
|||||||
this.handleSort = this.handleSort.bind(this);
|
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 { qsConfig, location } = this.props;
|
||||||
const queryParams = parseNamespacedQueryString(qsConfig, location.search);
|
const queryParams = parseNamespacedQueryString(qsConfig, location.search);
|
||||||
if (queryParams.order_by && queryParams.order_by.startsWith('-')) {
|
if (queryParams.order_by && queryParams.order_by.startsWith('-')) {
|
||||||
@@ -47,7 +55,20 @@ class PaginatedDataList extends React.Component {
|
|||||||
return [queryParams.order_by, 'ascending'];
|
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 });
|
this.pushHistoryState({ page: pageNumber });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,12 +75,13 @@ class OrganizationsList extends Component {
|
|||||||
this.setState({ deletionError: null });
|
this.setState({ deletionError: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleOrgDelete() {
|
async handleOrgDelete () {
|
||||||
const { selected } = this.state;
|
const { selected, itemCount } = this.state;
|
||||||
|
|
||||||
this.setState({ hasContentLoading: true });
|
this.setState({ hasContentLoading: true });
|
||||||
try {
|
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) {
|
} catch (err) {
|
||||||
this.setState({ deletionError: err });
|
this.setState({ deletionError: err });
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user