@firecms/core 3.0.0-alpha.44 → 3.0.0-alpha.46
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/contexts/NavigationContext.d.ts +2 -2
- package/dist/core/NavigationRoutes.d.ts +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/hooks/data/save.d.ts +2 -1
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/{useNavigationContext.d.ts → useNavigationController.d.ts} +2 -2
- package/dist/index.es.js +5444 -5440
- 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/{hooks → internal}/useBuildDataSource.d.ts +3 -2
- package/dist/internal/useBuildNavigationController.d.ts +14 -0
- package/dist/internal/useBuildSideEntityController.d.ts +2 -2
- package/dist/types/datasource.d.ts +3 -3
- package/dist/types/firecms.d.ts +4 -4
- package/dist/types/firecms_context.d.ts +2 -2
- package/dist/types/navigation.d.ts +2 -2
- package/package.json +2 -2
- package/src/components/EntityCollectionTable/fields/TableReferenceField.tsx +3 -3
- package/src/components/EntityCollectionTable/filters/ReferenceFilterField.tsx +3 -3
- package/src/components/EntityCollectionTable/useEntityCollectionTableController.tsx +2 -2
- package/src/components/EntityCollectionView/EntityCollectionView.tsx +4 -3
- package/src/components/EntityCollectionView/EntityCollectionViewActions.tsx +3 -3
- package/src/components/FireCMSAppBar.tsx +2 -2
- package/src/components/HomePage/DefaultHomePage.tsx +4 -4
- package/src/components/HomePage/FavouritesView.tsx +3 -3
- package/src/components/ReferenceSelectionInner.tsx +2 -2
- package/src/contexts/NavigationContext.tsx +2 -2
- package/src/core/Drawer.tsx +2 -2
- package/src/core/EntitySidePanel.tsx +4 -4
- package/src/core/FireCMS.tsx +29 -23
- package/src/core/NavigationRoutes.tsx +3 -3
- package/src/core/Scaffold.tsx +3 -3
- package/src/core/index.tsx +1 -1
- package/src/form/components/ReferenceWidget.tsx +4 -4
- package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +3 -3
- package/src/form/field_bindings/ReferenceFieldBinding.tsx +3 -3
- package/src/hooks/data/save.ts +11 -1
- package/src/hooks/data/useCollectionFetch.tsx +3 -3
- package/src/hooks/data/useEntityFetch.tsx +3 -3
- package/src/hooks/index.tsx +1 -2
- package/src/hooks/useFireCMSContext.tsx +2 -2
- package/src/hooks/{useNavigationContext.tsx → useNavigationController.tsx} +3 -3
- package/src/hooks/useReferenceDialog.tsx +2 -2
- package/src/{hooks → internal}/useBuildDataSource.ts +34 -25
- package/src/internal/{useBuildNavigationContext.tsx → useBuildNavigationController.tsx} +22 -18
- package/src/internal/useBuildSideEntityController.tsx +3 -3
- package/src/preview/components/ReferencePreview.tsx +3 -3
- package/src/types/datasource.ts +3 -3
- package/src/types/firecms.tsx +4 -4
- package/src/types/firecms_context.tsx +2 -2
- package/src/types/navigation.ts +2 -2
- package/dist/internal/useBuildNavigationContext.d.ts +0 -14
|
@@ -4,7 +4,7 @@ import { ReferencePreview } from "../../preview";
|
|
|
4
4
|
import { FieldHelperText, FormikArrayContainer, LabelWithIcon } from "../components";
|
|
5
5
|
import { getIconForProperty, getReferenceFrom } from "../../util";
|
|
6
6
|
|
|
7
|
-
import { useClearRestoreValue,
|
|
7
|
+
import { useClearRestoreValue, useNavigationController, useReferenceDialog } from "../../hooks";
|
|
8
8
|
import { Button, ExpandablePanel } from "../../ui";
|
|
9
9
|
import { ErrorView } from "../../components";
|
|
10
10
|
|
|
@@ -46,9 +46,9 @@ export function ArrayOfReferencesFieldBinding({
|
|
|
46
46
|
setValue
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
const
|
|
49
|
+
const navigationController = useNavigationController();
|
|
50
50
|
const collection: EntityCollection | undefined = useMemo(() => {
|
|
51
|
-
return ofProperty.path ?
|
|
51
|
+
return ofProperty.path ? navigationController.getCollection(ofProperty.path) : undefined;
|
|
52
52
|
}, [ofProperty.path]);
|
|
53
53
|
|
|
54
54
|
if (!collection) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useCallback, useMemo } from "react";
|
|
2
2
|
|
|
3
3
|
import { Entity, EntityCollection, EntityReference, FieldProps } from "../../types";
|
|
4
|
-
import { useClearRestoreValue,
|
|
4
|
+
import { useClearRestoreValue, useNavigationController, useReferenceDialog } from "../../hooks";
|
|
5
5
|
import { ReadOnlyFieldBinding } from "./ReadOnlyFieldBinding";
|
|
6
6
|
import { FieldHelperText, LabelWithIcon } from "../components";
|
|
7
7
|
import { ReferencePreview } from "../../preview";
|
|
@@ -51,9 +51,9 @@ function ReferenceFieldBindingInternal<M extends Record<string, any>>({
|
|
|
51
51
|
|
|
52
52
|
const validValue = value && value instanceof EntityReference;
|
|
53
53
|
|
|
54
|
-
const
|
|
54
|
+
const navigationController = useNavigationController();
|
|
55
55
|
const collection: EntityCollection | undefined = useMemo(() => {
|
|
56
|
-
return property.path ?
|
|
56
|
+
return property.path ? navigationController.getCollection(property.path) : undefined;
|
|
57
57
|
}, [property.path]);
|
|
58
58
|
|
|
59
59
|
if (!collection) {
|
package/src/hooks/data/save.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DataSource,
|
|
3
|
+
Entity,
|
|
4
|
+
EntityCallbacks,
|
|
5
|
+
EntityCollection,
|
|
6
|
+
EntityValues,
|
|
7
|
+
FireCMSContext,
|
|
8
|
+
SaveEntityProps,
|
|
9
|
+
User
|
|
10
|
+
} from "../../types";
|
|
2
11
|
import { useDataSource } from "./useDataSource";
|
|
3
12
|
import { resolveCollection } from "../../util";
|
|
4
13
|
|
|
@@ -55,6 +64,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, Use
|
|
|
55
64
|
onPreSaveHookError,
|
|
56
65
|
onSaveSuccessHookError
|
|
57
66
|
}: SaveEntityWithCallbacksProps<M> & {
|
|
67
|
+
collection: EntityCollection<M>,
|
|
58
68
|
dataSource: DataSource,
|
|
59
69
|
context: FireCMSContext<UserType>,
|
|
60
70
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
import { Entity, EntityCollection, FilterValues, FireCMSContext, User } from "../../types";
|
|
3
3
|
import { useDataSource } from "./useDataSource";
|
|
4
|
-
import {
|
|
4
|
+
import { useNavigationController } from "../useNavigationController";
|
|
5
5
|
import { useFireCMSContext } from "../useFireCMSContext";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -71,9 +71,9 @@ export function useCollectionFetch<M extends Record<string, any>, UserType exten
|
|
|
71
71
|
}: CollectionFetchProps<M>): CollectionFetchResult<M> {
|
|
72
72
|
|
|
73
73
|
const dataSource = useDataSource();
|
|
74
|
-
const
|
|
74
|
+
const navigationController = useNavigationController();
|
|
75
75
|
|
|
76
|
-
const path =
|
|
76
|
+
const path = navigationController.resolveAliasesFrom(inputPath);
|
|
77
77
|
|
|
78
78
|
const sortByProperty = sortBy ? sortBy[0] : undefined;
|
|
79
79
|
const currentSort = sortBy ? sortBy[1] : undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
import { Entity, EntityCollection, FireCMSContext, User } from "../../types";
|
|
3
3
|
import { useDataSource } from "./useDataSource";
|
|
4
|
-
import {
|
|
4
|
+
import { useNavigationController } from "../useNavigationController";
|
|
5
5
|
import { useFireCMSContext } from "../useFireCMSContext";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -44,9 +44,9 @@ export function useEntityFetch<M extends Record<string, any>, UserType extends U
|
|
|
44
44
|
}: EntityFetchProps<M>): EntityFetchResult<M> {
|
|
45
45
|
|
|
46
46
|
const dataSource = useDataSource();
|
|
47
|
-
const
|
|
47
|
+
const navigationController = useNavigationController();
|
|
48
48
|
|
|
49
|
-
const path =
|
|
49
|
+
const path = navigationController.resolveAliasesFrom(inputPath);
|
|
50
50
|
|
|
51
51
|
const context: FireCMSContext<UserType> = useFireCMSContext();
|
|
52
52
|
|
package/src/hooks/index.tsx
CHANGED
|
@@ -5,7 +5,7 @@ export * from "./data/save";
|
|
|
5
5
|
export * from "./data/delete";
|
|
6
6
|
|
|
7
7
|
export * from "../form/useClearRestoreValue";
|
|
8
|
-
export * from "./
|
|
8
|
+
export * from "./useNavigationController";
|
|
9
9
|
|
|
10
10
|
export * from "./useResolvedNavigationFrom";
|
|
11
11
|
|
|
@@ -22,4 +22,3 @@ export * from "./useLargeLayout";
|
|
|
22
22
|
|
|
23
23
|
export * from "./useReferenceDialog";
|
|
24
24
|
export * from "./useBrowserTitleAndIcon";
|
|
25
|
-
export * from "./useBuildDataSource";
|
|
@@ -2,7 +2,7 @@ import { createContext, useContext } from "react";
|
|
|
2
2
|
import { AuthController, FireCMSContext, User } from "../types";
|
|
3
3
|
import { useAuthController } from "./useAuthController";
|
|
4
4
|
import { useSideDialogsController } from "./useSideDialogsController";
|
|
5
|
-
import {
|
|
5
|
+
import { useNavigationController } from "./useNavigationController";
|
|
6
6
|
import { useSideEntityController } from "./useSideEntityController";
|
|
7
7
|
import { useDataSource } from "./data/useDataSource";
|
|
8
8
|
import { useStorageSource } from "./useStorageSource";
|
|
@@ -27,7 +27,7 @@ export const useFireCMSContext = <UserType extends User = User, AuthControllerTy
|
|
|
27
27
|
const authController = useAuthController<UserType, AuthControllerType>();
|
|
28
28
|
const sideDialogsController = useSideDialogsController();
|
|
29
29
|
const sideEntityController = useSideEntityController();
|
|
30
|
-
const navigation =
|
|
30
|
+
const navigation = useNavigationController();
|
|
31
31
|
const dataSource = useDataSource();
|
|
32
32
|
const storageSource = useStorageSource();
|
|
33
33
|
const snackbarController = useSnackbarController();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { NavigationController } from "../types";
|
|
3
|
+
import { NavigationContext } from "../contexts/NavigationContext";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Use this hook to get the navigation of the app.
|
|
@@ -9,4 +9,4 @@ import { NavigationContextInstance } from "../contexts/NavigationContext";
|
|
|
9
9
|
*
|
|
10
10
|
* @group Hooks and utilities
|
|
11
11
|
*/
|
|
12
|
-
export const
|
|
12
|
+
export const useNavigationController = (): NavigationController => useContext(NavigationContext);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useSideDialogsController } from "./useSideDialogsController";
|
|
2
2
|
import { ReferenceSelectionInner, ReferenceSelectionInnerProps } from "../components";
|
|
3
3
|
import { useCallback } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { useNavigationController } from "./useNavigationController";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* This hook is used to open a side dialog that allows the selection
|
|
@@ -18,7 +18,7 @@ export function useReferenceDialog<M extends Record<string, any>>(referenceDialo
|
|
|
18
18
|
onClose?: () => void;
|
|
19
19
|
}): { open: () => void; close: () => void } {
|
|
20
20
|
|
|
21
|
-
const navigation =
|
|
21
|
+
const navigation = useNavigationController();
|
|
22
22
|
const sideDialogsController = useSideDialogsController();
|
|
23
23
|
|
|
24
24
|
const open = useCallback(() => {
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
GeoPoint,
|
|
14
14
|
ListenCollectionProps,
|
|
15
15
|
ListenEntityProps,
|
|
16
|
+
NavigationController,
|
|
16
17
|
PropertyConfig,
|
|
17
18
|
ResolvedProperties,
|
|
18
19
|
SaveEntityProps
|
|
@@ -26,10 +27,12 @@ import { resolveCollection, updateDateAutoValues } from "../util";
|
|
|
26
27
|
*/
|
|
27
28
|
export function useBuildDataSource({
|
|
28
29
|
delegate,
|
|
29
|
-
propertyConfigs
|
|
30
|
+
propertyConfigs,
|
|
31
|
+
navigationController
|
|
30
32
|
}: {
|
|
31
33
|
delegate: DataSourceDelegate,
|
|
32
34
|
propertyConfigs?: Record<string, PropertyConfig>;
|
|
35
|
+
navigationController: NavigationController;
|
|
33
36
|
}): DataSource {
|
|
34
37
|
|
|
35
38
|
return {
|
|
@@ -50,7 +53,7 @@ export function useBuildDataSource({
|
|
|
50
53
|
*/
|
|
51
54
|
fetchCollection: useCallback(<M extends Record<string, any>>({
|
|
52
55
|
path,
|
|
53
|
-
collection,
|
|
56
|
+
collection: collectionProp,
|
|
54
57
|
filter,
|
|
55
58
|
limit,
|
|
56
59
|
startAfter,
|
|
@@ -59,7 +62,6 @@ export function useBuildDataSource({
|
|
|
59
62
|
order
|
|
60
63
|
}: FetchCollectionProps<M>
|
|
61
64
|
): Promise<Entity<M>[]> => {
|
|
62
|
-
|
|
63
65
|
return delegate.fetchCollection<M>({
|
|
64
66
|
path,
|
|
65
67
|
filter,
|
|
@@ -92,7 +94,7 @@ export function useBuildDataSource({
|
|
|
92
94
|
? useCallback(<M extends Record<string, any>>(
|
|
93
95
|
{
|
|
94
96
|
path,
|
|
95
|
-
collection,
|
|
97
|
+
collection: collectionProp,
|
|
96
98
|
filter,
|
|
97
99
|
limit,
|
|
98
100
|
startAfter,
|
|
@@ -104,7 +106,8 @@ export function useBuildDataSource({
|
|
|
104
106
|
}: ListenCollectionProps<M>
|
|
105
107
|
): () => void => {
|
|
106
108
|
|
|
107
|
-
const
|
|
109
|
+
const collection = collectionProp ?? navigationController.getCollection(path);
|
|
110
|
+
const isCollectionGroup = Boolean(collection?.collectionGroup) ?? false;
|
|
108
111
|
if (!delegate.listenCollection)
|
|
109
112
|
throw Error("useBuildDataSource delegate not initialised");
|
|
110
113
|
|
|
@@ -120,7 +123,7 @@ export function useBuildDataSource({
|
|
|
120
123
|
onError,
|
|
121
124
|
isCollectionGroup
|
|
122
125
|
});
|
|
123
|
-
}, [delegate])
|
|
126
|
+
}, [delegate, navigationController.getCollection])
|
|
124
127
|
: undefined,
|
|
125
128
|
|
|
126
129
|
/**
|
|
@@ -186,18 +189,22 @@ export function useBuildDataSource({
|
|
|
186
189
|
path,
|
|
187
190
|
entityId,
|
|
188
191
|
values,
|
|
189
|
-
collection,
|
|
192
|
+
collection: collectionProp,
|
|
190
193
|
status
|
|
191
194
|
}: SaveEntityProps<M>): Promise<Entity<M>> => {
|
|
192
195
|
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
const collection = collectionProp ?? navigationController.getCollection(path);
|
|
197
|
+
|
|
198
|
+
const resolvedCollection = collection
|
|
199
|
+
? resolveCollection<M>({
|
|
200
|
+
collection,
|
|
201
|
+
path,
|
|
202
|
+
entityId,
|
|
203
|
+
fields: propertyConfigs
|
|
204
|
+
})
|
|
205
|
+
: undefined;
|
|
199
206
|
|
|
200
|
-
const properties: ResolvedProperties<M> = resolvedCollection
|
|
207
|
+
const properties: ResolvedProperties<M> | undefined = resolvedCollection?.properties;
|
|
201
208
|
|
|
202
209
|
const firestoreValues = cmsToDelegateModel(
|
|
203
210
|
values,
|
|
@@ -206,14 +213,16 @@ export function useBuildDataSource({
|
|
|
206
213
|
delegate.buildDate,
|
|
207
214
|
delegate.buildDeleteFieldValue
|
|
208
215
|
);
|
|
209
|
-
const updatedFirestoreValues: EntityValues<M> =
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
216
|
+
const updatedFirestoreValues: EntityValues<M> = properties
|
|
217
|
+
? updateDateAutoValues(
|
|
218
|
+
{
|
|
219
|
+
inputValues: firestoreValues,
|
|
220
|
+
properties,
|
|
221
|
+
status,
|
|
222
|
+
timestampNowValue: delegate.currentTime(),
|
|
223
|
+
setDateToMidnight: delegate.setDateToMidnight
|
|
224
|
+
})
|
|
225
|
+
: firestoreValues;
|
|
217
226
|
|
|
218
227
|
console.debug("Saving entity", path, entityId, updatedFirestoreValues);
|
|
219
228
|
|
|
@@ -229,7 +238,7 @@ export function useBuildDataSource({
|
|
|
229
238
|
values: delegate.delegateToCMSModel(updatedFirestoreValues)
|
|
230
239
|
} as Entity<M>;
|
|
231
240
|
});
|
|
232
|
-
}, [delegate.saveEntity]),
|
|
241
|
+
}, [delegate.saveEntity, navigationController.getCollection]),
|
|
233
242
|
|
|
234
243
|
/**
|
|
235
244
|
* Delete an entity
|
|
@@ -242,7 +251,7 @@ export function useBuildDataSource({
|
|
|
242
251
|
entity
|
|
243
252
|
}: DeleteEntityProps<M>
|
|
244
253
|
): Promise<void> => {
|
|
245
|
-
return delegate.deleteEntity({entity});
|
|
254
|
+
return delegate.deleteEntity({ entity });
|
|
246
255
|
}, [delegate.deleteEntity]),
|
|
247
256
|
|
|
248
257
|
/**
|
|
@@ -265,7 +274,7 @@ export function useBuildDataSource({
|
|
|
265
274
|
}, [delegate.checkUniqueField]),
|
|
266
275
|
|
|
267
276
|
generateEntityId: useCallback((path: string): string => {
|
|
268
|
-
return delegate.generateEntityId(path,
|
|
277
|
+
return delegate.generateEntityId(path,);
|
|
269
278
|
}, [delegate.generateEntityId]),
|
|
270
279
|
|
|
271
280
|
countEntities: useCallback(async ({
|
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
AuthController,
|
|
6
6
|
CMSView,
|
|
7
7
|
CMSViewsBuilder,
|
|
8
|
-
DataSource,
|
|
8
|
+
DataSource, DataSourceDelegate,
|
|
9
9
|
EntityCollection,
|
|
10
10
|
EntityCollectionsBuilder,
|
|
11
11
|
EntityReference,
|
|
12
12
|
FireCMSPlugin,
|
|
13
|
-
|
|
13
|
+
NavigationController,
|
|
14
14
|
TopNavigationEntry,
|
|
15
15
|
TopNavigationResult,
|
|
16
16
|
User,
|
|
@@ -24,28 +24,32 @@ import {
|
|
|
24
24
|
resolvePermissions
|
|
25
25
|
} from "../util";
|
|
26
26
|
import { getParentReferencesFromPath } from "../util/parent_references_from_path";
|
|
27
|
+
import { useTraceUpdate } from "../util/useTraceUpdate";
|
|
28
|
+
|
|
29
|
+
const DEFAULT_BASE_PATH = "/";
|
|
30
|
+
const DEFAULT_COLLECTION_PATH = "/c";
|
|
27
31
|
|
|
28
32
|
type BuildNavigationContextProps<EC extends EntityCollection, UserType extends User> = {
|
|
29
|
-
basePath
|
|
30
|
-
baseCollectionPath
|
|
33
|
+
basePath?: string,
|
|
34
|
+
baseCollectionPath?: string,
|
|
31
35
|
authController: AuthController<UserType>;
|
|
32
36
|
collections?: EC[] | EntityCollectionsBuilder<EC>;
|
|
33
37
|
views?: CMSView[] | CMSViewsBuilder;
|
|
34
38
|
userConfigPersistence?: UserConfigurationPersistence;
|
|
35
39
|
plugins?: FireCMSPlugin[];
|
|
36
|
-
dataSource:
|
|
40
|
+
dataSource: DataSourceDelegate;
|
|
37
41
|
};
|
|
38
42
|
|
|
39
|
-
export function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
export function useBuildNavigationController<EC extends EntityCollection, UserType extends User>({
|
|
44
|
+
basePath = DEFAULT_BASE_PATH,
|
|
45
|
+
baseCollectionPath = DEFAULT_COLLECTION_PATH,
|
|
46
|
+
authController,
|
|
47
|
+
collections: baseCollections,
|
|
48
|
+
views: baseViews,
|
|
49
|
+
userConfigPersistence,
|
|
50
|
+
plugins,
|
|
51
|
+
dataSource
|
|
52
|
+
}: BuildNavigationContextProps<EC, UserType>): NavigationController {
|
|
49
53
|
|
|
50
54
|
const location = useLocation();
|
|
51
55
|
|
|
@@ -131,7 +135,7 @@ export function useBuildNavigationContext<EC extends EntityCollection, UserType
|
|
|
131
135
|
|
|
132
136
|
setNavigationLoading(false);
|
|
133
137
|
setInitialised(true);
|
|
134
|
-
}, [baseCollections, authController.user, authController.initialLoading,
|
|
138
|
+
}, [baseCollections, authController.user, authController.initialLoading, plugins, baseViews, computeTopNavigation]);
|
|
135
139
|
|
|
136
140
|
useEffect(() => {
|
|
137
141
|
refreshNavigation();
|
|
@@ -288,7 +292,7 @@ function filterOutNotAllowedCollections(resolvedCollections: EntityCollection[],
|
|
|
288
292
|
});
|
|
289
293
|
}
|
|
290
294
|
|
|
291
|
-
async function resolveCollections(collections: undefined | EntityCollection[] | EntityCollectionsBuilder<any>, authController: AuthController, dataSource:
|
|
295
|
+
async function resolveCollections(collections: undefined | EntityCollection[] | EntityCollectionsBuilder<any>, authController: AuthController, dataSource: DataSourceDelegate, plugins?: FireCMSPlugin[]) {
|
|
292
296
|
let resolvedCollections: EntityCollection[] = [];
|
|
293
297
|
if (typeof collections === "function") {
|
|
294
298
|
resolvedCollections = await collections({
|
|
@@ -312,7 +316,7 @@ async function resolveCollections(collections: undefined | EntityCollection[] |
|
|
|
312
316
|
return resolvedCollections;
|
|
313
317
|
}
|
|
314
318
|
|
|
315
|
-
async function resolveCMSViews(baseViews: CMSView[] | CMSViewsBuilder | undefined, authController: AuthController, dataSource:
|
|
319
|
+
async function resolveCMSViews(baseViews: CMSView[] | CMSViewsBuilder | undefined, authController: AuthController, dataSource: DataSourceDelegate) {
|
|
316
320
|
let resolvedViews: CMSView[] = [];
|
|
317
321
|
if (typeof baseViews === "function") {
|
|
318
322
|
resolvedViews = await baseViews({
|
|
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef } from "react";
|
|
|
2
2
|
import {
|
|
3
3
|
EntityCollection,
|
|
4
4
|
EntitySidePanelProps,
|
|
5
|
-
|
|
5
|
+
NavigationController,
|
|
6
6
|
SideDialogPanelProps,
|
|
7
7
|
SideDialogsController,
|
|
8
8
|
SideEntityController
|
|
@@ -23,7 +23,7 @@ export function getEntityViewWidth(props: EntitySidePanelProps<any>, small: bool
|
|
|
23
23
|
return !mainViewSelected ? `calc(${ADDITIONAL_TAB_WIDTH} + ${resolvedWidth ?? FORM_CONTAINER_WIDTH})` : resolvedWidth ?? FORM_CONTAINER_WIDTH
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export const useBuildSideEntityController = (navigation:
|
|
26
|
+
export const useBuildSideEntityController = (navigation: NavigationController,
|
|
27
27
|
sideDialogsController: SideDialogsController): SideEntityController => {
|
|
28
28
|
|
|
29
29
|
const location = useLocation();
|
|
@@ -142,7 +142,7 @@ export function buildSidePanelsFromUrl(path: string, collections: EntityCollecti
|
|
|
142
142
|
return sidePanels;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
const propsToSidePanel = (props: EntitySidePanelProps<any>, navigation:
|
|
145
|
+
const propsToSidePanel = (props: EntitySidePanelProps<any>, navigation: NavigationController, smallLayout: boolean): SideDialogPanelProps => {
|
|
146
146
|
|
|
147
147
|
const collectionPath = removeInitialAndTrailingSlashes(props.path);
|
|
148
148
|
const newPath = props.entityId
|
|
@@ -4,7 +4,7 @@ import { useMemo } from "react";
|
|
|
4
4
|
import { Entity, EntityCollection, EntityReference, ResolvedProperty } from "../../types";
|
|
5
5
|
|
|
6
6
|
import { getReferencePreviewKeys, getValueInPath, resolveCollection } from "../../util";
|
|
7
|
-
import { useEntityFetch, useFireCMSContext,
|
|
7
|
+
import { useEntityFetch, useFireCMSContext, useNavigationController, useSideEntityController } from "../../hooks";
|
|
8
8
|
import { PropertyPreview } from "../PropertyPreview";
|
|
9
9
|
import { PreviewSize } from "../PropertyPreviewProps";
|
|
10
10
|
import { SkeletonPropertyComponent } from "../property_previews/SkeletonPropertyComponent";
|
|
@@ -61,9 +61,9 @@ function ReferencePreviewInternal<M extends Record<string, any>>({
|
|
|
61
61
|
}: ReferencePreviewProps) {
|
|
62
62
|
|
|
63
63
|
const context = useFireCMSContext();
|
|
64
|
-
const
|
|
64
|
+
const navigationController = useNavigationController();
|
|
65
65
|
|
|
66
|
-
const collection =
|
|
66
|
+
const collection = navigationController.getCollection<EntityCollection<M>>(reference.path);
|
|
67
67
|
if (!collection) {
|
|
68
68
|
if (context.components?.missingReference) {
|
|
69
69
|
return <context.components.missingReference path={reference.path}/>;
|
package/src/types/datasource.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { ResolvedEntityCollection } from "./resolved_entities";
|
|
|
8
8
|
export interface FetchEntityProps<M extends Record<string, any> = any> {
|
|
9
9
|
path: string;
|
|
10
10
|
entityId: string;
|
|
11
|
-
collection
|
|
11
|
+
collection?: EntityCollection<M>
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -26,7 +26,7 @@ export type ListenEntityProps<M extends Record<string, any> = any> =
|
|
|
26
26
|
*/
|
|
27
27
|
export interface FetchCollectionProps<M extends Record<string, any> = any> {
|
|
28
28
|
path: string;
|
|
29
|
-
collection
|
|
29
|
+
collection?: EntityCollection<M> | ResolvedEntityCollection<M>;
|
|
30
30
|
filter?: FilterValues<Extract<keyof M, string>>,
|
|
31
31
|
limit?: number;
|
|
32
32
|
startAfter?: any[];
|
|
@@ -53,7 +53,7 @@ export interface SaveEntityProps<M extends Record<string, any> = any> {
|
|
|
53
53
|
values: Partial<EntityValues<M>>;
|
|
54
54
|
entityId?: string; // can be empty for new entities
|
|
55
55
|
previousValues?: Partial<EntityValues<M>>;
|
|
56
|
-
collection
|
|
56
|
+
collection?: EntityCollection<M> | ResolvedEntityCollection<M>;
|
|
57
57
|
status: EntityStatus;
|
|
58
58
|
}
|
|
59
59
|
|
package/src/types/firecms.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { User } from "./user";
|
|
3
3
|
import { AuthController } from "./auth";
|
|
4
|
-
import { DataSource } from "./datasource";
|
|
4
|
+
import { DataSource, DataSourceDelegate } from "./datasource";
|
|
5
5
|
import { EntityCollection, EntityCustomView } from "./collections";
|
|
6
6
|
import { CMSView } from "./navigation";
|
|
7
7
|
import { FireCMSContext } from "./firecms_context";
|
|
@@ -26,7 +26,7 @@ import { CMSAnalyticsEvent } from "./analytics";
|
|
|
26
26
|
export type EntityCollectionsBuilder<EC extends EntityCollection = EntityCollection> = (params: {
|
|
27
27
|
user: User | null,
|
|
28
28
|
authController: AuthController,
|
|
29
|
-
dataSource:
|
|
29
|
+
dataSource: DataSourceDelegate
|
|
30
30
|
}) => EC[] | Promise<EC[]>;
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -41,7 +41,7 @@ export type EntityCollectionsBuilder<EC extends EntityCollection = EntityCollect
|
|
|
41
41
|
export type CMSViewsBuilder = (params: {
|
|
42
42
|
user: User | null,
|
|
43
43
|
authController: AuthController,
|
|
44
|
-
dataSource:
|
|
44
|
+
dataSource: DataSourceDelegate
|
|
45
45
|
}) => CMSView[] | Promise<CMSView[]>;
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -112,7 +112,7 @@ export type FireCMSProps<UserType extends User, EC extends EntityCollection> = {
|
|
|
112
112
|
/**
|
|
113
113
|
* Connector to your database
|
|
114
114
|
*/
|
|
115
|
-
|
|
115
|
+
dataSourceDelegate: DataSourceDelegate;
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
118
|
* Connector to your file upload/fetch implementation
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Locale } from "./locales";
|
|
2
2
|
import { DataSource } from "./datasource";
|
|
3
3
|
import { StorageSource } from "./storage";
|
|
4
|
-
import {
|
|
4
|
+
import { NavigationController } from "./navigation";
|
|
5
5
|
import { SideEntityController } from "./side_entity_controller";
|
|
6
6
|
import { AuthController } from "./auth";
|
|
7
7
|
import { EntityLinkBuilder } from "./entity_link_builder";
|
|
@@ -50,7 +50,7 @@ export type FireCMSContext<UserType extends User = User, AuthControllerType exte
|
|
|
50
50
|
* attributes.
|
|
51
51
|
* @see useNavigation
|
|
52
52
|
*/
|
|
53
|
-
navigation:
|
|
53
|
+
navigation: NavigationController;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* Controller to open the side dialog displaying entity forms
|
package/src/types/navigation.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { EntityCollection } from "./collections";
|
|
|
2
2
|
import { EntityReference } from "./entities";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Controller that includes the resolved navigation and utility methods and
|
|
6
6
|
* attributes.
|
|
7
7
|
* @group Models
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
9
|
+
export type NavigationController = {
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* List of the mapped collections in the CMS.
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AuthController, CMSView, CMSViewsBuilder, DataSource, EntityCollection, EntityCollectionsBuilder, FireCMSPlugin, NavigationContext, User, UserConfigurationPersistence } from "../types";
|
|
2
|
-
type BuildNavigationContextProps<EC extends EntityCollection, UserType extends User> = {
|
|
3
|
-
basePath: string;
|
|
4
|
-
baseCollectionPath: string;
|
|
5
|
-
authController: AuthController<UserType>;
|
|
6
|
-
collections?: EC[] | EntityCollectionsBuilder<EC>;
|
|
7
|
-
views?: CMSView[] | CMSViewsBuilder;
|
|
8
|
-
userConfigPersistence?: UserConfigurationPersistence;
|
|
9
|
-
plugins?: FireCMSPlugin[];
|
|
10
|
-
dataSource: DataSource;
|
|
11
|
-
};
|
|
12
|
-
export declare function useBuildNavigationContext<EC extends EntityCollection, UserType extends User>({ basePath, baseCollectionPath, authController, collections: baseCollections, views: baseViews, userConfigPersistence, plugins, dataSource }: BuildNavigationContextProps<EC, UserType>): NavigationContext;
|
|
13
|
-
export declare function getSidePanelKey(path: string, entityId?: string): string;
|
|
14
|
-
export {};
|