@webbio/strapi-plugin-page-builder 0.14.0-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.
package/README.md CHANGED
@@ -134,14 +134,15 @@ Ik wil een lijst van vacature relaties selecteren. Deze vacatures moeten van het
134
134
  "targetField": "vacatures",
135
135
  // (Default: undefined) Adds filters to the $and query for result filtering
136
136
  "customFilters": [{ "title": { "$contains": "Hoi" } }],
137
- // (Default: true). Disables result filtering by globally selected platform
137
+ // (Default: false). Disables result filtering by globally selected platform
138
138
  "disablePlatformFilter": boolean,
139
139
  // (Default: false) Hides id of the entity that is edited if it's the same as the targetField uid. So if this is enabled on a vacancy entity and also targets other vacancies, the current vacancy that is edited will not be shown.
140
140
  "hideSameEntity": boolean,
141
141
  // (Default: ['title']) Defines searchable fields
142
142
  "searchableFields": string[],
143
- // If set the field will show a subtitle with the value that results in following this path.
143
+ // (Default: undefined) If set the field will show a subtitle with the value that results in following this path.
144
144
  "subTitlePath": string,
145
+ // (Default: undefined)
145
146
  // Conditional filters add the posibility to who results based on values from other fields.
146
147
  // For now this only works for fields on the same level as the targetfield.
147
148
  // The value found will be replacing the '${value}' string.
@@ -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 {
@@ -34,7 +34,7 @@ const CustomOption = styled(Box)`
34
34
  const CustomOptionSubTitle = styled(Box)`
35
35
  ${({ theme, disabled }) => css`
36
36
  font-size: ${theme.fontSizes[1]};
37
- opacity: 0.5;
37
+ color: ${theme.colors.neutral400};
38
38
  white-space: nowrap;
39
39
  overflow: hidden;
40
40
  text-overflow: ellipsis;
@@ -312,8 +312,7 @@ const RelationInput = ({
312
312
  onRelationDisconnect,
313
313
  publicationStateTranslations,
314
314
  relations,
315
- updatePositionOfRelation: handleUpdatePositionOfRelation,
316
- subTitle: 'ho'
315
+ updatePositionOfRelation: handleUpdatePositionOfRelation
317
316
  }}
318
317
  itemKey={(index) => `${relations[index].mainField}_${relations[index].id}`}
319
318
  innerElementType="ol"
@@ -452,7 +451,6 @@ interface ListItemProps extends Pick<RelationItemProps, 'index' | 'style'> {
452
451
  published: string;
453
452
  };
454
453
  relations: NormalizedRelation[];
455
- subTitle?: string;
456
454
  };
457
455
  }
458
456
 
@@ -472,7 +470,7 @@ const ListItem = ({ data, index, style }: ListItemProps) => {
472
470
  relations,
473
471
  updatePositionOfRelation
474
472
  } = data;
475
- const { publicationState, href, mainField, id } = relations[index];
473
+ const { publicationState, href, mainField, id, subTitle } = relations[index];
476
474
  const statusColor = publicationState === 'draft' ? 'secondary' : 'success';
477
475
 
478
476
  return (
@@ -512,14 +510,14 @@ const ListItem = ({ data, index, style }: ListItemProps) => {
512
510
  {href ? (
513
511
  <Flex direction="column" alignItems="start" gap={0}>
514
512
  <LinkEllipsis to={href}>{mainField ?? id}</LinkEllipsis>
515
- {data?.subTitle && <S.CustomOptionSubTitle>{data.subTitle}</S.CustomOptionSubTitle>}
513
+ {subTitle && <S.CustomOptionSubTitle>{subTitle}</S.CustomOptionSubTitle>}
516
514
  </Flex>
517
515
  ) : (
518
516
  <Flex direction="column" alignItems="start" gap={0}>
519
517
  <Typography textColor={disabled ? 'neutral600' : 'primary600'} ellipsis>
520
518
  {mainField ?? id}
521
519
  </Typography>
522
- {data?.subTitle && <S.CustomOptionSubTitle>{data.subTitle}</S.CustomOptionSubTitle>}
520
+ {subTitle && <S.CustomOptionSubTitle>{subTitle}</S.CustomOptionSubTitle>}
523
521
  </Flex>
524
522
  )}
525
523
  </Tooltip>
@@ -15,6 +15,7 @@ export type NormalizedRelation = Contracts.Relations.RelationResult & {
15
15
  href?: string;
16
16
  mainField: string;
17
17
  publicationState?: false | 'published' | 'draft';
18
+ subTitle?: string;
18
19
  };
19
20
 
20
21
  export const normalizeRelation = (
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.14.0-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"