@firecms/core 3.0.0-canary.59 → 3.0.0-canary.60

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.
@@ -1,6 +1,7 @@
1
1
  import { Entity, EntityStatus, EntityValues } from "./entities";
2
2
  import { EntityCollection, FilterValues } from "./collections";
3
3
  import { ResolvedEntityCollection } from "./resolved_entities";
4
+ import { FireCMSContext } from "./firecms_context";
4
5
  /**
5
6
  * @group Datasource
6
7
  */
@@ -145,6 +146,17 @@ export interface DataSource {
145
146
  * @param props
146
147
  */
147
148
  isFilterCombinationValid?(props: FilterCombinationValidProps): boolean;
149
+ /**
150
+ * Called when the user clicks on the search bar in a collection view.
151
+ * Useful for initializing a text search index.
152
+ * @param props
153
+ */
154
+ initTextSearch?: (props: {
155
+ context: FireCMSContext;
156
+ path: string;
157
+ collection: EntityCollection;
158
+ parentCollectionIds?: string[];
159
+ }) => Promise<boolean>;
148
160
  }
149
161
  export type FilterCombinationValidProps = {
150
162
  path: string;
@@ -241,14 +253,6 @@ export interface DataSourceDelegate {
241
253
  * @param props
242
254
  */
243
255
  isFilterCombinationValid?(props: Omit<FilterCombinationValidProps, "collection">): boolean;
244
- /**
245
- * Convert a FireCMS reference to a reference that can be used by the datasource
246
- * @param reference
247
- */
248
- /**
249
- * Convert a FireCMS GeoPoint to a GeoPoint that can be used by the datasource
250
- * @param geoPoint
251
- */
252
256
  /**
253
257
  * Get the object to generate the current time in the datasource
254
258
  */
@@ -256,4 +260,10 @@ export interface DataSourceDelegate {
256
260
  delegateToCMSModel: (data: any) => any;
257
261
  cmsToDelegateModel: (data: any) => any;
258
262
  setDateToMidnight: (input?: any) => any;
263
+ initTextSearch?: (props: {
264
+ context: FireCMSContext;
265
+ path: string;
266
+ collection: EntityCollection;
267
+ parentCollectionIds?: string[];
268
+ }) => Promise<boolean>;
259
269
  }
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.59",
4
+ "version": "3.0.0-canary.60",
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.59",
50
- "@firecms/ui": "^3.0.0-canary.59",
49
+ "@firecms/formex": "^3.0.0-canary.60",
50
+ "@firecms/ui": "^3.0.0-canary.60",
51
51
  "@fontsource/jetbrains-mono": "^5.0.20",
52
52
  "@hello-pangea/dnd": "^16.6.0",
53
53
  "@radix-ui/react-portal": "^1.0.4",
@@ -111,7 +111,7 @@
111
111
  "dist",
112
112
  "src"
113
113
  ],
114
- "gitHead": "870435eb903576cd282b2c22165ec3afa84c9340",
114
+ "gitHead": "b93bb64369b81ae43a6e0e0ae4748a818af6d7ae",
115
115
  "publishConfig": {
116
116
  "access": "public"
117
117
  },
@@ -1,7 +1,7 @@
1
1
  import { useState } from "react";
2
2
 
3
3
  import { EntityCollection } from "../../types";
4
- import { useCustomizationController, useFireCMSContext } from "../../hooks";
4
+ import { useCustomizationController, useDataSource, useFireCMSContext } from "../../hooks";
5
5
 
6
6
  export interface UseTableSearchHelperParams<M extends Record<string, any>> {
7
7
  collection: EntityCollection<M>;
@@ -9,27 +9,47 @@ export interface UseTableSearchHelperParams<M extends Record<string, any>> {
9
9
  parentCollectionIds?: string[];
10
10
  }
11
11
 
12
- export function useTableSearchHelper<M extends Record<string, any>>({ collection, fullPath, parentCollectionIds }: UseTableSearchHelperParams<M>) {
12
+ export function useTableSearchHelper<M extends Record<string, any>>({
13
+ collection,
14
+ fullPath,
15
+ parentCollectionIds
16
+ }: UseTableSearchHelperParams<M>) {
13
17
 
14
18
  const context = useFireCMSContext();
15
19
  const customizationController = useCustomizationController();
20
+ const dataSource = useDataSource();
16
21
 
17
22
  const [textSearchLoading, setTextSearchLoading] = useState<boolean>(false);
18
23
  const [textSearchInitialised, setTextSearchInitialised] = useState<boolean>(false);
19
24
  let onTextSearchClick: (() => void) | undefined;
20
25
  let textSearchEnabled = Boolean(collection.textSearchEnabled);
21
26
  if (customizationController?.plugins) {
22
- const addTextSearchClickListener = customizationController.plugins?.find(p => Boolean(p.collectionView?.onTextSearchClick));
27
+ const addTextSearchClickListener = dataSource?.initTextSearch || customizationController.plugins?.find(p => Boolean(p.collectionView?.onTextSearchClick));
23
28
 
24
29
  onTextSearchClick = addTextSearchClickListener
25
30
  ? () => {
26
31
  setTextSearchLoading(true);
27
- Promise.all(customizationController.plugins?.map(p => {
32
+ const promises: Promise<boolean>[] = [];
33
+ if (dataSource?.initTextSearch) {
34
+ promises.push(dataSource.initTextSearch({
35
+ context,
36
+ path: fullPath,
37
+ collection,
38
+ parentCollectionIds
39
+ }));
40
+ }
41
+ customizationController.plugins?.forEach(p => {
28
42
  if (p.collectionView?.onTextSearchClick)
29
- return p.collectionView.onTextSearchClick({ context, path: fullPath, collection, parentCollectionIds });
43
+ promises.push(p.collectionView.onTextSearchClick({
44
+ context,
45
+ path: fullPath,
46
+ collection,
47
+ parentCollectionIds
48
+ }));
30
49
  return Promise.resolve(true);
31
- }) as Promise<boolean>[])
32
- .then((res) => {
50
+ })
51
+ return Promise.all(promises)
52
+ .then((res: boolean[]) => {
33
53
  if (res.every(Boolean)) setTextSearchInitialised(true);
34
54
  })
35
55
  .finally(() => setTextSearchLoading(false));
@@ -39,9 +59,19 @@ export function useTableSearchHelper<M extends Record<string, any>>({ collection
39
59
  customizationController.plugins?.forEach(p => {
40
60
  if (!textSearchEnabled)
41
61
  if (p.collectionView?.showTextSearchBar) {
42
- textSearchEnabled = p.collectionView.showTextSearchBar({ context, path: fullPath, collection, parentCollectionIds });
62
+ textSearchEnabled = p.collectionView.showTextSearchBar({
63
+ context,
64
+ path: fullPath,
65
+ collection,
66
+ parentCollectionIds
67
+ });
43
68
  }
44
69
  })
45
70
  }
46
- return { textSearchLoading, textSearchInitialised, onTextSearchClick, textSearchEnabled };
71
+ return {
72
+ textSearchLoading,
73
+ textSearchInitialised,
74
+ onTextSearchClick,
75
+ textSearchEnabled
76
+ };
47
77
  }
@@ -9,6 +9,7 @@ import {
9
9
  FetchCollectionProps,
10
10
  FetchEntityProps,
11
11
  FilterValues,
12
+ FireCMSContext,
12
13
  ListenCollectionProps,
13
14
  ListenEntityProps,
14
15
  NavigationController,
@@ -313,6 +314,17 @@ export function useBuildDataSource({
313
314
  )
314
315
  }, [delegate.isFilterCombinationValid]),
315
316
 
317
+ initTextSearch: useCallback(async (props: {
318
+ context: FireCMSContext,
319
+ path: string,
320
+ collection: EntityCollection,
321
+ parentCollectionIds?: string[]
322
+ }): Promise<boolean> => {
323
+ if (!delegate.initTextSearch)
324
+ return false;
325
+ return delegate.initTextSearch(props)
326
+ }, [delegate.initTextSearch]),
327
+
316
328
  };
317
329
 
318
330
  }
@@ -1,6 +1,7 @@
1
1
  import { Entity, EntityReference, EntityStatus, EntityValues, GeoPoint } from "./entities";
2
2
  import { EntityCollection, FilterValues } from "./collections";
3
3
  import { ResolvedEntityCollection } from "./resolved_entities";
4
+ import { FireCMSContext } from "./firecms_context";
4
5
 
5
6
  /**
6
7
  * @group Datasource
@@ -217,6 +218,18 @@ export interface DataSource {
217
218
  */
218
219
  isFilterCombinationValid?(props: FilterCombinationValidProps): boolean;
219
220
 
221
+ /**
222
+ * Called when the user clicks on the search bar in a collection view.
223
+ * Useful for initializing a text search index.
224
+ * @param props
225
+ */
226
+ initTextSearch?: (props: {
227
+ context: FireCMSContext,
228
+ path: string,
229
+ collection: EntityCollection,
230
+ parentCollectionIds?: string[]
231
+ }) => Promise<boolean>;
232
+
220
233
  }
221
234
 
222
235
  export type FilterCombinationValidProps = {
@@ -363,30 +376,21 @@ export interface DataSourceDelegate {
363
376
  */
364
377
  isFilterCombinationValid?(props: Omit<FilterCombinationValidProps, "collection">): boolean;
365
378
 
366
- /**
367
- * Convert a FireCMS reference to a reference that can be used by the datasource
368
- * @param reference
369
- */
370
- // buildReference: (reference: EntityReference) => any,
371
-
372
- /**
373
- * Convert a FireCMS GeoPoint to a GeoPoint that can be used by the datasource
374
- * @param geoPoint
375
- */
376
- // buildGeoPoint: (geoPoint: GeoPoint) => any,
377
-
378
379
  /**
379
380
  * Get the object to generate the current time in the datasource
380
381
  */
381
382
  currentTime(): any;
382
383
 
383
- // buildDate: (date: Date) => any;
384
-
385
- // buildDeleteFieldValue: () => any;
386
-
387
384
  delegateToCMSModel: (data: any) => any;
388
385
 
389
386
  cmsToDelegateModel: (data: any) => any;
390
387
 
391
388
  setDateToMidnight: (input?: any) => any;
389
+
390
+ initTextSearch?: (props: {
391
+ context: FireCMSContext,
392
+ path: string,
393
+ collection: EntityCollection,
394
+ parentCollectionIds?: string[]
395
+ }) => Promise<boolean>;
392
396
  }