fix: watch list do not update when creating
This commit is contained in:
@@ -89,6 +89,10 @@ export function useUpdateChunkedList(options: {
|
||||
...cacheDataListRef.current
|
||||
].slice(0, limit);
|
||||
|
||||
options.setDataList?.([...cacheDataListRef.current], {
|
||||
createdIds: newDataList.map((item) => item.id)
|
||||
});
|
||||
|
||||
options.onCreate?.(latestCreateList);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ export default function useWatchList<T = Record<string, any>>(API: string) {
|
||||
cacheWatchDataListRef.current = cacheWatchDataListRef.current.filter(
|
||||
(item) => item.id !== id
|
||||
);
|
||||
setWatchDataList(cacheWatchDataListRef.current);
|
||||
setWatchDataList(() => cacheWatchDataListRef.current);
|
||||
};
|
||||
|
||||
const getAllDataList = useMemoizedFn(async () => {
|
||||
@@ -63,8 +63,7 @@ export default function useWatchList<T = Record<string, any>>(API: string) {
|
||||
listRequestTokenRef.current?.cancel?.();
|
||||
listRequestTokenRef.current = createAxiosToken();
|
||||
const params = {
|
||||
page: 1,
|
||||
perPage: 100
|
||||
page: -1
|
||||
};
|
||||
const res: any = await queryAllDataList(params, {
|
||||
token: listRequestTokenRef.current.token
|
||||
@@ -86,6 +85,7 @@ export default function useWatchList<T = Record<string, any>>(API: string) {
|
||||
|
||||
return {
|
||||
watchDataList,
|
||||
setWatchDataList,
|
||||
deleteItemFromCache: handleDeleteItemFromCache
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ const ModelRoutes: React.FC = () => {
|
||||
API: MODEL_ROUTES,
|
||||
contentForDelete: 'menu.models.routes'
|
||||
});
|
||||
const { watchDataList: allRouteTargets, deleteItemFromCache } =
|
||||
const { watchDataList, setWatchDataList, deleteItemFromCache } =
|
||||
useWatchList(MODEL_ROUTE_TARGETS);
|
||||
const [expandAtom] = useAtom(expandKeysAtom);
|
||||
const {
|
||||
@@ -128,6 +128,8 @@ const ModelRoutes: React.FC = () => {
|
||||
);
|
||||
const [modelList, setModelsList] = useState<Global.BaseOption<number>[]>([]);
|
||||
|
||||
console.log('dataSource', dataSource);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchModels = async () => {
|
||||
try {
|
||||
@@ -356,7 +358,7 @@ const ModelRoutes: React.FC = () => {
|
||||
></FilterBar>
|
||||
<TableProvider
|
||||
value={{
|
||||
allChildren: allRouteTargets,
|
||||
allChildren: watchDataList,
|
||||
setDisableExpand: setDisableExpand
|
||||
}}
|
||||
>
|
||||
@@ -429,11 +431,6 @@ const ModelRoutes: React.FC = () => {
|
||||
onClose={closeViewAPIInfo}
|
||||
></APIAccessInfoModal>
|
||||
<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) => (
|
||||
<ModelRouteConfigActionMount
|
||||
key={action.key}
|
||||
@@ -442,13 +439,6 @@ const ModelRoutes: React.FC = () => {
|
||||
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} />
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user