fix: fix the limit value when fetch api in the list page

Fix the limit value by the page size options, when the limit in the store is not in the page size options, use the default limit value.

Change-Id: I3868ebf9b33304ace884b0fa77eae28d89e80c20
This commit is contained in:
Jingwei.Zhang 2022-08-02 12:52:19 +08:00
parent 37885d343d
commit e5a54c31e7

View File

@ -401,7 +401,8 @@ export default class BaseList extends React.Component {
} }
get pageSizeOptions() { get pageSizeOptions() {
return undefined; // should be array of numbers
return [10, 20, 50, 100];
} }
get hideTotal() { get hideTotal() {
@ -483,7 +484,7 @@ export default class BaseList extends React.Component {
const pagination = { const pagination = {
total, total,
current: Number(page), current: Number(page),
pageSize: limit || 10, pageSize: this.getTablePageSize(limit),
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
showTotal: (total) => t('Total {total} items', { total }), showTotal: (total) => t('Total {total} items', { total }),
showSizeChanger: true, showSizeChanger: true,
@ -607,6 +608,10 @@ export default class BaseList extends React.Component {
newParams[this.allProjectsKey] = true; newParams[this.allProjectsKey] = true;
} }
if (this.isFilterByBackend) { if (this.isFilterByBackend) {
const { limit } = newParams;
if (limit) {
newParams.limit = this.getTablePageSize(limit);
}
this.fetchListWithTry(() => this.fetchListWithTry(() =>
this.fetchDataByPage(this.updateFetchParamsByPage(newParams)) this.fetchDataByPage(this.updateFetchParamsByPage(newParams))
); );
@ -1052,6 +1057,12 @@ export default class BaseList extends React.Component {
onCloseSuccessHint = () => {}; onCloseSuccessHint = () => {};
getTablePageSize = (limit) => {
const defaultOptions = [10, 20, 50, 100];
const options = this.pageSizeOptions || defaultOptions;
return options.includes(limit) ? limit : options[0] || defaultOptions[0];
};
debounceSetTableHeight() { debounceSetTableHeight() {
return debounce(this.setTableHeight, 1000); return debounce(this.setTableHeight, 1000);
} }