@webbio/strapi-plugin-page-builder 0.2.2 → 0.2.4

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.
Files changed (93) hide show
  1. package/README.md +98 -98
  2. package/admin/src/api/collection-type.ts +110 -110
  3. package/admin/src/api/has-page-relation.ts +34 -34
  4. package/admin/src/api/page-type.ts +31 -31
  5. package/admin/src/api/template.ts +27 -27
  6. package/admin/src/components/Combobox/index.tsx +77 -77
  7. package/admin/src/components/Combobox/react-select-custom-styles.tsx +120 -111
  8. package/admin/src/components/Combobox/styles.ts +22 -22
  9. package/admin/src/components/ConfirmModal/index.tsx +90 -90
  10. package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +124 -124
  11. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +104 -101
  12. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +19 -19
  13. package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +74 -74
  14. package/admin/src/components/EditView/Details/index.tsx +47 -47
  15. package/admin/src/components/EditView/Details/styles.ts +51 -51
  16. package/admin/src/components/EditView/PageSettings/index.tsx +104 -104
  17. package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -36
  18. package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +69 -69
  19. package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +38 -38
  20. package/admin/src/components/EditView/index.tsx +29 -29
  21. package/admin/src/components/EditView/page-type-select.tsx +32 -32
  22. package/admin/src/components/EditView/wrapper.tsx +35 -35
  23. package/admin/src/components/Initializer/index.tsx +24 -24
  24. package/admin/src/components/PageTypeFilter/index.tsx +17 -17
  25. package/admin/src/components/PageTypeFilter/page-type-filter.tsx +130 -130
  26. package/admin/src/components/PluginIcon/index.tsx +12 -12
  27. package/admin/src/constants.ts +3 -3
  28. package/admin/src/index.tsx +59 -59
  29. package/admin/src/middlewares/index.tsx +37 -37
  30. package/admin/src/pluginId.ts +5 -5
  31. package/admin/src/translations/en.json +6 -6
  32. package/admin/src/translations/nl.json +6 -6
  33. package/admin/src/utils/getRequestUrl.ts +11 -11
  34. package/admin/src/utils/getTrad.ts +5 -5
  35. package/admin/src/utils/hooks/useDebounce.ts +17 -17
  36. package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -9
  37. package/admin/src/utils/hooks/usePrevious.ts +12 -12
  38. package/admin/src/utils/sanitizeModules.ts +43 -10
  39. package/custom.d.ts +5 -5
  40. package/dist/package.json +9 -9
  41. package/dist/server/graphql/page-by-slug.js +9 -9
  42. package/dist/server/graphql/pages-by-uid.js +14 -14
  43. package/dist/server/services/builder.js +7 -4
  44. package/dist/server/services/template.js +1 -2
  45. package/dist/server/utils/graphql.js +18 -18
  46. package/dist/server/utils/strapi.js +1 -4
  47. package/dist/tsconfig.server.tsbuildinfo +1 -1
  48. package/package.json +71 -71
  49. package/server/bootstrap/collection-type-lifecycles.ts +47 -47
  50. package/server/bootstrap/permissions.ts +42 -42
  51. package/server/bootstrap.ts +198 -198
  52. package/server/config/index.ts +4 -4
  53. package/server/content-types/index.ts +1 -1
  54. package/server/controllers/collection-types.ts +27 -27
  55. package/server/controllers/index.ts +11 -11
  56. package/server/controllers/page-type.ts +13 -13
  57. package/server/controllers/page.ts +9 -9
  58. package/server/controllers/template.ts +16 -16
  59. package/server/destroy.ts +5 -5
  60. package/server/graphql/index.ts +9 -9
  61. package/server/graphql/page-by-slug.ts +98 -98
  62. package/server/graphql/page-type.ts +67 -67
  63. package/server/graphql/pages-by-uid.ts +127 -127
  64. package/server/index.ts +23 -23
  65. package/server/middlewares/index.ts +1 -1
  66. package/server/policies/index.ts +1 -1
  67. package/server/register.ts +15 -15
  68. package/server/routes/index.ts +58 -58
  69. package/server/schema/page-end.json +91 -91
  70. package/server/schema/page-start.json +87 -87
  71. package/server/schema/page-type-end.json +43 -43
  72. package/server/schema/page-type-start.json +38 -38
  73. package/server/schema/template-start.json +35 -35
  74. package/server/services/builder.ts +137 -134
  75. package/server/services/collection-types.ts +88 -88
  76. package/server/services/index.ts +13 -13
  77. package/server/services/page-type.ts +26 -26
  78. package/server/services/page.ts +24 -24
  79. package/server/services/template.ts +13 -14
  80. package/server/utils/filter-underscore-arguments.ts +12 -12
  81. package/server/utils/graphql.ts +113 -113
  82. package/server/utils/paginationValidation.ts +39 -39
  83. package/server/utils/reload-strapi-on-load.ts +13 -13
  84. package/server/utils/strapi.ts +45 -49
  85. package/shared/utils/constants.ts +4 -4
  86. package/shared/utils/sleep.ts +1 -1
  87. package/strapi-admin.js +3 -3
  88. package/strapi-server.js +3 -3
  89. package/tsconfig.json +20 -20
  90. package/tsconfig.server.json +25 -25
  91. package/dist/server/controllers/platform.js +0 -20
  92. package/dist/server/schema/platform-start.json +0 -31
  93. package/dist/server/services/platform.js +0 -36
@@ -1,38 +1,38 @@
1
- import { Template, useGetTemplates } from '../../../../api/template';
2
- import { sanitizeModules } from '../../../../utils/sanitizeModules';
3
- import { useFetchClient } from '@strapi/helper-plugin';
4
- import getRequestUrl from '../../../../utils/getRequestUrl';
5
-
6
- type OnChangeFormType = (props: { target: Record<string, any>; shouldSetInitialValue: boolean }) => void;
7
-
8
- export const useTemplateModules = (onChange: OnChangeFormType) => {
9
- const { data: templates } = useGetTemplates({});
10
- const fetchClient = useFetchClient();
11
-
12
- return {
13
- findTemplate,
14
- templates,
15
- replaceContentTypeModules: (id: number) => replaceContentTypeModules(id, fetchClient, onChange)
16
- };
17
- };
18
-
19
- const findTemplate = (templates?: Template[], selectedTemplateId?: string | number) =>
20
- templates?.find((template) => template.id === Number(selectedTemplateId));
21
-
22
- const sanatizeContentTypeModules = (onChange: OnChangeFormType, modules: Record<string, any>[]) => {
23
- const sanitizedModules = sanitizeModules(modules);
24
-
25
- return onChange({
26
- target: {
27
- name: 'modules',
28
- value: sanitizedModules
29
- },
30
- shouldSetInitialValue: true
31
- });
32
- };
33
-
34
- const replaceContentTypeModules = async (id: number, fetchClient: any, onChange: OnChangeFormType) => {
35
- const { get } = fetchClient;
36
- const result = await get(getRequestUrl(`/template/${id}`));
37
- return sanatizeContentTypeModules(onChange, result.data.modules);
38
- };
1
+ import { Template, useGetTemplates } from '../../../../api/template';
2
+ import { sanitizeModules } from '../../../../utils/sanitizeModules';
3
+ import { useFetchClient } from '@strapi/helper-plugin';
4
+ import getRequestUrl from '../../../../utils/getRequestUrl';
5
+
6
+ type OnChangeFormType = (props: { target: Record<string, any>; shouldSetInitialValue: boolean }) => void;
7
+
8
+ export const useTemplateModules = (onChange: OnChangeFormType) => {
9
+ const { data: templates } = useGetTemplates({});
10
+ const fetchClient = useFetchClient();
11
+
12
+ return {
13
+ findTemplate,
14
+ templates,
15
+ replaceContentTypeModules: (id: number) => replaceContentTypeModules(id, fetchClient, onChange)
16
+ };
17
+ };
18
+
19
+ const findTemplate = (templates?: Template[], selectedTemplateId?: string | number) =>
20
+ templates?.find((template) => template.id === Number(selectedTemplateId));
21
+
22
+ const sanatizeContentTypeModules = (onChange: OnChangeFormType, modules: Record<string, any>[]) => {
23
+ const sanitizedModules = sanitizeModules(modules);
24
+
25
+ return onChange({
26
+ target: {
27
+ name: 'modules',
28
+ value: sanitizedModules
29
+ },
30
+ shouldSetInitialValue: true
31
+ });
32
+ };
33
+
34
+ const replaceContentTypeModules = async (id: number, fetchClient: any, onChange: OnChangeFormType) => {
35
+ const { get } = fetchClient;
36
+ const result = await get(getRequestUrl(`/template/${id}`));
37
+ return sanatizeContentTypeModules(onChange, result.data.modules);
38
+ };
@@ -1,29 +1,29 @@
1
- import React from 'react';
2
-
3
- import { useCMEditViewDataManager } from '@strapi/helper-plugin';
4
-
5
- import { PAGE_UID } from '../../../../shared/utils/constants';
6
- import { PageSettings } from './PageSettings';
7
- import { CollectionTypeSettings } from './CollectionTypeSettings';
8
- import { useHasPageRelation } from '../../api/has-page-relation';
9
-
10
- export const EditView = () => {
11
- const { layout } = useCMEditViewDataManager();
12
-
13
- const isPageCollectionType = layout.uid === PAGE_UID;
14
- const isCollectionType = layout.kind === 'collectionType';
15
-
16
- const { data: hasPageRelation, isLoading } = useHasPageRelation({
17
- uid: layout.uid
18
- });
19
-
20
- if (isPageCollectionType) {
21
- return <PageSettings />;
22
- }
23
-
24
- if (isCollectionType && !isLoading && hasPageRelation) {
25
- return <CollectionTypeSettings />;
26
- }
27
-
28
- return null;
29
- };
1
+ import React from 'react';
2
+
3
+ import { useCMEditViewDataManager } from '@strapi/helper-plugin';
4
+
5
+ import { PAGE_UID } from '../../../../shared/utils/constants';
6
+ import { PageSettings } from './PageSettings';
7
+ import { CollectionTypeSettings } from './CollectionTypeSettings';
8
+ import { useHasPageRelation } from '../../api/has-page-relation';
9
+
10
+ export const EditView = () => {
11
+ const { layout } = useCMEditViewDataManager() as any;
12
+
13
+ const isPageCollectionType = layout.uid === PAGE_UID;
14
+ const isCollectionType = layout.kind === 'collectionType';
15
+
16
+ const { data: hasPageRelation, isLoading } = useHasPageRelation({
17
+ uid: layout.uid
18
+ });
19
+
20
+ if (isPageCollectionType) {
21
+ return <PageSettings />;
22
+ }
23
+
24
+ if (isCollectionType && !isLoading && hasPageRelation) {
25
+ return <CollectionTypeSettings />;
26
+ }
27
+
28
+ return null;
29
+ };
@@ -1,32 +1,32 @@
1
- import React from 'react';
2
-
3
- import { SingleSelect, SingleSelectOption } from '@strapi/design-system';
4
-
5
- import { PageType } from '../../api/page-type';
6
- import { PAGE_TYPE_PAGE } from '../../../../shared/utils/constants';
7
-
8
- interface Props {
9
- onChange: (pageTypeId: string) => void;
10
- selectedPageType?: PageType | null;
11
- pageTypes?: PageType[];
12
- disabled?: boolean;
13
- }
14
-
15
- export const PageTypeSelect = ({ onChange, pageTypes, selectedPageType, disabled }: Props) => {
16
- return (
17
- <SingleSelect
18
- label="Page type"
19
- placeholder="Choose a page type"
20
- value={selectedPageType?.id || PAGE_TYPE_PAGE}
21
- onChange={onChange}
22
- disabled={disabled}
23
- >
24
- <SingleSelectOption value={PAGE_TYPE_PAGE}>Page</SingleSelectOption>
25
- {pageTypes?.map((pageType: PageType) => (
26
- <SingleSelectOption key={pageType?.uid} value={pageType?.id}>
27
- {pageType?.title}
28
- </SingleSelectOption>
29
- ))}
30
- </SingleSelect>
31
- );
32
- };
1
+ import React from 'react';
2
+
3
+ import { SingleSelect, SingleSelectOption } from '@strapi/design-system';
4
+
5
+ import { PageType } from '../../api/page-type';
6
+ import { PAGE_TYPE_PAGE } from '../../../../shared/utils/constants';
7
+
8
+ interface Props {
9
+ onChange: (pageTypeId: string) => void;
10
+ selectedPageType?: PageType | null;
11
+ pageTypes?: PageType[];
12
+ disabled?: boolean;
13
+ }
14
+
15
+ export const PageTypeSelect = ({ onChange, pageTypes, selectedPageType, disabled }: Props) => {
16
+ return (
17
+ <SingleSelect
18
+ label="Page type"
19
+ placeholder="Choose a page type"
20
+ value={selectedPageType?.id || PAGE_TYPE_PAGE}
21
+ onChange={onChange}
22
+ disabled={Boolean(disabled)}
23
+ >
24
+ <SingleSelectOption value={PAGE_TYPE_PAGE}>Page</SingleSelectOption>
25
+ {pageTypes?.map((pageType: PageType) => (
26
+ <SingleSelectOption key={pageType?.uid} value={pageType?.id}>
27
+ {pageType?.title}
28
+ </SingleSelectOption>
29
+ ))}
30
+ </SingleSelect>
31
+ );
32
+ };
@@ -1,35 +1,35 @@
1
- import React from 'react';
2
- import { Flex, Box, Divider, Typography } from '@strapi/design-system';
3
-
4
- interface Props {
5
- title: string;
6
- children: React.ReactNode;
7
- }
8
-
9
- export const Wrapper = (props: Props) => {
10
- return (
11
- <Flex
12
- as="aside"
13
- direction="column"
14
- background="neutral0"
15
- borderColor="neutral150"
16
- hasRadius={true}
17
- paddingTop={6}
18
- paddingBottom={4}
19
- paddingRight={4}
20
- paddingLeft={4}
21
- shadow="tableShadow"
22
- alignItems="left"
23
- >
24
- <Typography variant="sigma" textColor="neutral600" id="additional-information">
25
- {props.title}
26
- </Typography>
27
-
28
- <Box paddingTop={2} paddingBottom={4}>
29
- <Divider />
30
- </Box>
31
-
32
- {props.children}
33
- </Flex>
34
- );
35
- };
1
+ import React from 'react';
2
+ import { Flex, Box, Divider, Typography } from '@strapi/design-system';
3
+
4
+ interface Props {
5
+ title: string;
6
+ children: React.ReactNode;
7
+ }
8
+
9
+ export const Wrapper = (props: Props) => {
10
+ return (
11
+ <Flex
12
+ as="aside"
13
+ direction="column"
14
+ background="neutral0"
15
+ borderColor="neutral150"
16
+ hasRadius={true}
17
+ paddingTop={6}
18
+ paddingBottom={4}
19
+ paddingRight={4}
20
+ paddingLeft={4}
21
+ shadow="tableShadow"
22
+ alignItems="left"
23
+ >
24
+ <Typography variant="sigma" textColor="neutral600" id="additional-information">
25
+ {props.title}
26
+ </Typography>
27
+
28
+ <Box paddingTop={2} paddingBottom={4}>
29
+ <Divider />
30
+ </Box>
31
+
32
+ {props.children}
33
+ </Flex>
34
+ );
35
+ };
@@ -1,24 +1,24 @@
1
- /**
2
- *
3
- * Initializer
4
- *
5
- */
6
-
7
- import { useEffect, useRef } from 'react';
8
- import pluginId from '../../pluginId';
9
-
10
- type InitializerProps = {
11
- setPlugin: (id: string) => void;
12
- };
13
-
14
- const Initializer = ({ setPlugin }: InitializerProps) => {
15
- const ref = useRef(setPlugin);
16
-
17
- useEffect(() => {
18
- ref.current(pluginId);
19
- }, []);
20
-
21
- return null;
22
- };
23
-
24
- export default Initializer;
1
+ /**
2
+ *
3
+ * Initializer
4
+ *
5
+ */
6
+
7
+ import { useEffect, useRef } from 'react';
8
+ import pluginId from '../../pluginId';
9
+
10
+ type InitializerProps = {
11
+ setPlugin: (id: string) => void;
12
+ };
13
+
14
+ const Initializer = ({ setPlugin }: InitializerProps) => {
15
+ const ref = useRef(setPlugin);
16
+
17
+ useEffect(() => {
18
+ ref.current(pluginId);
19
+ }, []);
20
+
21
+ return null;
22
+ };
23
+
24
+ export default Initializer;
@@ -1,17 +1,17 @@
1
- import React from 'react';
2
- import { useLocation } from 'react-router-dom';
3
-
4
- import { PageTypeFilter } from './page-type-filter';
5
- import { PAGE_UID } from '../../../../shared/utils/constants';
6
-
7
- const PageTypeFilterContainer = () => {
8
- const { pathname } = useLocation();
9
-
10
- if (pathname === `/content-manager/collectionType/${PAGE_UID}`) {
11
- return <PageTypeFilter />;
12
- }
13
-
14
- return null;
15
- };
16
-
17
- export default PageTypeFilterContainer;
1
+ import React from 'react';
2
+ import { useLocation } from 'react-router-dom';
3
+
4
+ import { PageTypeFilter } from './page-type-filter';
5
+ import { PAGE_UID } from '../../../../shared/utils/constants';
6
+
7
+ const PageTypeFilterContainer = () => {
8
+ const { pathname } = useLocation();
9
+
10
+ if (pathname === `/content-manager/collectionType/${PAGE_UID}`) {
11
+ return <PageTypeFilter />;
12
+ }
13
+
14
+ return null;
15
+ };
16
+
17
+ export default PageTypeFilterContainer;
@@ -1,130 +1,130 @@
1
- import React, { useEffect, useState } from 'react';
2
- import set from 'lodash/set';
3
-
4
- import { SingleSelectOption, SingleSelect } from '@strapi/design-system';
5
- import { useQueryParams } from '@strapi/helper-plugin';
6
-
7
- import { useGetPageTypes } from '../../api/page-type';
8
- import { PAGE_TYPE_NO_FILTER } from '../../constants';
9
- import { PAGE_TYPE_PAGE } from '../../../../shared/utils/constants';
10
-
11
- const PageTypeFilter = () => {
12
- const [{ query }, setQuery] = useQueryParams();
13
- const { data: pageTypes } = useGetPageTypes({});
14
- const initialPageTypeUid = getInitialPageType(query, pageTypes);
15
- const [selectedPageTypeUid, setSelectedPageTypeUid] = useState(initialPageTypeUid);
16
-
17
- const removeFilters = () => {
18
- const newAndFilters = query.filters?.$and?.filter(
19
- (x?: Record<string, any>) => Object.keys(x || {})?.[0] !== 'pageType'
20
- );
21
- const filters = { ...query.filters, $and: newAndFilters };
22
-
23
- if (newAndFilters && newAndFilters.length === 0) {
24
- delete filters.$and;
25
- }
26
-
27
- setQuery({
28
- page: 1,
29
- filters
30
- });
31
- };
32
-
33
- const handleFilterChange = (filters: Record<string, any>) => {
34
- const currentFilters = query.filters?.$and ? query.filters : { ...query.filters, $and: [] }; // Make sure $and exists.
35
- const pageTypeFilterIndex = currentFilters.$and.findIndex(
36
- (x?: Record<string, any>) => Object.keys(x || {})?.[0] === 'pageType'
37
- );
38
-
39
- if (pageTypeFilterIndex > -1) {
40
- set(currentFilters, `$and[${pageTypeFilterIndex}]`, filters); // If the pageType filter already exists, replace it
41
- } else {
42
- currentFilters.$and.push(filters);
43
- }
44
-
45
- setQuery({
46
- page: 1,
47
- filters: currentFilters
48
- });
49
- };
50
-
51
- const handleSelect = (value: string) => {
52
- setSelectedPageTypeUid(value);
53
-
54
- if (value === 'all') {
55
- removeFilters();
56
- return;
57
- }
58
-
59
- if (value === PAGE_TYPE_PAGE) {
60
- handleFilterChange(nullPageTypeQueryFilter);
61
- return;
62
- }
63
-
64
- handleFilterChange(getPageTypeQueryFilter(value));
65
- };
66
-
67
- useEffect(() => {
68
- setSelectedPageTypeUid(getInitialPageType(query, pageTypes));
69
- }, [pageTypes]);
70
-
71
- useEffect(() => {
72
- if (!query?.filters) {
73
- setSelectedPageTypeUid(null);
74
- }
75
- }, [query]);
76
-
77
- return (
78
- <SingleSelect placeholder="Select page type" onChange={handleSelect} size="S" value={selectedPageTypeUid}>
79
- <SingleSelectOption key={PAGE_TYPE_NO_FILTER} value={PAGE_TYPE_NO_FILTER}>
80
- All Pagetypes
81
- </SingleSelectOption>
82
- <SingleSelectOption key={PAGE_TYPE_PAGE} value={PAGE_TYPE_PAGE}>
83
- Page
84
- </SingleSelectOption>
85
- {pageTypes?.map((pageType) => (
86
- <SingleSelectOption key={pageType.uid} value={pageType.uid}>
87
- {pageType.title || pageType.uid}
88
- </SingleSelectOption>
89
- ))}
90
- </SingleSelect>
91
- );
92
- };
93
-
94
- export { PageTypeFilter };
95
-
96
- const getPageTypeQueryFilter = (pageType: string) => ({
97
- pageType: {
98
- uid: {
99
- $eq: pageType
100
- }
101
- }
102
- });
103
-
104
- const nullPageTypeQueryFilter = {
105
- pageType: {
106
- uid: {
107
- $null: true
108
- }
109
- }
110
- };
111
-
112
- const getInitialPageType = (query: any, pageTypes: any) => {
113
- const pageTypeFromQuery = query?.filters?.$and?.find(
114
- (x?: Record<string, any>) => Object.keys(x || {})?.[0] === 'pageType'
115
- )?.pageType;
116
-
117
- if (pageTypeFromQuery?.uid?.$null === 'true') {
118
- return PAGE_TYPE_PAGE;
119
- }
120
-
121
- if (pageTypeFromQuery?.uid?.$eq) {
122
- const matchingPageType = pageTypes?.find((pageType: any) => pageType?.uid === pageTypeFromQuery.uid.$eq);
123
-
124
- if (matchingPageType) {
125
- return matchingPageType.uid;
126
- }
127
- }
128
-
129
- return PAGE_TYPE_NO_FILTER;
130
- };
1
+ import React, { useEffect, useState } from 'react';
2
+ import set from 'lodash/set';
3
+
4
+ import { SingleSelectOption, SingleSelect } from '@strapi/design-system';
5
+ import { useQueryParams } from '@strapi/helper-plugin';
6
+
7
+ import { useGetPageTypes } from '../../api/page-type';
8
+ import { PAGE_TYPE_NO_FILTER } from '../../constants';
9
+ import { PAGE_TYPE_PAGE } from '../../../../shared/utils/constants';
10
+
11
+ const PageTypeFilter = () => {
12
+ const [{ query }, setQuery] = useQueryParams() as any;
13
+ const { data: pageTypes } = useGetPageTypes({});
14
+ const initialPageTypeUid = getInitialPageType(query, pageTypes);
15
+ const [selectedPageTypeUid, setSelectedPageTypeUid] = useState(initialPageTypeUid);
16
+
17
+ const removeFilters = () => {
18
+ const newAndFilters = query.filters?.$and?.filter(
19
+ (x?: Record<string, any>) => Object.keys(x || {})?.[0] !== 'pageType'
20
+ );
21
+ const filters = { ...query.filters, $and: newAndFilters };
22
+
23
+ if (newAndFilters && newAndFilters.length === 0) {
24
+ delete filters.$and;
25
+ }
26
+
27
+ setQuery({
28
+ page: 1,
29
+ filters
30
+ });
31
+ };
32
+
33
+ const handleFilterChange = (filters: Record<string, any>) => {
34
+ const currentFilters = query.filters?.$and ? query.filters : { ...query.filters, $and: [] }; // Make sure $and exists.
35
+ const pageTypeFilterIndex = currentFilters.$and.findIndex(
36
+ (x?: Record<string, any>) => Object.keys(x || {})?.[0] === 'pageType'
37
+ );
38
+
39
+ if (pageTypeFilterIndex > -1) {
40
+ set(currentFilters, `$and[${pageTypeFilterIndex}]`, filters); // If the pageType filter already exists, replace it
41
+ } else {
42
+ currentFilters.$and.push(filters);
43
+ }
44
+
45
+ setQuery({
46
+ page: 1,
47
+ filters: currentFilters
48
+ });
49
+ };
50
+
51
+ const handleSelect = (value: string) => {
52
+ setSelectedPageTypeUid(value);
53
+
54
+ if (value === 'all') {
55
+ removeFilters();
56
+ return;
57
+ }
58
+
59
+ if (value === PAGE_TYPE_PAGE) {
60
+ handleFilterChange(nullPageTypeQueryFilter);
61
+ return;
62
+ }
63
+
64
+ handleFilterChange(getPageTypeQueryFilter(value));
65
+ };
66
+
67
+ useEffect(() => {
68
+ setSelectedPageTypeUid(getInitialPageType(query, pageTypes));
69
+ }, [pageTypes]);
70
+
71
+ useEffect(() => {
72
+ if (!query?.filters) {
73
+ setSelectedPageTypeUid(null);
74
+ }
75
+ }, [query]);
76
+
77
+ return (
78
+ <SingleSelect placeholder="Select page type" onChange={handleSelect} size="S" value={selectedPageTypeUid}>
79
+ <SingleSelectOption key={PAGE_TYPE_NO_FILTER} value={PAGE_TYPE_NO_FILTER}>
80
+ Alle Paginatypes
81
+ </SingleSelectOption>
82
+ <SingleSelectOption key={PAGE_TYPE_PAGE} value={PAGE_TYPE_PAGE}>
83
+ Pagina
84
+ </SingleSelectOption>
85
+ {pageTypes?.map((pageType) => (
86
+ <SingleSelectOption key={pageType.uid} value={pageType.uid}>
87
+ {pageType.title || pageType.uid}
88
+ </SingleSelectOption>
89
+ ))}
90
+ </SingleSelect>
91
+ );
92
+ };
93
+
94
+ export { PageTypeFilter };
95
+
96
+ const getPageTypeQueryFilter = (pageType: string) => ({
97
+ pageType: {
98
+ uid: {
99
+ $eq: pageType
100
+ }
101
+ }
102
+ });
103
+
104
+ const nullPageTypeQueryFilter = {
105
+ pageType: {
106
+ uid: {
107
+ $null: true
108
+ }
109
+ }
110
+ };
111
+
112
+ const getInitialPageType = (query: any, pageTypes: any) => {
113
+ const pageTypeFromQuery = query?.filters?.$and?.find(
114
+ (x?: Record<string, any>) => Object.keys(x || {})?.[0] === 'pageType'
115
+ )?.pageType;
116
+
117
+ if (pageTypeFromQuery?.uid?.$null === 'true') {
118
+ return PAGE_TYPE_PAGE;
119
+ }
120
+
121
+ if (pageTypeFromQuery?.uid?.$eq) {
122
+ const matchingPageType = pageTypes?.find((pageType: any) => pageType?.uid === pageTypeFromQuery.uid.$eq);
123
+
124
+ if (matchingPageType) {
125
+ return matchingPageType.uid;
126
+ }
127
+ }
128
+
129
+ return PAGE_TYPE_NO_FILTER;
130
+ };
@@ -1,12 +1,12 @@
1
- /**
2
- *
3
- * PluginIcon
4
- *
5
- */
6
-
7
- import React from 'react';
8
- import { Puzzle } from '@strapi/icons';
9
-
10
- const PluginIcon = () => <Puzzle />;
11
-
12
- export default PluginIcon;
1
+ /**
2
+ *
3
+ * PluginIcon
4
+ *
5
+ */
6
+
7
+ import React from 'react';
8
+ import { Puzzle } from '@strapi/icons';
9
+
10
+ const PluginIcon = () => <Puzzle />;
11
+
12
+ export default PluginIcon;
@@ -1,3 +1,3 @@
1
- export const PAGE_TYPE_NO_FILTER = 'all';
2
- export const PLATFORM_NO_FILTER = 'allPlatforms';
3
- export const PAGE_TYPE = 'pageType';
1
+ export const PAGE_TYPE_NO_FILTER = 'all';
2
+ export const PLATFORM_NO_FILTER = 'allPlatforms';
3
+ export const PAGE_TYPE = 'pageType';