@firecms/core 3.0.0-beta.2 → 3.0.0-beta.4.pre.1

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 (157) hide show
  1. package/README.md +1 -1
  2. package/dist/components/EntityCollectionTable/EntityCollectionRowActions.d.ts +3 -7
  3. package/dist/components/EntityCollectionTable/EntityCollectionTable.d.ts +2 -2
  4. package/dist/components/EntityCollectionTable/PropertyTableCell.d.ts +2 -2
  5. package/dist/components/EntityCollectionView/EntityCollectionView.d.ts +1 -2
  6. package/dist/components/EntityCollectionView/useSelectionController.d.ts +2 -0
  7. package/dist/components/EntityPreview.d.ts +25 -7
  8. package/dist/components/EntityView.d.ts +11 -0
  9. package/dist/components/FieldCaption.d.ts +4 -0
  10. package/dist/components/HomePage/NavigationCard.d.ts +8 -0
  11. package/dist/components/HomePage/{NavigationCollectionCard.d.ts → NavigationCardBinding.d.ts} +2 -2
  12. package/dist/components/HomePage/SmallNavigationCard.d.ts +6 -0
  13. package/dist/components/HomePage/index.d.ts +3 -1
  14. package/dist/components/ReferenceWidget.d.ts +3 -3
  15. package/dist/components/VirtualTable/VirtualTableProps.d.ts +1 -1
  16. package/dist/components/index.d.ts +4 -3
  17. package/dist/{internal/EntityView.d.ts → core/EntityEditView.d.ts} +2 -2
  18. package/dist/core/SideEntityView.d.ts +7 -0
  19. package/dist/core/index.d.ts +0 -2
  20. package/dist/form/EntityForm.d.ts +1 -1
  21. package/dist/form/components/StorageItemPreview.d.ts +3 -2
  22. package/dist/form/components/StorageUploadProgress.d.ts +1 -1
  23. package/dist/form/components/index.d.ts +1 -0
  24. package/dist/form/field_bindings/KeyValueFieldBinding.d.ts +1 -1
  25. package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
  26. package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +4 -3
  27. package/dist/form/field_bindings/TextFieldBinding.d.ts +2 -2
  28. package/dist/form/index.d.ts +1 -0
  29. package/dist/form/validation.d.ts +1 -1
  30. package/dist/hooks/data/useDataSource.d.ts +2 -2
  31. package/dist/hooks/index.d.ts +2 -1
  32. package/dist/{core → hooks}/useBuildModeController.d.ts +1 -1
  33. package/dist/hooks/useBuildNavigationController.d.ts +5 -2
  34. package/dist/hooks/useProjectLog.d.ts +5 -1
  35. package/dist/hooks/useStorageSource.d.ts +2 -2
  36. package/dist/index.es.js +8444 -8152
  37. package/dist/index.es.js.map +1 -1
  38. package/dist/index.umd.js +5 -5
  39. package/dist/index.umd.js.map +1 -1
  40. package/dist/internal/useBuildDataSource.d.ts +4 -0
  41. package/dist/internal/useRestoreScroll.d.ts +1 -1
  42. package/dist/preview/PropertyPreview.d.ts +1 -1
  43. package/dist/preview/components/BooleanPreview.d.ts +5 -1
  44. package/dist/preview/components/EnumValuesChip.d.ts +1 -1
  45. package/dist/preview/components/ReferencePreview.d.ts +1 -7
  46. package/dist/types/analytics.d.ts +1 -1
  47. package/dist/types/auth.d.ts +8 -1
  48. package/dist/types/collections.d.ts +14 -1
  49. package/dist/types/entities.d.ts +1 -0
  50. package/dist/types/entity_overrides.d.ts +6 -0
  51. package/dist/types/index.d.ts +1 -0
  52. package/dist/types/navigation.d.ts +10 -9
  53. package/dist/types/permissions.d.ts +5 -1
  54. package/dist/types/plugins.d.ts +15 -17
  55. package/dist/types/properties.d.ts +2 -2
  56. package/dist/types/property_config.d.ts +2 -2
  57. package/dist/util/collections.d.ts +9 -1
  58. package/dist/util/icons.d.ts +8 -2
  59. package/dist/util/index.d.ts +1 -0
  60. package/dist/util/permissions.d.ts +4 -4
  61. package/dist/util/references.d.ts +4 -2
  62. package/dist/util/resolutions.d.ts +1 -1
  63. package/package.json +31 -23
  64. package/src/components/DeleteEntityDialog.tsx +4 -4
  65. package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +35 -39
  66. package/src/components/EntityCollectionTable/EntityCollectionTable.tsx +276 -282
  67. package/src/components/EntityCollectionTable/EntityCollectionTableProps.tsx +1 -1
  68. package/src/components/EntityCollectionTable/PropertyTableCell.tsx +13 -13
  69. package/src/components/EntityCollectionTable/fields/TableReferenceField.tsx +9 -16
  70. package/src/components/EntityCollectionTable/fields/TableStorageUpload.tsx +3 -3
  71. package/src/components/EntityCollectionTable/internal/CollectionTableToolbar.tsx +1 -1
  72. package/src/components/EntityCollectionTable/internal/default_entity_actions.tsx +9 -5
  73. package/src/components/EntityCollectionView/EntityCollectionView.tsx +37 -58
  74. package/src/components/EntityCollectionView/EntityCollectionViewActions.tsx +5 -6
  75. package/src/components/EntityCollectionView/useSelectionController.tsx +30 -0
  76. package/src/components/EntityPreview.tsx +204 -70
  77. package/src/components/EntityView.tsx +84 -0
  78. package/src/components/FieldCaption.tsx +13 -0
  79. package/src/components/FireCMSAppBar.tsx +8 -0
  80. package/src/components/HomePage/DefaultHomePage.tsx +13 -9
  81. package/src/components/HomePage/NavigationCard.tsx +69 -0
  82. package/src/components/HomePage/NavigationCardBinding.tsx +116 -0
  83. package/src/components/HomePage/SmallNavigationCard.tsx +45 -0
  84. package/src/components/HomePage/index.tsx +3 -1
  85. package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +3 -4
  86. package/src/components/ReferenceWidget.tsx +7 -7
  87. package/src/components/SelectableTable/filters/ReferenceFilterField.tsx +11 -19
  88. package/src/components/VirtualTable/VirtualTableProps.tsx +1 -1
  89. package/src/components/common/useDataSourceEntityCollectionTableController.tsx +1 -1
  90. package/src/components/index.tsx +4 -3
  91. package/src/core/Drawer.tsx +66 -39
  92. package/src/{internal/EntityView.tsx → core/EntityEditView.tsx} +22 -39
  93. package/src/core/EntitySidePanel.tsx +2 -2
  94. package/src/core/FireCMS.tsx +18 -2
  95. package/src/core/NavigationRoutes.tsx +8 -0
  96. package/src/core/SideEntityView.tsx +38 -0
  97. package/src/core/index.tsx +0 -2
  98. package/src/form/EntityForm.tsx +19 -11
  99. package/src/form/components/StorageItemPreview.tsx +5 -3
  100. package/src/form/components/StorageUploadProgress.tsx +6 -5
  101. package/src/form/components/index.tsx +1 -0
  102. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +2 -3
  103. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +12 -15
  104. package/src/form/field_bindings/BlockFieldBinding.tsx +2 -3
  105. package/src/form/field_bindings/DateTimeFieldBinding.tsx +3 -3
  106. package/src/form/field_bindings/KeyValueFieldBinding.tsx +18 -18
  107. package/src/form/field_bindings/MapFieldBinding.tsx +17 -17
  108. package/src/form/field_bindings/MarkdownFieldBinding.tsx +1 -2
  109. package/src/form/field_bindings/MultiSelectBinding.tsx +2 -3
  110. package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +3 -3
  111. package/src/form/field_bindings/ReferenceFieldBinding.tsx +6 -4
  112. package/src/form/field_bindings/RepeatFieldBinding.tsx +3 -3
  113. package/src/form/field_bindings/SelectFieldBinding.tsx +2 -3
  114. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +15 -6
  115. package/src/form/field_bindings/SwitchFieldBinding.tsx +2 -3
  116. package/src/form/field_bindings/TextFieldBinding.tsx +10 -9
  117. package/src/form/index.tsx +1 -0
  118. package/src/form/validation.ts +3 -4
  119. package/src/hooks/data/useCollectionFetch.tsx +1 -1
  120. package/src/hooks/data/useDataSource.tsx +8 -3
  121. package/src/hooks/data/useEntityFetch.tsx +1 -1
  122. package/src/hooks/index.tsx +3 -1
  123. package/src/{core → hooks}/useBuildModeController.tsx +1 -1
  124. package/src/hooks/useBuildNavigationController.tsx +105 -49
  125. package/src/hooks/useProjectLog.tsx +11 -3
  126. package/src/hooks/useReferenceDialog.tsx +2 -2
  127. package/src/hooks/useStorageSource.tsx +7 -2
  128. package/src/internal/useBuildDataSource.ts +7 -2
  129. package/src/preview/PropertyPreview.tsx +2 -2
  130. package/src/preview/components/BooleanPreview.tsx +16 -3
  131. package/src/preview/components/EnumValuesChip.tsx +1 -1
  132. package/src/preview/components/ReferencePreview.tsx +55 -147
  133. package/src/preview/property_previews/StringPropertyPreview.tsx +8 -7
  134. package/src/types/analytics.ts +1 -0
  135. package/src/types/auth.tsx +11 -1
  136. package/src/types/collections.ts +16 -1
  137. package/src/types/entities.ts +4 -0
  138. package/src/types/entity_actions.tsx +4 -0
  139. package/src/types/entity_overrides.tsx +7 -0
  140. package/src/types/firecms.tsx +0 -1
  141. package/src/types/index.ts +1 -0
  142. package/src/types/navigation.ts +11 -10
  143. package/src/types/permissions.ts +6 -1
  144. package/src/types/plugins.tsx +22 -25
  145. package/src/types/properties.ts +1 -1
  146. package/src/types/property_config.tsx +2 -2
  147. package/src/types/side_entity_controller.tsx +1 -0
  148. package/src/util/collections.ts +22 -0
  149. package/src/util/icons.tsx +11 -3
  150. package/src/util/index.ts +1 -0
  151. package/src/util/permissions.ts +11 -8
  152. package/src/util/references.ts +36 -5
  153. package/src/components/HomePage/NavigationCollectionCard.tsx +0 -146
  154. /package/dist/{components → form/components}/LabelWithIcon.d.ts +0 -0
  155. /package/dist/{core → hooks}/useBuildLocalConfigurationPersistence.d.ts +0 -0
  156. /package/src/{components → form/components}/LabelWithIcon.tsx +0 -0
  157. /package/src/{core → hooks}/useBuildLocalConfigurationPersistence.tsx +0 -0
@@ -7,6 +7,7 @@ import { FieldProps, FormContext } from "./fields";
7
7
  import { CMSType, Property } from "./properties";
8
8
  import { EntityStatus } from "./entities";
9
9
  import { ResolvedProperty } from "./resolved_entities";
10
+ import { CMSView } from "./navigation";
10
11
 
11
12
  /**
12
13
  * Interface used to define plugins for FireCMS.
@@ -26,31 +27,6 @@ export type FireCMSPlugin<PROPS = any, FORM_PROPS = any, EC extends EntityCollec
26
27
  */
27
28
  loading?: boolean;
28
29
 
29
- collections?: {
30
-
31
- /**
32
- * Use this component to add custom actions to the entity collections
33
- * toolbar.
34
- */
35
- CollectionActions?: React.ComponentType<CollectionActionsProps<any, any, EC> & COL_ACTIONS_PROPS> | React.ComponentType<CollectionActionsProps<any, any, EC> & COL_ACTIONS_PROPS>[];
36
-
37
- collectionActionsProps?: COL_ACTIONS_PROPS;
38
-
39
- }
40
-
41
- form?: {
42
- provider?: {
43
- Component: React.ComponentType<PropsWithChildren<FORM_PROPS & PluginFormActionProps<any, EC>>>;
44
- props?: FORM_PROPS;
45
- }
46
-
47
- Actions?: React.ComponentType<PluginFormActionProps<any, EC>>;
48
-
49
- fieldBuilder?: <T extends CMSType = CMSType>(props: PluginFieldBuilderParams<T, any, EC>) => React.ComponentType<FieldProps<T>> | null;
50
-
51
- fieldBuilderEnabled?: <T extends CMSType = CMSType>(props: PluginFieldBuilderParams<T>) => boolean;
52
- }
53
-
54
30
  /**
55
31
  * You can use this prop to add higher order components to the CMS.
56
32
  * The components will be added to the root of the CMS, so any component
@@ -113,6 +89,14 @@ export type FireCMSPlugin<PROPS = any, FORM_PROPS = any, EC extends EntityCollec
113
89
 
114
90
  collectionView?: {
115
91
 
92
+ /**
93
+ * Use this component to add custom actions to the entity collections
94
+ * toolbar.
95
+ */
96
+ CollectionActions?: React.ComponentType<CollectionActionsProps<any, any, EC> & COL_ACTIONS_PROPS> | React.ComponentType<CollectionActionsProps<any, any, EC> & COL_ACTIONS_PROPS>[];
97
+
98
+ collectionActionsProps?: COL_ACTIONS_PROPS;
99
+
116
100
  showTextSearchBar?: (props: {
117
101
  context: FireCMSContext,
118
102
  path: string,
@@ -151,6 +135,19 @@ export type FireCMSPlugin<PROPS = any, FORM_PROPS = any, EC extends EntityCollec
151
135
  }>;
152
136
  }
153
137
 
138
+ form?: {
139
+ provider?: {
140
+ Component: React.ComponentType<PropsWithChildren<FORM_PROPS & PluginFormActionProps<any, EC>>>;
141
+ props?: FORM_PROPS;
142
+ }
143
+
144
+ Actions?: React.ComponentType<PluginFormActionProps<any, EC>>;
145
+
146
+ fieldBuilder?: <T extends CMSType = CMSType>(props: PluginFieldBuilderParams<T, any, EC>) => React.ComponentType<FieldProps<T>> | null;
147
+
148
+ fieldBuilderEnabled?: <T extends CMSType = CMSType>(props: PluginFieldBuilderParams<T>) => boolean;
149
+ }
150
+
154
151
  }
155
152
 
156
153
  /**
@@ -695,7 +695,7 @@ export interface ArrayPropertyValidationSchema extends PropertyValidationSchema
695
695
  * Additional configuration related to Storage related fields
696
696
  * @group Entity properties
697
697
  */
698
- export interface StorageConfig {
698
+ export type StorageConfig = {
699
699
 
700
700
  /**
701
701
  * File MIME types that can be uploaded to this reference. Don't specify for
@@ -11,7 +11,7 @@ export type PropertyConfig<T extends CMSType = any> = {
11
11
  /**
12
12
  * Key used to identify this property config.
13
13
  */
14
- key: string,
14
+ key: PropertyConfigId | string;
15
15
 
16
16
  /**
17
17
  * Name of this field type.
@@ -48,7 +48,7 @@ export type PropertyConfig<T extends CMSType = any> = {
48
48
 
49
49
  }
50
50
 
51
- export type FieldConfigId =
51
+ export type PropertyConfigId =
52
52
  "text_field" |
53
53
  "multiline" |
54
54
  "markdown" |
@@ -1,6 +1,7 @@
1
1
  import { EntityCollection } from "./collections";
2
2
  import { ResolvedEntityCollection } from "./resolved_entities";
3
3
  import { Entity } from "./entities";
4
+ import { EntityOverrides } from "./entity_overrides";
4
5
 
5
6
  /**
6
7
  * Props used to open a side dialog
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  DefaultSelectedViewBuilder,
3
3
  DefaultSelectedViewParams,
4
+ EntityCollection,
5
+ PermissionsBuilder,
4
6
  PropertiesOrBuilders,
5
7
  PropertyOrBuilder
6
8
  } from "../types";
@@ -48,3 +50,23 @@ export function resolveDefaultSelectedView(
48
50
  return defaultSelectedView(params);
49
51
  }
50
52
  }
53
+
54
+ /**
55
+ * If a collection is not applying permissions, we apply the given permissionsBuilder.
56
+ * This is used to apply the role permissions to the collections, unless they are already
57
+ * applying permissions.
58
+ * @param collections
59
+ * @param permissionsBuilder
60
+ */
61
+ export const applyPermissionsFunctionIfEmpty = (collections: EntityCollection[], permissionsBuilder?: PermissionsBuilder): EntityCollection[] => {
62
+
63
+ return collections.map(collection => {
64
+ if (collection.permissions) {
65
+ return collection;
66
+ }
67
+ return ({
68
+ ...collection,
69
+ permissions: permissionsBuilder
70
+ });
71
+ });
72
+ }
@@ -1,5 +1,4 @@
1
1
  import React from "react";
2
- import { CMSView, EntityCollection } from "../types";
3
2
  import { hashString } from "./hash";
4
3
  import { coolIconKeys, Icon, iconKeys } from "@firecms/ui";
5
4
  import { slugify } from "./strings";
@@ -14,8 +13,17 @@ export function getIcon(iconKey?: string, className?: string): React.ReactElemen
14
13
  return iconKey in iconKeysMap ? <Icon iconKey={iconKey} size={"medium"} className={className}/> : undefined;
15
14
  }
16
15
 
16
+ export type IconViewProps = {
17
+ path: string;
18
+ name: string;
19
+ singularName?: string;
20
+ group?: string;
21
+ icon?: string;
22
+ }
23
+
17
24
  export const IconForView = React.memo(
18
- function IconForView({ collectionOrView, className }: { collectionOrView: EntityCollection | CMSView, className?: string }): React.ReactElement {
25
+ function IconForView({ collectionOrView, className }: { collectionOrView?: IconViewProps, className?: string }): React.ReactElement {
26
+ if (!collectionOrView) return <></>;
19
27
  const icon = getIcon(collectionOrView.icon, className);
20
28
  if (collectionOrView?.icon && icon)
21
29
  return icon;
@@ -39,7 +47,7 @@ export const IconForView = React.memo(
39
47
 
40
48
  return <Icon iconKey={key} size={"medium"} className={className}/>;
41
49
  }, (prevProps, nextProps) => {
42
- return equal(prevProps.collectionOrView.icon, nextProps.collectionOrView.icon);
50
+ return equal(prevProps.collectionOrView?.icon, nextProps.collectionOrView?.icon);
43
51
  });
44
52
 
45
53
  const iconKeysMap: Record<string, string> = iconKeys.reduce((acc: Record<string, string>, key) => {
package/src/util/index.ts CHANGED
@@ -20,3 +20,4 @@ export * from "./flatten_object";
20
20
  export * from "./make_properties_editable";
21
21
  export * from "./join_collections";
22
22
  export * from "./builders";
23
+ export * from "./useTraceUpdate";
@@ -1,4 +1,5 @@
1
1
  import { AuthController, Entity, EntityCollection, Permissions, User } from "../types";
2
+ import { fullPathToCollectionSegments } from "./paths";
2
3
 
3
4
  const DEFAULT_PERMISSIONS = {
4
5
  read: true,
@@ -10,8 +11,8 @@ const DEFAULT_PERMISSIONS = {
10
11
  export function resolvePermissions<M extends Record<string, any>, UserType extends User>
11
12
  (collection: EntityCollection<M>,
12
13
  authController: AuthController<UserType>,
13
- pathSegments: string[],
14
- entity: Entity<M> | null): Permissions {
14
+ path: string,
15
+ entity: Entity<M> | null): Permissions | undefined {
15
16
 
16
17
  const permission = collection.permissions;
17
18
  if (permission === undefined) {
@@ -19,8 +20,10 @@ export function resolvePermissions<M extends Record<string, any>, UserType exten
19
20
  } else if (typeof permission === "object") {
20
21
  return permission as Permissions;
21
22
  } else if (typeof permission === "function") {
23
+ const pathSegments = fullPathToCollectionSegments(path);
22
24
  return permission({
23
25
  entity,
26
+ path,
24
27
  user: authController.user,
25
28
  authController,
26
29
  collection,
@@ -35,27 +38,27 @@ export function canEditEntity<M extends Record<string, any>, UserType extends Us
35
38
  (
36
39
  collection: EntityCollection<M>,
37
40
  authController: AuthController<UserType>,
38
- paths: string[],
41
+ path: string,
39
42
  entity: Entity<M> | null): boolean {
40
- return resolvePermissions(collection, authController, paths, entity).edit ?? DEFAULT_PERMISSIONS.edit;
43
+ return resolvePermissions(collection, authController, path, entity)?.edit ?? DEFAULT_PERMISSIONS.edit;
41
44
  }
42
45
 
43
46
  export function canCreateEntity<M extends Record<string, any>, UserType extends User>
44
47
  (
45
48
  collection: EntityCollection<M>,
46
49
  authController: AuthController<UserType>,
47
- paths: string[],
50
+ path: string,
48
51
  entity: Entity<M> | null): boolean {
49
- return resolvePermissions(collection, authController, paths, entity).create ?? DEFAULT_PERMISSIONS.create;
52
+ return resolvePermissions(collection, authController, path, entity)?.create ?? DEFAULT_PERMISSIONS.create;
50
53
  }
51
54
 
52
55
  export function canDeleteEntity<M extends Record<string, any>, UserType extends User>
53
56
  (
54
57
  collection: EntityCollection<M>,
55
58
  authController: AuthController<UserType>,
56
- paths: string[],
59
+ path: string,
57
60
  entity: Entity<M> | null): boolean {
58
- return resolvePermissions(collection, authController, paths, entity).delete ?? DEFAULT_PERMISSIONS.delete;
61
+ return resolvePermissions(collection, authController, path, entity)?.delete ?? DEFAULT_PERMISSIONS.delete;
59
62
  }
60
63
 
61
64
  // export function resolveCollectionsPermissions(roles: Role[]): Record<string, Permissions> {
@@ -1,11 +1,12 @@
1
- import { EntityCollection, PropertyConfig } from "../types";
1
+ import { EntityCollection, PropertyConfig, ResolvedEntityCollection } from "../types";
2
2
  import { isReferenceProperty } from "./property_utils";
3
3
  import { isPropertyBuilder } from "./entities";
4
+ import { getFieldConfig } from "../core";
4
5
 
5
- export function getReferencePreviewKeys(targetCollection: EntityCollection<any>,
6
- fields: Record<string, PropertyConfig>,
7
- previewProperties?: string[],
8
- limit = 3) {
6
+ export function getEntityPreviewKeys(targetCollection: EntityCollection<any>,
7
+ fields: Record<string, PropertyConfig>,
8
+ previewProperties?: string[],
9
+ limit = 3) {
9
10
  const allProperties = Object.keys(targetCollection.properties);
10
11
  let listProperties = previewProperties?.filter(p => allProperties.includes(p as string));
11
12
  if (listProperties && listProperties.length > 0) {
@@ -18,3 +19,33 @@ export function getReferencePreviewKeys(targetCollection: EntityCollection<any>,
18
19
  }).slice(0, limit);
19
20
  }
20
21
  }
22
+
23
+ export function getEntityTitlePropertyKey<M extends Record<string, any>>(collection: EntityCollection<M>, propertyConfigs: Record<string, PropertyConfig<any>>): string | undefined {
24
+ if (collection.titleProperty) {
25
+ return collection.titleProperty as string;
26
+ }
27
+ // find first text field property
28
+ for (const key in collection.properties) {
29
+ const property = collection.properties[key];
30
+ if (!isPropertyBuilder(property)) {
31
+ const field = getFieldConfig(property, propertyConfigs);
32
+ if (field?.key === "text_field") {
33
+ return key;
34
+ }
35
+ }
36
+ }
37
+ return undefined;
38
+ }
39
+
40
+ export function getEntityImagePreviewPropertyKey<M extends object>(collection: ResolvedEntityCollection<M>): string | undefined {
41
+
42
+ // find first text field property
43
+ for (const key in collection.properties) {
44
+ const property = collection.properties[key];
45
+ if (property.dataType === "string" && property.storage?.acceptedFiles?.includes("image/*")) {
46
+ return key;
47
+ }
48
+
49
+ }
50
+ return undefined;
51
+ }
@@ -1,146 +0,0 @@
1
- import { useNavigate } from "react-router-dom";
2
-
3
- import { useCustomizationController, useFireCMSContext } from "../../hooks";
4
- import { PluginHomePageActionsProps, TopNavigationEntry } from "../../types";
5
- import { IconForView } from "../../util";
6
- import { useUserConfigurationPersistence } from "../../hooks/useUserConfigurationPersistence";
7
- import { ArrowForwardIcon, Card, cn, IconButton, Markdown, StarBorderIcon, StarIcon, Typography } from "@firecms/ui";
8
-
9
- /**
10
- * This is the component used in the home page to render a card for each
11
- * collection.
12
- * @group Components
13
- * @param view
14
- * @param path
15
- * @param collection
16
- * @param url
17
- * @param name
18
- * @param description
19
- * @param onClick
20
- * @constructor
21
- */
22
- export function NavigationCollectionCard({
23
- view,
24
- path,
25
- collection,
26
- url,
27
- name,
28
- description,
29
- onClick
30
- }: TopNavigationEntry & {
31
- onClick?: () => void
32
- }) {
33
-
34
- const userConfigurationPersistence = useUserConfigurationPersistence();
35
- const collectionIcon = <IconForView collectionOrView={collection ?? view}/>;
36
-
37
- const navigate = useNavigate();
38
- const context = useFireCMSContext();
39
- const customizationController = useCustomizationController();
40
-
41
- const favourite = (userConfigurationPersistence?.favouritePaths ?? []).includes(path);
42
-
43
- let actions: React.ReactNode | undefined;
44
- if (customizationController.plugins && collection) {
45
- const actionProps: PluginHomePageActionsProps = {
46
- path,
47
- collection,
48
- context
49
- };
50
- actions = <>
51
- {customizationController.plugins.map((plugin, i) => (
52
- plugin.homePage?.CollectionActions
53
- ? <plugin.homePage.CollectionActions
54
- key={`actions_${i}`}
55
- {...actionProps}
56
- extraProps={plugin.homePage.extraProps}
57
- />
58
- : null
59
- ))}
60
- </>
61
- ;
62
- }
63
-
64
- return (
65
- <Card
66
- className={cn("h-full p-4 cursor-pointer min-h-[230px]")}
67
- onClick={() => {
68
- onClick?.();
69
- navigate(url);
70
- if (userConfigurationPersistence) {
71
- userConfigurationPersistence.setRecentlyVisitedPaths(
72
- [path, ...(userConfigurationPersistence.recentlyVisitedPaths ?? []).filter(p => p !== path)]
73
- );
74
- }
75
- }}>
76
-
77
- <div className="flex flex-col items-start h-full">
78
- <div
79
- className="flex-grow w-full">
80
-
81
- <div
82
- className="h-10 flex items-center w-full justify-between text-gray-300 dark:text-gray-600">
83
-
84
- {collectionIcon}
85
-
86
- <div
87
- className="flex items-center gap-1"
88
- onClick={(event: React.MouseEvent) => {
89
- event.preventDefault();
90
- event.stopPropagation();
91
- }}>
92
-
93
- {actions}
94
-
95
- {userConfigurationPersistence &&
96
- <IconButton
97
- onClick={(e) => {
98
- e.preventDefault();
99
- e.stopPropagation();
100
- if (favourite) {
101
- userConfigurationPersistence.setFavouritePaths(
102
- userConfigurationPersistence.favouritePaths.filter(p => p !== path)
103
- );
104
- } else {
105
- userConfigurationPersistence.setFavouritePaths(
106
- [...userConfigurationPersistence.favouritePaths, path]
107
- );
108
- }
109
- }}>
110
- {
111
- favourite
112
- ? <StarIcon
113
- size={18}
114
- className={"text-secondary"}/>
115
- : <StarBorderIcon
116
- size={18}
117
- className={"text-gray-400 dark:text-gray-500"}/>}
118
- </IconButton>}
119
-
120
- </div>
121
-
122
- </div>
123
-
124
- <Typography gutterBottom variant="h5"
125
- component="h2">
126
- {name}
127
- </Typography>
128
-
129
- {description && <Typography variant="body2"
130
- color="secondary"
131
- component="div">
132
- <Markdown source={description}/>
133
- </Typography>}
134
- </div>
135
-
136
- <div style={{ alignSelf: "flex-end" }}>
137
-
138
- <div className={"p-4"}>
139
- <ArrowForwardIcon className="text-primary"/>
140
- </div>
141
- </div>
142
-
143
- </div>
144
-
145
- </Card>);
146
- }