fix: watch list do not update when creating

This commit is contained in:
jialin
2026-06-10 15:37:27 +08:00
committed by jialin
parent 6f96260993
commit 698090b17a
3 changed files with 11 additions and 17 deletions
+4
View File
@@ -89,6 +89,10 @@ export function useUpdateChunkedList(options: {
...cacheDataListRef.current ...cacheDataListRef.current
].slice(0, limit); ].slice(0, limit);
options.setDataList?.([...cacheDataListRef.current], {
createdIds: newDataList.map((item) => item.id)
});
options.onCreate?.(latestCreateList); options.onCreate?.(latestCreateList);
} }
+3 -3
View File
@@ -55,7 +55,7 @@ export default function useWatchList<T = Record<string, any>>(API: string) {
cacheWatchDataListRef.current = cacheWatchDataListRef.current.filter( cacheWatchDataListRef.current = cacheWatchDataListRef.current.filter(
(item) => item.id !== id (item) => item.id !== id
); );
setWatchDataList(cacheWatchDataListRef.current); setWatchDataList(() => cacheWatchDataListRef.current);
}; };
const getAllDataList = useMemoizedFn(async () => { const getAllDataList = useMemoizedFn(async () => {
@@ -63,8 +63,7 @@ export default function useWatchList<T = Record<string, any>>(API: string) {
listRequestTokenRef.current?.cancel?.(); listRequestTokenRef.current?.cancel?.();
listRequestTokenRef.current = createAxiosToken(); listRequestTokenRef.current = createAxiosToken();
const params = { const params = {
page: 1, page: -1
perPage: 100
}; };
const res: any = await queryAllDataList(params, { const res: any = await queryAllDataList(params, {
token: listRequestTokenRef.current.token token: listRequestTokenRef.current.token
@@ -86,6 +85,7 @@ export default function useWatchList<T = Record<string, any>>(API: string) {
return { return {
watchDataList, watchDataList,
setWatchDataList,
deleteItemFromCache: handleDeleteItemFromCache deleteItemFromCache: handleDeleteItemFromCache
}; };
} }
+4 -14
View File
@@ -98,7 +98,7 @@ const ModelRoutes: React.FC = () => {
API: MODEL_ROUTES, API: MODEL_ROUTES,
contentForDelete: 'menu.models.routes' contentForDelete: 'menu.models.routes'
}); });
const { watchDataList: allRouteTargets, deleteItemFromCache } = const { watchDataList, setWatchDataList, deleteItemFromCache } =
useWatchList(MODEL_ROUTE_TARGETS); useWatchList(MODEL_ROUTE_TARGETS);
const [expandAtom] = useAtom(expandKeysAtom); const [expandAtom] = useAtom(expandKeysAtom);
const { const {
@@ -128,6 +128,8 @@ const ModelRoutes: React.FC = () => {
); );
const [modelList, setModelsList] = useState<Global.BaseOption<number>[]>([]); const [modelList, setModelsList] = useState<Global.BaseOption<number>[]>([]);
console.log('dataSource', dataSource);
useEffect(() => { useEffect(() => {
const fetchModels = async () => { const fetchModels = async () => {
try { try {
@@ -356,7 +358,7 @@ const ModelRoutes: React.FC = () => {
></FilterBar> ></FilterBar>
<TableProvider <TableProvider
value={{ value={{
allChildren: allRouteTargets, allChildren: watchDataList,
setDisableExpand: setDisableExpand setDisableExpand: setDisableExpand
}} }}
> >
@@ -429,11 +431,6 @@ const ModelRoutes: React.FC = () => {
onClose={closeViewAPIInfo} onClose={closeViewAPIInfo}
></APIAccessInfoModal> ></APIAccessInfoModal>
<DeleteModal ref={modalRef}></DeleteModal> <DeleteModal ref={modalRef}></DeleteModal>
{/* One mount per registered action. Each mount calls its
entry's `useCreate` (single hook per component, so iterating
the plugin list doesn't violate the Rules of Hooks),
renders the form, and registers its controller so dropdown
clicks can dispatch to it. */}
{configActions.map((action) => ( {configActions.map((action) => (
<ModelRouteConfigActionMount <ModelRouteConfigActionMount
key={action.key} key={action.key}
@@ -442,13 +439,6 @@ const ModelRoutes: React.FC = () => {
onOk={handleConfigActionOk} onOk={handleConfigActionOk}
/> />
))} ))}
{/* Page-level data lifecycle for plugin-contributed extra
columns. Receives the current list of visible route ids so
the plugin can bulk-fetch their per-user defaults in one
call (used by the quota-default column cells); `refreshToken`
bumps after a per-row save so derived page data refetches
even when the row set is unchanged. Renders nothing when no
plugin is registered. */}
<PluginExtraFields name="ModelRoutesPageGlobal" context={pluginContext} /> <PluginExtraFields name="ModelRoutesPageGlobal" context={pluginContext} />
</> </>
); );