fix: worker list update by watch
This commit is contained in:
@@ -224,13 +224,13 @@ export default function useTableFetch<T>(
|
|||||||
const createModelsChunkRequest = async (params?: any) => {
|
const createModelsChunkRequest = async (params?: any) => {
|
||||||
if (!API || !watch) return;
|
if (!API || !watch) return;
|
||||||
shouldUpdateRef.current = false;
|
shouldUpdateRef.current = false;
|
||||||
// loadendRef.current = false;
|
|
||||||
chunkRequedtRef.current?.current?.cancel?.();
|
chunkRequedtRef.current?.current?.cancel?.();
|
||||||
try {
|
try {
|
||||||
|
const currentParams = params || queryParams;
|
||||||
currentWatchParamsRef.current = {
|
currentWatchParamsRef.current = {
|
||||||
query: { ...(params || queryParams) }
|
query: { ...currentParams }
|
||||||
};
|
};
|
||||||
const query = _.omit(params || queryParams, ['page', 'perPage']);
|
const query = _.omit(currentParams, ['page', 'perPage']);
|
||||||
|
|
||||||
chunkRequedtRef.current = setChunkRequest({
|
chunkRequedtRef.current = setChunkRequest({
|
||||||
url: `${API}?${qs.stringify(_.pickBy(query, (val: any) => !!val))}`,
|
url: `${API}?${qs.stringify(_.pickBy(query, (val: any) => !!val))}`,
|
||||||
@@ -262,20 +262,11 @@ export default function useTableFetch<T>(
|
|||||||
// for filters change
|
// for filters change
|
||||||
const handleQueryChange = async (params: any) => {
|
const handleQueryChange = async (params: any) => {
|
||||||
loadendRef.current = false;
|
loadendRef.current = false;
|
||||||
setQueryParams((pre: any) => {
|
const newQueryParams = { ...queryParams, ...params };
|
||||||
return {
|
setQueryParams(newQueryParams);
|
||||||
...pre,
|
await fetchData({ query: newQueryParams });
|
||||||
...params
|
|
||||||
};
|
|
||||||
});
|
|
||||||
await fetchData({ query: { ...queryParams, ...params } });
|
|
||||||
if (watch) {
|
if (watch) {
|
||||||
setTimeout(() => {
|
createModelsChunkRequest(newQueryParams);
|
||||||
createModelsChunkRequest({
|
|
||||||
...queryParams,
|
|
||||||
...params
|
|
||||||
});
|
|
||||||
}, 200);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -291,19 +282,14 @@ export default function useTableFetch<T>(
|
|||||||
) => {
|
) => {
|
||||||
if (extra.action === 'sort') {
|
if (extra.action === 'sort') {
|
||||||
const sortKeys = handleMultiSortChange(sorter);
|
const sortKeys = handleMultiSortChange(sorter);
|
||||||
setQueryParams((pre: any) => {
|
const newQueryParams = {
|
||||||
return {
|
...queryParams,
|
||||||
...pre,
|
page: 1,
|
||||||
page: 1,
|
sort_by: sortKeys.join(',')
|
||||||
sort_by: sortKeys.join(',')
|
};
|
||||||
};
|
setQueryParams(newQueryParams);
|
||||||
});
|
|
||||||
fetchData({
|
fetchData({
|
||||||
query: {
|
query: newQueryParams
|
||||||
...queryParams,
|
|
||||||
page: 1,
|
|
||||||
sort_by: sortKeys.join(',')
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user