@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 ADDED
@@ -0,0 +1,114 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: Firecms S.L.
6
+ Licensed Work: Firecms CMS packages:
7
+ cli
8
+ collection_editor
9
+ collection_editor_firebase
10
+ data_enhancement
11
+ data_export
12
+ data_export
13
+ editor
14
+ firecms_cloud
15
+ schema_inference
16
+ user_management
17
+
18
+ The Licensed Work is (c) 2024 Firecms S.L
19
+ Additional Use Grant: You may make use of the Licensed Work, provided that
20
+ you may not use the Licensed Work for a CMS Data Enhancement
21
+ Service.
22
+
23
+ A “CMS package” is a commercial offering that
24
+ allows third parties (other than your employees and
25
+ contractors) to access the functionality of the
26
+ Licensed Work by using software to extend the base features of
27
+ content management system controlled by such third parties.
28
+
29
+ Change Date: Four years from the date the Licensed Work is published.
30
+
31
+ Change License: MIT
32
+
33
+ For information about alternative licensing arrangements for the Software,
34
+ please visit: https://firecms.co
35
+
36
+ Notice
37
+
38
+ The Business Source License (this document, or the “License”) is not an Open
39
+ Source license. However, the Licensed Work will eventually be made available
40
+ under an Open Source License, as stated in this License.
41
+
42
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
43
+ “Business Source License” is a trademark of MariaDB Corporation Ab.
44
+
45
+ -----------------------------------------------------------------------------
46
+
47
+ Business Source License 1.1
48
+
49
+ Terms
50
+
51
+ The Licensor hereby grants you the right to copy, modify, create derivative
52
+ works, redistribute, and make non-production use of the Licensed Work. The
53
+ Licensor may make an Additional Use Grant, above, permitting limited
54
+ production use.
55
+
56
+ Effective on the Change Date, or the fourth anniversary of the first publicly
57
+ available distribution of a specific version of the Licensed Work under this
58
+ License, whichever comes first, the Licensor hereby grants you rights under
59
+ the terms of the Change License, and the rights granted in the paragraph
60
+ above terminate.
61
+
62
+ If your use of the Licensed Work does not comply with the requirements
63
+ currently in effect as described in this License, you must purchase a
64
+ commercial license from the Licensor, its affiliated entities, or authorized
65
+ resellers, or you must refrain from using the Licensed Work.
66
+
67
+ All copies of the original and modified Licensed Work, and derivative works
68
+ of the Licensed Work, are subject to this License. This License applies
69
+ separately for each version of the Licensed Work and the Change Date may vary
70
+ for each version of the Licensed Work released by Licensor.
71
+
72
+ You must conspicuously display this License on each original or modified copy
73
+ of the Licensed Work. If you receive the Licensed Work in original or
74
+ modified form from a third party, the terms and conditions set forth in this
75
+ License apply to your use of that work.
76
+
77
+ Any use of the Licensed Work in violation of this License will automatically
78
+ terminate your rights under this License for the current and all other
79
+ versions of the Licensed Work.
80
+
81
+ This License does not grant you any right in any trademark or logo of
82
+ Licensor or its affiliates (provided that you may use a trademark or logo of
83
+ Licensor as expressly required by this License).
84
+
85
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
86
+ AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
87
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
88
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
89
+ TITLE.
90
+
91
+ MariaDB hereby grants you permission to use this License’s text to license
92
+ your works, and to refer to it using the trademark “Business Source License”,
93
+ as long as you comply with the Covenants of Licensor below.
94
+
95
+ Covenants of Licensor
96
+
97
+ In consideration of the right to use this License’s text and the “Business
98
+ Source License” name and trademark, Licensor covenants to MariaDB, and to all
99
+ other recipients of the licensed work to be provided by Licensor:
100
+
101
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
102
+ or a license that is compatible with GPL Version 2.0 or a later version,
103
+ where “compatible” means that software provided under the Change License can
104
+ be included in a program with software provided under GPL Version 2.0 or a
105
+ later version. Licensor may specify additional Change Licenses without
106
+ limitation.
107
+
108
+ 2. To either: (a) specify an additional grant of rights to use that does not
109
+ impose any additional restriction on the right granted in this License, as
110
+ the Additional Use Grant; or (b) insert the text “None”.
111
+
112
+ 3. To specify a Change Date.
113
+
114
+ 4. Not to modify this License in any other way.
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # FireCMS Entity History Plugin
2
+
3
+ This plugin adds a history view to your entities in FireCMS. It allows you to track changes made to entities over time,
4
+ showing who made the change and when.
5
+
6
+ The document history will be stored in a subcollection called `__history` within the entity's document.
7
+ Each change will be recorded as a new document in this subcollection.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @firecms/entity_history
13
+ # or
14
+ yarn add @firecms/entity_history
15
+ ```
16
+
17
+ ## Features
18
+
19
+ - Adds a "History" tab to entity detail views.
20
+ - Displays a log of changes for each entity.
21
+ - Can be enabled globally or on a per-collection basis.
22
+ - Allows customization of user display in the history log.
23
+
24
+ ## Basic Usage
25
+
26
+ To use the plugin, import `useEntityHistoryPlugin` and add it to your `FirebaseCMSApp` plugins array.
27
+
28
+ ```tsx
29
+ import React from "react";
30
+ import { FirebaseCMSApp } from "@firecms/core";
31
+ import { useEntityHistoryPlugin } from "@firecms/entity_history";
32
+
33
+
34
+ export default function App() {
35
+
36
+ // Basic setup with default options
37
+ const entityHistoryPlugin = useEntityHistoryPlugin();
38
+
39
+ return <FirebaseCMSApp
40
+ name={"My Online Shop"}
41
+ plugins={[entityHistoryPlugin]}
42
+ authentication={myAuthenticator}
43
+ collections={myCollections}
44
+ firebaseConfig={firebaseConfig}
45
+ />;
46
+ }
47
+ ```
48
+
49
+ By default, the history feature is not enabled for any collection. You need to enable it explicitly in your collection
50
+ configuration:
51
+
52
+ ```tsx
53
+ import { buildCollection } from "@firecms/core";
54
+
55
+ const productsCollection = buildCollection({
56
+ name: "Products",
57
+ path: "products",
58
+ properties: {
59
+ name: {
60
+ name: "Name",
61
+ dataType: "string"
62
+ }
63
+ // ...other properties
64
+ },
65
+ history: true // Enable history for this collection
66
+ });
67
+ ```
68
+
69
+ ## Advanced Configuration
70
+
71
+ You can customize the plugin's behavior by passing props to `useEntityHistoryPlugin`.
72
+ If you are using the user management plugin, you can provide a function to resolve user details from a UID.
73
+ You can also pass your own custom `getUser` function to fetch user details.
74
+
75
+ ```tsx
76
+ import { useEntityHistoryPlugin } from "@firecms/entity_history";
77
+ import { User } from "@firecms/core";
78
+
79
+ export function App() {
80
+
81
+ // ...
82
+
83
+ const userManagement = useBuildUserManagement({
84
+ dataSourceDelegate: firestoreDelegate,
85
+ authController: authController
86
+ });
87
+
88
+ const entityHistoryPlugin = useEntityHistoryPlugin({
89
+ // Enable history for all collections by default
90
+ // This can be overridden by setting `history: false` in a specific collection
91
+ defaultEnabled: true,
92
+
93
+ // Provide a function to resolve user details from a UID
94
+ getUser: userManagement.getUser
95
+ });
96
+
97
+ // ...
98
+ }
99
+ ```
100
+
101
+ ## Configuration Options
102
+
103
+ | Option | Type | Description |
104
+ |------------------|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
105
+ | `defaultEnabled` | `boolean` | If `true`, the history view will be enabled for all collections by default. Each collection can override this by setting its `history` property. |
106
+ | `getUser` | `(uid: string) => User \| null` | Optional function to get the user object (display name, photo, etc.) from a user ID to display in the history log. |
107
+
108
+ ## Collection Configuration
109
+
110
+ To enable or disable history for a specific collection, set the `history` property in the collection configuration:
111
+
112
+ ```tsx
113
+ const sampleCollection = buildCollection({
114
+ // ...
115
+ history: true // or false
116
+ });
117
+ ```
118
+
119
+ ## Additional Notes
120
+
121
+ - The plugin relies on callbacks to record entity changes. Ensure that your data persistence logic correctly triggers
122
+ these callbacks.
123
+ - The `getUser` function is crucial for displaying meaningful user information in the history log. If not provided, only
124
+ user IDs might be shown.
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ import { User } from "@firecms/core";
3
+ export type HistoryConfigController = {
4
+ /**
5
+ * Function to get a user by uid.
6
+ * @param uid
7
+ */
8
+ getUser?: (uid: string) => User | null;
9
+ };
10
+ export declare const HistoryControllerContext: React.Context<HistoryConfigController>;
11
+ export declare const useHistoryController: () => HistoryConfigController;
12
+ export interface HistoryControllerProviderProps {
13
+ getUser?: (uid: string) => User | null;
14
+ }
15
+ export declare const HistoryControllerProvider: React.NamedExoticComponent<React.PropsWithChildren<HistoryControllerProviderProps>>;
@@ -0,0 +1,17 @@
1
+ import * as React from "react";
2
+ import { Entity, EntityCollection, PreviewSize } from "@firecms/core";
3
+ export type EntityPreviewProps = {
4
+ size: PreviewSize;
5
+ actions?: React.ReactNode;
6
+ collection?: EntityCollection;
7
+ hover?: boolean;
8
+ previewKeys?: string[];
9
+ disabled?: boolean;
10
+ entity: Entity<any>;
11
+ onClick?: (e: React.SyntheticEvent) => void;
12
+ };
13
+ /**
14
+ * This view is used to display a preview of an entity.
15
+ * It is used by default in reference fields and whenever a reference is displayed.
16
+ */
17
+ export declare function EntityHistoryEntry({ actions, disabled, hover, collection: collectionProp, previewKeys, onClick, size, entity }: EntityPreviewProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { EntityCustomViewParams } from "@firecms/core";
2
+ export declare function EntityHistoryView({ entity, collection, formContext }: EntityCustomViewParams): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { User } from "@firecms/core";
2
+ export declare function UserChip({ user }: {
3
+ user: User;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { EntityCallbacks } from "@firecms/core";
2
+ export declare const entityHistoryCallbacks: EntityCallbacks;
@@ -0,0 +1,2 @@
1
+ export * from "./useEntityHistoryPlugin";
2
+ export * from "./HistoryControllerProvider";