@firecms/core 3.0.0-alpha.47 → 3.0.0-alpha.48
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/index.es.js +50 -32
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +10 -10
- package/dist/index.umd.js.map +1 -1
- package/dist/util/join_collections.d.ts +2 -2
- package/package.json +2 -2
- package/src/components/EntityCollectionTable/EntityCollectionTable.tsx +1 -0
- package/src/components/ReferenceSelectionInner.tsx +34 -30
- package/src/components/VirtualTable/VirtualTableRow.tsx +10 -8
- package/src/util/join_collections.ts +34 -12
|
@@ -2,8 +2,8 @@ import { EntityCollection, ModifyCollectionProps } from "../types";
|
|
|
2
2
|
/**
|
|
3
3
|
*
|
|
4
4
|
*/
|
|
5
|
-
export declare function joinCollectionLists(targetCollections: EntityCollection[], sourceCollections: EntityCollection[] | undefined, parentPaths?: string[], modifyCollection?: (props: ModifyCollectionProps) => EntityCollection |
|
|
5
|
+
export declare function joinCollectionLists(targetCollections: EntityCollection[], sourceCollections: EntityCollection[] | undefined, parentPaths?: string[], modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void): EntityCollection[];
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
export declare function mergeCollection(target: EntityCollection, source: EntityCollection, parentPaths?: string[], modifyCollection?: (props: ModifyCollectionProps) => EntityCollection |
|
|
9
|
+
export declare function mergeCollection(target: EntityCollection, source: EntityCollection, parentPaths?: string[], modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void): EntityCollection;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firecms/core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.48",
|
|
4
4
|
"description": "Awesome Firebase/Firestore-based headless open-source CMS",
|
|
5
5
|
"funding": {
|
|
6
6
|
"url": "https://github.com/sponsors/firecmsco"
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
"dist",
|
|
134
134
|
"src"
|
|
135
135
|
],
|
|
136
|
-
"gitHead": "
|
|
136
|
+
"gitHead": "04d4690b0b71a4dd56a01a77e4c639d6af79be86",
|
|
137
137
|
"publishConfig": {
|
|
138
138
|
"access": "public"
|
|
139
139
|
}
|
|
@@ -142,6 +142,7 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
|
|
|
142
142
|
const onRowClick = useCallback(({ rowData }: {
|
|
143
143
|
rowData: Entity<M>
|
|
144
144
|
}) => {
|
|
145
|
+
console.debug("EntityCollectionTable click");
|
|
145
146
|
if (inlineEditing)
|
|
146
147
|
return;
|
|
147
148
|
return onEntityClick && onEntityClick(rowData);
|
|
@@ -19,6 +19,7 @@ import { useEntityCollectionTableController } from "./EntityCollectionTable/useE
|
|
|
19
19
|
import { AddIcon } from "../icons";
|
|
20
20
|
import { useColumnIds } from "./EntityCollectionView/useColumnsIds";
|
|
21
21
|
import { useSideDialogContext } from "../core";
|
|
22
|
+
import { useTraceUpdate } from "../util/useTraceUpdate";
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @group Components
|
|
@@ -99,6 +100,8 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
|
|
|
99
100
|
maxSelection
|
|
100
101
|
}: ReferenceSelectionInnerProps<M>) {
|
|
101
102
|
|
|
103
|
+
console.log("ReferenceSelectionInner");
|
|
104
|
+
|
|
102
105
|
const sideDialogContext = useSideDialogContext();
|
|
103
106
|
const sideEntityController = useSideEntityController();
|
|
104
107
|
const navigation = useNavigationController();
|
|
@@ -142,7 +145,7 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
|
|
|
142
145
|
};
|
|
143
146
|
}, [dataSource, fullPath, selectedEntityIdsProp, collection, selectionController.setSelectedEntities]);
|
|
144
147
|
|
|
145
|
-
const onClear =
|
|
148
|
+
const onClear = () => {
|
|
146
149
|
context.onAnalyticsEvent?.("reference_selection_clear", {
|
|
147
150
|
path: fullPath
|
|
148
151
|
});
|
|
@@ -152,9 +155,10 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
|
|
|
152
155
|
} else if (onMultipleEntitiesSelected) {
|
|
153
156
|
onMultipleEntitiesSelected([]);
|
|
154
157
|
}
|
|
155
|
-
}
|
|
158
|
+
};
|
|
156
159
|
|
|
157
|
-
const toggleEntitySelection =
|
|
160
|
+
const toggleEntitySelection = (entity: Entity<any>) => {
|
|
161
|
+
console.debug("ReferenceSelectionInner toggleEntitySelection", entity);
|
|
158
162
|
let newValue;
|
|
159
163
|
const selectedEntities = selectionController.selectedEntities;
|
|
160
164
|
|
|
@@ -176,9 +180,10 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
|
|
|
176
180
|
if (onMultipleEntitiesSelected)
|
|
177
181
|
onMultipleEntitiesSelected(newValue);
|
|
178
182
|
}
|
|
179
|
-
}
|
|
183
|
+
};
|
|
180
184
|
|
|
181
|
-
const onEntityClick =
|
|
185
|
+
const onEntityClick = (entity: Entity<any>) => {
|
|
186
|
+
console.debug("ReferenceSelectionInner onEntityClick", entity);
|
|
182
187
|
|
|
183
188
|
if (!multiselect && onSingleEntitySelected) {
|
|
184
189
|
context.onAnalyticsEvent?.("reference_selected_single", {
|
|
@@ -190,32 +195,31 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
|
|
|
190
195
|
} else {
|
|
191
196
|
toggleEntitySelection(entity);
|
|
192
197
|
}
|
|
193
|
-
}
|
|
198
|
+
};
|
|
194
199
|
|
|
195
200
|
// create a new entity from within the reference dialog
|
|
196
|
-
const onNewClick =
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}: {
|
|
201
|
+
const onNewClick = () => {
|
|
202
|
+
context.onAnalyticsEvent?.("reference_selection_new_entity", {
|
|
203
|
+
path: fullPath
|
|
204
|
+
});
|
|
205
|
+
sideEntityController.open({
|
|
206
|
+
path: fullPath,
|
|
207
|
+
collection,
|
|
208
|
+
updateUrl: true,
|
|
209
|
+
onUpdate: ({ entity }) => {
|
|
210
|
+
setEntitiesDisplayedFirst([entity, ...entitiesDisplayedFirst]);
|
|
211
|
+
onEntityClick(entity);
|
|
212
|
+
},
|
|
213
|
+
closeOnSave: true
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const tableRowActionsBuilder = ({
|
|
218
|
+
entity,
|
|
219
|
+
size,
|
|
220
|
+
width,
|
|
221
|
+
frozen
|
|
222
|
+
}: {
|
|
219
223
|
entity: Entity<any>,
|
|
220
224
|
size: CollectionSize,
|
|
221
225
|
width: number,
|
|
@@ -234,7 +238,7 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
|
|
|
234
238
|
fullPath={fullPath}
|
|
235
239
|
selectionController={selectionController}/>;
|
|
236
240
|
|
|
237
|
-
}
|
|
241
|
+
};
|
|
238
242
|
|
|
239
243
|
const onDone = useCallback((event: React.SyntheticEvent) => {
|
|
240
244
|
event.stopPropagation();
|
|
@@ -15,16 +15,18 @@ export const VirtualTableRow = React.memo<VirtualTableRowProps<any>>(
|
|
|
15
15
|
size,
|
|
16
16
|
style,
|
|
17
17
|
hoverRow,
|
|
18
|
-
rowClassName
|
|
18
|
+
rowClassName
|
|
19
19
|
}: VirtualTableRowProps<T>) {
|
|
20
20
|
|
|
21
|
-
const onClick = useCallback((event: React.SyntheticEvent) =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const onClick = useCallback((event: React.SyntheticEvent) => {
|
|
22
|
+
console.debug("VirtualTableRow click");
|
|
23
|
+
if (onRowClick)
|
|
24
|
+
onRowClick({
|
|
25
|
+
rowData,
|
|
26
|
+
rowIndex,
|
|
27
|
+
event
|
|
28
|
+
})
|
|
29
|
+
}, [onRowClick, rowData, rowIndex]);
|
|
28
30
|
|
|
29
31
|
return (
|
|
30
32
|
<div
|
|
@@ -16,19 +16,27 @@ import { isPropertyBuilder } from "./entities";
|
|
|
16
16
|
export function joinCollectionLists(targetCollections: EntityCollection[],
|
|
17
17
|
sourceCollections: EntityCollection[] | undefined,
|
|
18
18
|
parentPaths: string[] = [],
|
|
19
|
-
modifyCollection?: (props: ModifyCollectionProps) => EntityCollection |
|
|
19
|
+
modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void): EntityCollection[] {
|
|
20
20
|
|
|
21
21
|
// merge collections that are in both lists
|
|
22
22
|
const updatedCollections = (sourceCollections ?? [])
|
|
23
|
-
.map((
|
|
24
|
-
const
|
|
25
|
-
return collection.id ===
|
|
23
|
+
.map((sourceCol) => {
|
|
24
|
+
const targetCol = targetCollections?.find((collection) => {
|
|
25
|
+
return collection.id === sourceCol.id;
|
|
26
26
|
// return collection.path === codedCollection.path || collection.id && codedCollection.id;
|
|
27
27
|
});
|
|
28
|
-
if (!
|
|
29
|
-
|
|
28
|
+
if (!targetCol) {
|
|
29
|
+
if (modifyCollection) {
|
|
30
|
+
const modified = modifyCollection({
|
|
31
|
+
collection: sourceCol,
|
|
32
|
+
parentPaths
|
|
33
|
+
});
|
|
34
|
+
return modified ?? sourceCol;
|
|
35
|
+
} else {
|
|
36
|
+
return sourceCol;
|
|
37
|
+
}
|
|
30
38
|
} else {
|
|
31
|
-
return mergeCollection(
|
|
39
|
+
return mergeCollection(targetCol, sourceCol, parentPaths, modifyCollection);
|
|
32
40
|
}
|
|
33
41
|
});
|
|
34
42
|
|
|
@@ -37,7 +45,10 @@ export function joinCollectionLists(targetCollections: EntityCollection[],
|
|
|
37
45
|
.filter((col) => !updatedCollections.map(c => c.id).includes(col.id))
|
|
38
46
|
.map((col) => {
|
|
39
47
|
if (modifyCollection) {
|
|
40
|
-
const modified = modifyCollection({
|
|
48
|
+
const modified = modifyCollection({
|
|
49
|
+
collection: col,
|
|
50
|
+
parentPaths
|
|
51
|
+
});
|
|
41
52
|
return modified ?? col;
|
|
42
53
|
} else {
|
|
43
54
|
return col;
|
|
@@ -53,7 +64,7 @@ export function joinCollectionLists(targetCollections: EntityCollection[],
|
|
|
53
64
|
export function mergeCollection(target: EntityCollection,
|
|
54
65
|
source: EntityCollection,
|
|
55
66
|
parentPaths: string[] = [],
|
|
56
|
-
modifyCollection?: (props: ModifyCollectionProps) => EntityCollection |
|
|
67
|
+
modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void
|
|
57
68
|
): EntityCollection {
|
|
58
69
|
|
|
59
70
|
const subcollectionsMerged = joinCollectionLists(
|
|
@@ -86,7 +97,10 @@ export function mergeCollection(target: EntityCollection,
|
|
|
86
97
|
entityViews: mergedEntityViews
|
|
87
98
|
};
|
|
88
99
|
if (modifyCollection) {
|
|
89
|
-
const modifiedCollection = modifyCollection({
|
|
100
|
+
const modifiedCollection = modifyCollection({
|
|
101
|
+
collection: resultCollection,
|
|
102
|
+
parentPaths
|
|
103
|
+
});
|
|
90
104
|
if (modifiedCollection)
|
|
91
105
|
resultCollection = modifiedCollection;
|
|
92
106
|
}
|
|
@@ -112,9 +126,17 @@ function mergePropertyOrBuilder(target: Property, source: PropertyOrBuilder): Pr
|
|
|
112
126
|
if (property)
|
|
113
127
|
mergedProperties[key] = mergePropertyOrBuilder(property, sourceProperties[key] as PropertyOrBuilder);
|
|
114
128
|
});
|
|
115
|
-
return {
|
|
129
|
+
return {
|
|
130
|
+
...mergedProperty,
|
|
131
|
+
editable: targetEditable && sourceEditable,
|
|
132
|
+
properties: mergedProperties,
|
|
133
|
+
propertiesOrder: mergedPropertiesOrder
|
|
134
|
+
} as MapProperty;
|
|
116
135
|
}
|
|
117
|
-
return {
|
|
136
|
+
return {
|
|
137
|
+
...mergedProperty,
|
|
138
|
+
editable: targetEditable && sourceEditable
|
|
139
|
+
};
|
|
118
140
|
}
|
|
119
141
|
}
|
|
120
142
|
|