@firecms/core 3.0.0-alpha.32 → 3.0.0-alpha.34
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 +1181 -1187
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +13 -13
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collections.d.ts +12 -1
- package/dist/types/firecms.d.ts +1 -1
- package/package.json +2 -2
- package/src/core/components/EntityCollectionTable/EntityCollectionTable.tsx +9 -7
- package/src/core/components/EntityCollectionView/EntityCollectionView.tsx +2 -2
- package/src/core/components/EntityCollectionView/useColumnsIds.tsx +2 -2
- package/src/core/util/property_utils.tsx +1 -1
- package/src/types/collections.ts +10 -1
- package/src/types/firecms.tsx +1 -1
|
@@ -324,7 +324,7 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any, Us
|
|
|
324
324
|
* ID of this column. You can use this id in the `properties` field of the
|
|
325
325
|
* collection in any order you want
|
|
326
326
|
*/
|
|
327
|
-
|
|
327
|
+
key: string;
|
|
328
328
|
/**
|
|
329
329
|
* Header of this column
|
|
330
330
|
*/
|
|
@@ -346,6 +346,17 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any, Us
|
|
|
346
346
|
* it will be updated in every render.
|
|
347
347
|
*/
|
|
348
348
|
dependencies?: Extract<keyof M, string>[];
|
|
349
|
+
/**
|
|
350
|
+
* Use this prop to define the value of the column as a string or number.
|
|
351
|
+
* This is the value that will be used for exporting the collection.
|
|
352
|
+
* If `Builder` is defined, this prop will be ignored in the collection
|
|
353
|
+
* view.
|
|
354
|
+
* @param entity
|
|
355
|
+
*/
|
|
356
|
+
value?: (props: {
|
|
357
|
+
entity: Entity<M>;
|
|
358
|
+
context: FireCMSContext;
|
|
359
|
+
}) => string | number | Promise<string | number> | undefined;
|
|
349
360
|
}
|
|
350
361
|
/**
|
|
351
362
|
* You can use this builder to render a custom panel in the entity detail view.
|
package/dist/types/firecms.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ import { CMSAnalyticsEvent } from "./analytics";
|
|
|
22
22
|
* APIs directly, or a REST API.
|
|
23
23
|
* @category Models
|
|
24
24
|
*/
|
|
25
|
-
export type EntityCollectionsBuilder<EC extends EntityCollection> = (params: {
|
|
25
|
+
export type EntityCollectionsBuilder<EC extends EntityCollection = EntityCollection> = (params: {
|
|
26
26
|
user: User | null;
|
|
27
27
|
authController: AuthController;
|
|
28
28
|
dataSource: DataSource;
|
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.34",
|
|
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": "97fea385cfd4a0ab9301d45d50e1d145021c1df5",
|
|
137
137
|
"publishConfig": {
|
|
138
138
|
"access": "public"
|
|
139
139
|
}
|
|
@@ -95,7 +95,6 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
|
|
|
95
95
|
setFilterValues,
|
|
96
96
|
sortBy,
|
|
97
97
|
setSortBy,
|
|
98
|
-
searchString,
|
|
99
98
|
setSearchString,
|
|
100
99
|
clearFilter,
|
|
101
100
|
itemCount,
|
|
@@ -159,7 +158,7 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
|
|
|
159
158
|
const additionalFieldsMap: Record<string, AdditionalFieldDelegate<M, UserType>> = useMemo(() => {
|
|
160
159
|
return (additionalFields
|
|
161
160
|
? additionalFields
|
|
162
|
-
.map((aC) => ({ [aC.
|
|
161
|
+
.map((aC) => ({ [aC.key]: aC as AdditionalFieldDelegate<M, any> }))
|
|
163
162
|
.reduce((a, b) => ({ ...a, ...b }), {})
|
|
164
163
|
: {}) as Record<string, AdditionalFieldDelegate<M, UserType>>;
|
|
165
164
|
}, [additionalFields]);
|
|
@@ -252,10 +251,14 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
|
|
|
252
251
|
: entity;
|
|
253
252
|
|
|
254
253
|
const Builder = additionalField.Builder;
|
|
255
|
-
if (!Builder) {
|
|
256
|
-
throw new Error("
|
|
254
|
+
if (!Builder && !additionalField.value) {
|
|
255
|
+
throw new Error("When using additional fields you need to provide a Builder or a value");
|
|
257
256
|
}
|
|
258
257
|
|
|
258
|
+
const child = Builder
|
|
259
|
+
? <Builder entity={entity} context={context}/>
|
|
260
|
+
: <>{additionalField.value?.({ entity, context })}</>;
|
|
261
|
+
|
|
259
262
|
return (
|
|
260
263
|
<EntityTableCell
|
|
261
264
|
key={`additional_table_cell_${entity.id}_${column.key}`}
|
|
@@ -270,8 +273,7 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
|
|
|
270
273
|
disabledTooltip={"This column can't be edited directly"}
|
|
271
274
|
>
|
|
272
275
|
<ErrorBoundary>
|
|
273
|
-
|
|
274
|
-
context={context}/>
|
|
276
|
+
{child}
|
|
275
277
|
</ErrorBoundary>
|
|
276
278
|
</EntityTableCell>
|
|
277
279
|
);
|
|
@@ -311,7 +313,7 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
|
|
|
311
313
|
const additionalTableColumns: VirtualTableColumn[] = additionalFields
|
|
312
314
|
? additionalFields.map((additionalField) =>
|
|
313
315
|
({
|
|
314
|
-
key: additionalField.
|
|
316
|
+
key: additionalField.key,
|
|
315
317
|
align: "left",
|
|
316
318
|
sortable: false,
|
|
317
319
|
title: additionalField.name,
|
|
@@ -353,7 +353,7 @@ export const EntityCollectionView = React.memo(
|
|
|
353
353
|
const additionalFields = useMemo(() => {
|
|
354
354
|
const subcollectionColumns: AdditionalFieldDelegate<M, any>[] = collection.subcollections?.map((subcollection) => {
|
|
355
355
|
return {
|
|
356
|
-
|
|
356
|
+
key: getSubcollectionColumnId(subcollection),
|
|
357
357
|
name: subcollection.name,
|
|
358
358
|
width: 200,
|
|
359
359
|
dependencies: [],
|
|
@@ -379,7 +379,7 @@ export const EntityCollectionView = React.memo(
|
|
|
379
379
|
|
|
380
380
|
const collectionGroupParentCollections: AdditionalFieldDelegate<M, any>[] = collection.collectionGroup
|
|
381
381
|
? [{
|
|
382
|
-
|
|
382
|
+
key: COLLECTION_GROUP_PARENT_ID,
|
|
383
383
|
name: "Parent entities",
|
|
384
384
|
width: 260,
|
|
385
385
|
dependencies: [],
|
|
@@ -31,7 +31,7 @@ function hideAndExpandKeys<M extends Record<string, any>>(collection: ResolvedEn
|
|
|
31
31
|
}];
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const additionalField = collection.additionalFields?.find(field => field.
|
|
34
|
+
const additionalField = collection.additionalFields?.find(field => field.key === key);
|
|
35
35
|
if (additionalField) {
|
|
36
36
|
return [{
|
|
37
37
|
key,
|
|
@@ -68,7 +68,7 @@ function getDefaultColumnKeys<M extends Record<string, any> = any>(collection: R
|
|
|
68
68
|
|
|
69
69
|
const columnIds: string[] = [
|
|
70
70
|
...propertyKeys,
|
|
71
|
-
...additionalFields.map((field) => field.
|
|
71
|
+
...additionalFields.map((field) => field.key)
|
|
72
72
|
];
|
|
73
73
|
|
|
74
74
|
if (includeSubCollections) {
|
|
@@ -126,5 +126,5 @@ export function getPropertiesWithPropertiesOrder<M extends Record<string, any>>(
|
|
|
126
126
|
|
|
127
127
|
export function getDefaultPropertiesOrder(collection: EntityCollection<any>): string[] {
|
|
128
128
|
if (collection.propertiesOrder) return collection.propertiesOrder;
|
|
129
|
-
return [...Object.keys(collection.properties), ...(collection.additionalFields ?? []).map(field => field.
|
|
129
|
+
return [...Object.keys(collection.properties), ...(collection.additionalFields ?? []).map(field => field.key)];
|
|
130
130
|
}
|
package/src/types/collections.ts
CHANGED
|
@@ -387,7 +387,7 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any,
|
|
|
387
387
|
* ID of this column. You can use this id in the `properties` field of the
|
|
388
388
|
* collection in any order you want
|
|
389
389
|
*/
|
|
390
|
-
|
|
390
|
+
key: string;
|
|
391
391
|
|
|
392
392
|
/**
|
|
393
393
|
* Header of this column
|
|
@@ -413,6 +413,15 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any,
|
|
|
413
413
|
* it will be updated in every render.
|
|
414
414
|
*/
|
|
415
415
|
dependencies?: Extract<keyof M, string>[];
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Use this prop to define the value of the column as a string or number.
|
|
419
|
+
* This is the value that will be used for exporting the collection.
|
|
420
|
+
* If `Builder` is defined, this prop will be ignored in the collection
|
|
421
|
+
* view.
|
|
422
|
+
* @param entity
|
|
423
|
+
*/
|
|
424
|
+
value?: (props: { entity: Entity<M>, context: FireCMSContext }) => string | number | Promise<string | number> | undefined;
|
|
416
425
|
}
|
|
417
426
|
|
|
418
427
|
/**
|
package/src/types/firecms.tsx
CHANGED
|
@@ -23,7 +23,7 @@ import { CMSAnalyticsEvent } from "./analytics";
|
|
|
23
23
|
* APIs directly, or a REST API.
|
|
24
24
|
* @category Models
|
|
25
25
|
*/
|
|
26
|
-
export type EntityCollectionsBuilder<EC extends EntityCollection> = (params: {
|
|
26
|
+
export type EntityCollectionsBuilder<EC extends EntityCollection = EntityCollection> = (params: {
|
|
27
27
|
user: User | null,
|
|
28
28
|
authController: AuthController,
|
|
29
29
|
dataSource: DataSource
|