@firecms/core 3.0.0-canary.211 → 3.0.0-canary.212

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 (47) hide show
  1. package/dist/components/ArrayContainer.d.ts +12 -5
  2. package/dist/hooks/data/save.d.ts +1 -1
  3. package/dist/index.es.js +10039 -10176
  4. package/dist/index.es.js.map +1 -1
  5. package/dist/index.umd.js +9909 -10046
  6. package/dist/index.umd.js.map +1 -1
  7. package/dist/internal/useBuildDataSource.d.ts +3 -2
  8. package/dist/internal/useBuildSideEntityController.d.ts +3 -3
  9. package/dist/types/collections.d.ts +2 -0
  10. package/dist/types/properties.d.ts +16 -1
  11. package/dist/util/property_utils.d.ts +2 -2
  12. package/dist/util/references.d.ts +2 -2
  13. package/dist/util/resolutions.d.ts +7 -2
  14. package/package.json +5 -5
  15. package/src/components/ArrayContainer.tsx +40 -23
  16. package/src/components/DeleteEntityDialog.tsx +4 -2
  17. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +4 -2
  18. package/src/components/EntityCollectionView/EntityCollectionView.tsx +4 -2
  19. package/src/components/EntityPreview.tsx +10 -3
  20. package/src/components/EntityView.tsx +4 -1
  21. package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +3 -1
  22. package/src/core/FireCMS.tsx +12 -11
  23. package/src/form/EntityForm.tsx +11 -6
  24. package/src/form/PropertyFieldBinding.tsx +6 -3
  25. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +4 -1
  26. package/src/form/field_bindings/BlockFieldBinding.tsx +1 -1
  27. package/src/form/field_bindings/KeyValueFieldBinding.tsx +1 -1
  28. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +6 -2
  29. package/src/form/field_bindings/RepeatFieldBinding.tsx +8 -2
  30. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +4 -1
  31. package/src/hooks/data/save.ts +24 -29
  32. package/src/hooks/useFireCMSContext.tsx +0 -30
  33. package/src/internal/useBuildDataSource.ts +9 -5
  34. package/src/internal/useBuildSideEntityController.tsx +22 -16
  35. package/src/preview/PropertyPreview.tsx +4 -2
  36. package/src/preview/property_previews/ArrayOfMapsPreview.tsx +4 -3
  37. package/src/preview/property_previews/ArrayOfReferencesPreview.tsx +4 -3
  38. package/src/preview/property_previews/ArrayOfStorageComponentsPreview.tsx +4 -2
  39. package/src/preview/property_previews/ArrayOfStringsPreview.tsx +4 -3
  40. package/src/preview/property_previews/ArrayOneOfPreview.tsx +4 -2
  41. package/src/preview/property_previews/ArrayPropertyPreview.tsx +4 -2
  42. package/src/types/collections.ts +2 -0
  43. package/src/types/properties.ts +20 -1
  44. package/src/util/property_utils.tsx +7 -3
  45. package/src/util/references.ts +8 -6
  46. package/src/util/resolutions.ts +13 -7
  47. package/src/util/useStorageUploadController.tsx +4 -2
@@ -2,7 +2,7 @@ import React from "react";
2
2
 
3
3
  import { resolveArrayProperty } from "../../util";
4
4
  import { ResolvedProperty } from "../../types";
5
- import { useCustomizationController } from "../../hooks";
5
+ import { useAuthController, useCustomizationController } from "../../hooks";
6
6
  import { PreviewSize, PropertyPreviewProps } from "../PropertyPreviewProps";
7
7
  import { PropertyPreview } from "../PropertyPreview";
8
8
  import { cls, defaultBorderMixin } from "@firecms/ui";
@@ -19,11 +19,13 @@ export function ArrayPropertyPreview({
19
19
  size
20
20
  }: PropertyPreviewProps<any[]>) {
21
21
 
22
+ const authController = useAuthController();
22
23
  const customizationController = useCustomizationController();
23
24
  const property = resolveArrayProperty({
24
25
  propertyKey,
25
26
  property: inputProperty,
26
- propertyConfigs: customizationController.propertyConfigs
27
+ propertyConfigs: customizationController.propertyConfigs,
28
+ authController
27
29
  });
28
30
 
29
31
  if (!property.of) {
@@ -215,6 +215,7 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
215
215
  * Force a filter in this view. If applied, the rest of the filters will
216
216
  * be disabled. Filters applied with this prop cannot be changed.
217
217
  * e.g. `forceFilter: { age: [">=", 18] }`
218
+ * e.g. `forceFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
218
219
  */
219
220
  forceFilter?: FilterValues<Extract<keyof M, string>>;
220
221
 
@@ -222,6 +223,7 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
222
223
  * Initial filters applied to the collection this collection is related to.
223
224
  * Defaults to none. Filters applied with this prop can be changed.
224
225
  * e.g. `initialFilter: { age: [">=", 18] }`
226
+ * e.g. `initialFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
225
227
  */
226
228
  initialFilter?: FilterValues<Extract<keyof M, string>>; // setting FilterValues<M> can break defining collections by code
227
229
 
@@ -5,6 +5,7 @@ import { EntityReference, EntityValues, GeoPoint, Vector } from "./entities";
5
5
  import { ResolvedArrayProperty, ResolvedStringProperty } from "./resolved_entities";
6
6
  import { FilterValues } from "./collections";
7
7
  import { ChipColorKey, ChipColorScheme } from "@firecms/ui";
8
+ import { AuthController } from "./auth";
8
9
 
9
10
  /**
10
11
  * @group Entity properties
@@ -270,6 +271,11 @@ export type PropertyBuilderProps<M extends Record<string, any> = any> =
270
271
  * Entity ID
271
272
  */
272
273
  entityId?: string;
274
+
275
+ /**
276
+ * Controller to manage authentication
277
+ */
278
+ authController: AuthController;
273
279
  };
274
280
 
275
281
  /**
@@ -285,7 +291,8 @@ export type PropertyBuilder<T extends CMSType = any, M extends Record<string, an
285
291
  propertyValue,
286
292
  index,
287
293
  path,
288
- entityId
294
+ entityId,
295
+ authController
289
296
  }: PropertyBuilderProps<M>) => Property<T> | null;
290
297
 
291
298
  /**
@@ -481,6 +488,18 @@ export interface ArrayProperty<T extends ArrayT[] = any[], ArrayT extends CMSTyp
481
488
  */
482
489
  minimalistView?: boolean;
483
490
 
491
+ /**
492
+ * Can the elements in this array be reordered. Defaults to `true`.
493
+ * This prop has no effect if `disabled` is set to true.
494
+ */
495
+ sortable?: boolean;
496
+
497
+ /**
498
+ * Can the elements in this array be added. Defaults to `true`
499
+ * This prop has no effect if `disabled` is set to true.
500
+ */
501
+ canAddElements?: boolean;
502
+
484
503
  }
485
504
 
486
505
  /**
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
 
3
3
  import {
4
+ AuthController,
4
5
  EntityCollection,
5
6
  PropertiesOrBuilders,
6
7
  PropertyConfig,
@@ -13,12 +14,15 @@ import { resolveProperty } from "./resolutions";
13
14
  import { CircleIcon, FunctionsIcon } from "@firecms/ui";
14
15
  import { getFieldConfig } from "../core";
15
16
 
16
- export function isReferenceProperty(propertyOrBuilder: PropertyOrBuilder,
17
- fields: Record<string, PropertyConfig>) {
17
+ export function isReferenceProperty(
18
+ authController: AuthController,
19
+ propertyOrBuilder: PropertyOrBuilder,
20
+ fields: Record<string, PropertyConfig>) {
18
21
  const resolvedProperty = resolveProperty({
19
22
  propertyKey: "ignore", // TODO
20
23
  propertyOrBuilder,
21
- propertyConfigs: fields
24
+ propertyConfigs: fields,
25
+ authController
22
26
  });
23
27
  if (!resolvedProperty) return null;
24
28
  if (resolvedProperty.dataType === "reference") {
@@ -1,12 +1,14 @@
1
- import { EntityCollection, PropertyConfig, ResolvedEntityCollection } from "../types";
1
+ import { AuthController, EntityCollection, PropertyConfig, ResolvedEntityCollection } from "../types";
2
2
  import { isReferenceProperty } from "./property_utils";
3
3
  import { isPropertyBuilder } from "./entities";
4
4
  import { getFieldConfig } from "../core";
5
5
 
6
- export function getEntityPreviewKeys(targetCollection: EntityCollection<any>,
7
- fields: Record<string, PropertyConfig>,
8
- previewProperties?: string[],
9
- limit = 3) {
6
+ export function getEntityPreviewKeys(
7
+ authController: AuthController,
8
+ targetCollection: EntityCollection<any>,
9
+ fields: Record<string, PropertyConfig>,
10
+ previewProperties?: string[],
11
+ limit = 3) {
10
12
  const allProperties = Object.keys(targetCollection.properties);
11
13
  let listProperties = previewProperties?.filter(p => allProperties.includes(p as string));
12
14
  if (!listProperties && targetCollection.previewProperties) {
@@ -18,7 +20,7 @@ export function getEntityPreviewKeys(targetCollection: EntityCollection<any>,
18
20
  listProperties = allProperties;
19
21
  return listProperties.filter(key => {
20
22
  const propertyOrBuilder = targetCollection.properties[key];
21
- return propertyOrBuilder && !isPropertyBuilder(propertyOrBuilder) && !isReferenceProperty(propertyOrBuilder, fields);
23
+ return propertyOrBuilder && !isPropertyBuilder(propertyOrBuilder) && !isReferenceProperty(authController, propertyOrBuilder, fields);
22
24
  }).slice(0, limit);
23
25
  }
24
26
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  ArrayProperty,
3
+ AuthController,
3
4
  CMSType,
4
5
  CustomizationController,
5
6
  EntityCollection,
@@ -27,9 +28,7 @@ import { getDefaultValuesFor, isPropertyBuilder } from "./entities";
27
28
  import { DEFAULT_ONE_OF_TYPE } from "./common";
28
29
  import { getIn } from "@firecms/formex";
29
30
  import { enumToObjectEntries } from "./enums";
30
- import { isDefaultFieldConfigId } from "../core/field_configs";
31
-
32
- // import util from "util";
31
+ import { isDefaultFieldConfigId } from "../core";
33
32
 
34
33
  export const resolveCollection = <M extends Record<string, any>, >
35
34
  ({
@@ -40,7 +39,8 @@ export const resolveCollection = <M extends Record<string, any>, >
40
39
  previousValues,
41
40
  userConfigPersistence,
42
41
  propertyConfigs,
43
- ignoreMissingFields = false
42
+ ignoreMissingFields = false,
43
+ authController
44
44
  }: {
45
45
  collection: EntityCollection<M> | ResolvedEntityCollection<M>;
46
46
  path: string,
@@ -50,6 +50,7 @@ export const resolveCollection = <M extends Record<string, any>, >
50
50
  userConfigPersistence?: UserConfigurationPersistence;
51
51
  propertyConfigs?: Record<string, PropertyConfig>;
52
52
  ignoreMissingFields?: boolean;
53
+ authController: AuthController;
53
54
  }): ResolvedEntityCollection<M> => {
54
55
 
55
56
  const collectionOverride = userConfigPersistence?.getCollectionConfig<M>(path);
@@ -69,7 +70,8 @@ export const resolveCollection = <M extends Record<string, any>, >
69
70
  path,
70
71
  entityId,
71
72
  propertyConfigs: propertyConfigs,
72
- ignoreMissingFields
73
+ ignoreMissingFields,
74
+ authController
73
75
  });
74
76
  if (!childResolvedProperty) return {};
75
77
  return ({
@@ -114,6 +116,7 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
114
116
  fromBuilder?: boolean;
115
117
  propertyConfigs?: Record<string, PropertyConfig<any>>;
116
118
  ignoreMissingFields?: boolean;
119
+ authController: AuthController;
117
120
  }): ResolvedProperty<T> | null {
118
121
 
119
122
  if (typeof propertyOrBuilder === "object" && "resolved" in propertyOrBuilder) {
@@ -234,7 +237,8 @@ export function getArrayResolvedProperties<M>({
234
237
  entityId?: string;
235
238
  index?: number;
236
239
  fromBuilder?: boolean;
237
- propertyConfigs?: Record<string, PropertyConfig>
240
+ propertyConfigs?: Record<string, PropertyConfig>;
241
+ authController: AuthController;
238
242
  }) {
239
243
 
240
244
  const of = property.of;
@@ -266,6 +270,7 @@ export function resolveArrayProperty<T extends any[], M>({
266
270
  fromBuilder?: boolean;
267
271
  propertyConfigs?: Record<string, PropertyConfig>;
268
272
  ignoreMissingFields?: boolean;
273
+ authController: AuthController;
269
274
  }): ResolvedArrayProperty {
270
275
  const propertyValue = propertyKey ? getIn(props.values, propertyKey) : undefined;
271
276
 
@@ -281,7 +286,7 @@ export function resolveArrayProperty<T extends any[], M>({
281
286
  propertyOrBuilder: p as Property<any>,
282
287
  ignoreMissingFields,
283
288
  ...props,
284
- index
289
+ index,
285
290
  });
286
291
  })
287
292
  } as ResolvedArrayProperty;
@@ -373,6 +378,7 @@ export function resolveProperties<M extends Record<string, any>>({
373
378
  fromBuilder?: boolean;
374
379
  propertyConfigs?: Record<string, PropertyConfig>;
375
380
  ignoreMissingFields?: boolean;
381
+ authController: AuthController;
376
382
  }): ResolvedProperties<M> {
377
383
  return Object.entries<PropertyOrBuilder>(properties as Record<string, PropertyOrBuilder>)
378
384
  .map(([key, property]) => {
@@ -18,6 +18,7 @@ import { PreviewSize } from "../preview";
18
18
  import { randomString } from "./strings";
19
19
  import { resolveStorageFilenameString, resolveStoragePathString } from "./storage";
20
20
  import { resolveProperty } from "./resolutions";
21
+ import { useAuthController } from "../hooks";
21
22
 
22
23
  /**
23
24
  * Internal representation of an item in the storage
@@ -34,7 +35,6 @@ export interface StorageFieldItem {
34
35
  size: PreviewSize
35
36
  }
36
37
 
37
-
38
38
  export function useStorageUploadController<M extends object>({
39
39
  entityId,
40
40
  entityValues,
@@ -58,6 +58,7 @@ export function useStorageUploadController<M extends object>({
58
58
  onChange: (value: string | string[] | null) => void
59
59
  }) {
60
60
 
61
+ const authController = useAuthController();
61
62
  const storage: StorageConfig | undefined = property.dataType === "string"
62
63
  ? property.storage
63
64
  : property.dataType === "array" &&
@@ -90,7 +91,8 @@ export function useStorageUploadController<M extends object>({
90
91
 
91
92
  const resolvedProperty = resolveProperty({
92
93
  propertyOrBuilder: property as PropertyOrBuilder,
93
- values: entityValues
94
+ values: entityValues,
95
+ authController
94
96
  }) as ResolvedStringProperty | ResolvedArrayProperty<string[]>;
95
97
 
96
98
  const fileNameBuilder = useCallback(async (file: File) => {