@firecms/core 3.0.0-beta.10 → 3.0.0-beta.11

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 (166) hide show
  1. package/dist/components/ArrayContainer.d.ts +17 -5
  2. package/dist/components/EntityCollectionTable/EntityCollectionTable.d.ts +1 -1
  3. package/dist/components/EntityCollectionTable/EntityCollectionTableProps.d.ts +2 -2
  4. package/dist/components/EntityCollectionTable/internal/popup_field/PopupFormField.d.ts +6 -3
  5. package/dist/components/common/useDataSourceEntityCollectionTableController.d.ts +1 -1
  6. package/dist/core/EntityEditView.d.ts +1 -1
  7. package/dist/core/FireCMS.d.ts +1 -1
  8. package/dist/form/PropertyFieldBinding.d.ts +1 -1
  9. package/dist/form/components/index.d.ts +0 -1
  10. package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
  11. package/dist/form/field_bindings/ReferenceFieldBinding.d.ts +2 -2
  12. package/dist/form/field_bindings/SwitchFieldBinding.d.ts +1 -2
  13. package/dist/hooks/data/delete.d.ts +4 -4
  14. package/dist/hooks/data/save.d.ts +3 -3
  15. package/dist/hooks/data/useCollectionFetch.d.ts +1 -1
  16. package/dist/hooks/data/useEntityFetch.d.ts +3 -3
  17. package/dist/hooks/useAuthController.d.ts +1 -1
  18. package/dist/hooks/useBuildNavigationController.d.ts +3 -3
  19. package/dist/hooks/useFireCMSContext.d.ts +1 -1
  20. package/dist/hooks/useResolvedNavigationFrom.d.ts +3 -3
  21. package/dist/hooks/useValidateAuthenticator.d.ts +3 -3
  22. package/dist/index.es.js +17515 -14786
  23. package/dist/index.es.js.map +1 -1
  24. package/dist/index.umd.js +17912 -15184
  25. package/dist/index.umd.js.map +1 -1
  26. package/dist/preview/PropertyPreviewProps.d.ts +1 -1
  27. package/dist/preview/components/EnumValuesChip.d.ts +1 -1
  28. package/dist/preview/util.d.ts +3 -3
  29. package/dist/types/auth.d.ts +7 -9
  30. package/dist/types/collections.d.ts +14 -13
  31. package/dist/types/datasource.d.ts +0 -4
  32. package/dist/types/entity_actions.d.ts +4 -4
  33. package/dist/types/entity_callbacks.d.ts +16 -16
  34. package/dist/types/export_import.d.ts +4 -4
  35. package/dist/types/fields.d.ts +18 -2
  36. package/dist/types/firecms.d.ts +2 -2
  37. package/dist/types/firecms_context.d.ts +1 -1
  38. package/dist/types/permissions.d.ts +4 -4
  39. package/dist/types/plugins.d.ts +8 -8
  40. package/dist/types/property_config.d.ts +0 -2
  41. package/dist/types/user.d.ts +1 -0
  42. package/dist/util/builders.d.ts +2 -2
  43. package/dist/util/entities.d.ts +1 -1
  44. package/dist/util/icon_synonyms.d.ts +0 -1
  45. package/dist/util/icons.d.ts +3 -1
  46. package/dist/util/objects.d.ts +1 -0
  47. package/dist/util/permissions.d.ts +4 -4
  48. package/dist/util/property_utils.d.ts +2 -2
  49. package/dist/util/resolutions.d.ts +6 -6
  50. package/package.json +131 -125
  51. package/src/app/Scaffold.tsx +4 -4
  52. package/src/components/ArrayContainer.tsx +79 -17
  53. package/src/components/CircularProgressCenter.tsx +1 -1
  54. package/src/components/ConfirmationDialog.tsx +2 -2
  55. package/src/components/DeleteEntityDialog.tsx +9 -18
  56. package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +4 -1
  57. package/src/components/EntityCollectionTable/EntityCollectionTable.tsx +14 -14
  58. package/src/components/EntityCollectionTable/EntityCollectionTableProps.tsx +2 -2
  59. package/src/components/EntityCollectionTable/PropertyTableCell.tsx +6 -4
  60. package/src/components/EntityCollectionTable/fields/TableReferenceField.tsx +8 -9
  61. package/src/components/EntityCollectionTable/fields/TableStorageUpload.tsx +5 -11
  62. package/src/components/EntityCollectionTable/internal/CollectionTableToolbar.tsx +2 -2
  63. package/src/components/EntityCollectionTable/internal/EntityTableCell.tsx +5 -5
  64. package/src/components/EntityCollectionTable/internal/EntityTableCellActions.tsx +2 -2
  65. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +79 -69
  66. package/src/components/EntityCollectionView/EntityCollectionView.tsx +9 -10
  67. package/src/components/EntityCollectionView/useSelectionController.tsx +5 -4
  68. package/src/components/EntityPreview.tsx +39 -30
  69. package/src/components/EntityView.tsx +5 -5
  70. package/src/components/ErrorView.tsx +3 -3
  71. package/src/components/HomePage/DefaultHomePage.tsx +1 -0
  72. package/src/components/HomePage/FavouritesView.tsx +6 -11
  73. package/src/components/HomePage/NavigationCard.tsx +1 -1
  74. package/src/components/HomePage/NavigationCardBinding.tsx +4 -9
  75. package/src/components/HomePage/NavigationGroup.tsx +1 -1
  76. package/src/components/PropertyConfigBadge.tsx +1 -1
  77. package/src/components/PropertyIdCopyTooltip.tsx +1 -1
  78. package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +2 -2
  79. package/src/components/SelectableTable/SelectableTable.tsx +2 -2
  80. package/src/components/SelectableTable/filters/DateTimeFilterField.tsx +4 -2
  81. package/src/components/SelectableTable/filters/ReferenceFilterField.tsx +3 -1
  82. package/src/components/SelectableTable/filters/StringNumberFilterField.tsx +7 -5
  83. package/src/components/VirtualTable/VirtualTableHeader.tsx +8 -8
  84. package/src/components/VirtualTable/VirtualTableHeaderRow.tsx +1 -1
  85. package/src/components/VirtualTable/VirtualTableRow.tsx +1 -1
  86. package/src/components/VirtualTable/fields/VirtualTableDateField.tsx +1 -1
  87. package/src/components/VirtualTable/fields/VirtualTableSelect.tsx +2 -0
  88. package/src/components/common/useDataSourceEntityCollectionTableController.tsx +2 -2
  89. package/src/contexts/SnackbarProvider.tsx +2 -0
  90. package/src/core/DefaultAppBar.tsx +12 -11
  91. package/src/core/DefaultDrawer.tsx +11 -9
  92. package/src/core/DrawerNavigationItem.tsx +4 -4
  93. package/src/core/EntityEditView.tsx +50 -52
  94. package/src/core/FireCMS.tsx +5 -5
  95. package/src/core/SideDialogs.tsx +1 -1
  96. package/src/core/field_configs.tsx +4 -4
  97. package/src/form/PropertyFieldBinding.tsx +27 -20
  98. package/src/form/components/CustomIdField.tsx +2 -0
  99. package/src/form/components/StorageItemPreview.tsx +3 -3
  100. package/src/form/components/index.tsx +0 -1
  101. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +3 -2
  102. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +16 -10
  103. package/src/form/field_bindings/BlockFieldBinding.tsx +41 -23
  104. package/src/form/field_bindings/DateTimeFieldBinding.tsx +1 -1
  105. package/src/form/field_bindings/KeyValueFieldBinding.tsx +10 -7
  106. package/src/form/field_bindings/MapFieldBinding.tsx +58 -39
  107. package/src/form/field_bindings/ReferenceFieldBinding.tsx +4 -4
  108. package/src/form/field_bindings/RepeatFieldBinding.tsx +25 -20
  109. package/src/form/field_bindings/SelectFieldBinding.tsx +5 -4
  110. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +1 -1
  111. package/src/form/field_bindings/SwitchFieldBinding.tsx +25 -25
  112. package/src/form/field_bindings/TextFieldBinding.tsx +3 -3
  113. package/src/hooks/data/delete.ts +4 -4
  114. package/src/hooks/data/save.ts +7 -8
  115. package/src/hooks/data/useCollectionFetch.tsx +2 -2
  116. package/src/hooks/data/useEntityFetch.tsx +5 -5
  117. package/src/hooks/useAuthController.tsx +1 -1
  118. package/src/hooks/useBuildNavigationController.tsx +5 -6
  119. package/src/hooks/useFireCMSContext.tsx +5 -5
  120. package/src/hooks/useResolvedNavigationFrom.tsx +5 -5
  121. package/src/hooks/useValidateAuthenticator.tsx +3 -3
  122. package/src/internal/useBuildDataSource.ts +1 -1
  123. package/src/internal/useUnsavedChangesDialog.tsx +2 -2
  124. package/src/preview/PropertyPreview.tsx +3 -3
  125. package/src/preview/PropertyPreviewProps.tsx +1 -1
  126. package/src/preview/components/BooleanPreview.tsx +1 -1
  127. package/src/preview/components/EmptyValue.tsx +1 -1
  128. package/src/preview/components/EnumValuesChip.tsx +1 -1
  129. package/src/preview/components/ImagePreview.tsx +5 -6
  130. package/src/preview/components/UrlComponentPreview.tsx +4 -4
  131. package/src/preview/property_previews/ArrayOfMapsPreview.tsx +1 -1
  132. package/src/preview/property_previews/ArrayOfReferencesPreview.tsx +2 -2
  133. package/src/preview/property_previews/ArrayOfStorageComponentsPreview.tsx +2 -2
  134. package/src/preview/property_previews/ArrayOfStringsPreview.tsx +1 -1
  135. package/src/preview/property_previews/ArrayOneOfPreview.tsx +2 -2
  136. package/src/preview/property_previews/ArrayPropertyPreview.tsx +2 -2
  137. package/src/preview/property_previews/MapPropertyPreview.tsx +4 -4
  138. package/src/preview/property_previews/SkeletonPropertyComponent.tsx +12 -12
  139. package/src/preview/property_previews/StringPropertyPreview.tsx +2 -2
  140. package/src/preview/util.ts +10 -10
  141. package/src/types/auth.tsx +8 -12
  142. package/src/types/collections.ts +14 -13
  143. package/src/types/datasource.ts +0 -5
  144. package/src/types/entity_actions.tsx +4 -4
  145. package/src/types/entity_callbacks.ts +18 -18
  146. package/src/types/export_import.ts +4 -4
  147. package/src/types/fields.tsx +20 -2
  148. package/src/types/firecms.tsx +2 -2
  149. package/src/types/firecms_context.tsx +1 -1
  150. package/src/types/permissions.ts +5 -5
  151. package/src/types/plugins.tsx +8 -8
  152. package/src/types/property_config.tsx +0 -2
  153. package/src/types/user.ts +2 -0
  154. package/src/util/builders.ts +6 -6
  155. package/src/util/entities.ts +3 -1
  156. package/src/util/icon_list.ts +1 -0
  157. package/src/util/icon_synonyms.ts +0 -1
  158. package/src/util/icons.tsx +12 -8
  159. package/src/util/objects.ts +20 -0
  160. package/src/util/permissions.ts +8 -8
  161. package/src/util/property_utils.tsx +10 -3
  162. package/src/util/references.ts +8 -2
  163. package/src/util/resolutions.ts +8 -8
  164. package/src/util/useStorageUploadController.tsx +1 -1
  165. package/dist/form/components/FormikArrayContainer.d.ts +0 -19
  166. package/src/form/components/FormikArrayContainer.tsx +0 -47
@@ -41,7 +41,7 @@ import { getRowHeight } from "../common/table_height";
41
41
  * @see VirtualTable
42
42
  * @group Components
43
43
  */
44
- export const EntityCollectionTable = function EntityCollectionTable<M extends Record<string, any>, UserType extends User>
44
+ export const EntityCollectionTable = function EntityCollectionTable<M extends Record<string, any>, USER extends User>
45
45
  ({
46
46
  className,
47
47
  style,
@@ -84,12 +84,10 @@ export const EntityCollectionTable = function EntityCollectionTable<M extends Re
84
84
  const largeLayout = useLargeLayout();
85
85
  const selectedEntities = (selectionController?.selectedEntities?.length > 0 ? selectionController?.selectedEntities : highlightedEntities)?.filter(Boolean);
86
86
 
87
- const context: FireCMSContext<UserType> = useFireCMSContext();
87
+ const context: FireCMSContext<USER> = useFireCMSContext();
88
88
 
89
89
  const [size, setSize] = React.useState<CollectionSize>(defaultSize ?? "m");
90
90
 
91
- const selectedEntityIds = selectedEntities?.map(e => e.id);
92
-
93
91
  const updateSize = useCallback((size: CollectionSize) => {
94
92
  if (onSizeChanged)
95
93
  onSizeChanged(size);
@@ -98,12 +96,12 @@ export const EntityCollectionTable = function EntityCollectionTable<M extends Re
98
96
 
99
97
  const onTextSearch = useCallback((newSearchString?: string) => tableController.setSearchString?.(newSearchString), []);
100
98
 
101
- const additionalFieldsMap: Record<string, AdditionalFieldDelegate<M, UserType>> = useMemo(() => {
99
+ const additionalFieldsMap: Record<string, AdditionalFieldDelegate<M, USER>> = useMemo(() => {
102
100
  return (additionalFields
103
101
  ? additionalFields
104
102
  .map((aC) => ({ [aC.key]: aC as AdditionalFieldDelegate<M, any> }))
105
103
  .reduce((a, b) => ({ ...a, ...b }), {})
106
- : {}) as Record<string, AdditionalFieldDelegate<M, UserType>>;
104
+ : {}) as Record<string, AdditionalFieldDelegate<M, USER>>;
107
105
  }, [additionalFields]);
108
106
 
109
107
  const customFieldValidator: CustomFieldValidator | undefined = uniqueFieldValidator;
@@ -176,12 +174,14 @@ export const EntityCollectionTable = function EntityCollectionTable<M extends Re
176
174
  throw new Error("When using additional fields you need to provide a Builder or a value");
177
175
  }
178
176
 
179
- const child = Builder
177
+ const child: React.ReactNode = Builder
180
178
  ? <Builder entity={entity} context={context}/>
181
- : <>{additionalField.value?.({
182
- entity,
183
- context
184
- })}</>;
179
+ : <>
180
+ {additionalField.value?.({
181
+ entity,
182
+ context
183
+ })?.toString()}
184
+ </>;
185
185
 
186
186
  return (
187
187
  <EntityTableCell
@@ -202,7 +202,7 @@ export const EntityCollectionTable = function EntityCollectionTable<M extends Re
202
202
  </EntityTableCell>
203
203
  );
204
204
 
205
- }, [size, selectedEntityIds]);
205
+ }, [size]);
206
206
 
207
207
  const collectionColumns: VirtualTableColumn[] = (() => {
208
208
  const columnsResult: VirtualTableColumn[] = propertiesToColumns({
@@ -292,7 +292,7 @@ export const EntityCollectionTable = function EntityCollectionTable<M extends Re
292
292
 
293
293
  <div ref={ref}
294
294
  style={style}
295
- className={cls("h-full w-full flex flex-col bg-white dark:bg-gray-950", className)}>
295
+ className={cls("h-full w-full flex flex-col bg-white dark:bg-surface-950", className)}>
296
296
 
297
297
  <CollectionTableToolbar
298
298
  onTextSearch={textSearchEnabled ? onTextSearch : undefined}
@@ -310,7 +310,7 @@ export const EntityCollectionTable = function EntityCollectionTable<M extends Re
310
310
  inlineEditing={inlineEditing}
311
311
  cellRenderer={cellRenderer}
312
312
  onEntityClick={onEntityClick}
313
- highlightedRow={useCallback((entity: Entity<M>) => selectedEntityIds?.includes(entity.id) ?? false, [selectedEntityIds])}
313
+ highlightedRow={(entity: Entity<M>) => Boolean(selectedEntities?.find(e => e.id === entity.id && e.path === entity.path))}
314
314
  tableController={tableController}
315
315
  onValueChange={onValueChange}
316
316
  onColumnResize={onColumnResize}
@@ -16,7 +16,7 @@ import { OnCellValueChange, OnColumnResizeParams, UniqueFieldValidator } from ".
16
16
  * @group Collection components
17
17
  */
18
18
  export type EntityCollectionTableProps<M extends Record<string, any>,
19
- UserType extends User = User> = {
19
+ USER extends User = User> = {
20
20
 
21
21
  className?: string;
22
22
 
@@ -103,7 +103,7 @@ export type EntityCollectionTableProps<M extends Record<string, any>,
103
103
 
104
104
  inlineEditing?: boolean;
105
105
 
106
- additionalFields?: AdditionalFieldDelegate<M, UserType>[];
106
+ additionalFields?: AdditionalFieldDelegate<M, USER>[];
107
107
 
108
108
  defaultSize?: CollectionSize;
109
109
 
@@ -89,8 +89,8 @@ export const PropertyTableCell = React.memo<PropertyTableCellProps<any>>(
89
89
  } = useSelectableTableController();
90
90
 
91
91
  const selected = selectedCell?.propertyKey === propertyKey &&
92
- selectedCell?.entity.path === entity.path &&
93
- selectedCell?.entity.id === entity.id;
92
+ selectedCell?.entityPath === entity.path &&
93
+ selectedCell?.entityId === entity.id;
94
94
 
95
95
  const [internalValue, setInternalValue] = useState<any | null>(value);
96
96
  const internalValueRef = useRef(value);
@@ -193,7 +193,8 @@ export const PropertyTableCell = React.memo<PropertyTableCellProps<any>>(
193
193
  select({
194
194
  width,
195
195
  height,
196
- entity,
196
+ entityPath: entity.path,
197
+ entityId: entity.id,
197
198
  cellRect,
198
199
  propertyKey: propertyKey as Extract<keyof M, string>
199
200
  });
@@ -209,7 +210,8 @@ export const PropertyTableCell = React.memo<PropertyTableCellProps<any>>(
209
210
  setPopupCell({
210
211
  width,
211
212
  height,
212
- entity,
213
+ entityPath: entity.path,
214
+ entityId: entity.id,
213
215
  cellRect,
214
216
  propertyKey: propertyKey as Extract<keyof M, string>
215
217
  });
@@ -8,7 +8,7 @@ import { getPreviewSizeFrom } from "../../../preview/util";
8
8
  import { getReferenceFrom, IconForView } from "../../../util";
9
9
  import { useCustomizationController, useNavigationController, useReferenceDialog } from "../../../hooks";
10
10
  import { ErrorView } from "../../ErrorView";
11
- import { cls } from "@firecms/ui";
11
+ import { cls, EditIcon } from "@firecms/ui";
12
12
  import { EntityPreviewContainer } from "../../EntityPreview";
13
13
 
14
14
  type TableReferenceFieldProps = {
@@ -123,7 +123,7 @@ export const TableReferenceFieldInternal = React.memo(
123
123
  key={`preview_array_ref_${name}_${index}`}>
124
124
  <ReferencePreview
125
125
  onClick={disabled ? undefined : handleOpen}
126
- size={"smallest"}
126
+ size={"small"}
127
127
  reference={reference}
128
128
  hover={!disabled}
129
129
  disabled={!path}
@@ -151,18 +151,17 @@ export const TableReferenceFieldInternal = React.memo(
151
151
 
152
152
  {valueNotSet &&
153
153
  <EntityPreviewContainer
154
- className={cls("px-4 py-2 text-sm font-medium flex items-center uppercase",
154
+ className={cls("px-3 py-2 text-sm font-medium flex items-center",
155
155
  multiselect ? "gap-4" : "gap-6",
156
156
  disabled
157
- ? "text-slate-500"
158
- : "cursor-pointer text-slate-700 dark:text-slate-300 hover:bg-slate-50 dark:hover:bg-gray-800 group-hover:bg-slate-50 dark:group-hover:bg-gray-800")}
157
+ ? "text-surface-accent-500"
158
+ : "cursor-pointer text-text-secondary dark:text-text-secondary-dark hover:bg-surface-accent-50 dark:hover:bg-surface-800 group-hover:bg-surface-accent-50 dark:group-hover:bg-surface-800")}
159
159
  onClick={handleOpen}
160
160
  size={"medium"}>
161
- <IconForView
161
+ <EditIcon
162
162
  size={"small"}
163
- collectionOrView={collection}
164
- className={"text-gray-300 dark:text-gray-600"}/>
165
- Edit {title}
163
+ className={"ml-2 mr-1 text-surface-300 dark:text-surface-600"}/>
164
+ {title}
166
165
  </EntityPreviewContainer>}
167
166
 
168
167
  </div>
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { useMemo, useState } from "react";
2
+ import { useMemo } from "react";
3
3
 
4
4
  import { Entity, ResolvedArrayProperty, ResolvedStringProperty, StorageConfig } from "../../../types";
5
5
  import { useDropzone } from "react-dropzone";
@@ -140,9 +140,7 @@ function StorageUpload({
140
140
  storagePathBuilder,
141
141
  }: StorageUploadProps) {
142
142
 
143
- const [onHover, setOnHover] = useState(false);
144
-
145
- const previewSize = multipleFilesSupported && previewSizeInput === "medium" ? "small" : previewSizeInput;
143
+ const previewSize = previewSizeInput;
146
144
  if (multipleFilesSupported) {
147
145
  const arrayProperty = property as ResolvedArrayProperty<string[]>;
148
146
  if (Array.isArray(arrayProperty.of)) {
@@ -212,9 +210,6 @@ function StorageUpload({
212
210
 
213
211
  return (
214
212
  <div {...rootProps}
215
- onMouseEnter={() => setOnHover(true)}
216
- onMouseMove={() => setOnHover(true)}
217
- onMouseLeave={() => setOnHover(false)}
218
213
  className={cls(dropZoneClasses,
219
214
  "relative w-full h-full flex",
220
215
  `justify-${hasValue ? "start" : "center"}`,
@@ -252,14 +247,13 @@ function StorageUpload({
252
247
  }
253
248
 
254
249
  return child;
255
- })
256
- }
250
+ })}
257
251
 
258
252
  {!internalValue && <div
259
253
  className="flex-grow m-2 max-w-[200px]"
260
254
  onClick={open}>
261
255
  <Typography
262
- className="text-gray-400 dark:text-gray-600"
256
+ className="text-surface-400 dark:text-surface-600"
263
257
  variant={"body2"}
264
258
  align={"center"}>
265
259
  {helpText}
@@ -276,7 +270,7 @@ function StorageUpload({
276
270
  color={"inherit"}
277
271
  size={"small"}
278
272
  onClick={open}>
279
- <EditIcon size={"small"} className={"text-gray-500"}/>
273
+ <EditIcon size={"small"} className={"text-surface-500"}/>
280
274
  </IconButton>
281
275
  </EntityTableCellActions>
282
276
 
@@ -56,7 +56,7 @@ export function CollectionTableToolbar({
56
56
  <Select
57
57
  value={size as string}
58
58
  className="w-16 h-10"
59
- size={"small"}
59
+ size={"medium"}
60
60
  onValueChange={(v) => onSizeChanged(v as CollectionSize)}
61
61
  renderValue={(v) => <div className={"font-medium"}>{v.toUpperCase()}</div>}
62
62
  >
@@ -71,7 +71,7 @@ export function CollectionTableToolbar({
71
71
 
72
72
  return (
73
73
  <div
74
- className={cls(defaultBorderMixin, "no-scrollbar min-h-[56px] overflow-x-auto px-2 md:px-4 bg-gray-50 dark:bg-gray-900 border-b flex flex-row justify-between items-center w-full")}>
74
+ className={cls(defaultBorderMixin, "no-scrollbar min-h-[56px] overflow-x-auto px-2 md:px-4 bg-surface-50 dark:bg-surface-900 border-b flex flex-row justify-between items-center w-full")}>
75
75
 
76
76
  <div className="flex items-center gap-2 md:mr-4 mr-2">
77
77
 
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"
2
2
 
3
3
  import useMeasure from "react-use-measure";
4
4
 
5
- import { cls, RemoveCircleIcon, Tooltip } from "@firecms/ui";
5
+ import { cls, DoNotDisturbOnIcon, Tooltip } from "@firecms/ui";
6
6
  import { ErrorBoundary } from "../../../components";
7
7
  import { getRowHeight, TableSize } from "../../common/table_height";
8
8
 
@@ -188,10 +188,10 @@ export const EntityTableCell = React.memo<EntityTableCellProps>(
188
188
  className={cls(
189
189
  "transition-colors duration-100 ease-in-out",
190
190
  `flex relative h-full rounded-md p-${p} border border-4 border-opacity-75`,
191
- onHover && !disabled ? "bg-gray-50 dark:bg-gray-900" : "",
192
- saved ? "bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75" : "",
191
+ onHover && !disabled ? "bg-surface-50 dark:bg-surface-900" : "",
192
+ saved ? "bg-surface-100 bg-opacity-75 dark:bg-surface-800 dark:bg-opacity-75" : "",
193
193
  hideOverflow ? "overflow-hidden" : "",
194
- isSelected ? "bg-gray-50 dark:bg-gray-900" : "",
194
+ isSelected ? "bg-surface-50 dark:bg-surface-900" : "",
195
195
  borderClass
196
196
  )}
197
197
  ref={ref}
@@ -236,7 +236,7 @@ export const EntityTableCell = React.memo<EntityTableCellProps>(
236
236
  {disabled && onHover && disabledTooltip &&
237
237
  <div className="absolute top-1 right-1 text-xs">
238
238
  <Tooltip title={disabledTooltip}>
239
- <RemoveCircleIcon size={"smallest"} color={"disabled"} className={"text-gray-500"}/>
239
+ <DoNotDisturbOnIcon size={"smallest"} color={"disabled"} className={"text-surface-500"}/>
240
240
  </Tooltip>
241
241
  </div>}
242
242
 
@@ -1,4 +1,4 @@
1
- import { ErrorOutlineIcon, IconButton } from "@firecms/ui";
1
+ import { ErrorIcon, IconButton } from "@firecms/ui";
2
2
  import { ErrorTooltip } from "../../ErrorTooltip";
3
3
  import { useCallback, useEffect, useRef } from "react";
4
4
 
@@ -68,7 +68,7 @@ export function EntityTableCellActions({
68
68
  width: 32,
69
69
  height: 32
70
70
  }}>
71
- <ErrorOutlineIcon
71
+ <ErrorIcon
72
72
  size={"small"}
73
73
  color={"error"}
74
74
  />
@@ -1,5 +1,4 @@
1
1
  import React, { useCallback, useEffect, useLayoutEffect, useMemo, useState } from "react";
2
- import equal from "react-fast-compare"
3
2
 
4
3
  import * as Portal from "@radix-ui/react-portal";
5
4
 
@@ -19,20 +18,20 @@ import { useDraggable } from "./useDraggable";
19
18
  import { CustomFieldValidator, getYupEntitySchema } from "../../../../form/validation";
20
19
  import { useWindowSize } from "./useWindowSize";
21
20
  import { ElementResizeListener } from "./ElementResizeListener";
22
- import { ErrorView } from "../../../ErrorView";
23
21
  import { getPropertyInPath, isReadOnly, resolveCollection } from "../../../../util";
24
- import { Button, ClearIcon, DialogActions, IconButton, Typography } from "@firecms/ui";
22
+ import { Button, CloseIcon, DialogActions, IconButton, Typography } from "@firecms/ui";
25
23
  import { PropertyFieldBinding } from "../../../../form";
26
- import { useCustomizationController, useFireCMSContext } from "../../../../hooks";
24
+ import { useCustomizationController, useDataSource, useFireCMSContext } from "../../../../hooks";
27
25
  import { OnCellValueChangeParams } from "../../../common";
26
+ import { yupToFormErrors } from "../../../../core/EntityEditView";
28
27
 
29
28
  interface PopupFormFieldProps<M extends Record<string, any>> {
30
- entity: Entity<M>;
31
29
  customFieldValidator?: CustomFieldValidator;
32
30
  path: string;
31
+ entityId: string;
33
32
  tableKey: string;
34
33
  propertyKey?: Extract<keyof M, string>;
35
- collection?: EntityCollection<M>;
34
+ collection?: EntityCollection<any>;
36
35
  cellRect?: DOMRect;
37
36
  open: boolean;
38
37
  onClose: () => void;
@@ -46,13 +45,54 @@ interface PopupFormFieldProps<M extends Record<string, any>> {
46
45
 
47
46
  export function PopupFormField<M extends Record<string, any>>(props: PopupFormFieldProps<M>) {
48
47
  if (!props.open) return null;
49
- return <PopupFormFieldInternal {...props} />;
48
+ return <PopupFormFieldLoading {...props} />;
50
49
 
51
50
  }
52
51
 
52
+ export function PopupFormFieldLoading<M extends Record<string, any>>({
53
+ tableKey,
54
+ entityId,
55
+ customFieldValidator,
56
+ propertyKey,
57
+ collection: inputCollection,
58
+ path,
59
+ cellRect,
60
+ open,
61
+ onClose,
62
+ onCellValueChange,
63
+ container
64
+ }: PopupFormFieldProps<M>) {
65
+ const dataSource = useDataSource();
66
+ const [entity, setEntity] = useState<Entity<M> | undefined>(undefined);
67
+ useEffect(() => {
68
+ if (entityId && inputCollection) {
69
+ dataSource.fetchEntity({
70
+ path,
71
+ entityId,
72
+ collection: inputCollection
73
+ }).then(setEntity);
74
+ }
75
+ }, [entityId, inputCollection]);
76
+
77
+ if (!entity) return null;
78
+ return <PopupFormFieldInternal {...{
79
+ tableKey,
80
+ entityId,
81
+ customFieldValidator,
82
+ propertyKey,
83
+ collection: inputCollection,
84
+ path,
85
+ cellRect,
86
+ open,
87
+ onClose,
88
+ onCellValueChange,
89
+ container
90
+ }} entity={entity}/>;
91
+ }
92
+
53
93
  export function PopupFormFieldInternal<M extends Record<string, any>>({
54
94
  tableKey,
55
- entity: entityProp,
95
+ entityId,
56
96
  customFieldValidator,
57
97
  propertyKey,
58
98
  collection: inputCollection,
@@ -61,10 +101,12 @@ export function PopupFormFieldInternal<M extends Record<string, any>>({
61
101
  open,
62
102
  onClose,
63
103
  onCellValueChange,
64
- container
65
- }: PopupFormFieldProps<M>) {
104
+ container,
105
+ entity
106
+ }: PopupFormFieldProps<M> & {
107
+ entity?: Entity<M>
108
+ }) {
66
109
 
67
- // const dataSource = useDataSource();
68
110
  const fireCMSContext = useFireCMSContext();
69
111
  const customizationController = useCustomizationController();
70
112
 
@@ -74,34 +116,13 @@ export function PopupFormFieldInternal<M extends Record<string, any>>({
74
116
  y: number
75
117
  }>();
76
118
 
77
- const entityId = entityProp.id;
78
- const [entity, setEntity] = useState<Entity<M> | undefined>(entityProp);
79
- // useEffect(() => {
80
- // if (entityId && inputCollection) {
81
- // return dataSource.listenEntity?.({
82
- // path,
83
- // entityId,
84
- // collection: inputCollection,
85
- // onUpdate: (e) => {
86
- // setEntity(e);
87
- // setInternalValue(e?.values);
88
- // }
89
- // });
90
- // } else {
91
- // return () => {
92
- // };
93
- // }
94
- // }, [dataSource, entityId, inputCollection, path, open]);
95
-
96
- const [internalValue, setInternalValue] = useState<EntityValues<M> | undefined>(entity?.values);
97
-
98
119
  const collection: ResolvedEntityCollection<M> | undefined = inputCollection
99
120
  ? resolveCollection<M>({
100
121
  collection: inputCollection,
101
122
  path,
102
- values: internalValue,
123
+ values: entity?.values,
103
124
  entityId,
104
- fields: customizationController.propertyConfigs
125
+ propertyConfigs: customizationController.propertyConfigs
105
126
  })
106
127
  : undefined;
107
128
 
@@ -214,46 +235,39 @@ export function PopupFormFieldInternal<M extends Record<string, any>>({
214
235
  return Promise.resolve();
215
236
  };
216
237
 
217
- if (!entity)
218
- return <></>;
219
-
220
- // eslint-disable-next-line react-hooks/rules-of-hooks
221
238
  const formex = useCreateFormex<M>({
222
239
  initialValues: (entity?.values ?? {}) as EntityValues<M>,
223
240
  validation: (values) => {
224
241
  return validationSchema?.validate(values, { abortEarly: false })
225
242
  .then(() => ({}))
226
243
  .catch((e) => {
227
- const errors: Record<string, string> = {};
228
- e.inner.forEach((error: any) => {
229
- errors[error.path] = error.message;
230
- });
231
- return errors;
244
+ // const errors: Record<string, string> = {};
245
+ // e.inner.forEach((error: any) => {
246
+ // errors[error.path] = error.message;
247
+ // });
248
+ // return errors;
249
+ return yupToFormErrors(e);
232
250
  });
233
251
  },
234
252
  validateOnInitialRender: true,
235
253
  onSubmit: (values, actions) => {
236
254
  saveValue(values)
237
- .then(() => onClose())
255
+ .then(() => {
256
+ formex.resetForm({
257
+ values: values
258
+ })
259
+ onClose();
260
+ })
238
261
  .finally(() => actions.setSubmitting(false));
239
262
  }
240
263
  });
241
264
 
242
- const { values, isSubmitting, setFieldValue, handleSubmit } = formex;
243
-
244
- // eslint-disable-next-line react-hooks/rules-of-hooks
245
- useEffect(() => {
246
- if (!equal(values, internalValue)) {
247
- setInternalValue(values);
248
- }
249
- }, [values]);
250
-
251
- if (!entity)
252
- return <ErrorView
253
- error={"PopupFormField misconfiguration"}/>;
254
-
255
- if (!collection)
256
- return <></>;
265
+ const {
266
+ values,
267
+ isSubmitting,
268
+ setFieldValue,
269
+ handleSubmit
270
+ } = formex;
257
271
 
258
272
  const disabled = isSubmitting;
259
273
 
@@ -267,7 +281,7 @@ export function PopupFormFieldInternal<M extends Record<string, any>>({
267
281
  formex
268
282
  };
269
283
 
270
- const property: ResolvedProperty<any> | undefined = propertyKey && getPropertyInPath(collection.properties, propertyKey as string);
284
+ const property: ResolvedProperty<any> | undefined = propertyKey && getPropertyInPath(collection?.properties ?? {} as ResolvedProperties, propertyKey as string);
271
285
  const fieldProps: PropertyFieldBindingProps<any, M> | undefined = propertyKey && property
272
286
  ? {
273
287
  propertyKey: propertyKey as string,
@@ -285,7 +299,7 @@ export function PopupFormFieldInternal<M extends Record<string, any>>({
285
299
  let internalForm = <>
286
300
  <div
287
301
  key={`popup_form_${tableKey}_${entityId}_${propertyKey}`}
288
- className="w-[560px] max-w-full max-h-[85vh]">
302
+ className="w-[700px] max-w-full max-h-[85vh]">
289
303
  <form
290
304
  onSubmit={handleSubmit}
291
305
  noValidate>
@@ -320,10 +334,6 @@ export function PopupFormFieldInternal<M extends Record<string, any>>({
320
334
 
321
335
  const plugins = customizationController.plugins;
322
336
  if (plugins) {
323
- // const formController: FormContext<M> = {
324
- // values,
325
- // setFieldValue
326
- // }
327
337
  plugins.forEach((plugin: FireCMSPlugin) => {
328
338
  if (plugin.form?.provider) {
329
339
  internalForm = (
@@ -343,7 +353,7 @@ export function PopupFormFieldInternal<M extends Record<string, any>>({
343
353
  });
344
354
  }
345
355
  const form = <div
346
- className={`text-gray-900 dark:text-white overflow-auto rounded rounded-md bg-white dark:bg-gray-950 ${!open ? "hidden" : ""} cursor-grab max-w-[100vw]`}>
356
+ className={`text-surface-900 dark:text-white overflow-auto rounded rounded-md bg-white dark:bg-surface-950 ${!open ? "hidden" : ""} cursor-grab max-w-[100vw]`}>
347
357
 
348
358
  {internalForm}
349
359
 
@@ -360,7 +370,7 @@ export function PopupFormFieldInternal<M extends Record<string, any>>({
360
370
  style={{
361
371
  boxShadow: "0 0 0 2px rgba(128,128,128,0.2)",
362
372
  }}
363
- className={`inline-block fixed z-20 shadow-outline rounded-md bg-white dark:bg-gray-950 ${
373
+ className={`inline-block fixed z-20 shadow-outline rounded-md bg-white dark:bg-surface-950 ${
364
374
  !open ? "invisible" : "visible"
365
375
  } cursor-grab overflow-visible`}
366
376
  ref={draggableRef}>
@@ -373,7 +383,7 @@ export function PopupFormFieldInternal<M extends Record<string, any>>({
373
383
  {form}
374
384
 
375
385
  <div
376
- className="absolute -top-3.5 -right-3.5 bg-gray-500 rounded-full"
386
+ className="absolute -top-3.5 -right-3.5 bg-surface-500 rounded-full"
377
387
  style={{
378
388
  width: "32px",
379
389
  height: "32px"
@@ -384,7 +394,7 @@ export function PopupFormFieldInternal<M extends Record<string, any>>({
384
394
  event.stopPropagation();
385
395
  onClose();
386
396
  }}>
387
- <ClearIcon className="text-white"
397
+ <CloseIcon className="text-white"
388
398
  size={"small"}/>
389
399
  </IconButton>
390
400
  </div>
@@ -353,7 +353,7 @@ export const EntityCollectionView = React.memo(
353
353
  const resolvedCollection = useMemo(() => resolveCollection<M>({
354
354
  collection,
355
355
  path: fullPath,
356
- fields: customizationController.propertyConfigs
356
+ propertyConfigs: customizationController.propertyConfigs
357
357
  }), [collection, fullPath]);
358
358
 
359
359
  const getPropertyFor = useCallback(({
@@ -374,7 +374,7 @@ export const EntityCollectionView = React.memo(
374
374
  path: entity.path,
375
375
  values: entity.values,
376
376
  entityId: entity.id,
377
- fields: customizationController.propertyConfigs
377
+ propertyConfigs: customizationController.propertyConfigs
378
378
  });
379
379
  }, [collection.properties, customizationController.propertyConfigs, resolvedCollection.properties]);
380
380
 
@@ -422,7 +422,7 @@ export const EntityCollectionView = React.memo(
422
422
  <ReferencePreview
423
423
  key={reference.path + "/" + reference.id}
424
424
  reference={reference}
425
- size={"smallest"}/>
425
+ size={"small"}/>
426
426
  );
427
427
  })}
428
428
  </div>
@@ -482,7 +482,7 @@ export const EntityCollectionView = React.memo(
482
482
  frozen?: boolean
483
483
  }) => {
484
484
 
485
- const isSelected = usedSelectionController.selectedEntities.map(e => e.id).includes(entity.id);
485
+ const isSelected = Boolean(usedSelectionController.selectedEntities.find(e => e.id == entity.id && e.path == entity.path));
486
486
 
487
487
  const actions = getActionsForEntity({
488
488
  entity,
@@ -538,7 +538,7 @@ export const EntityCollectionView = React.memo(
538
538
  </div>}
539
539
  >
540
540
 
541
- {collection.description && <div className="m-4 text-gray-900 dark:text-white">
541
+ {collection.description && <div className="m-4 text-surface-900 dark:text-white">
542
542
  <Markdown source={collection.description}/>
543
543
  </div>}
544
544
 
@@ -665,13 +665,13 @@ export const EntityCollectionView = React.memo(
665
665
  />
666
666
 
667
667
  {popupCell && <PopupFormField
668
- key={`popup_form_${popupCell?.propertyKey}_${popupCell?.entity?.id}`}
668
+ key={`popup_form_${popupCell?.propertyKey}_${popupCell?.entityId}`}
669
669
  open={Boolean(popupCell)}
670
670
  onClose={onPopupClose}
671
671
  cellRect={popupCell?.cellRect}
672
672
  propertyKey={popupCell?.propertyKey}
673
673
  collection={collection}
674
- entity={popupCell.entity}
674
+ entityId={popupCell.entityId}
675
675
  tableKey={tableKey.current}
676
676
  customFieldValidator={uniqueFieldValidator}
677
677
  path={resolvedFullPath}
@@ -785,7 +785,6 @@ function EntityIdHeaderWidget({
785
785
  const [recentIds, setRecentIds] = React.useState<string[]>(getRecentIds(collection.id));
786
786
  const sideEntityController = useSideEntityController();
787
787
 
788
-
789
788
  return (
790
789
  <Tooltip title={!openPopup ? "Find by ID" : undefined} asChild={false}>
791
790
  <Popover
@@ -799,7 +798,7 @@ function EntityIdHeaderWidget({
799
798
  <SearchIcon size={"small"}/>
800
799
  </IconButton>
801
800
  }>
802
- <div className={cls("my-2 rounded-lg bg-gray-50 dark:bg-gray-950 text-gray-900 dark:text-white")}>
801
+ <div className={cls("my-2 rounded-lg bg-surface-50 dark:bg-surface-950 text-surface-900 dark:text-white")}>
803
802
  <form noValidate={true}
804
803
  onSubmit={(e) => {
805
804
  e.preventDefault();
@@ -824,7 +823,7 @@ function EntityIdHeaderWidget({
824
823
  setSearchString(e.target.value);
825
824
  }}
826
825
  value={searchString}
827
- className={"rounded-lg bg-white dark:bg-gray-800 flex-grow bg-transparent outline-none p-2 " + focusedDisabled}/>
826
+ className={"rounded-lg bg-white dark:bg-surface-800 flex-grow bg-transparent outline-none p-2 " + focusedDisabled}/>
828
827
  <Button variant={"text"}
829
828
  disabled={!(searchString.trim())}
830
829
  type={"submit"}