mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 18:07:36 -02:30
Address PR feedback and format.
This commit is contained in:
@@ -40,13 +40,13 @@ class PaginatedDataList extends React.Component {
|
|||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
const { itemCount: prevItemCount } = prevProps;
|
const { itemCount: prevItemCount } = prevProps;
|
||||||
const { itemCount } = this.props
|
const { itemCount } = this.props;
|
||||||
if (prevItemCount !== itemCount) {
|
if (prevItemCount !== itemCount) {
|
||||||
this.getCurrPage(itemCount);
|
this.getCurrPage(itemCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSortOrder () {
|
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('-')) {
|
||||||
@@ -55,20 +55,22 @@ class PaginatedDataList extends React.Component {
|
|||||||
return [queryParams.order_by, 'ascending'];
|
return [queryParams.order_by, 'ascending'];
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrPage (itemCount) {
|
getCurrPage(itemCount) {
|
||||||
if (itemCount < 0) {
|
if (itemCount < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { qsConfig, location } = this.props;
|
const { qsConfig, location } = this.props;
|
||||||
const queryParams = parseNamespacedQueryString(qsConfig, location.search);
|
const { page_size, page: currPage } = parseNamespacedQueryString(
|
||||||
const maxPages = Math.ceil(itemCount / queryParams.page_size);
|
qsConfig,
|
||||||
const currPage = queryParams.page;
|
location.search
|
||||||
if (currPage > maxPages) {
|
);
|
||||||
this.pushHistoryState({ page: (currPage + (maxPages - currPage)) || 1 })
|
const lastPage = Math.ceil(itemCount / page_size);
|
||||||
|
if (currPage > lastPage) {
|
||||||
|
this.pushHistoryState({ page: lastPage || 1 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSetPage (event, pageNumber) {
|
handleSetPage(event, pageNumber) {
|
||||||
this.pushHistoryState({ page: pageNumber });
|
this.pushHistoryState({ page: pageNumber });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ describe('<PaginatedDataList />', () => {
|
|||||||
integerFields: [],
|
integerFields: [],
|
||||||
};
|
};
|
||||||
const testParams = [5, 25, 0, -1]; // number of items
|
const testParams = [5, 25, 0, -1]; // number of items
|
||||||
const expected = [5, 5, 1, 1] // expected current page
|
const expected = [5, 5, 1, 1]; // expected current page
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/organizations/1/teams'],
|
initialEntries: ['/organizations/1/teams'],
|
||||||
});
|
});
|
||||||
@@ -146,13 +146,16 @@ describe('<PaginatedDataList />', () => {
|
|||||||
order_by: 'name',
|
order_by: 'name',
|
||||||
}}
|
}}
|
||||||
qsConfig={customQSConfig}
|
qsConfig={customQSConfig}
|
||||||
/>, { context: { router: { history } } }
|
/>,
|
||||||
|
{ context: { router: { history } } }
|
||||||
);
|
);
|
||||||
testParams.forEach((param, i) => {
|
testParams.forEach((param, i) => {
|
||||||
wrapper.setProps({ itemCount: param });
|
wrapper.setProps({ itemCount: param });
|
||||||
expect(history.location.search).toEqual(`?${customQSConfig.namespace}.page=${expected[i]}`)
|
expect(history.location.search).toEqual(
|
||||||
|
`?${customQSConfig.namespace}.page=${expected[i]}`
|
||||||
|
);
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
})
|
});
|
||||||
wrapper.unmount();
|
wrapper.unmount();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -75,12 +75,12 @@ class OrganizationsList extends Component {
|
|||||||
this.setState({ deletionError: null });
|
this.setState({ deletionError: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleOrgDelete () {
|
async handleOrgDelete() {
|
||||||
const { selected, itemCount } = 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 });
|
this.setState({ itemCount: itemCount - selected.length });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ deletionError: err });
|
this.setState({ deletionError: err });
|
||||||
|
|||||||
@@ -77,20 +77,22 @@ class TemplatesList extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleTemplateDelete () {
|
async handleTemplateDelete() {
|
||||||
const { selected, itemCount } = this.state;
|
const { selected, itemCount } = this.state;
|
||||||
|
|
||||||
this.setState({ hasContentLoading: true });
|
this.setState({ hasContentLoading: true });
|
||||||
try {
|
try {
|
||||||
await Promise.all(selected.map(({ type, id }) => {
|
await Promise.all(
|
||||||
let deletePromise;
|
selected.map(({ type, id }) => {
|
||||||
if (type === 'job_template') {
|
let deletePromise;
|
||||||
deletePromise = JobTemplatesAPI.destroy(id);
|
if (type === 'job_template') {
|
||||||
} else if (type === 'workflow_job_template') {
|
deletePromise = JobTemplatesAPI.destroy(id);
|
||||||
deletePromise = WorkflowJobTemplatesAPI.destroy(id);
|
} else if (type === 'workflow_job_template') {
|
||||||
}
|
deletePromise = WorkflowJobTemplatesAPI.destroy(id);
|
||||||
return deletePromise;
|
}
|
||||||
}));
|
return deletePromise;
|
||||||
|
})
|
||||||
|
);
|
||||||
this.setState({ itemCount: itemCount - selected.length });
|
this.setState({ itemCount: itemCount - selected.length });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ deletionError: err });
|
this.setState({ deletionError: err });
|
||||||
|
|||||||
Reference in New Issue
Block a user