@firecms/core 3.0.0-canary.45 → 3.0.0-canary.47
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/dist/components/EntityCollectionTable/EntityCollectionTable.d.ts +1 -1
- package/dist/components/EntityCollectionTable/EntityCollectionTableProps.d.ts +1 -1
- package/dist/components/EntityCollectionTable/column_utils.d.ts +1 -2
- package/dist/components/common/useDataSourceEntityCollectionTableController.d.ts +3 -0
- package/dist/index.es.js +12390 -12384
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +5 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collections.d.ts +7 -0
- package/dist/types/entity_actions.d.ts +14 -0
- package/dist/util/icon_synonyms.d.ts +1 -4
- package/dist/util/resolutions.d.ts +3 -6
- package/package.json +139 -122
- package/src/components/EntityCollectionTable/EntityCollectionTable.tsx +2 -4
- package/src/components/EntityCollectionTable/EntityCollectionTableProps.tsx +4 -2
- package/src/components/EntityCollectionTable/column_utils.tsx +3 -3
- package/src/components/EntityCollectionView/EntityCollectionView.tsx +5 -5
- package/src/components/FireCMSAppBar.tsx +3 -4
- package/src/components/HomePage/SmallNavigationCard.tsx +3 -3
- package/src/components/SearchIconsView.tsx +4 -4
- package/src/components/common/useDataSourceEntityCollectionTableController.tsx +11 -0
- package/src/core/EntityEditView.tsx +2 -3
- package/src/form/EntityForm.tsx +25 -9
- package/src/form/PropertyFieldBinding.tsx +0 -2
- package/src/internal/useBuildSideEntityController.tsx +70 -10
- package/src/preview/PropertyPreview.tsx +0 -1
- package/src/preview/property_previews/ArrayOfMapsPreview.tsx +0 -1
- package/src/preview/property_previews/ArrayOfReferencesPreview.tsx +0 -1
- package/src/preview/property_previews/ArrayOfStorageComponentsPreview.tsx +0 -1
- package/src/preview/property_previews/ArrayOfStringsPreview.tsx +0 -1
- package/src/preview/property_previews/ArrayOneOfPreview.tsx +0 -1
- package/src/preview/property_previews/ArrayPropertyPreview.tsx +0 -1
- package/src/types/collections.ts +9 -0
- package/src/types/entity_actions.tsx +16 -3
- package/src/util/icon_list.ts +2 -2
- package/src/util/icon_synonyms.ts +1 -4
- package/src/util/objects.ts +0 -14
- package/src/util/resolutions.ts +4 -21
- package/dist/core/SideEntityView.d.ts +0 -7
- package/src/core/SideEntityView.tsx +0 -38
package/src/form/EntityForm.tsx
CHANGED
|
@@ -135,12 +135,13 @@ export type EntityFormSaveParams<M extends Record<string, any>> = {
|
|
|
135
135
|
* @constructor
|
|
136
136
|
* @group Components
|
|
137
137
|
*/
|
|
138
|
-
export const EntityForm =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
export const EntityForm = EntityFormInternal;
|
|
139
|
+
// export const EntityForm = React.memo<EntityFormProps<any>>(EntityFormInternal,
|
|
140
|
+
// (a: EntityFormProps<any>, b: EntityFormProps<any>) => {
|
|
141
|
+
// return a.status === b.status &&
|
|
142
|
+
// a.path === b.path &&
|
|
143
|
+
// equal(a.entity?.values, b.entity?.values);
|
|
144
|
+
// }) as typeof EntityFormInternal;
|
|
144
145
|
|
|
145
146
|
function getDataSourceEntityValues<M extends object>(initialResolvedCollection: ResolvedEntityCollection,
|
|
146
147
|
status: "new" | "existing" | "copy",
|
|
@@ -175,6 +176,8 @@ function EntityFormInternal<M extends Record<string, any>>({
|
|
|
175
176
|
onIdUpdateError,
|
|
176
177
|
}: EntityFormProps<M>) {
|
|
177
178
|
|
|
179
|
+
console.log("inputCollection", inputCollection)
|
|
180
|
+
|
|
178
181
|
const analyticsController = useAnalyticsController();
|
|
179
182
|
|
|
180
183
|
const customizationController = useCustomizationController();
|
|
@@ -345,6 +348,9 @@ function EntityFormInternal<M extends Record<string, any>>({
|
|
|
345
348
|
fields: customizationController.propertyConfigs
|
|
346
349
|
});
|
|
347
350
|
|
|
351
|
+
console.log("internalValues", internalValues);
|
|
352
|
+
console.log("resolvedCollection", resolvedCollection);
|
|
353
|
+
|
|
348
354
|
const titlePropertyKey = getEntityTitlePropertyKey(resolvedCollection, customizationController.propertyConfigs);
|
|
349
355
|
const title = internalValues && titlePropertyKey ? getValueInPath(internalValues, titlePropertyKey) : undefined;
|
|
350
356
|
|
|
@@ -415,7 +421,8 @@ function EntityFormInternal<M extends Record<string, any>>({
|
|
|
415
421
|
const pluginActions: React.ReactNode[] = [];
|
|
416
422
|
|
|
417
423
|
const formContext: FormContext<M> = {
|
|
418
|
-
|
|
424
|
+
// @ts-ignore
|
|
425
|
+
setFieldValue: useCallback(formex.setFieldValue, []),
|
|
419
426
|
values: formex.values,
|
|
420
427
|
collection: resolvedCollection,
|
|
421
428
|
entityId,
|
|
@@ -423,12 +430,14 @@ function EntityFormInternal<M extends Record<string, any>>({
|
|
|
423
430
|
save
|
|
424
431
|
};
|
|
425
432
|
|
|
433
|
+
const submittedFormContext = useRef<FormContext<M> | null>(null);
|
|
426
434
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
427
435
|
useEffect(() => {
|
|
428
|
-
if (onFormContextChange) {
|
|
436
|
+
if (onFormContextChange && !formContextsEqual(submittedFormContext.current ?? undefined, formContext)) {
|
|
429
437
|
onFormContextChange(formContext);
|
|
438
|
+
submittedFormContext.current = formContext;
|
|
430
439
|
}
|
|
431
|
-
}, [
|
|
440
|
+
}, [formContext, onFormContextChange]);
|
|
432
441
|
|
|
433
442
|
if (plugins && inputCollection) {
|
|
434
443
|
const actionProps: PluginFormActionProps = {
|
|
@@ -726,3 +735,10 @@ export function yupToFormErrors(yupError: ValidationError): Record<string, any>
|
|
|
726
735
|
}
|
|
727
736
|
return errors;
|
|
728
737
|
}
|
|
738
|
+
|
|
739
|
+
function formContextsEqual(a: FormContext<any> | undefined, b: FormContext<any> | undefined): boolean {
|
|
740
|
+
return a?.path === b?.path &&
|
|
741
|
+
a?.entityId === b?.entityId &&
|
|
742
|
+
equal(a?.values, b?.values) &&
|
|
743
|
+
equal(a?.collection, b?.collection);
|
|
744
|
+
}
|
|
@@ -92,7 +92,6 @@ function PropertyFieldBindingInternal<T extends CMSType = CMSType, M extends Rec
|
|
|
92
92
|
let Component: ComponentType<FieldProps<T>> | undefined;
|
|
93
93
|
const resolvedProperty: ResolvedProperty<T> | null = resolveProperty({
|
|
94
94
|
propertyKey,
|
|
95
|
-
propertyValue: fieldProps.field.value,
|
|
96
95
|
propertyOrBuilder: property,
|
|
97
96
|
values: fieldProps.form.values,
|
|
98
97
|
path: context.path,
|
|
@@ -116,7 +115,6 @@ function PropertyFieldBindingInternal<T extends CMSType = CMSType, M extends Rec
|
|
|
116
115
|
}
|
|
117
116
|
const configProperty = resolveProperty({
|
|
118
117
|
propertyOrBuilder: propertyConfig.property,
|
|
119
|
-
propertyValue: fieldProps.field.value,
|
|
120
118
|
values: fieldProps.form.values,
|
|
121
119
|
path: context.path,
|
|
122
120
|
entityId: context.entityId,
|
|
@@ -3,13 +3,14 @@ import {
|
|
|
3
3
|
EntityCollection,
|
|
4
4
|
EntitySidePanelProps,
|
|
5
5
|
NavigationController,
|
|
6
|
+
ResolvedProperty,
|
|
6
7
|
SideDialogPanelProps,
|
|
7
8
|
SideDialogsController,
|
|
8
9
|
SideEntityController
|
|
9
10
|
} from "../types";
|
|
10
11
|
import { getNavigationEntriesFromPathInternal, NavigationViewInternal } from "../util/navigation_from_path";
|
|
11
12
|
import { useLocation } from "react-router-dom";
|
|
12
|
-
import { removeInitialAndTrailingSlashes, resolveDefaultSelectedView } from "../util";
|
|
13
|
+
import { removeInitialAndTrailingSlashes, resolveCollection, resolveDefaultSelectedView } from "../util";
|
|
13
14
|
import { ADDITIONAL_TAB_WIDTH, CONTAINER_FULL_WIDTH, FORM_CONTAINER_WIDTH } from "./common";
|
|
14
15
|
import { useLargeLayout } from "../hooks";
|
|
15
16
|
import { EntitySidePanel } from "../core/EntitySidePanel";
|
|
@@ -19,8 +20,66 @@ const NEW_URL_HASH = "new";
|
|
|
19
20
|
export function getEntityViewWidth(props: EntitySidePanelProps<any>, small: boolean): string {
|
|
20
21
|
if (small) return CONTAINER_FULL_WIDTH;
|
|
21
22
|
const mainViewSelected = !props.selectedSubPath;
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
let resolvedWidth: string | undefined;
|
|
24
|
+
if (props.width) {
|
|
25
|
+
resolvedWidth = typeof props.width === "number" ? `${props.width}px` : props.width;
|
|
26
|
+
} else if (props.collection?.sideDialogWidth) {
|
|
27
|
+
resolvedWidth = typeof props.collection.sideDialogWidth === "number" ? `${props.collection.sideDialogWidth}px` : props.collection.sideDialogWidth;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!mainViewSelected) {
|
|
31
|
+
return `calc(${ADDITIONAL_TAB_WIDTH} + ${resolvedWidth ?? FORM_CONTAINER_WIDTH})`
|
|
32
|
+
} else {
|
|
33
|
+
if (resolvedWidth) {
|
|
34
|
+
return resolvedWidth
|
|
35
|
+
} else if (!props.collection) {
|
|
36
|
+
return FORM_CONTAINER_WIDTH;
|
|
37
|
+
} else {
|
|
38
|
+
return calculateCollectionDesiredWidth(props.collection);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const collectionViewWidthCache: { [key: string]: string } = {};
|
|
44
|
+
|
|
45
|
+
function calculateCollectionDesiredWidth(collection: EntityCollection<any>): string {
|
|
46
|
+
if (collectionViewWidthCache[collection.id]) {
|
|
47
|
+
return collectionViewWidthCache[collection.id];
|
|
48
|
+
}
|
|
49
|
+
const resolvedCollection = resolveCollection({
|
|
50
|
+
collection,
|
|
51
|
+
path: "__ignored"
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
let result = FORM_CONTAINER_WIDTH
|
|
55
|
+
if (resolvedCollection?.properties) {
|
|
56
|
+
const values = Object.values(resolvedCollection.properties).map((p: ResolvedProperty) => getNestedPropertiesDepth(p));
|
|
57
|
+
const maxDepth = Math.max(...values);
|
|
58
|
+
if (maxDepth < 3) {
|
|
59
|
+
result = FORM_CONTAINER_WIDTH;
|
|
60
|
+
} else {
|
|
61
|
+
result = 768 + 32 * (maxDepth - 2) + "px";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
collectionViewWidthCache[collection.id] = result;
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getNestedPropertiesDepth(property: ResolvedProperty, accumulator: number = 0): number {
|
|
69
|
+
if (property.dataType === "map" && property.properties) {
|
|
70
|
+
const values = Object.values(property.properties).flatMap((property) => getNestedPropertiesDepth(property, accumulator + 1));
|
|
71
|
+
return Math.max(...values);
|
|
72
|
+
} else if (property.dataType === "array" && property.oneOf) {
|
|
73
|
+
return accumulator + 3;
|
|
74
|
+
} else if (property.dataType === "array" && property.of) {
|
|
75
|
+
if (Array.isArray(property.of)) {
|
|
76
|
+
return Math.max(...property.of.map((p) => getNestedPropertiesDepth(p, accumulator + 1)));
|
|
77
|
+
} else {
|
|
78
|
+
return getNestedPropertiesDepth(property.of, accumulator + 1);
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
return accumulator + 1;
|
|
82
|
+
}
|
|
24
83
|
}
|
|
25
84
|
|
|
26
85
|
export const useBuildSideEntityController = (navigation: NavigationController,
|
|
@@ -40,12 +99,12 @@ export const useBuildSideEntityController = (navigation: NavigationController,
|
|
|
40
99
|
const entityOrCollectionPath = navigation.urlPathToDataPath(location.pathname);
|
|
41
100
|
const panelsFromUrl = buildSidePanelsFromUrl(entityOrCollectionPath, navigation.collections ?? [], newFlag);
|
|
42
101
|
for (let i = 0; i < panelsFromUrl.length; i++) {
|
|
43
|
-
const
|
|
102
|
+
const props = panelsFromUrl[i];
|
|
44
103
|
setTimeout(() => {
|
|
45
104
|
if (i === 0)
|
|
46
|
-
sideDialogsController.replace(propsToSidePanel(
|
|
105
|
+
sideDialogsController.replace(propsToSidePanel(props, navigation.buildUrlCollectionPath, navigation.resolveAliasesFrom, smallLayout));
|
|
47
106
|
else
|
|
48
|
-
sideDialogsController.open(propsToSidePanel(
|
|
107
|
+
sideDialogsController.open(propsToSidePanel(props, navigation.buildUrlCollectionPath, navigation.resolveAliasesFrom, smallLayout))
|
|
49
108
|
}, 1);
|
|
50
109
|
}
|
|
51
110
|
} else {
|
|
@@ -119,7 +178,8 @@ export function buildSidePanelsFromUrl(path: string, collections: EntityCollecti
|
|
|
119
178
|
sidePanels.push({
|
|
120
179
|
path: navigationEntry.path,
|
|
121
180
|
entityId: navigationEntry.entityId,
|
|
122
|
-
copy: false
|
|
181
|
+
copy: false,
|
|
182
|
+
width: navigationEntry.parentCollection?.sideDialogWidth
|
|
123
183
|
}
|
|
124
184
|
);
|
|
125
185
|
} else if (navigationEntry.type === "custom_view") {
|
|
@@ -163,16 +223,16 @@ const propsToSidePanel = (props: EntitySidePanelProps<any>,
|
|
|
163
223
|
|
|
164
224
|
const resolvedPanelProps: EntitySidePanelProps<any> = {
|
|
165
225
|
...props,
|
|
166
|
-
path: resolvedPath
|
|
226
|
+
path: resolvedPath,
|
|
167
227
|
};
|
|
168
228
|
|
|
169
|
-
return
|
|
229
|
+
return {
|
|
170
230
|
key: `${props.path}/${props.entityId}`,
|
|
171
231
|
component: <EntitySidePanel {...resolvedPanelProps}/>,
|
|
172
232
|
urlPath: newPath,
|
|
173
233
|
parentUrlPath: buildUrlCollectionPath(collectionPath),
|
|
174
234
|
width: getEntityViewWidth(props, smallLayout),
|
|
175
235
|
onClose: props.onClose
|
|
176
|
-
}
|
|
236
|
+
};
|
|
177
237
|
}
|
|
178
238
|
;
|
package/src/types/collections.ts
CHANGED
|
@@ -294,7 +294,16 @@ export interface EntityCollection<M extends Record<string, any> = any, UserType
|
|
|
294
294
|
* are writing custom code
|
|
295
295
|
*/
|
|
296
296
|
ownerId?: string;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Overrides for the entity view, like the data source or the storage source.
|
|
300
|
+
*/
|
|
297
301
|
overrides?: EntityOverrides;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Width of the side dialog (in pixels) when opening an entity in this collection.
|
|
305
|
+
*/
|
|
306
|
+
sideDialogWidth?: number | string;
|
|
298
307
|
}
|
|
299
308
|
|
|
300
309
|
/**
|
|
@@ -4,11 +4,26 @@ import { Entity } from "./entities";
|
|
|
4
4
|
import { EntityCollection, SelectionController } from "./collections";
|
|
5
5
|
import { User } from "./user";
|
|
6
6
|
import { SideEntityController } from "./side_entity_controller";
|
|
7
|
-
import { EntityOverrides } from "./entity_overrides";
|
|
8
7
|
|
|
8
|
+
/**
|
|
9
|
+
* An entity action is a custom action that can be performed on an entity.
|
|
10
|
+
* They are displayed in the entity view and in the collection view.
|
|
11
|
+
*/
|
|
9
12
|
export type EntityAction<M extends object = any, UserType extends User = User> = {
|
|
13
|
+
/**
|
|
14
|
+
* Title of the action
|
|
15
|
+
*/
|
|
10
16
|
name: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Icon of the action
|
|
20
|
+
*/
|
|
11
21
|
icon?: React.ReactElement;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Callback when the action is clicked
|
|
25
|
+
* @param props
|
|
26
|
+
*/
|
|
12
27
|
onClick: (props: EntityActionClickProps<M, UserType>) => Promise<void> | void;
|
|
13
28
|
|
|
14
29
|
/**
|
|
@@ -25,8 +40,6 @@ export type EntityAction<M extends object = any, UserType extends User = User> =
|
|
|
25
40
|
|
|
26
41
|
}
|
|
27
42
|
|
|
28
|
-
|
|
29
|
-
|
|
30
43
|
export type EntityActionClickProps<M extends object, UserType extends User = User> = {
|
|
31
44
|
entity: Entity<M>;
|
|
32
45
|
context: FireCMSContext<UserType>;
|
package/src/util/icon_list.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { iconSynonyms } from "./icon_synonyms";
|
|
2
2
|
import { iconKeys } from "@firecms/ui";
|
|
3
3
|
|
|
4
4
|
// @ts-ignore
|
|
@@ -12,6 +12,6 @@ iconsSearch.addDocuments(iconKeys
|
|
|
12
12
|
return {
|
|
13
13
|
key: importName,
|
|
14
14
|
// @ts-ignore
|
|
15
|
-
synonyms:
|
|
15
|
+
synonyms: iconSynonyms[importName] ?? [],
|
|
16
16
|
}
|
|
17
17
|
}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const iconSynonyms = {
|
|
2
2
|
abc: "alphabet character font letter symbol text type",
|
|
3
3
|
access_alarm: "clock time",
|
|
4
4
|
access_alarms: "clock time",
|
|
@@ -84,7 +84,6 @@ export const icon_synonyms = {
|
|
|
84
84
|
apartment: "accommodation architecture building city company estate flat home house office places real residence residential shelter units workplace",
|
|
85
85
|
api: "developer development enterprise software",
|
|
86
86
|
app_blocking: "Android applications cancel cell device hardware iOS mobile phone stopped tablet",
|
|
87
|
-
apple: "brand logo",
|
|
88
87
|
app_registration: "apps edit pencil register",
|
|
89
88
|
approval: "apply approvals approve certificate certification disapproval drive file impression ink mark postage stamp",
|
|
90
89
|
apps: "all applications circles collection components dots grid homescreen icons interface squares ui ux",
|
|
@@ -527,7 +526,6 @@ export const icon_synonyms = {
|
|
|
527
526
|
egg_alt: "breakfast brunch food",
|
|
528
527
|
eighteen_mp: "camera digits font image letters megapixels numbers quality resolution symbol text type",
|
|
529
528
|
eight_k: "8000 8K alphabet character digit display font letter number pixels resolution symbol text type video",
|
|
530
|
-
eight_k_plus: "+ 7000 8K alphabet character digit display font letter number pixels resolution symbol text type video",
|
|
531
529
|
eight_mp: "camera digit font image letters megapixels number quality resolution symbol text type",
|
|
532
530
|
eightteen_mp: "camera digits font image letters megapixels numbers quality resolution symbol text type",
|
|
533
531
|
eject: "arrow disc drive dvd player remove triangle up usb",
|
|
@@ -722,7 +720,6 @@ export const icon_synonyms = {
|
|
|
722
720
|
four_g_mobiledata: "alphabet cellular character digit font letter network number phone signal speed symbol text type wifi",
|
|
723
721
|
four_g_plus_mobiledata: "alphabet cellular character digit font letter network number phone signal speed symbol text type wifi",
|
|
724
722
|
four_k: "4000 4K alphabet character digit display font letter number pixels resolution symbol text type video",
|
|
725
|
-
four_k_plus: "+ 4000 4K alphabet character digit display font letter number pixels resolution symbol text type video",
|
|
726
723
|
four_mp: "camera digit font image letters megapixels number quality resolution symbol text type",
|
|
727
724
|
fourteen_mp: "camera digits font image letters megapixels numbers quality resolution symbol text type",
|
|
728
725
|
free_breakfast: "beverage cafe coffee cup drink mug tea",
|
package/src/util/objects.ts
CHANGED
|
@@ -30,20 +30,6 @@ export function mergeDeep<T extends object>(target: T, source: any): T {
|
|
|
30
30
|
return output;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
// export function getValueInPath(o: object | undefined, path: string): any {
|
|
34
|
-
// if (!o) return undefined;
|
|
35
|
-
// if (typeof o === "object") {
|
|
36
|
-
// if (path in o) {
|
|
37
|
-
// return (o as any)[path];
|
|
38
|
-
// }
|
|
39
|
-
// if (path.includes(".")) {
|
|
40
|
-
// const pathSegments = path.split(".");
|
|
41
|
-
// return getValueInPath((o as any)[pathSegments[0]], pathSegments.slice(1).join("."))
|
|
42
|
-
// }
|
|
43
|
-
// }
|
|
44
|
-
// return undefined;
|
|
45
|
-
// }
|
|
46
|
-
|
|
47
33
|
export function getValueInPath(o: object | undefined, path: string): any {
|
|
48
34
|
if (!o) return undefined;
|
|
49
35
|
if (typeof o === "object") {
|
package/src/util/resolutions.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { getDefaultValuesFor, isPropertyBuilder } from "./entities";
|
|
|
26
26
|
import { DEFAULT_ONE_OF_TYPE } from "./common";
|
|
27
27
|
import { getIn } from "@firecms/formex";
|
|
28
28
|
import { enumToObjectEntries } from "./enums";
|
|
29
|
-
import { isDefaultFieldConfigId } from "../core";
|
|
29
|
+
import { isDefaultFieldConfigId } from "../core/field_configs";
|
|
30
30
|
|
|
31
31
|
// import util from "util";
|
|
32
32
|
|
|
@@ -58,14 +58,12 @@ export const resolveCollection = <M extends Record<string, any>, >
|
|
|
58
58
|
|
|
59
59
|
const resolvedProperties = Object.entries(collection.properties)
|
|
60
60
|
.map(([key, propertyOrBuilder]) => {
|
|
61
|
-
const propertyValue = usedValues ? getIn(usedValues, key) : undefined;
|
|
62
61
|
const childResolvedProperty = resolveProperty({
|
|
63
62
|
propertyKey: key,
|
|
64
63
|
propertyOrBuilder: propertyOrBuilder as PropertyOrBuilder | ResolvedProperty,
|
|
65
64
|
values: usedValues,
|
|
66
65
|
previousValues: usedPreviousValues,
|
|
67
66
|
path,
|
|
68
|
-
propertyValue,
|
|
69
67
|
entityId,
|
|
70
68
|
fields
|
|
71
69
|
});
|
|
@@ -99,13 +97,11 @@ export const resolveCollection = <M extends Record<string, any>, >
|
|
|
99
97
|
*/
|
|
100
98
|
export function resolveProperty<T extends CMSType = CMSType, M extends Record<string, any> = any>({
|
|
101
99
|
propertyOrBuilder,
|
|
102
|
-
propertyValue,
|
|
103
100
|
fromBuilder = false,
|
|
104
101
|
...props
|
|
105
102
|
}: {
|
|
106
103
|
propertyKey?: string,
|
|
107
104
|
propertyOrBuilder: PropertyOrBuilder<T, M> | ResolvedProperty<T>,
|
|
108
|
-
propertyValue?: unknown,
|
|
109
105
|
values?: Partial<M>,
|
|
110
106
|
previousValues?: Partial<M>,
|
|
111
107
|
path?: string,
|
|
@@ -128,10 +124,11 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
|
|
|
128
124
|
if (!path)
|
|
129
125
|
throw Error("Trying to resolve a property builder without specifying the entity path");
|
|
130
126
|
|
|
127
|
+
const usedPropertyValue = props.propertyKey ? getIn(props.values, props.propertyKey) : undefined;
|
|
131
128
|
const result: Property<T> | null = propertyOrBuilder({
|
|
132
129
|
...props,
|
|
133
130
|
path,
|
|
134
|
-
propertyValue,
|
|
131
|
+
propertyValue: usedPropertyValue,
|
|
135
132
|
values: props.values ?? {},
|
|
136
133
|
previousValues: props.previousValues ?? props.values ?? {}
|
|
137
134
|
});
|
|
@@ -142,7 +139,6 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
|
|
|
142
139
|
|
|
143
140
|
resolvedProperty = resolveProperty({
|
|
144
141
|
...props,
|
|
145
|
-
propertyValue,
|
|
146
142
|
propertyOrBuilder: result,
|
|
147
143
|
fromBuilder: true
|
|
148
144
|
});
|
|
@@ -152,7 +148,6 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
|
|
|
152
148
|
const properties = resolveProperties({
|
|
153
149
|
...props,
|
|
154
150
|
properties: property.properties,
|
|
155
|
-
propertyValue
|
|
156
151
|
});
|
|
157
152
|
resolvedProperty = {
|
|
158
153
|
...property,
|
|
@@ -163,7 +158,6 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
|
|
|
163
158
|
} else if (property.dataType === "array") {
|
|
164
159
|
resolvedProperty = resolveArrayProperty({
|
|
165
160
|
property,
|
|
166
|
-
propertyValue,
|
|
167
161
|
fromBuilder,
|
|
168
162
|
...props
|
|
169
163
|
}) as ResolvedProperty<any>;
|
|
@@ -198,7 +192,6 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
|
|
|
198
192
|
}
|
|
199
193
|
const customFieldProperty = resolveProperty<any>({
|
|
200
194
|
propertyOrBuilder: configPropertyOrBuilder,
|
|
201
|
-
propertyValue,
|
|
202
195
|
...props
|
|
203
196
|
});
|
|
204
197
|
if (customFieldProperty) {
|
|
@@ -219,12 +212,10 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
|
|
|
219
212
|
export function resolveArrayProperty<T extends any[], M>({
|
|
220
213
|
propertyKey,
|
|
221
214
|
property,
|
|
222
|
-
propertyValue,
|
|
223
215
|
...props
|
|
224
216
|
}: {
|
|
225
217
|
propertyKey?: string,
|
|
226
218
|
property: ArrayProperty<T> | ResolvedArrayProperty<T>,
|
|
227
|
-
propertyValue: any,
|
|
228
219
|
values?: Partial<M>,
|
|
229
220
|
previousValues?: Partial<M>,
|
|
230
221
|
path?: string,
|
|
@@ -233,6 +224,7 @@ export function resolveArrayProperty<T extends any[], M>({
|
|
|
233
224
|
fromBuilder?: boolean;
|
|
234
225
|
fields?: Record<string, PropertyConfig>;
|
|
235
226
|
}): ResolvedArrayProperty {
|
|
227
|
+
const propertyValue = propertyKey ? getIn(props.values, propertyKey) : undefined;
|
|
236
228
|
|
|
237
229
|
if (property.of) {
|
|
238
230
|
if (Array.isArray(property.of)) {
|
|
@@ -244,7 +236,6 @@ export function resolveArrayProperty<T extends any[], M>({
|
|
|
244
236
|
return resolveProperty({
|
|
245
237
|
propertyKey: `${propertyKey}.${index}`,
|
|
246
238
|
propertyOrBuilder: p as Property<any>,
|
|
247
|
-
propertyValue: Array.isArray(propertyValue) ? propertyValue[index] : undefined,
|
|
248
239
|
...props,
|
|
249
240
|
index
|
|
250
241
|
});
|
|
@@ -256,7 +247,6 @@ export function resolveArrayProperty<T extends any[], M>({
|
|
|
256
247
|
? propertyValue.map((v: any, index: number) => resolveProperty({
|
|
257
248
|
propertyKey: `${propertyKey}.${index}`,
|
|
258
249
|
propertyOrBuilder: of,
|
|
259
|
-
propertyValue: v,
|
|
260
250
|
...props,
|
|
261
251
|
index
|
|
262
252
|
})).filter(e => Boolean(e)) as ResolvedProperty[]
|
|
@@ -264,7 +254,6 @@ export function resolveArrayProperty<T extends any[], M>({
|
|
|
264
254
|
const ofProperty = resolveProperty({
|
|
265
255
|
propertyKey: `${propertyKey}`,
|
|
266
256
|
propertyOrBuilder: of,
|
|
267
|
-
propertyValue: undefined,
|
|
268
257
|
...props
|
|
269
258
|
});
|
|
270
259
|
if (!ofProperty)
|
|
@@ -287,14 +276,12 @@ export function resolveArrayProperty<T extends any[], M>({
|
|
|
287
276
|
return resolveProperty({
|
|
288
277
|
propertyKey: `${propertyKey}.${index}`,
|
|
289
278
|
propertyOrBuilder: childProperty,
|
|
290
|
-
propertyValue,
|
|
291
279
|
...props
|
|
292
280
|
});
|
|
293
281
|
}).filter(e => Boolean(e)) as ResolvedProperty[]
|
|
294
282
|
: [];
|
|
295
283
|
const properties = resolveProperties<any>({
|
|
296
284
|
properties: property.oneOf.properties,
|
|
297
|
-
propertyValue: undefined,
|
|
298
285
|
...props
|
|
299
286
|
});
|
|
300
287
|
return {
|
|
@@ -326,11 +313,9 @@ export function resolveArrayProperty<T extends any[], M>({
|
|
|
326
313
|
*/
|
|
327
314
|
export function resolveProperties<M extends Record<string, any>>({
|
|
328
315
|
properties,
|
|
329
|
-
propertyValue,
|
|
330
316
|
...props
|
|
331
317
|
}: {
|
|
332
318
|
properties: PropertiesOrBuilders<M>,
|
|
333
|
-
propertyValue: unknown,
|
|
334
319
|
values?: Partial<M>,
|
|
335
320
|
previousValues?: Partial<M>,
|
|
336
321
|
path?: string,
|
|
@@ -341,11 +326,9 @@ export function resolveProperties<M extends Record<string, any>>({
|
|
|
341
326
|
}): ResolvedProperties<M> {
|
|
342
327
|
return Object.entries<PropertyOrBuilder>(properties as Record<string, PropertyOrBuilder>)
|
|
343
328
|
.map(([key, property]) => {
|
|
344
|
-
const thisPropertyValue = propertyValue && typeof propertyValue === "object" ? getValueInPath(propertyValue, key) : undefined;
|
|
345
329
|
const childResolvedProperty = resolveProperty({
|
|
346
330
|
propertyKey: key,
|
|
347
331
|
propertyOrBuilder: property,
|
|
348
|
-
propertyValue: thisPropertyValue,
|
|
349
332
|
...props
|
|
350
333
|
});
|
|
351
334
|
if (!childResolvedProperty) return {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { User } from "../types";
|
|
2
|
-
import { EntityEditViewProps } from "./EntityEditView";
|
|
3
|
-
export type SideEntityViewProps<M extends Record<string, any>> = EntityEditViewProps<M> & {
|
|
4
|
-
formWidth?: number | string;
|
|
5
|
-
onClose?: () => void;
|
|
6
|
-
};
|
|
7
|
-
export declare function SideEntityView<M extends Record<string, any>, UserType extends User>({ path, entityId, selectedSubPath, copy, collection, parentCollectionIds, onValuesAreModified, formWidth, onUpdate, onClose }: SideEntityViewProps<M>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { User } from "../types";
|
|
2
|
-
import { useSideDialogContext } from "./SideDialogs";
|
|
3
|
-
import { useSideEntityController } from "../hooks";
|
|
4
|
-
import { FORM_CONTAINER_WIDTH } from "../internal/common";
|
|
5
|
-
import { EntityEditViewProps } from "./EntityEditView";
|
|
6
|
-
|
|
7
|
-
export type SideEntityViewProps<M extends Record<string, any>> = EntityEditViewProps<M> & {
|
|
8
|
-
formWidth?: number | string;
|
|
9
|
-
onClose?: () => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function SideEntityView<M extends Record<string, any>, UserType extends User>({
|
|
13
|
-
path,
|
|
14
|
-
entityId,
|
|
15
|
-
selectedSubPath,
|
|
16
|
-
copy,
|
|
17
|
-
collection,
|
|
18
|
-
parentCollectionIds,
|
|
19
|
-
onValuesAreModified,
|
|
20
|
-
formWidth,
|
|
21
|
-
onUpdate,
|
|
22
|
-
onClose
|
|
23
|
-
}: SideEntityViewProps<M>) {
|
|
24
|
-
|
|
25
|
-
const sideDialogContext = useSideDialogContext();
|
|
26
|
-
const sideEntityController = useSideEntityController();
|
|
27
|
-
const resolvedFormWidth: string = typeof formWidth === "number" ? `${formWidth}px` : formWidth ?? FORM_CONTAINER_WIDTH;
|
|
28
|
-
|
|
29
|
-
const onCloseHandler = () => {
|
|
30
|
-
if (onClose) {
|
|
31
|
-
onClose();
|
|
32
|
-
} else {
|
|
33
|
-
sideDialogContext.close();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return <></>;
|
|
38
|
-
}
|