@firecms/core 3.0.0-canary.1 → 3.0.0-canary.3

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.
@@ -20,3 +20,4 @@ export * from "./flatten_object";
20
20
  export * from "./make_properties_editable";
21
21
  export * from "./join_collections";
22
22
  export * from "./builders";
23
+ export * from "./useTraceUpdate";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@firecms/core",
3
3
  "type": "module",
4
- "version": "3.0.0-canary.1",
4
+ "version": "3.0.0-canary.3",
5
5
  "description": "Awesome Firebase/Firestore-based headless open-source CMS",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/firecmsco"
@@ -46,8 +46,8 @@
46
46
  "./package.json": "./package.json"
47
47
  },
48
48
  "dependencies": {
49
- "@firecms/formex": "^3.0.0-canary.1",
50
- "@firecms/ui": "^3.0.0-canary.1",
49
+ "@firecms/formex": "^3.0.0-canary.3",
50
+ "@firecms/ui": "^3.0.0-canary.3",
51
51
  "@fontsource/ibm-plex-mono": "^5.0.8",
52
52
  "@fontsource/roboto": "^5.0.8",
53
53
  "@hello-pangea/dnd": "^16.5.0",
@@ -115,7 +115,7 @@
115
115
  "dist",
116
116
  "src"
117
117
  ],
118
- "gitHead": "2e4b4126562ef2d7e099bba8b116f77ba3e1e3cf",
118
+ "gitHead": "9d587b683991dfcefd28e1c13b693364b5de72b2",
119
119
  "publishConfig": {
120
120
  "access": "public"
121
121
  }
@@ -1,5 +1,4 @@
1
1
  import React, { MouseEvent, useCallback } from "react";
2
- import equal from "react-fast-compare"
3
2
 
4
3
  import { CollectionSize, Entity, EntityAction, EntityCollection, SelectionController } from "../../types";
5
4
  import { Checkbox, cn, IconButton, Menu, MenuItem, MoreVertIcon, Skeleton, Tooltip, Typography } from "@firecms/ui";
@@ -1,5 +1,6 @@
1
- import { useCallback, useEffect, useMemo, useState } from "react";
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
2
  import { useLocation } from "react-router-dom";
3
+ import equal from "react-fast-compare"
3
4
 
4
5
  import {
5
6
  AuthController,
@@ -49,7 +50,7 @@ export function useBuildNavigationController<EC extends EntityCollection, UserTy
49
50
  basePath = DEFAULT_BASE_PATH,
50
51
  baseCollectionPath = DEFAULT_COLLECTION_PATH,
51
52
  authController,
52
- collections: baseCollections,
53
+ collections: collectionsProp,
53
54
  views: baseViews,
54
55
  userConfigPersistence,
55
56
  dataSourceDelegate,
@@ -58,6 +59,7 @@ export function useBuildNavigationController<EC extends EntityCollection, UserTy
58
59
 
59
60
  const location = useLocation();
60
61
 
62
+ const collectionsRef = useRef<EntityCollection[] | null>();
61
63
  const [collections, setCollections] = useState<EntityCollection[] | undefined>();
62
64
  const [views, setViews] = useState<CMSView[] | undefined>();
63
65
  const [initialised, setInitialised] = useState<boolean>(false);
@@ -80,7 +82,6 @@ export function useBuildNavigationController<EC extends EntityCollection, UserTy
80
82
  [baseCollectionPath]);
81
83
 
82
84
  const computeTopNavigation = useCallback((collections: EntityCollection[], views: CMSView[]): TopNavigationResult => {
83
- // return (collection.editable && resolvePermissions(collection, authController, paths).editCollection) ?? DEFAULT_PERMISSIONS.editCollection;
84
85
  const navigationEntries: TopNavigationEntry[] = [
85
86
  ...(collections ?? []).map(collection => (!collection.hideFromNavigation
86
87
  ? {
@@ -125,14 +126,16 @@ export function useBuildNavigationController<EC extends EntityCollection, UserTy
125
126
 
126
127
  try {
127
128
  const [resolvedCollections = [], resolvedViews = []] = await Promise.all([
128
- resolveCollections(baseCollections, authController, dataSourceDelegate, injectCollections),
129
+ resolveCollections(collectionsProp, authController, dataSourceDelegate, injectCollections),
129
130
  resolveCMSViews(baseViews, authController, dataSourceDelegate)
130
131
  ]
131
132
  );
132
-
133
- setCollections(resolvedCollections);
134
- setViews(resolvedViews);
135
- setTopLevelNavigation(computeTopNavigation(resolvedCollections ?? [], resolvedViews));
133
+ if (!equal(collectionsRef.current, resolvedCollections) || !equal(views, resolvedViews) || !equal(topLevelNavigation, computeTopNavigation(resolvedCollections, resolvedViews))) {
134
+ collectionsRef.current = resolvedCollections;
135
+ setCollections(resolvedCollections);
136
+ setViews(resolvedViews);
137
+ setTopLevelNavigation(computeTopNavigation(resolvedCollections ?? [], resolvedViews));
138
+ }
136
139
  } catch (e) {
137
140
  console.error(e);
138
141
  setNavigationLoadingError(e as any);
@@ -140,7 +143,7 @@ export function useBuildNavigationController<EC extends EntityCollection, UserTy
140
143
 
141
144
  setNavigationLoading(false);
142
145
  setInitialised(true);
143
- }, [baseCollections, authController.user, authController.initialLoading, baseViews, computeTopNavigation, injectCollections]);
146
+ }, [collectionsProp, authController.user, authController.initialLoading, baseViews, computeTopNavigation, injectCollections]);
144
147
 
145
148
  useEffect(() => {
146
149
  refreshNavigation();
@@ -276,15 +279,7 @@ export function useBuildNavigationController<EC extends EntityCollection, UserTy
276
279
  }
277
280
 
278
281
  // for each odd path segment, get the collection
279
- const parentCollectionIds = result.map(r => getCollectionFromPaths(r)?.id).filter(Boolean) as string[];
280
-
281
- getCollectionFromPaths(oddPathSegments);
282
-
283
- // const allParentCollectionsForPath = getAllParentReferencesForPath(path);
284
- // console.log("allParentCollectionsForPath", allParentCollectionsForPath);
285
- // const parentCollectionIds = allParentCollectionsForPath.map(r => r.id);
286
- console.log("getParentCollectionIds", path, parentCollectionIds);
287
- return parentCollectionIds;
282
+ return result.map(r => getCollectionFromPaths(r)?.id).filter(Boolean) as string[];
288
283
  }, [getAllParentReferencesForPath])
289
284
 
290
285
  const convertIdsToPaths = useCallback((ids: string[]): string[] => {
package/src/util/index.ts CHANGED
@@ -20,3 +20,4 @@ export * from "./flatten_object";
20
20
  export * from "./make_properties_editable";
21
21
  export * from "./join_collections";
22
22
  export * from "./builders";
23
+ export * from "./useTraceUpdate";