fix: fetch list page more than total page
This commit is contained in:
@@ -35,11 +35,13 @@ export default function useTableFetch<ListItem>(options: {
|
|||||||
loading: boolean;
|
loading: boolean;
|
||||||
loadend: boolean;
|
loadend: boolean;
|
||||||
total: number;
|
total: number;
|
||||||
|
totalPage: number;
|
||||||
}>({
|
}>({
|
||||||
dataList: [...defaultData],
|
dataList: [...defaultData],
|
||||||
loading: false,
|
loading: false,
|
||||||
loadend: false,
|
loadend: false,
|
||||||
total: 0
|
total: 0,
|
||||||
|
totalPage: 0
|
||||||
});
|
});
|
||||||
const [queryParams, setQueryParams] = useState<any>({
|
const [queryParams, setQueryParams] = useState<any>({
|
||||||
page: 1,
|
page: 1,
|
||||||
@@ -55,6 +57,7 @@ export default function useTableFetch<ListItem>(options: {
|
|||||||
setDataSource((pre) => {
|
setDataSource((pre) => {
|
||||||
return {
|
return {
|
||||||
total: pre.total,
|
total: pre.total,
|
||||||
|
totalPage: pre.totalPage,
|
||||||
loading: false,
|
loading: false,
|
||||||
loadend: true,
|
loadend: true,
|
||||||
dataList: list,
|
dataList: list,
|
||||||
@@ -97,11 +100,32 @@ export default function useTableFetch<ListItem>(options: {
|
|||||||
};
|
};
|
||||||
const res = await fetchAPI(params);
|
const res = await fetchAPI(params);
|
||||||
|
|
||||||
|
if (
|
||||||
|
!res.items.length &&
|
||||||
|
params.page > res.pagination.totalPage &&
|
||||||
|
res.pagination.totalPage > 0
|
||||||
|
) {
|
||||||
|
const newParams = {
|
||||||
|
...params,
|
||||||
|
page: res.pagination.totalPage
|
||||||
|
};
|
||||||
|
const newRes = await fetchAPI(newParams);
|
||||||
|
setDataSource({
|
||||||
|
dataList: newRes.items || [],
|
||||||
|
loading: false,
|
||||||
|
loadend: true,
|
||||||
|
total: newRes.pagination.total,
|
||||||
|
totalPage: newRes.pagination.totalPage
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setDataSource({
|
setDataSource({
|
||||||
dataList: res.items || [],
|
dataList: res.items || [],
|
||||||
loading: false,
|
loading: false,
|
||||||
loadend: true,
|
loadend: true,
|
||||||
total: res.pagination.total
|
total: res.pagination.total,
|
||||||
|
totalPage: res.pagination.totalPage
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error', error);
|
console.log('error', error);
|
||||||
@@ -109,7 +133,8 @@ export default function useTableFetch<ListItem>(options: {
|
|||||||
dataList: [],
|
dataList: [],
|
||||||
loading: false,
|
loading: false,
|
||||||
loadend: true,
|
loadend: true,
|
||||||
total: dataSource.total
|
total: dataSource.total,
|
||||||
|
totalPage: dataSource.totalPage
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -170,13 +170,13 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
|
|||||||
onValuesChange?.({}, form.getFieldsValue());
|
onValuesChange?.({}, form.getFieldsValue());
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSelectorChange = (field: string) => {
|
const onSelectorChange = (field: string, allowEmpty?: boolean) => {
|
||||||
const workerSelector = form.getFieldValue(field);
|
const workerSelector = form.getFieldValue(field);
|
||||||
// check if all keys have values
|
// check if all keys have values
|
||||||
const hasEmptyValue = _.some(_.keys(workerSelector), (k: string) => {
|
const hasEmptyValue = _.some(_.keys(workerSelector), (k: string) => {
|
||||||
return !workerSelector[k];
|
return !workerSelector[k];
|
||||||
});
|
});
|
||||||
if (!hasEmptyValue) {
|
if (!hasEmptyValue || allowEmpty) {
|
||||||
onValuesChange?.({}, form.getFieldsValue());
|
onValuesChange?.({}, form.getFieldsValue());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -190,7 +190,7 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleEnvSelectorOnBlur = () => {
|
const handleEnvSelectorOnBlur = () => {
|
||||||
onSelectorChange('env');
|
onSelectorChange('env', true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteEnvSelector = (index: number) => {
|
const handleDeleteEnvSelector = (index: number) => {
|
||||||
@@ -428,32 +428,7 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
|
|||||||
}
|
}
|
||||||
></ListInput>
|
></ListInput>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item<FormData>
|
<Form.Item<FormData> name="env">
|
||||||
name="env"
|
|
||||||
rules={[
|
|
||||||
() => ({
|
|
||||||
validator(rule, value) {
|
|
||||||
if (_.keys(value).length > 0) {
|
|
||||||
if (_.some(_.keys(value), (k: string) => !value[k])) {
|
|
||||||
return Promise.reject(
|
|
||||||
intl.formatMessage(
|
|
||||||
{
|
|
||||||
id: 'common.validate.value'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: intl.formatMessage({
|
|
||||||
id: 'common.text.variable'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<LabelSelector
|
<LabelSelector
|
||||||
label={intl.formatMessage({
|
label={intl.formatMessage({
|
||||||
id: 'models.form.env'
|
id: 'models.form.env'
|
||||||
|
|||||||
@@ -123,6 +123,29 @@ const Models: React.FC = () => {
|
|||||||
const res: any = await queryModelsList(params, {
|
const res: any = await queryModelsList(params, {
|
||||||
cancelToken: axiosToken.token
|
cancelToken: axiosToken.token
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
!res.items.length &&
|
||||||
|
params.page > res.pagination.totalPage &&
|
||||||
|
res.pagination.totalPage > 0
|
||||||
|
) {
|
||||||
|
const newParams = {
|
||||||
|
...params,
|
||||||
|
page: res.pagination.totalPage
|
||||||
|
};
|
||||||
|
const newRes: any = await queryModelsList(newParams, {
|
||||||
|
cancelToken: axiosToken.token
|
||||||
|
});
|
||||||
|
setDataSource({
|
||||||
|
dataList: newRes.items || [],
|
||||||
|
loading: false,
|
||||||
|
loadend: true,
|
||||||
|
total: newRes.pagination.total,
|
||||||
|
deletedIds: []
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setDataSource({
|
setDataSource({
|
||||||
dataList: res.items || [],
|
dataList: res.items || [],
|
||||||
loading: false,
|
loading: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user