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