@firecms/core 3.0.0-canary.279 → 3.0.0-canary.280

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.
Files changed (46) hide show
  1. package/dist/components/UserDisplay.d.ts +7 -0
  2. package/dist/components/VirtualTable/fields/VirtualTableUserSelect.d.ts +12 -0
  3. package/dist/contexts/InternalUserManagementContext.d.ts +3 -0
  4. package/dist/core/FireCMS.d.ts +0 -1
  5. package/dist/core/field_configs.d.ts +1 -1
  6. package/dist/form/field_bindings/UserSelectFieldBinding.d.ts +12 -0
  7. package/dist/hooks/index.d.ts +1 -0
  8. package/dist/hooks/useInternalUserManagementController.d.ts +12 -0
  9. package/dist/index.es.js +474 -84
  10. package/dist/index.es.js.map +1 -1
  11. package/dist/index.umd.js +473 -83
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/preview/components/UserPreview.d.ts +8 -0
  14. package/dist/preview/index.d.ts +1 -0
  15. package/dist/types/firecms.d.ts +15 -0
  16. package/dist/types/firecms_context.d.ts +16 -0
  17. package/dist/types/index.d.ts +1 -0
  18. package/dist/types/internal_user_management.d.ts +20 -0
  19. package/dist/types/plugins.d.ts +2 -0
  20. package/dist/types/properties.d.ts +9 -0
  21. package/dist/types/property_config.d.ts +1 -1
  22. package/dist/types/user.d.ts +1 -1
  23. package/package.json +5 -5
  24. package/src/components/EntityCollectionTable/PropertyTableCell.tsx +12 -0
  25. package/src/components/UserDisplay.tsx +54 -0
  26. package/src/components/VirtualTable/fields/VirtualTableUserSelect.tsx +99 -0
  27. package/src/contexts/InternalUserManagementContext.tsx +4 -0
  28. package/src/core/FireCMS.tsx +22 -13
  29. package/src/core/field_configs.tsx +15 -1
  30. package/src/form/field_bindings/UserSelectFieldBinding.tsx +94 -0
  31. package/src/hooks/index.tsx +2 -0
  32. package/src/hooks/useFireCMSContext.tsx +6 -2
  33. package/src/hooks/useInternalUserManagementController.tsx +16 -0
  34. package/src/preview/PropertyPreview.tsx +8 -0
  35. package/src/preview/components/UserPreview.tsx +22 -0
  36. package/src/preview/index.ts +1 -0
  37. package/src/types/firecms.tsx +16 -0
  38. package/src/types/firecms_context.tsx +17 -0
  39. package/src/types/index.ts +1 -0
  40. package/src/types/internal_user_management.ts +24 -0
  41. package/src/types/plugins.tsx +3 -0
  42. package/src/types/properties.ts +10 -0
  43. package/src/types/property_config.tsx +1 -0
  44. package/src/types/user.ts +1 -1
  45. package/src/util/entities.ts +1 -1
  46. package/src/util/entity_cache.ts +2 -2
@@ -31,6 +31,7 @@ import { DatePreview } from "./components/DatePreview";
31
31
  import { BooleanPreview } from "./components/BooleanPreview";
32
32
  import { NumberPropertyPreview } from "./property_previews/NumberPropertyPreview";
33
33
  import { ErrorView } from "../components";
34
+ import { UserPreview } from "./components/UserPreview";
34
35
 
35
36
  /**
36
37
  * @group Preview components
@@ -97,6 +98,13 @@ export const PropertyPreview = React.memo(function PropertyPreview<T extends CMS
97
98
  previewType={stringProperty.url}/>;
98
99
  } else if (stringProperty.markdown) {
99
100
  content = <Markdown source={value} size={"small"}/>;
101
+ } else if (stringProperty.userSelect) {
102
+ content = <UserPreview
103
+ value={value}
104
+ property={stringProperty}
105
+ propertyKey={propertyKey}
106
+ size={props.size}
107
+ />;
100
108
  } else if (stringProperty.reference) {
101
109
  if (typeof stringProperty.reference.path === "string") {
102
110
  content = <ReferencePreview
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { PropertyPreviewProps } from "../PropertyPreviewProps";
3
+ import { useInternalUserManagementController } from "../../hooks";
4
+ import { UserDisplay } from "../../components/UserDisplay";
5
+
6
+ /**
7
+ * Preview component for displaying user information.
8
+ * This is a simple wrapper around UserDisplay.
9
+ *
10
+ * @group Preview components
11
+ */
12
+ export function UserPreview({ value }: PropertyPreviewProps<string>) {
13
+ const { getUser } = useInternalUserManagementController();
14
+
15
+ if (!value) {
16
+ return null;
17
+ }
18
+
19
+ const user = getUser(value);
20
+
21
+ return <UserDisplay user={user} />;
22
+ }
@@ -25,3 +25,4 @@ export * from "./components/EnumValuesChip";
25
25
  export * from "./components/EmptyValue";
26
26
  export * from "./components/ImagePreview";
27
27
  export * from "./components/ReferencePreview";
28
+ export * from "./components/UserPreview";
@@ -13,6 +13,7 @@ import { UserConfigurationPersistence } from "./local_config_persistence";
13
13
  import { FireCMSPlugin } from "./plugins";
14
14
  import { CMSAnalyticsEvent } from "./analytics";
15
15
  import { EntityAction } from "./entity_actions";
16
+ import { InternalUserManagement } from "./internal_user_management";
16
17
 
17
18
  /**
18
19
  * Use this callback to build entity collections dynamically.
@@ -139,6 +140,7 @@ export type FireCMSProps<USER extends User> = {
139
140
  * Use plugins to modify the behaviour of the CMS.
140
141
  * DEPRECATED: use the `plugins` prop in the `useBuildNavigationController` instead.
141
142
  * This prop will work as a fallback for the `plugins` prop in the `useBuildNavigationController`.
143
+ * @deprecated
142
144
  */
143
145
  plugins?: FireCMSPlugin<any, any, any>[];
144
146
 
@@ -153,6 +155,20 @@ export type FireCMSProps<USER extends User> = {
153
155
  */
154
156
  entityLinkBuilder?: EntityLinkBuilder;
155
157
 
158
+ /**
159
+ * You can use this props to provide your own user management implementation.
160
+ * Note that this will not affect the UI, but it will be used to show user information
161
+ * in various places of the CMS, for example, to show who created or modified an entity,
162
+ * or to assign ownership of an entity.
163
+ *
164
+ * You can also use this data to be retrieved in your custom properties,
165
+ * for example, to show a list of users in a dropdown.
166
+ *
167
+ * If you are using the FireCMS user management plugin, this
168
+ * prop will be implemented automatically.
169
+ */
170
+ userManagement?: InternalUserManagement
171
+
156
172
  components?: {
157
173
 
158
174
  /**
@@ -10,6 +10,7 @@ import { SideDialogsController } from "./side_dialogs_controller";
10
10
  import { DialogsController } from "./dialogs_controller";
11
11
  import { CustomizationController } from "./customization_controller";
12
12
  import { AnalyticsController } from "./analytics_controller";
13
+ import { InternalUserManagement } from "./internal_user_management";
13
14
 
14
15
  /**
15
16
  * Context that includes the internal controllers and contexts used by the app.
@@ -80,4 +81,20 @@ export type FireCMSContext<USER extends User = User, AuthControllerType extends
80
81
  */
81
82
  analyticsController?: AnalyticsController;
82
83
 
84
+ /**
85
+ * This section is used to manage users in the CMS.
86
+ * It is used to show user information in various places of the CMS,
87
+ * for example, to show who created or modified an entity,
88
+ * or to assign ownership of an entity.
89
+ *
90
+ * In the base CMS, this information is not used for access control.
91
+ * You can pass your own implementation of this section, to populate
92
+ * the dropdown of users when assigning ownership of an entity,
93
+ * or to show more information about the user.
94
+ *
95
+ * If you are using the FireCMS user management plugin, this
96
+ * section will be implemented automatically.
97
+ */
98
+ userManagement: InternalUserManagement<USER>
99
+
83
100
  };
@@ -13,6 +13,7 @@ export * from "./fields";
13
13
  export * from "./property_config";
14
14
  export * from "./datasource";
15
15
  export * from "./entity_link_builder";
16
+ export * from "./internal_user_management";
16
17
  export * from "./side_entity_controller";
17
18
  export * from "./side_dialogs_controller";
18
19
  export * from "./firecms_context";
@@ -0,0 +1,24 @@
1
+ import { User } from "./user";
2
+
3
+ export type InternalUserManagement<USER extends User = User> = {
4
+
5
+ /**
6
+ * List of users to be managed by the CMS.
7
+ */
8
+ users: USER[];
9
+
10
+ /**
11
+ * Function to get a user by its uid. This is used to show
12
+ * user information when assigning ownership of an entity.
13
+ *
14
+ * You can pass your own implementation if you want to show
15
+ * more information about the user.
16
+ *
17
+ * If you are using the FireCMS user management plugin, this
18
+ * function will be implemented automatically.
19
+ *
20
+ * @param uid
21
+ */
22
+ getUser: (uid: string) => USER | null;
23
+
24
+ }
@@ -8,6 +8,7 @@ import { CMSType, Property } from "./properties";
8
8
  import { EntityStatus } from "./entities";
9
9
  import { ResolvedProperty } from "./resolved_entities";
10
10
  import { NavigationGroupMapping } from "./navigation";
11
+ import { InternalUserManagement } from "./internal_user_management";
11
12
 
12
13
  /**
13
14
  * Interface used to define plugins for FireCMS.
@@ -43,6 +44,8 @@ export type FireCMSPlugin<PROPS = any, FORM_PROPS = any, EC extends EntityCollec
43
44
  props?: PROPS;
44
45
  };
45
46
 
47
+ userManagement?: InternalUserManagement
48
+
46
49
  homePage?: {
47
50
 
48
51
  /**
@@ -388,6 +388,16 @@ export interface StringProperty extends BaseProperty<string> {
388
388
  */
389
389
  storage?: StorageConfig;
390
390
 
391
+ /**
392
+ * This property is used to indicate that the string is a user ID, and
393
+ * it will be rendered as a user picker.
394
+ * Note that the user ID needs to be the one used in your authentication
395
+ * provider, e.g. Firebase Auth.
396
+ * You can also use a property builder to specify the user path dynamically
397
+ * based on other values of the entity.
398
+ */
399
+ userSelect?: boolean;
400
+
391
401
  /**
392
402
  * If the value of this property is a URL, you can set this flag to true
393
403
  * to add a link, or one of the supported media types to render a preview
@@ -52,6 +52,7 @@ export type PropertyConfigId =
52
52
  "markdown" |
53
53
  "url" |
54
54
  "email" |
55
+ "user_select" |
55
56
  "select" |
56
57
  "multi_select" |
57
58
  "number_input" |
package/src/types/user.ts CHANGED
@@ -37,7 +37,7 @@ export type User = {
37
37
  readonly isAnonymous: boolean;
38
38
 
39
39
  /**
40
- *
40
+ * Custom roles assigned to the user.
41
41
  */
42
42
  roles?: Role[];
43
43
 
@@ -142,7 +142,7 @@ export function sanitizeData<M extends Record<string, any>>
142
142
  }
143
143
 
144
144
  export function getReferenceFrom<M extends Record<string, any>>(entity: Entity<M>): EntityReference {
145
- return new EntityReference(entity.id, entity.path);
145
+ return new EntityReference(entity.id, entity.path, entity.databaseId);
146
146
  }
147
147
 
148
148
  export function traverseValuesProperties<M extends Record<string, any>>(
@@ -24,7 +24,7 @@ function customReplacer(key: string): any {
24
24
  // Handle EntityReference
25
25
  // @ts-ignore
26
26
  if (value instanceof EntityReference) {
27
- return { __type: "EntityReference", id: value.id, path: value.path };
27
+ return { __type: "EntityReference", id: value.id, path: value.path, databaseId: value.databaseId };
28
28
  }
29
29
 
30
30
  // Handle GeoPoint
@@ -49,7 +49,7 @@ function customReviver(key: string, value: any): any {
49
49
  case "Date":
50
50
  return new Date(value.value);
51
51
  case "EntityReference":
52
- return new EntityReference(value.id, value.path);
52
+ return new EntityReference(value.id, value.path, value.databaseId);
53
53
  case "GeoPoint":
54
54
  return new GeoPoint(value.latitude, value.longitude);
55
55
  case "Vector":