* feat: snapshort init * feat: snapshot update yarn.lock * feat: snapshot add to preset * feat: snapshot add field fix * feat: snapshot remove Table Column SnapshotField * feat: snapshot field label fix * feat: snapshot request error fix * feat: snapshot 二级关联数据打开 * feat: snapshot batch edit fix * feat: snapshot 2 level draw fix * feat: snapshot translate * feat: snapshot global historyCollection provider * feat: snapshot install initial * feat: snapshot refreshCH * feat: snapshot add transaction * feat: snapshot default collecitonField * feat: snapshot build fix * feat: snapshot useSnapshotFieldTargetCollectionKey * feat: snapshot batch update * feat: snapshot linkto support * feat: snapshot use getRepository * feat: snapshot recreate fix * feat: snapshot collectionKey to collectionName & rebuild collection * feat: snapshot remove SnapshotHistoryCollectionProvider & collectionName * feat: snapshot use historyCollections in inherit table * feat: snapshot fix TableSelectorBlock appends * feat: snapshot kanban fix * feat: snapshot snapshot association field fix * feat: snapshot add CollectionFieldProvider fallback * feat: snapshot AssociationSelect fix * feat: snapshot TableField fix
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import { CollectionManagerContext, useHistoryCollectionsByNames } from '@nocobase/client';
|
|
import React, { useContext } from 'react';
|
|
|
|
export const SnapshotHistoryCollectionProvider: React.FC<{ collectionName: string }> = (props) => {
|
|
const { collectionName } = props;
|
|
const { collections: allCollections, ...rest } = useContext(CollectionManagerContext);
|
|
|
|
// 目标表
|
|
const snapshotTargetCollection = useHistoryCollectionsByNames([collectionName])?.[0];
|
|
// 目标如果是继承表则获取继承表
|
|
const inheritCollections = useHistoryCollectionsByNames(snapshotTargetCollection?.inherits ?? []);
|
|
// 目标表内关联字段的表
|
|
const associationFieldTargetCollections = useHistoryCollectionsByNames(
|
|
snapshotTargetCollection?.fields.filter((i) => i.interface !== 'snapshot').map((i) => i.target) ?? [],
|
|
);
|
|
|
|
// 替换表的集合
|
|
const finallyHistoryCollecionts = [
|
|
snapshotTargetCollection,
|
|
...associationFieldTargetCollections,
|
|
...inheritCollections,
|
|
].filter((i) => i);
|
|
|
|
// 过滤出不需要替换的表
|
|
const filterdAllCollection = allCollections.filter(
|
|
(c) => !finallyHistoryCollecionts.map((i) => i.name).includes(c.name),
|
|
);
|
|
|
|
// 最终替换后的表
|
|
const overridedCollections = [...filterdAllCollection, ...finallyHistoryCollecionts];
|
|
|
|
return (
|
|
<CollectionManagerContext.Provider
|
|
value={{
|
|
...rest,
|
|
collections: overridedCollections,
|
|
}}
|
|
>
|
|
{props.children}
|
|
</CollectionManagerContext.Provider>
|
|
);
|
|
};
|