@firecms/entity_history 3.0.0-canary.237
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +114 -0
- package/README.md +124 -0
- package/dist/HistoryControllerProvider.d.ts +15 -0
- package/dist/components/EntityHistoryEntry.d.ts +17 -0
- package/dist/components/EntityHistoryView.d.ts +2 -0
- package/dist/components/UserChip.d.ts +4 -0
- package/dist/entity_history_callbacks.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +567 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +581 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/useEntityHistoryPlugin.d.ts +17 -0
- package/package.json +86 -0
- package/src/HistoryControllerProvider.tsx +40 -0
- package/src/components/EntityHistoryEntry.tsx +161 -0
- package/src/components/EntityHistoryView.tsx +222 -0
- package/src/components/UserChip.tsx +15 -0
- package/src/entity_history_callbacks.ts +99 -0
- package/src/index.ts +2 -0
- package/src/useEntityHistoryPlugin.tsx +62 -0
- package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
2
|
+
import { EntityCollection, FireCMSPlugin, mergeCallbacks, User } from "@firecms/core";
|
3
|
+
import { EntityHistoryView } from "./components/EntityHistoryView";
|
4
|
+
import { HistoryIcon } from "@firecms/ui";
|
5
|
+
import { entityHistoryCallbacks } from "./entity_history_callbacks";
|
6
|
+
import { HistoryControllerProvider } from "./HistoryControllerProvider";
|
7
|
+
|
8
|
+
/**
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
export function useEntityHistoryPlugin(props?: EntityHistoryPluginProps): FireCMSPlugin<any, any, any, EntityHistoryPluginProps> {
|
12
|
+
|
13
|
+
const { defaultEnabled = false } = props ?? {};
|
14
|
+
|
15
|
+
const modifyCollection = useCallback((collection: EntityCollection) => {
|
16
|
+
if (collection.history === true || defaultEnabled) {
|
17
|
+
return {
|
18
|
+
...collection,
|
19
|
+
history: true,
|
20
|
+
entityViews: [
|
21
|
+
...(collection.entityViews ?? []),
|
22
|
+
{
|
23
|
+
key: "__history",
|
24
|
+
name: "History",
|
25
|
+
tabComponent: <HistoryIcon size={"small"}/>,
|
26
|
+
Builder: EntityHistoryView,
|
27
|
+
position: "start"
|
28
|
+
}
|
29
|
+
],
|
30
|
+
callbacks: mergeCallbacks(collection.callbacks, entityHistoryCallbacks)
|
31
|
+
} satisfies EntityCollection;
|
32
|
+
}
|
33
|
+
return collection;
|
34
|
+
}, []);
|
35
|
+
|
36
|
+
return useMemo(() => ({
|
37
|
+
key: "entity_history",
|
38
|
+
provider: {
|
39
|
+
Component: HistoryControllerProvider,
|
40
|
+
props: {
|
41
|
+
getUser: props?.getUser
|
42
|
+
}
|
43
|
+
},
|
44
|
+
collection: {
|
45
|
+
modifyCollection
|
46
|
+
}
|
47
|
+
} satisfies FireCMSPlugin), [props]);
|
48
|
+
}
|
49
|
+
|
50
|
+
export type EntityHistoryPluginProps = {
|
51
|
+
/**
|
52
|
+
* If true, the history view will be enabled to all collections by default.
|
53
|
+
* Each collection can override this value by setting the `history` property.
|
54
|
+
*/
|
55
|
+
defaultEnabled?: boolean;
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Function to get the user object from the uid.
|
59
|
+
* @param uid
|
60
|
+
*/
|
61
|
+
getUser?: (uid: string) => User | null;
|
62
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
/// <reference types="vite/client" />
|