This commit is contained in:
dream2023 2024-01-12 15:20:23 +08:00
parent 4132659670
commit 5f37f7a523
4 changed files with 16 additions and 11 deletions

View File

@ -305,6 +305,8 @@ export class CollectionManagerV2<Mixins = {}> {
private getInheritData() {
return {
collections: this.collections,
collectionFieldGroups: this.collectionFieldGroups,
reloadCallbacks: this.reloadCallbacks,
collectionTemplateInstances: this.collectionTemplateInstances,
fieldInterfaceInstances: this.fieldInterfaceInstances,
collectionMixins: this.collectionMixins,

View File

@ -55,6 +55,7 @@ export class CollectionPlugin extends Plugin {
this.addFieldInterfaces();
this.addCollectionTemplates();
this.addFieldInterfaces();
this.addFieldGroups();
this.collectionManager.setReloadFn(this.reloadCollections.bind(this));
}

View File

@ -12,14 +12,13 @@ export const useCollectionManager = () => {
const [random, setRandom] = useState(uid());
const interfaces = useMemo(() => cm?.getFieldInterfaces(), [cm, random]);
const templates = useMemo(() => cm?.getCollectionTemplates(), [cm, random]);
const collections = useMemo(
() =>
cm
const getCollections = useCallback(() => {
return cm
?.getCollections()
.filter((item) => !item.isLocal)
.map((item) => item.getOptions()),
[cm, random],
);
.map((item) => item.getOptions());
}, [cm]);
const collections = useMemo(() => getCollections(), [cm, random]);
const { refresh } = useSchemaComponentContext();
const service = useCallback(() => cm?.reload(refresh), [cm]);
const updateCollection = cm?.setCollections.bind(cm);
@ -236,6 +235,7 @@ export const useCollectionManager = () => {
templates,
getTemplate,
getInterface,
getCollections,
getParentCollectionFields,
getInheritCollections,
getChildrenCollections,

View File

@ -372,7 +372,7 @@ export const GraphDrawPage = React.memo(() => {
const [collectionData, setCollectionData] = useState<any>([]);
const [collectionList, setCollectionList] = useState<any>([]);
const [loading, setLoading] = useState(false);
const { collections } = useCollectionManager();
const { collections, getCollections } = useCollectionManager();
const cm = useCollectionManagerV2();
const currentAppInfo = useCurrentAppInfo();
const app = useApp();
@ -412,7 +412,9 @@ export const GraphDrawPage = React.memo(() => {
refreshPositions();
}
};
const reloadCallback = async (collections) => {
const reloadCallback = async () => {
const collections = getCollections();
if (!targetGraph) return;
targetGraph.collections = collections;
targetGraph.updatePositionAction = updatePositionAction;
targetGraph.saveGraphPositionAction = saveGraphPositionAction;
@ -1072,7 +1074,7 @@ export const GraphDrawPage = React.memo(() => {
setLoading(true);
refreshPositions()
.then(async () => {
await reloadCallback(collections);
await reloadCallback();
setLoading(false);
})
.catch((err) => {