@webbio/strapi-plugin-page-builder 0.3.6-platform → 0.3.7-legacy
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 +101 -91
- package/admin/src/api/collection-type.ts +1 -7
- package/admin/src/api/page-type.ts +4 -5
- package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +12 -15
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +42 -34
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +37 -61
- package/admin/src/components/EditView/Details/index.tsx +1 -1
- package/admin/src/components/EditView/PageSettings/index.tsx +5 -60
- package/admin/src/components/PageTypeFilter/index.tsx +17 -0
- package/admin/src/components/PageTypeFilter/page-type-filter.tsx +130 -0
- package/admin/src/index.tsx +2 -2
- package/admin/src/utils/sanitizeModules.ts +92 -9
- package/custom.d.ts +5 -5
- package/dist/package.json +16 -10
- package/dist/server/bootstrap/permissions.js +10 -68
- package/dist/server/bootstrap.js +33 -45
- package/dist/server/controllers/index.js +1 -3
- package/dist/server/controllers/page.js +19 -0
- package/dist/server/controllers/platform.js +5 -5
- package/dist/server/graphql/index.js +2 -2
- package/dist/server/graphql/page-by-path.js +17 -16
- package/dist/server/graphql/page-by-slug.js +37 -44
- package/dist/server/graphql/pages-by-uid.js +9 -11
- package/dist/server/register.js +2 -2
- package/dist/server/routes/index.js +5 -21
- package/dist/server/schema/page-end.json +0 -5
- package/dist/server/schema/platform-start.json +0 -10
- package/dist/server/schema/template-end.json +40 -0
- package/dist/server/services/builder.js +5 -15
- package/dist/server/services/index.js +1 -3
- package/dist/server/services/platform.js +6 -11
- package/dist/server/services/template.js +1 -2
- package/dist/server/utils/strapi.js +1 -4
- package/dist/shared/utils/constants.js +1 -3
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +76 -70
- package/server/bootstrap/collection-type-lifecycles.ts +1 -1
- package/server/bootstrap/permissions.ts +10 -75
- package/server/bootstrap.ts +45 -58
- package/server/controllers/index.ts +1 -3
- package/server/controllers/page.ts +24 -0
- package/server/graphql/index.ts +2 -2
- package/server/graphql/page-by-slug.ts +98 -0
- package/server/graphql/pages-by-uid.ts +9 -11
- package/server/register.ts +2 -2
- package/server/routes/index.ts +5 -21
- package/server/schema/page-end.json +0 -5
- package/server/services/builder.ts +6 -18
- package/server/services/index.ts +1 -3
- package/server/services/template.ts +1 -2
- package/server/utils/strapi.ts +1 -5
- package/shared/utils/constants.ts +4 -6
- package/shared/utils/sleep.ts +1 -1
- package/strapi-admin.js +3 -3
- package/strapi-server.js +3 -3
- package/tsconfig.json +20 -20
- package/tsconfig.server.json +25 -25
- package/admin/src/api/platform-page-types.ts +0 -40
- package/admin/src/api/platform.ts +0 -34
- package/admin/src/components/EditView/Platform/platform-select.tsx +0 -30
- package/admin/src/components/PageFilters/PageTypeFilter/index.tsx +0 -39
- package/admin/src/components/PageFilters/PlatformFilter/index.tsx +0 -28
- package/admin/src/components/PageFilters/filters.tsx +0 -180
- package/admin/src/components/PageFilters/index.tsx +0 -30
- package/server/controllers/platform.ts +0 -21
- package/server/graphql/page-by-path.ts +0 -105
- package/server/schema/platform-start.json +0 -31
- package/server/services/platform.ts +0 -36
|
@@ -4,14 +4,13 @@ import { Common } from '@strapi/strapi';
|
|
|
4
4
|
import pageStart from '../schema/page-start.json';
|
|
5
5
|
import pageEnd from '../schema/page-end.json';
|
|
6
6
|
import pluginId from '../../admin/src/pluginId';
|
|
7
|
-
import { PAGE_UID, TEMPLATE_UID, PAGE_TYPE_UID
|
|
7
|
+
import { PAGE_UID, TEMPLATE_UID, PAGE_TYPE_UID } from '../../shared/utils/constants';
|
|
8
8
|
import { reloadStrapiOnLoad } from '../utils/reload-strapi-on-load';
|
|
9
9
|
import pageTypeStart from '../schema/page-type-start.json';
|
|
10
10
|
import pageTypeEnd from '../schema/page-type-end.json';
|
|
11
11
|
import templateStart from '../schema/template-start.json';
|
|
12
|
-
import platformStart from '../schema/platform-start.json';
|
|
13
12
|
|
|
14
|
-
const UIDS: Common.UID.ContentType[] = [TEMPLATE_UID, PAGE_TYPE_UID,
|
|
13
|
+
const UIDS: Common.UID.ContentType[] = [TEMPLATE_UID, PAGE_TYPE_UID, PAGE_UID];
|
|
15
14
|
|
|
16
15
|
export default {
|
|
17
16
|
async buildContentTypes() {
|
|
@@ -88,10 +87,6 @@ export default {
|
|
|
88
87
|
[TEMPLATE_UID]: {
|
|
89
88
|
create: this.getTemplateContentType(),
|
|
90
89
|
update: this.getTemplateContentType()
|
|
91
|
-
},
|
|
92
|
-
[PLATFORM_UID]: {
|
|
93
|
-
create: this.getPlatformContentType(),
|
|
94
|
-
update: this.getPlatformContentType()
|
|
95
90
|
}
|
|
96
91
|
};
|
|
97
92
|
|
|
@@ -99,30 +94,23 @@ export default {
|
|
|
99
94
|
},
|
|
100
95
|
getPageContentType(create?: boolean) {
|
|
101
96
|
const page = create ? pageStart : pageEnd;
|
|
102
|
-
const contentType = this.
|
|
97
|
+
const contentType = this.mergeCollectionTypeWithModules(page, PAGE_UID);
|
|
103
98
|
|
|
104
99
|
return { uid: PAGE_UID, contentType };
|
|
105
100
|
},
|
|
106
101
|
getPageTypeContentType(create?: boolean) {
|
|
107
102
|
const pageType = create ? pageTypeStart : pageTypeEnd;
|
|
108
|
-
const contentType = this.
|
|
103
|
+
const contentType = this.mergeCollectionTypeWithModules(pageType, PAGE_TYPE_UID);
|
|
109
104
|
|
|
110
105
|
return { uid: PAGE_TYPE_UID, contentType };
|
|
111
106
|
},
|
|
112
107
|
getTemplateContentType() {
|
|
113
108
|
const template = templateStart;
|
|
114
|
-
const contentType = this.
|
|
109
|
+
const contentType = this.mergeCollectionTypeWithModules(template, TEMPLATE_UID);
|
|
115
110
|
|
|
116
111
|
return { uid: TEMPLATE_UID, contentType };
|
|
117
112
|
},
|
|
118
|
-
|
|
119
|
-
const platform = platformStart;
|
|
120
|
-
|
|
121
|
-
const contentType = this.mergeCollectionTypeWithOld(platform, PLATFORM_UID);
|
|
122
|
-
|
|
123
|
-
return { uid: PLATFORM_UID, contentType };
|
|
124
|
-
},
|
|
125
|
-
mergeCollectionTypeWithOld(collectionType: Record<string, any>, uid: Common.UID.ContentType) {
|
|
113
|
+
mergeCollectionTypeWithModules(collectionType: Record<string, any>, uid: Common.UID.ContentType) {
|
|
126
114
|
const { pluginOptions: oldPluginOptions, __schema__: oldSchema } = (strapi.contentType(uid) as any) || {};
|
|
127
115
|
const modulesFromConfig = oldSchema?.attributes?.modules ? this.getConfigModuleComponents() : undefined;
|
|
128
116
|
|
package/server/services/index.ts
CHANGED
|
@@ -3,13 +3,11 @@ import builder from './builder';
|
|
|
3
3
|
import pageType from './page-type';
|
|
4
4
|
import collectionTypes from './collection-types';
|
|
5
5
|
import template from './template';
|
|
6
|
-
import platform from './platform';
|
|
7
6
|
|
|
8
7
|
export default {
|
|
9
8
|
page,
|
|
10
9
|
builder,
|
|
11
10
|
'page-type': pageType,
|
|
12
11
|
'collection-types': collectionTypes,
|
|
13
|
-
template
|
|
14
|
-
platform
|
|
12
|
+
template
|
|
15
13
|
};
|
package/server/utils/strapi.ts
CHANGED
|
@@ -14,17 +14,13 @@ export const getDeepPopulate = (uid: Common.UID.Component, populate?: any, depth
|
|
|
14
14
|
return Object.keys(attributes).reduce((populateAcc, attributeName) => {
|
|
15
15
|
const attribute = attributes[attributeName];
|
|
16
16
|
|
|
17
|
-
if (attribute.type === 'relation') {
|
|
18
|
-
return populateAcc;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
17
|
if (attribute.type === 'component') {
|
|
22
18
|
populateAcc[attributeName] = {
|
|
23
19
|
populate: getDeepPopulate(attribute.component, null, depth + 1)
|
|
24
20
|
};
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
if (attribute.type === 'media') {
|
|
23
|
+
if (attribute.type === 'relation' || attribute.type === 'media') {
|
|
28
24
|
populateAcc[attributeName] = true;
|
|
29
25
|
}
|
|
30
26
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export const PAGE_UID = 'api::page.page';
|
|
2
|
-
export const TEMPLATE_UID = 'api::template.template';
|
|
3
|
-
export const PAGE_TYPE_UID = 'api::page-type.page-type';
|
|
4
|
-
export const
|
|
5
|
-
export const PAGE_TYPE_PAGE = 'page';
|
|
6
|
-
export const PLATFORM = 'platform';
|
|
1
|
+
export const PAGE_UID = 'api::page.page';
|
|
2
|
+
export const TEMPLATE_UID = 'api::template.template';
|
|
3
|
+
export const PAGE_TYPE_UID = 'api::page-type.page-type';
|
|
4
|
+
export const PAGE_TYPE_PAGE = 'page';
|
package/shared/utils/sleep.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
1
|
+
export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
package/strapi-admin.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = require('./admin/src').default;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = require('./admin/src').default;
|
package/strapi-server.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = require('./dist/server');
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = require('./dist/server');
|
package/tsconfig.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@strapi/typescript-utils/tsconfigs/admin",
|
|
3
|
-
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"strict": true
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
"include": ["admin", "custom.d.ts"],
|
|
10
|
-
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules/",
|
|
13
|
-
"dist/",
|
|
14
|
-
|
|
15
|
-
// Do not include server files in the server compilation
|
|
16
|
-
"server/",
|
|
17
|
-
// Do not include test files
|
|
18
|
-
"**/*.test.ts"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "@strapi/typescript-utils/tsconfigs/admin",
|
|
3
|
+
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"strict": true
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
"include": ["admin", "custom.d.ts"],
|
|
10
|
+
|
|
11
|
+
"exclude": [
|
|
12
|
+
"node_modules/",
|
|
13
|
+
"dist/",
|
|
14
|
+
|
|
15
|
+
// Do not include server files in the server compilation
|
|
16
|
+
"server/",
|
|
17
|
+
// Do not include test files
|
|
18
|
+
"**/*.test.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|
package/tsconfig.server.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@strapi/typescript-utils/tsconfigs/server",
|
|
3
|
-
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"rootDir": "."
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
"include": [
|
|
10
|
-
// Include the root directory
|
|
11
|
-
"server",
|
|
12
|
-
// Force the JSON files in the src folder to be included
|
|
13
|
-
"server/**/*.json"
|
|
14
|
-
],
|
|
15
|
-
|
|
16
|
-
"exclude": [
|
|
17
|
-
"node_modules/",
|
|
18
|
-
"dist/",
|
|
19
|
-
|
|
20
|
-
// Do not include admin files in the server compilation
|
|
21
|
-
"admin/",
|
|
22
|
-
// Do not include test files
|
|
23
|
-
"**/*.test.ts"
|
|
24
|
-
]
|
|
25
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "@strapi/typescript-utils/tsconfigs/server",
|
|
3
|
+
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"rootDir": "."
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
"include": [
|
|
10
|
+
// Include the root directory
|
|
11
|
+
"server",
|
|
12
|
+
// Force the JSON files in the src folder to be included
|
|
13
|
+
"server/**/*.json"
|
|
14
|
+
],
|
|
15
|
+
|
|
16
|
+
"exclude": [
|
|
17
|
+
"node_modules/",
|
|
18
|
+
"dist/",
|
|
19
|
+
|
|
20
|
+
// Do not include admin files in the server compilation
|
|
21
|
+
"admin/",
|
|
22
|
+
// Do not include test files
|
|
23
|
+
"**/*.test.ts"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useQuery } from 'react-query';
|
|
2
|
-
|
|
3
|
-
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
|
-
|
|
5
|
-
import { PageType } from './page-type';
|
|
6
|
-
|
|
7
|
-
const QUERY_KEY = 'pageTypesForPlatform';
|
|
8
|
-
|
|
9
|
-
const fetchPageTypesForPlatform = async ({ fetchClient, id }: Record<string, any>): Promise<PageType[]> => {
|
|
10
|
-
if (!id) return [];
|
|
11
|
-
|
|
12
|
-
const { get } = fetchClient;
|
|
13
|
-
const pageTypesByPlatformResult = await get(
|
|
14
|
-
`/content-manager/relations/api::platform.platform/${id}/pageTypes?page=1&pageSize=100`
|
|
15
|
-
);
|
|
16
|
-
const pageTypesResult = await get(`/content-manager/collection-types/api::page-type.page-type?page=1&pageSize=100`);
|
|
17
|
-
|
|
18
|
-
return pageTypesByPlatformResult?.data?.results?.map((entity: Record<string, any>) => {
|
|
19
|
-
const fullPageType = pageTypesResult?.data?.results?.find(
|
|
20
|
-
(pageType: Record<string, any>) => pageType.id === entity.id
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
id: entity.id,
|
|
25
|
-
uid: fullPageType.uid,
|
|
26
|
-
title: fullPageType.title,
|
|
27
|
-
templateId: fullPageType?.template?.id
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const useGetPageTypesForPlatform = (params: Record<string, any>) => {
|
|
33
|
-
const fetchClient = useFetchClient();
|
|
34
|
-
params = {
|
|
35
|
-
...params,
|
|
36
|
-
fetchClient
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return useQuery<PageType[], Error>([QUERY_KEY, params?.id], () => fetchPageTypesForPlatform(params));
|
|
40
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { useQuery } from 'react-query';
|
|
2
|
-
|
|
3
|
-
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
|
-
|
|
5
|
-
import { PageType } from './page-type';
|
|
6
|
-
|
|
7
|
-
export type Platform = {
|
|
8
|
-
id: number;
|
|
9
|
-
title?: string;
|
|
10
|
-
pageTypes?: PageType[];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const QUERY_KEY = 'platforms';
|
|
14
|
-
|
|
15
|
-
const fetchPlatforms = async ({ fetchClient }: Record<string, any>): Promise<Platform[]> => {
|
|
16
|
-
const { get } = fetchClient;
|
|
17
|
-
const result = await get('/content-manager/collection-types/api::platform.platform?page=1&pageSize=100');
|
|
18
|
-
|
|
19
|
-
return result?.data?.results.map((entity: Record<string, any>) => ({
|
|
20
|
-
id: entity.id,
|
|
21
|
-
title: entity.title,
|
|
22
|
-
pageTypes: entity.pageTypes
|
|
23
|
-
}));
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const useGetPlatforms = (params: Record<string, any>) => {
|
|
27
|
-
const fetchClient = useFetchClient();
|
|
28
|
-
params = {
|
|
29
|
-
...params,
|
|
30
|
-
fetchClient
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return useQuery<Platform[], Error>(QUERY_KEY, () => fetchPlatforms(params));
|
|
34
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { SingleSelect, SingleSelectOption } from '@strapi/design-system';
|
|
4
|
-
|
|
5
|
-
import { Platform } from '../../../api/platform';
|
|
6
|
-
import { PLATFORM } from '../../../../../shared/utils/constants';
|
|
7
|
-
|
|
8
|
-
interface Props {
|
|
9
|
-
onChange: (platformId: string) => void;
|
|
10
|
-
selectedPlatform?: Platform | null;
|
|
11
|
-
platforms?: Platform[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const PlatformSelect = ({ onChange, platforms, selectedPlatform }: Props) => {
|
|
15
|
-
return (
|
|
16
|
-
<SingleSelect
|
|
17
|
-
label="Platform"
|
|
18
|
-
placeholder="Choose a platform"
|
|
19
|
-
value={selectedPlatform?.id || PLATFORM}
|
|
20
|
-
onChange={onChange}
|
|
21
|
-
>
|
|
22
|
-
<SingleSelectOption value={PLATFORM}>Platform</SingleSelectOption>
|
|
23
|
-
{platforms?.map((pageType: Platform) => (
|
|
24
|
-
<SingleSelectOption key={pageType?.id} value={pageType?.id}>
|
|
25
|
-
{pageType?.title}
|
|
26
|
-
</SingleSelectOption>
|
|
27
|
-
))}
|
|
28
|
-
</SingleSelect>
|
|
29
|
-
);
|
|
30
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { SingleSelectOption, SingleSelect } from '@strapi/design-system';
|
|
4
|
-
|
|
5
|
-
import { PageType } from '../../../api/page-type';
|
|
6
|
-
import { PAGE_TYPE_NO_FILTER } from '../../../constants';
|
|
7
|
-
import { PAGE_TYPE_PAGE } from '../../../../../shared/utils/constants';
|
|
8
|
-
|
|
9
|
-
interface Props {
|
|
10
|
-
onChange: (pageTypeUId: string) => void;
|
|
11
|
-
selectedPageTypeUid?: string;
|
|
12
|
-
pageTypes?: PageType[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const PageTypeFilter = ({ onChange, pageTypes, selectedPageTypeUid }: Props) => {
|
|
16
|
-
return (
|
|
17
|
-
<SingleSelect
|
|
18
|
-
placeholder="Select page type"
|
|
19
|
-
onChange={onChange}
|
|
20
|
-
size="S"
|
|
21
|
-
value={selectedPageTypeUid}
|
|
22
|
-
disabled={(pageTypes?.length || 0) === 0}
|
|
23
|
-
>
|
|
24
|
-
<SingleSelectOption key={PAGE_TYPE_NO_FILTER} value={PAGE_TYPE_NO_FILTER}>
|
|
25
|
-
All Pagetypes
|
|
26
|
-
</SingleSelectOption>
|
|
27
|
-
<SingleSelectOption key={PAGE_TYPE_PAGE} value={PAGE_TYPE_PAGE}>
|
|
28
|
-
Page
|
|
29
|
-
</SingleSelectOption>
|
|
30
|
-
{pageTypes?.map((pageType) => (
|
|
31
|
-
<SingleSelectOption key={pageType.uid} value={pageType.uid}>
|
|
32
|
-
{pageType.title || pageType.uid}
|
|
33
|
-
</SingleSelectOption>
|
|
34
|
-
))}
|
|
35
|
-
</SingleSelect>
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export default PageTypeFilter;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { SingleSelectOption, SingleSelect } from '@strapi/design-system';
|
|
4
|
-
import { Platform } from '../../../api/platform';
|
|
5
|
-
import { PLATFORM_NO_FILTER } from '../../../constants';
|
|
6
|
-
|
|
7
|
-
interface Props {
|
|
8
|
-
onChange?: (platformId: string) => void;
|
|
9
|
-
selectedPlatform?: string;
|
|
10
|
-
platforms?: Platform[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const PlatformFilter = ({ onChange, platforms, selectedPlatform }: Props) => {
|
|
14
|
-
return (
|
|
15
|
-
<SingleSelect placeholder="Select platform" onChange={onChange} size="S" value={selectedPlatform}>
|
|
16
|
-
<SingleSelectOption key={PLATFORM_NO_FILTER} value={PLATFORM_NO_FILTER}>
|
|
17
|
-
All Platforms
|
|
18
|
-
</SingleSelectOption>
|
|
19
|
-
{platforms?.map((platform: Platform) => (
|
|
20
|
-
<SingleSelectOption key={platform?.id} value={platform?.title}>
|
|
21
|
-
{platform?.title}
|
|
22
|
-
</SingleSelectOption>
|
|
23
|
-
))}
|
|
24
|
-
</SingleSelect>
|
|
25
|
-
);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default PlatformFilter;
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import set from 'lodash/set';
|
|
3
|
-
|
|
4
|
-
import { Stack } from '@strapi/design-system';
|
|
5
|
-
import { useQueryParams } from '@strapi/helper-plugin';
|
|
6
|
-
|
|
7
|
-
import PageTypeFilter from './PageTypeFilter';
|
|
8
|
-
import { PAGE_TYPE_PAGE, PLATFORM } from '../../../../shared/utils/constants';
|
|
9
|
-
import PlatformFilter from './PlatformFilter';
|
|
10
|
-
import { Platform, useGetPlatforms } from '../../api/platform';
|
|
11
|
-
import { PAGE_TYPE, PAGE_TYPE_NO_FILTER, PLATFORM_NO_FILTER } from '../../constants';
|
|
12
|
-
import { PageType } from '../../api/page-type';
|
|
13
|
-
import { useGetPageTypesForPlatform } from '../../api/platform-page-types';
|
|
14
|
-
|
|
15
|
-
interface PageFiltersProps {
|
|
16
|
-
hidePageType?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const PageFilters = ({ hidePageType }: PageFiltersProps) => {
|
|
20
|
-
const [{ query }, setQuery] = useQueryParams() as any;
|
|
21
|
-
|
|
22
|
-
const { data: platforms } = useGetPlatforms({});
|
|
23
|
-
|
|
24
|
-
const selectedPlatformTitle = useMemo(() => getPlatformFromQuery(query, platforms), [query, platforms]);
|
|
25
|
-
|
|
26
|
-
const { data: pageTypesForPlatform } = useGetPageTypesForPlatform({
|
|
27
|
-
id: platforms?.find((p) => p.title === selectedPlatformTitle)?.id
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const selectedPageTypeUid = useMemo(() => getPageTypeFromQuery(query, []), [query, platforms, selectedPlatformTitle]);
|
|
31
|
-
|
|
32
|
-
const handleFilterChange = (
|
|
33
|
-
filters: Record<string, any>,
|
|
34
|
-
filterCategory: string,
|
|
35
|
-
filterCategoryToRemove?: string
|
|
36
|
-
) => {
|
|
37
|
-
const currentFilters = query.filters?.$and ? query.filters : { ...query.filters, $and: [] };
|
|
38
|
-
const filterIndex = currentFilters.$and.findIndex(
|
|
39
|
-
(x?: Record<string, any>) => Object.keys(x || {})?.[0] === filterCategory
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
if (filterIndex > -1) {
|
|
43
|
-
set(currentFilters, `$and[${filterIndex}]`, filters); // If the filter in this category already exists, replace it
|
|
44
|
-
} else {
|
|
45
|
-
currentFilters.$and.push(filters);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const removedFilters = removeFiltersFromQuery({ filters: currentFilters }, filterCategoryToRemove);
|
|
49
|
-
|
|
50
|
-
setQuery({
|
|
51
|
-
page: 1,
|
|
52
|
-
filters: removedFilters
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const removeFilters = (filterCategory: string) => {
|
|
57
|
-
const filters = removeFiltersFromQuery(query, filterCategory);
|
|
58
|
-
|
|
59
|
-
setQuery({
|
|
60
|
-
page: 1,
|
|
61
|
-
filters
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const handlePlatformSelect = (platformId: string) => {
|
|
66
|
-
if (platformId === PLATFORM_NO_FILTER) {
|
|
67
|
-
removeFilters(PLATFORM);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
handleFilterChange(getPlatformQueryFilter(platformId), PLATFORM, PAGE_TYPE);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const handlePageTypeSelect = (pageType: string) => {
|
|
75
|
-
if (pageType === PAGE_TYPE_NO_FILTER) {
|
|
76
|
-
removeFilters(PAGE_TYPE);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (pageType === PAGE_TYPE_PAGE) {
|
|
81
|
-
handleFilterChange(nullPageTypeQueryFilter, PAGE_TYPE);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
handleFilterChange(getPageTypeQueryFilter(pageType), PAGE_TYPE);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<Stack horizontal spacing={2}>
|
|
90
|
-
<PlatformFilter onChange={handlePlatformSelect} platforms={platforms} selectedPlatform={selectedPlatformTitle} />
|
|
91
|
-
{!hidePageType && (
|
|
92
|
-
<PageTypeFilter
|
|
93
|
-
onChange={handlePageTypeSelect}
|
|
94
|
-
pageTypes={pageTypesForPlatform}
|
|
95
|
-
selectedPageTypeUid={selectedPageTypeUid}
|
|
96
|
-
/>
|
|
97
|
-
)}
|
|
98
|
-
</Stack>
|
|
99
|
-
);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export default PageFilters;
|
|
103
|
-
|
|
104
|
-
const getPageTypeFromQuery = (query: Record<string, any>, pageTypes?: PageType[]) => {
|
|
105
|
-
const pageTypeFromQuery = query?.filters?.$and?.find(
|
|
106
|
-
(x?: Record<string, any>) => Object.keys(x || {})?.[0] === PAGE_TYPE
|
|
107
|
-
)?.pageType;
|
|
108
|
-
|
|
109
|
-
if (pageTypeFromQuery?.uid?.$null === 'true') {
|
|
110
|
-
return PAGE_TYPE_PAGE;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (pageTypeFromQuery?.uid?.$eq) {
|
|
114
|
-
const matchingPageType = pageTypes?.find((pageType: any) => pageType?.uid === pageTypeFromQuery.uid.$eq);
|
|
115
|
-
|
|
116
|
-
if (matchingPageType) {
|
|
117
|
-
return matchingPageType.uid;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return PAGE_TYPE_NO_FILTER;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const getPlatformFromQuery = (query: Record<string, any>, platforms?: Platform[]): string | undefined => {
|
|
125
|
-
const platformFromQuery = query?.filters?.$and?.find(
|
|
126
|
-
(x?: Record<string, any>) => Object.keys(x || {})?.[0] === PLATFORM
|
|
127
|
-
)?.platform;
|
|
128
|
-
|
|
129
|
-
if (platformFromQuery?.title?.$null === 'true') {
|
|
130
|
-
return PLATFORM_NO_FILTER;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (platformFromQuery?.title?.$eq) {
|
|
134
|
-
const matchingPageType = platforms?.find((platforms: Platform) => platforms?.title === platformFromQuery.title.$eq);
|
|
135
|
-
|
|
136
|
-
if (matchingPageType) {
|
|
137
|
-
return matchingPageType.title;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return PLATFORM_NO_FILTER;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const getPlatformQueryFilter = (platform: string) => ({
|
|
145
|
-
platform: {
|
|
146
|
-
title: {
|
|
147
|
-
$eq: platform
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const getPageTypeQueryFilter = (pageType: string) => ({
|
|
153
|
-
pageType: {
|
|
154
|
-
uid: {
|
|
155
|
-
$eq: pageType
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const nullPageTypeQueryFilter = {
|
|
161
|
-
pageType: {
|
|
162
|
-
uid: {
|
|
163
|
-
$null: true
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const removeFiltersFromQuery = (query: Record<string, any>, filterCategory?: string) => {
|
|
169
|
-
const newAndFilters = query.filters?.$and?.filter(
|
|
170
|
-
(x?: Record<string, any>) => Object.keys(x || {})?.[0] !== filterCategory
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
const filters = { ...query.filters, $and: newAndFilters };
|
|
174
|
-
|
|
175
|
-
if (newAndFilters && newAndFilters.length === 0) {
|
|
176
|
-
delete filters.$and;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return filters;
|
|
180
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import { useLocation } from 'react-router-dom';
|
|
4
|
-
|
|
5
|
-
import { PAGE_UID } from '../../../../shared/utils/constants';
|
|
6
|
-
|
|
7
|
-
import PageFilters from './filters';
|
|
8
|
-
import { useHasPageRelation } from '../../api/has-page-relation';
|
|
9
|
-
|
|
10
|
-
const PageFiltersContainer = () => {
|
|
11
|
-
const { pathname } = useLocation();
|
|
12
|
-
const uid = pathname.split('/').find((x) => x.startsWith('api::')) || '';
|
|
13
|
-
const isPageCollectionType = uid === PAGE_UID;
|
|
14
|
-
|
|
15
|
-
const { data: hasPageRelation, isLoading } = useHasPageRelation({
|
|
16
|
-
uid
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
if (isPageCollectionType) {
|
|
20
|
-
return <PageFilters />;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!isPageCollectionType && hasPageRelation && !isLoading) {
|
|
24
|
-
return <PageFilters hidePageType />;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return null;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default PageFiltersContainer;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Strapi } from '@strapi/strapi';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
async findAll() {
|
|
5
|
-
return await (strapi as Strapi).service('plugin::page-builder.platform').findAll();
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
async findOneByUid(ctx: any) {
|
|
9
|
-
const uid = ctx?.params?.uid;
|
|
10
|
-
|
|
11
|
-
if (!uid) {
|
|
12
|
-
return ctx.badRequest('uid is missing.');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return await strapi.service('plugin::page-builder.platform').findOneByUid(uid);
|
|
16
|
-
},
|
|
17
|
-
async findPageTypesByPlatform(ctx: any) {
|
|
18
|
-
const platform = ctx?.params?.platform;
|
|
19
|
-
return await (strapi as Strapi).services['plugin::page-builder.platform'].findPageTypesByPlatform(platform);
|
|
20
|
-
}
|
|
21
|
-
};
|