@webbio/strapi-plugin-page-builder 0.14.1-platform → 0.14.2-platform

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,10 +1,10 @@
1
1
  import { useQuery, UseQueryOptions } from 'react-query';
2
- import orderBy from 'lodash/orderBy';
3
2
  import objGet from 'lodash/get';
4
3
 
5
4
  import { useFetchClient } from '@strapi/helper-plugin';
6
5
  import qs from 'qs';
7
- import { getConditionalFilters } from '../components/PlatformFilteredSelectField/utils/get-condition-filters';
6
+
7
+ import Fuse from 'fuse.js';
8
8
 
9
9
  export type SearchFilteredEntitiesResult = {
10
10
  pagination: {
@@ -81,32 +81,44 @@ export const getSearchFilteredEntities = async ({
81
81
  });
82
82
 
83
83
  const { data } = await get(`/content-manager/collection-types/${uid}?${filters}`);
84
- const mapResults = data.results.map(
85
- (result: Record<string, any>): SearchFilteredEntitiesResult['results'][number] => {
86
- const getPublicationState = () => {
87
- if (result?.publishedAt !== undefined) {
88
- return result?.publishedAt ? 'published' : 'draft';
89
- }
90
-
91
- return false;
92
- };
93
-
94
- const subTitle = subTitlePath ? objGet(result, subTitlePath) : undefined;
95
-
96
- return {
97
- id: result.id,
98
- title: result?.[mainFieldName],
99
- publicationState: getPublicationState(),
100
- publishedAt: result?.publishedAt,
101
- href: `/content-manager/collectionType/${uid}/${result.id}`,
102
- subTitle: typeof subTitle === 'string' || typeof subTitle === 'number' ? String(subTitle) : ''
103
- };
84
+ let results = data.results;
85
+
86
+ if (searchQuery) {
87
+ const fuse = new Fuse(data.results, {
88
+ keys: searchableFields
89
+ });
90
+
91
+ const fuseSearch = fuse.search(searchQuery);
92
+
93
+ if (fuseSearch && fuseSearch.length > 0) {
94
+ results = fuseSearch.map((r) => r.item);
104
95
  }
105
- );
96
+ }
97
+
98
+ const mapResults = results.map((result: Record<string, any>): SearchFilteredEntitiesResult['results'][number] => {
99
+ const getPublicationState = () => {
100
+ if (result?.publishedAt !== undefined) {
101
+ return result?.publishedAt ? 'published' : 'draft';
102
+ }
103
+
104
+ return false;
105
+ };
106
+
107
+ const subTitle = subTitlePath ? objGet(result, subTitlePath) : undefined;
108
+
109
+ return {
110
+ id: result.id,
111
+ title: result?.[mainFieldName],
112
+ publicationState: getPublicationState(),
113
+ publishedAt: result?.publishedAt,
114
+ href: `/content-manager/collectionType/${uid}/${result.id}`,
115
+ subTitle: typeof subTitle === 'string' || typeof subTitle === 'number' ? String(subTitle) : ''
116
+ };
117
+ });
106
118
 
107
119
  return {
108
120
  pagination: data.pagination,
109
- results: orderBy(mapResults, ['title'], ['asc'])
121
+ results: mapResults
110
122
  };
111
123
  } catch (e) {
112
124
  return {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.14.1-platform",
3
+ "version": "0.14.2-platform",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -31,6 +31,7 @@
31
31
  "@strapi/utils": "^4.15.0",
32
32
  "add": "^2.0.6",
33
33
  "aws-sdk": "^2.1528.0",
34
+ "fuse.js": "^7.0.0",
34
35
  "handlebars": "^4.7.8",
35
36
  "react-select": "^5.7.4",
36
37
  "sitemap": "^7.1.1"