@webbio/strapi-plugin-page-builder 0.3.5-platform → 0.3.7-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/admin/src/api/has-platform-relation.ts +37 -0
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +43 -27
- package/admin/src/components/EditView/Details/index.tsx +12 -1
- package/admin/src/components/EditView/PageSettings/index.tsx +1 -0
- package/admin/src/components/EditView/Platform/platform-select.tsx +3 -2
- package/admin/src/components/EditView/index.tsx +8 -2
- package/dist/package.json +2 -2
- package/dist/server/controllers/collection-types.js +5 -0
- package/dist/server/graphql/index.js +2 -2
- package/dist/server/graphql/page-by-path.js +89 -0
- package/dist/server/register.js +2 -2
- package/dist/server/routes/index.js +5 -0
- package/dist/server/services/collection-types.js +7 -0
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/controllers/collection-types.ts +5 -0
- package/server/graphql/index.ts +2 -2
- package/server/graphql/{page-by-slug.ts → page-by-path.ts} +6 -6
- package/server/register.ts +2 -2
- package/server/routes/index.ts +5 -0
- package/server/services/collection-types.ts +8 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useQuery, UseQueryOptions } from 'react-query';
|
|
2
|
+
|
|
3
|
+
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
|
+
|
|
5
|
+
import getRequestUrl from '../utils/getRequestUrl';
|
|
6
|
+
|
|
7
|
+
type HasPlatformRelationQueryParams = {
|
|
8
|
+
uid: string;
|
|
9
|
+
fetchClient?: any;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const QUERY_KEY = ['platformRelation'];
|
|
13
|
+
|
|
14
|
+
const fetchHasPlatformRelation = async ({ fetchClient, uid }: HasPlatformRelationQueryParams): Promise<boolean> => {
|
|
15
|
+
const { get } = fetchClient;
|
|
16
|
+
const result = await get(`${getRequestUrl('collection-types')}/hasPlatform/${uid}`);
|
|
17
|
+
|
|
18
|
+
return Boolean(result?.data?.hasPlatformRelation);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const useHasPlatformRelation = (
|
|
22
|
+
params: HasPlatformRelationQueryParams,
|
|
23
|
+
options?: UseQueryOptions<boolean, Error>
|
|
24
|
+
) => {
|
|
25
|
+
const fetchClient = useFetchClient();
|
|
26
|
+
|
|
27
|
+
return useQuery<boolean, Error>(
|
|
28
|
+
[
|
|
29
|
+
QUERY_KEY,
|
|
30
|
+
{
|
|
31
|
+
...params
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
() => fetchHasPlatformRelation({ ...params, fetchClient }),
|
|
35
|
+
options
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
|
-
import { Flex } from '@strapi/design-system';
|
|
4
|
+
import { Flex, Box } from '@strapi/design-system';
|
|
5
5
|
import { Link } from '@strapi/icons';
|
|
6
6
|
|
|
7
7
|
import { Wrapper } from '../wrapper';
|
|
@@ -11,7 +11,11 @@ import S from '../Details/styles';
|
|
|
11
11
|
import { PlatformSelect } from '../Platform/platform-select';
|
|
12
12
|
import { Platform, useGetPlatforms } from '../../../api/platform';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
interface CollectionTypeSettingsProps {
|
|
15
|
+
onlyPlatform?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const CollectionTypeSettings = ({ onlyPlatform }: CollectionTypeSettingsProps) => {
|
|
15
19
|
const { layout, isCreatingEntry, initialData, onChange } = useCMEditViewDataManager() as any;
|
|
16
20
|
const { data: platforms } = useGetPlatforms({});
|
|
17
21
|
const [selectedPlatform, setSelectedPlatform] = useState<Platform | undefined | null>(initialData?.platform?.[0]);
|
|
@@ -32,10 +36,6 @@ export const CollectionTypeSettings = () => {
|
|
|
32
36
|
}
|
|
33
37
|
}, []);
|
|
34
38
|
|
|
35
|
-
if (isCreatingEntry) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
39
|
useEffect(() => {
|
|
40
40
|
setSelectedPlatform(initialData?.platform?.[0]);
|
|
41
41
|
}, [initialData]);
|
|
@@ -69,28 +69,44 @@ export const CollectionTypeSettings = () => {
|
|
|
69
69
|
|
|
70
70
|
return (
|
|
71
71
|
<>
|
|
72
|
-
|
|
73
|
-
<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
{(isCreatingEntry || onlyPlatform) && (
|
|
73
|
+
<Wrapper title="Platform">
|
|
74
|
+
<PlatformSelect
|
|
75
|
+
platforms={platforms}
|
|
76
|
+
selectedPlatform={selectedPlatform}
|
|
77
|
+
onChange={handleSelectPlatform}
|
|
78
|
+
noLabel
|
|
79
|
+
/>
|
|
80
|
+
</Wrapper>
|
|
81
|
+
)}
|
|
82
|
+
{!isCreatingEntry && !onlyPlatform && (
|
|
83
|
+
<Wrapper title="Gekoppelde pagina">
|
|
84
|
+
<Flex direction="column" gap={4} width="100%" alignItems="start">
|
|
85
|
+
<Box width="100%">
|
|
86
|
+
<PlatformSelect
|
|
87
|
+
platforms={platforms}
|
|
88
|
+
selectedPlatform={selectedPlatform}
|
|
89
|
+
onChange={handleSelectPlatform}
|
|
90
|
+
/>
|
|
91
|
+
</Box>
|
|
92
|
+
{showCreatePageButton && <CreatePageButton />}
|
|
78
93
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
{url && (
|
|
95
|
+
<Flex direction="column" alignItems="start" width="100%" gap={1}>
|
|
96
|
+
<S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
|
|
97
|
+
{PAGE_TYPE_PAGE}
|
|
98
|
+
</S.SubtleType>
|
|
99
|
+
<S.EntityLinkWrapper variant="pi" textColor="neutral800">
|
|
100
|
+
<S.EntityLink title={linkedPage.title || '-'} to={url} variant="pi">
|
|
101
|
+
<Link />
|
|
102
|
+
{linkedPage.title || '-'}
|
|
103
|
+
</S.EntityLink>
|
|
104
|
+
</S.EntityLinkWrapper>
|
|
105
|
+
</Flex>
|
|
106
|
+
)}
|
|
107
|
+
</Flex>
|
|
108
|
+
</Wrapper>
|
|
109
|
+
)}
|
|
94
110
|
</>
|
|
95
111
|
);
|
|
96
112
|
};
|
|
@@ -12,15 +12,26 @@ interface Props {
|
|
|
12
12
|
entityId?: number;
|
|
13
13
|
entityTitle?: string;
|
|
14
14
|
locale?: string;
|
|
15
|
+
platformTitle?: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const Details = (props: Props) => {
|
|
18
|
-
const { entityTitle, pageType } = props;
|
|
19
|
+
const { entityTitle, pageType, platformTitle } = props;
|
|
19
20
|
|
|
20
21
|
const url = generateLink(props);
|
|
21
22
|
|
|
22
23
|
return (
|
|
23
24
|
<Flex gap={4} width="100%" direction="column">
|
|
25
|
+
{platformTitle && (
|
|
26
|
+
<Flex direction="column" alignItems="start" width="100%" gap={1}>
|
|
27
|
+
<S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
|
|
28
|
+
Platform
|
|
29
|
+
</S.SubtleType>
|
|
30
|
+
<S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
|
|
31
|
+
{platformTitle}
|
|
32
|
+
</S.SubtleType>
|
|
33
|
+
</Flex>
|
|
34
|
+
)}
|
|
24
35
|
<Flex direction="column" alignItems="start" width="100%" gap={1}>
|
|
25
36
|
<S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
|
|
26
37
|
{pageType?.title || PAGE_TYPE_PAGE}
|
|
@@ -140,6 +140,7 @@ export const PageSettings = () => {
|
|
|
140
140
|
pageType={selectedPageType}
|
|
141
141
|
entityId={modifiedData.collectionTypeId}
|
|
142
142
|
entityTitle={modifiedData.collectionTypeTitle}
|
|
143
|
+
platformTitle={selectedPlatform?.title}
|
|
143
144
|
/>
|
|
144
145
|
)}
|
|
145
146
|
{(!showEditFields || isEditting) && (
|
|
@@ -9,12 +9,13 @@ interface Props {
|
|
|
9
9
|
onChange: (platformId: string) => void;
|
|
10
10
|
selectedPlatform?: Platform | null;
|
|
11
11
|
platforms?: Platform[];
|
|
12
|
+
noLabel?: boolean;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export const PlatformSelect = ({ onChange, platforms, selectedPlatform }: Props) => {
|
|
15
|
+
export const PlatformSelect = ({ onChange, platforms, selectedPlatform, noLabel }: Props) => {
|
|
15
16
|
return (
|
|
16
17
|
<SingleSelect
|
|
17
|
-
label=
|
|
18
|
+
label={!noLabel && 'Platform'}
|
|
18
19
|
placeholder="Choose a platform"
|
|
19
20
|
value={selectedPlatform?.id || PLATFORM}
|
|
20
21
|
onChange={onChange}
|
|
@@ -6,6 +6,7 @@ import { PAGE_UID } from '../../../../shared/utils/constants';
|
|
|
6
6
|
import { PageSettings } from './PageSettings';
|
|
7
7
|
import { CollectionTypeSettings } from './CollectionTypeSettings';
|
|
8
8
|
import { useHasPageRelation } from '../../api/has-page-relation';
|
|
9
|
+
import { useHasPlatformRelation } from '../../api/has-platform-relation';
|
|
9
10
|
|
|
10
11
|
export const EditView = () => {
|
|
11
12
|
const { layout } = useCMEditViewDataManager() as any;
|
|
@@ -17,12 +18,17 @@ export const EditView = () => {
|
|
|
17
18
|
uid: layout.uid
|
|
18
19
|
});
|
|
19
20
|
|
|
21
|
+
const { data: hasPlatformRelation, isLoading: isLoadingPlatformRelation } = useHasPlatformRelation({
|
|
22
|
+
uid: layout.uid
|
|
23
|
+
});
|
|
24
|
+
|
|
20
25
|
if (isPageCollectionType) {
|
|
21
26
|
return <PageSettings />;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
if
|
|
25
|
-
|
|
29
|
+
// Show collectiontype settings if it's not a page and it has a page relation OR a platform relation
|
|
30
|
+
if (isCollectionType && !isLoading && !isLoadingPlatformRelation && (hasPageRelation || hasPlatformRelation)) {
|
|
31
|
+
return <CollectionTypeSettings onlyPlatform={!hasPageRelation && hasPlatformRelation} />;
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
return null;
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webbio/strapi-plugin-page-builder",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7-platform",
|
|
4
4
|
"description": "This is the description of the plugin.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"develop": "tsc -p tsconfig.server.json -w",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@strapi/strapi": "^4.15.0",
|
|
43
|
-
"@webbio/strapi-plugin-slug": "^2.0.
|
|
43
|
+
"@webbio/strapi-plugin-slug": "^2.0.5",
|
|
44
44
|
"react": "^17.0.0 || ^18.0.0",
|
|
45
45
|
"react-dom": "^17.0.0 || ^18.0.0",
|
|
46
46
|
"react-router-dom": "^5.3.4",
|
|
@@ -6,6 +6,11 @@ exports.default = {
|
|
|
6
6
|
const uid = (_a = ctx.params) === null || _a === void 0 ? void 0 : _a.uid;
|
|
7
7
|
return strapi.service('plugin::page-builder.collection-types').hasPageRelation(uid);
|
|
8
8
|
},
|
|
9
|
+
async hasPlatformRelation(ctx) {
|
|
10
|
+
var _a;
|
|
11
|
+
const uid = (_a = ctx.params) === null || _a === void 0 ? void 0 : _a.uid;
|
|
12
|
+
return strapi.service('plugin::page-builder.collection-types').hasPlatformRelation(uid);
|
|
13
|
+
},
|
|
9
14
|
async getTranslationPageLinks(ctx) {
|
|
10
15
|
const { uid, ids } = ctx.params || {};
|
|
11
16
|
const idsArr = ids === null || ids === void 0 ? void 0 : ids.split(',').map(Number).filter((x) => !isNaN(x));
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const page_type_1 = __importDefault(require("./page-type"));
|
|
7
|
-
const
|
|
7
|
+
const page_by_path_1 = __importDefault(require("./page-by-path"));
|
|
8
8
|
const pages_by_uid_1 = __importDefault(require("./pages-by-uid"));
|
|
9
9
|
exports.default = {
|
|
10
10
|
getPageInfoFromUID: pages_by_uid_1.default,
|
|
11
11
|
pageType: page_type_1.default,
|
|
12
|
-
|
|
12
|
+
pageByPath: page_by_path_1.default
|
|
13
13
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const filter_underscore_arguments_1 = require("../utils/filter-underscore-arguments");
|
|
4
|
+
const constants_1 = require("../../shared/utils/constants");
|
|
5
|
+
const getPageByPath = (strapi) => {
|
|
6
|
+
const typeDefs = () => {
|
|
7
|
+
return `
|
|
8
|
+
extend type Page {
|
|
9
|
+
collectionType: GenericMorph
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type Query {
|
|
13
|
+
getPageByPath(path: String, _domain: String, _locale: String, _publicationState: PublicationState): PageEntity
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
`;
|
|
17
|
+
};
|
|
18
|
+
const resolvers = (strapi) => {
|
|
19
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
20
|
+
return {
|
|
21
|
+
Query: {
|
|
22
|
+
getPageByPath: {
|
|
23
|
+
resolve: async (_parent, args, ctx) => {
|
|
24
|
+
var _a;
|
|
25
|
+
try {
|
|
26
|
+
const filteredArgs = {
|
|
27
|
+
...(0, filter_underscore_arguments_1.filterUnderscoreArguments)(args),
|
|
28
|
+
platform: { domain: args._domain }
|
|
29
|
+
};
|
|
30
|
+
const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
|
|
31
|
+
const getPage = async () => {
|
|
32
|
+
var _a, _b, _c;
|
|
33
|
+
const transformedArgs = transformArgs(filteredArgs, {
|
|
34
|
+
contentType: strapi.contentTypes[constants_1.PAGE_UID],
|
|
35
|
+
usePagination: false
|
|
36
|
+
});
|
|
37
|
+
const results = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_UID, {
|
|
38
|
+
filters: filteredArgs,
|
|
39
|
+
locale: args._locale,
|
|
40
|
+
publicationState: args._publicationState,
|
|
41
|
+
populate: '*'
|
|
42
|
+
}));
|
|
43
|
+
const entityResponse = toEntityResponse((results === null || results === void 0 ? void 0 : results[0]) || {}, {
|
|
44
|
+
args: transformedArgs,
|
|
45
|
+
resourceUID: constants_1.PAGE_UID
|
|
46
|
+
});
|
|
47
|
+
if (!(entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) || Object.keys(entityResponse.value).length === 0) {
|
|
48
|
+
throw new Error(ctx.koaContext.response.message);
|
|
49
|
+
}
|
|
50
|
+
const collectionTypeDataFilter = (_c = (_b = entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) === null || _b === void 0 ? void 0 : _b.collectionTypeData) === null || _c === void 0 ? void 0 : _c.filter(Boolean);
|
|
51
|
+
const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter === null || collectionTypeDataFilter === void 0 ? void 0 : collectionTypeDataFilter[0] : null;
|
|
52
|
+
const addedAttributes = {
|
|
53
|
+
collectionType: collectionType
|
|
54
|
+
};
|
|
55
|
+
const result = {
|
|
56
|
+
...entityResponse.value,
|
|
57
|
+
...addedAttributes
|
|
58
|
+
};
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
const results = await getPage();
|
|
62
|
+
if (((_a = Object.values(results)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error(ctx.koaContext.response.message);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.log('Error in getPageByPath:', error);
|
|
71
|
+
throw new Error(ctx.koaContext.response.message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const resolversConfig = {
|
|
79
|
+
'Query.getPageByPath': {
|
|
80
|
+
auth: false
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
typeDefs: typeDefs(),
|
|
85
|
+
resolvers: resolvers(strapi),
|
|
86
|
+
resolversConfig
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.default = getPageByPath;
|
package/dist/server/register.js
CHANGED
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const page_by_path_1 = __importDefault(require("./graphql/page-by-path"));
|
|
7
7
|
const page_type_1 = __importDefault(require("./graphql/page-type"));
|
|
8
8
|
const pages_by_uid_1 = __importDefault(require("./graphql/pages-by-uid"));
|
|
9
9
|
exports.default = async ({ strapi }) => {
|
|
10
10
|
var _a, _b;
|
|
11
11
|
const extensionService = strapi.plugin('graphql').service('extension');
|
|
12
12
|
extensionService.use(page_type_1.default);
|
|
13
|
-
extensionService.use((0,
|
|
13
|
+
extensionService.use((0, page_by_path_1.default)(strapi));
|
|
14
14
|
extensionService.use((0, pages_by_uid_1.default)(strapi));
|
|
15
15
|
await ((_b = (_a = strapi.services) === null || _a === void 0 ? void 0 : _a['plugin::page-builder.builder']) === null || _b === void 0 ? void 0 : _b.buildContentTypes());
|
|
16
16
|
};
|
|
@@ -36,6 +36,11 @@ const routes = {
|
|
|
36
36
|
method: 'GET',
|
|
37
37
|
path: '/collection-types-page-links/:uid/:ids?',
|
|
38
38
|
handler: 'collection-types.getTranslationPageLinks'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
method: 'GET',
|
|
42
|
+
path: '/collection-types/hasPlatform/:uid',
|
|
43
|
+
handler: 'collection-types.hasPlatformRelation'
|
|
39
44
|
}
|
|
40
45
|
]
|
|
41
46
|
},
|
|
@@ -22,6 +22,13 @@ exports.default = {
|
|
|
22
22
|
pageTypesWithUid.length > 0)
|
|
23
23
|
};
|
|
24
24
|
},
|
|
25
|
+
async hasPlatformRelation(uid) {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
const contentType = (_a = strapi.contentTypes) === null || _a === void 0 ? void 0 : _a[uid];
|
|
28
|
+
return {
|
|
29
|
+
hasPlatformRelation: Boolean(((_c = (_b = contentType === null || contentType === void 0 ? void 0 : contentType.attributes) === null || _b === void 0 ? void 0 : _b.platform) === null || _c === void 0 ? void 0 : _c.target) === constants_1.PLATFORM_UID)
|
|
30
|
+
};
|
|
31
|
+
},
|
|
25
32
|
withPageMorph() {
|
|
26
33
|
const { getTypeName, getFiltersInputTypeName } = strapi.plugin('graphql').service('utils').naming;
|
|
27
34
|
const collectionTypes = Object.entries(strapi.contentTypes)
|