fix: do not cache while watching during manual updates
This commit is contained in:
@@ -81,6 +81,7 @@ const DeleteModal = forwardRef((props, ref) => {
|
||||
const [configuration, setConfiguration] = useState<Configuration>({
|
||||
checked: false
|
||||
});
|
||||
const [delLoading, setDelLoading] = useState(false);
|
||||
const [config, setConfig] = useState<ModalFuncProps & DataOptions>({} as any);
|
||||
|
||||
const show = (data: ModalFuncProps & DataOptions) => {
|
||||
@@ -105,6 +106,7 @@ const DeleteModal = forwardRef((props, ref) => {
|
||||
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
setDelLoading(true);
|
||||
const res = await config.onOk?.();
|
||||
const isArray = Array.isArray(res);
|
||||
if (isArray) {
|
||||
@@ -121,6 +123,7 @@ const DeleteModal = forwardRef((props, ref) => {
|
||||
// Handle error if needed
|
||||
} finally {
|
||||
setVisible(false);
|
||||
setDelLoading(false);
|
||||
restoreScrollHeight();
|
||||
}
|
||||
};
|
||||
@@ -156,7 +159,13 @@ const DeleteModal = forwardRef((props, ref) => {
|
||||
? intl.formatMessage({ id: config.cancelText })
|
||||
: intl.formatMessage({ id: 'common.button.cancel' })}
|
||||
</Button>
|
||||
<Button type="primary" onClick={handleOk} size="middle" danger>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={handleOk}
|
||||
size="middle"
|
||||
danger
|
||||
loading={delLoading}
|
||||
>
|
||||
{config.okText
|
||||
? intl.formatMessage({ id: config.okText })
|
||||
: intl.formatMessage({ id: 'common.button.delete' })}
|
||||
|
||||
@@ -112,7 +112,6 @@ export default function useTableFetch<T>(
|
||||
const params = {
|
||||
..._.pickBy(query || queryParams, (val: any) => !!val)
|
||||
};
|
||||
chunkRequestRef.current?.current?.cancel?.();
|
||||
axiosTokenRef.current?.cancel?.('CANCEL_PREVIOUS_REQUEST');
|
||||
axiosTokenRef.current = createAxiosToken();
|
||||
const res = await fetchAPI(params, {
|
||||
@@ -187,8 +186,8 @@ export default function useTableFetch<T>(
|
||||
}
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
const debounceFetchData = _.debounce(() => fetchData(), 300);
|
||||
// @ts-ignore for watch mode
|
||||
const debounceFetchData = _.debounce(() => fetchData({}, true), 1000);
|
||||
|
||||
const { updateChunkedList, cacheDataListRef } = useUpdateChunkedList({
|
||||
events: events,
|
||||
@@ -269,6 +268,8 @@ export default function useTableFetch<T>(
|
||||
paginate?: boolean;
|
||||
}
|
||||
) => {
|
||||
// cancel previous chunk request so that we can create a new one with updated params
|
||||
chunkRequestRef.current?.current?.cancel?.();
|
||||
const newQueryParams = { ...queryParams, ...params };
|
||||
setQueryParams(newQueryParams);
|
||||
const res = await fetchData({ query: newQueryParams });
|
||||
|
||||
@@ -71,9 +71,9 @@ export function useUpdateChunkedList(options: {
|
||||
(sItem: any) => sItem.id === item.id
|
||||
);
|
||||
const updateItem = { ...item };
|
||||
if (updateIndex === -1) {
|
||||
if (updateIndex === -1 && !triggerAt?.current) {
|
||||
acc.push(updateItem);
|
||||
} else {
|
||||
} else if (!triggerAt?.current) {
|
||||
cacheDataListRef.current[updateIndex] = updateItem;
|
||||
}
|
||||
|
||||
@@ -116,8 +116,6 @@ export function useUpdateChunkedList(options: {
|
||||
deletedIds: [...deletedIdsRef.current]
|
||||
});
|
||||
|
||||
console.log('deletedList:', deletedList);
|
||||
|
||||
options.onDelete?.(deletedList);
|
||||
}
|
||||
|
||||
@@ -135,9 +133,9 @@ export function useUpdateChunkedList(options: {
|
||||
updateItem,
|
||||
...cacheDataListRef.current.slice(0, limit - 1)
|
||||
];
|
||||
if (options.onCreate && triggerAt?.current) {
|
||||
if (options.onUpdate && triggerAt?.current) {
|
||||
if (Date.parse(item.created_at) >= triggerAt.current) {
|
||||
options.onCreate?.([updateItem]);
|
||||
options.onUpdate?.([updateItem]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export default {
|
||||
'providers.form.proxy.timeout': 'Proxy Timeout (seconds)',
|
||||
'providers.form.customConfig': 'Custom Configuration',
|
||||
'providers.form.model.test': 'Test',
|
||||
'providers.form.model.test.tips': 'Test Connection',
|
||||
'providers.form.model.test.tips': 'Test Connection (LLM only)',
|
||||
'providers.form.target.placeholder': 'provider/models',
|
||||
'providers.form.fallback.token': 'Fallback API Keys',
|
||||
'providers.form.custombeckendUrl': 'Custom Base URL',
|
||||
|
||||
@@ -13,7 +13,7 @@ export default {
|
||||
'providers.form.proxy.timeout': 'Proxy Timeout (seconds)',
|
||||
'providers.form.customConfig': 'Custom Configuration',
|
||||
'providers.form.model.test': 'Test',
|
||||
'providers.form.model.test.tips': 'Test Connection',
|
||||
'providers.form.model.test.tips': 'Test Connection (LLM only)',
|
||||
'providers.form.target.placeholder': 'provider/models',
|
||||
'providers.form.fallback.token': 'Fallback API Keys',
|
||||
'providers.form.custombeckendUrl': 'Custom Base URL',
|
||||
|
||||
@@ -13,7 +13,7 @@ export default {
|
||||
'providers.form.proxy.timeout': 'Proxy Timeout (seconds)',
|
||||
'providers.form.customConfig': 'Custom Configuration',
|
||||
'providers.form.model.test': 'Test',
|
||||
'providers.form.model.test.tips': 'Test Connection',
|
||||
'providers.form.model.test.tips': 'Test Connection (LLM only)',
|
||||
'providers.form.target.placeholder': 'provider/models',
|
||||
'providers.form.fallback.token': 'Fallback API Keys',
|
||||
'providers.form.custombeckendUrl': 'Custom Base URL',
|
||||
|
||||
@@ -13,7 +13,7 @@ export default {
|
||||
'providers.form.proxy.timeout': '代理超时(秒)',
|
||||
'providers.form.customConfig': '自定义配置',
|
||||
'providers.form.model.test': '测试',
|
||||
'providers.form.model.test.tips': '测试连接',
|
||||
'providers.form.model.test.tips': '测试连接(只支持 LLM)',
|
||||
'providers.form.target.placeholder': '提供商/模型',
|
||||
'providers.form.fallback.token': '备用 API Key',
|
||||
'providers.form.custombeckendUrl': '自定义 Base URL',
|
||||
|
||||
@@ -36,6 +36,12 @@ export default function useAddWorkerMessage() {
|
||||
newItemsRef.current = newItemsRef.current.concat(newItems);
|
||||
showAddWorkerMessage();
|
||||
}
|
||||
},
|
||||
onUpdate: (newItems: any) => {
|
||||
if (triggerAtRef.current) {
|
||||
newItemsRef.current = newItemsRef.current.concat(newItems);
|
||||
showAddWorkerMessage();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user