@webbio/strapi-plugin-page-builder 0.9.9-platform → 0.10.1-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/page-type-relation.ts +41 -0
- package/admin/src/api/search-filtered-entity.ts +18 -9
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +9 -4
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +3 -1
- package/admin/src/components/EditView/PageSettings/index.tsx +8 -2
- package/admin/src/components/PlatformFilteredSelectField/Single/index.tsx +2 -2
- package/dist/package.json +2 -2
- package/dist/server/bootstrap/permissions.js +18 -3
- package/dist/server/bootstrap.js +61 -70
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/bootstrap/permissions.ts +16 -3
- package/server/bootstrap.ts +66 -80
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery } from 'react-query';
|
|
2
|
+
|
|
3
|
+
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
|
+
import { PageType } from './platform-page-types';
|
|
5
|
+
|
|
6
|
+
const QUERY_KEY = 'pageTypeRelations';
|
|
7
|
+
|
|
8
|
+
const fetchPageTypeRelation = async ({
|
|
9
|
+
fetchClient,
|
|
10
|
+
id,
|
|
11
|
+
uid
|
|
12
|
+
}: Record<string, any> & UseGetPageTypeRelationParams): Promise<PageType | undefined> => {
|
|
13
|
+
try {
|
|
14
|
+
if (!uid || !id) {
|
|
15
|
+
throw new Error('No uid or id');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { get } = fetchClient;
|
|
19
|
+
const result = await get(`/content-manager/relations/${uid}/${id}/pageType?page=1&pageSize=5`);
|
|
20
|
+
|
|
21
|
+
return result?.data?.data;
|
|
22
|
+
} catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type UseGetPageTypeRelationParams = {
|
|
28
|
+
uid: string;
|
|
29
|
+
id: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const useGetPageTypeRelation = (params: Record<string, any> & UseGetPageTypeRelationParams) => {
|
|
33
|
+
const fetchClient = useFetchClient();
|
|
34
|
+
|
|
35
|
+
return useQuery<PageType | undefined, Error>([QUERY_KEY, params], () =>
|
|
36
|
+
fetchPageTypeRelation({
|
|
37
|
+
...params,
|
|
38
|
+
fetchClient
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
};
|
|
@@ -15,7 +15,7 @@ export type SearchFilteredEntitiesResult = {
|
|
|
15
15
|
id: number;
|
|
16
16
|
title: string;
|
|
17
17
|
href: string;
|
|
18
|
-
publicationState?: string;
|
|
18
|
+
publicationState?: string | false;
|
|
19
19
|
publishedAt?: string;
|
|
20
20
|
}[];
|
|
21
21
|
};
|
|
@@ -64,15 +64,24 @@ export const getSearchFilteredEntities = async ({
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
const { data } = await get(`/content-manager/collection-types/${uid}?${filters}`);
|
|
67
|
-
|
|
68
67
|
const mapResults = data.results.map(
|
|
69
|
-
(result: Record<string, any>): SearchFilteredEntitiesResult['results'][number] =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
(result: Record<string, any>): SearchFilteredEntitiesResult['results'][number] => {
|
|
69
|
+
const getPublicationState = () => {
|
|
70
|
+
if (result?.publishedAt !== undefined) {
|
|
71
|
+
return result?.publishedAt ? 'published' : 'draft';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return false;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
id: result.id,
|
|
79
|
+
title: result.title,
|
|
80
|
+
publicationState: getPublicationState(),
|
|
81
|
+
publishedAt: result?.publishedAt,
|
|
82
|
+
href: `/content-manager/collectionType/${uid}/${result.id}`
|
|
83
|
+
};
|
|
84
|
+
}
|
|
76
85
|
);
|
|
77
86
|
|
|
78
87
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
2
|
import slugify from 'slugify';
|
|
3
3
|
import { useSelector } from 'react-redux';
|
|
4
4
|
import { useHistory } from 'react-router-dom';
|
|
@@ -17,12 +17,14 @@ import { Platform } from '../../../../api/platform';
|
|
|
17
17
|
|
|
18
18
|
interface ICreatePageButtonProps {
|
|
19
19
|
selectedPlatform: Platform;
|
|
20
|
+
onCreatedPage?: (page: Record<string, any>) => void;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
export const CreatePageButton = ({ selectedPlatform }: ICreatePageButtonProps) => {
|
|
23
|
+
export const CreatePageButton = ({ selectedPlatform, onCreatedPage }: ICreatePageButtonProps) => {
|
|
23
24
|
const history = useHistory();
|
|
24
25
|
const form = (useCMEditViewDataManager() || {}) as Record<string, any>;
|
|
25
|
-
|
|
26
|
+
|
|
27
|
+
const { layout, initialData, modifiedData } = form;
|
|
26
28
|
|
|
27
29
|
const { locales } = useSelector((state: any) => state.i18n_locales);
|
|
28
30
|
|
|
@@ -64,10 +66,13 @@ export const CreatePageButton = ({ selectedPlatform }: ICreatePageButtonProps) =
|
|
|
64
66
|
layoutUid: layout.uid,
|
|
65
67
|
relatedEntityId: createLocalizedPage ? linkedPages.data?.[0]?.id : undefined
|
|
66
68
|
});
|
|
69
|
+
|
|
67
70
|
if (newPage?.id) {
|
|
71
|
+
onCreatedPage?.(newPage);
|
|
68
72
|
await put(`/content-manager/collection-types/${layout.uid}/${initialData.id}`, {
|
|
69
73
|
hasPage: false
|
|
70
74
|
});
|
|
75
|
+
|
|
71
76
|
history.push(`/content-manager/collectionType/${PAGE_UID}/${newPage.id}?plugins[i18n][locale]=${locale}`);
|
|
72
77
|
}
|
|
73
78
|
} catch (error) {
|
|
@@ -77,7 +82,7 @@ export const CreatePageButton = ({ selectedPlatform }: ICreatePageButtonProps) =
|
|
|
77
82
|
|
|
78
83
|
return (
|
|
79
84
|
<S.CreateButton to={url} onClick={handleCreatePage} size="S" variant="secondary" startIcon={<Plus />} width="100%">
|
|
80
|
-
|
|
85
|
+
Maak een pagina aan
|
|
81
86
|
</S.CreateButton>
|
|
82
87
|
);
|
|
83
88
|
};
|
|
@@ -50,7 +50,9 @@ export const CollectionTypeSettings = ({ onlyPlatform }: CollectionTypeSettingsP
|
|
|
50
50
|
{!isCreatingEntry && !onlyPlatform && (
|
|
51
51
|
<Wrapper title="Gekoppelde pagina">
|
|
52
52
|
<Flex direction="column" gap={4} width="100%" alignItems="start">
|
|
53
|
-
{showCreatePageButton && selectedPlatform &&
|
|
53
|
+
{showCreatePageButton && selectedPlatform && (
|
|
54
|
+
<CreatePageButton onCreatedPage={(page) => setLinkedPage(page)} selectedPlatform={selectedPlatform} />
|
|
55
|
+
)}
|
|
54
56
|
|
|
55
57
|
{url && (
|
|
56
58
|
<Flex direction="column" alignItems="start" width="100%" gap={1}>
|
|
@@ -11,18 +11,24 @@ import { Details } from '../Details';
|
|
|
11
11
|
import { usePlatformFormData } from '../../../utils/hooks/usePlatformFormData';
|
|
12
12
|
import { useGetPageTypesForPlatform } from '../../../api/platform-page-types';
|
|
13
13
|
import S from '../Details/styles';
|
|
14
|
+
import { useGetPageTypeRelation } from '../../../api/page-type-relation';
|
|
14
15
|
|
|
15
16
|
export const PageSettings = () => {
|
|
16
17
|
const form = (useCMEditViewDataManager() || {}) as Record<string, any>;
|
|
17
|
-
const { isCreatingEntry, initialData, onChange, modifiedData } = form;
|
|
18
|
+
const { isCreatingEntry, initialData, onChange, modifiedData, layout } = form;
|
|
18
19
|
const { selectedPlatform, isLoadingPlatform } = usePlatformFormData(form);
|
|
20
|
+
const { data: pageTypeRelation } = useGetPageTypeRelation({
|
|
21
|
+
id: initialData?.id,
|
|
22
|
+
uid: layout.uid
|
|
23
|
+
});
|
|
19
24
|
|
|
20
25
|
const { data: pageTypesForPlatform } = useGetPageTypesForPlatform({
|
|
21
26
|
id: selectedPlatform?.id
|
|
22
27
|
});
|
|
23
28
|
const selectedPageType = pageTypesForPlatform?.find(
|
|
24
|
-
(pageType) => pageType.id === Number(modifiedData?.pageType?.[0]?.id)
|
|
29
|
+
(pageType) => pageType.id === Number(modifiedData?.pageType?.[0]?.id || pageTypeRelation?.id)
|
|
25
30
|
);
|
|
31
|
+
|
|
26
32
|
const noPlatformSelected = useMemo(() => !Boolean(selectedPlatform), [selectedPlatform]);
|
|
27
33
|
const [isEditting, setIsEditting] = useState(false);
|
|
28
34
|
const showEditFields = useMemo(
|
|
@@ -23,7 +23,7 @@ export interface ISinglePlatformFilteredSelectFieldProps extends IPlatformFilter
|
|
|
23
23
|
|
|
24
24
|
interface CustomReactSelectValue extends Omit<IReactSelectValue, 'initialSelected'> {
|
|
25
25
|
href?: string;
|
|
26
|
-
publicationState?: string;
|
|
26
|
+
publicationState?: string | false;
|
|
27
27
|
publishedAt?: string;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -175,7 +175,7 @@ const CustomOption = (props: OptionProps<CustomReactSelectValue, false>) => {
|
|
|
175
175
|
return (
|
|
176
176
|
<components.Option {...props}>
|
|
177
177
|
<S.CustomOption>
|
|
178
|
-
<S.CustomOptionStatus publicationState={props.data?.publicationState} />
|
|
178
|
+
{props.data?.publicationState && <S.CustomOptionStatus publicationState={props.data?.publicationState} />}
|
|
179
179
|
{props.children}
|
|
180
180
|
</S.CustomOption>
|
|
181
181
|
</components.Option>
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webbio/strapi-plugin-page-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1-platform",
|
|
4
4
|
"description": "This is the description of the plugin.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"develop": "tsc -p tsconfig.server.json -w",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@strapi/strapi": "^4.15.0",
|
|
45
|
-
"@webbio/strapi-plugin-slug": "^3.
|
|
45
|
+
"@webbio/strapi-plugin-slug": "^3.3.0",
|
|
46
46
|
"react": "^17.0.0 || ^18.0.0",
|
|
47
47
|
"react-dom": "^17.0.0 || ^18.0.0",
|
|
48
48
|
"react-router-dom": "^5.3.4",
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
3
7
|
const constants_1 = require("../../shared/utils/constants");
|
|
4
8
|
exports.default = async ({ strapi }) => {
|
|
5
9
|
var _a;
|
|
@@ -49,6 +53,7 @@ exports.default = async ({ strapi }) => {
|
|
|
49
53
|
return permission.permission;
|
|
50
54
|
}
|
|
51
55
|
});
|
|
56
|
+
const uniquePermissions = (0, uniq_1.default)(permissions);
|
|
52
57
|
return {
|
|
53
58
|
$and: [
|
|
54
59
|
{
|
|
@@ -57,9 +62,19 @@ exports.default = async ({ strapi }) => {
|
|
|
57
62
|
}
|
|
58
63
|
},
|
|
59
64
|
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
$or: [
|
|
66
|
+
{
|
|
67
|
+
'pageType.uid': {
|
|
68
|
+
$in: uniquePermissions
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
'pageType.uid': {
|
|
73
|
+
// This means there is no pageType (which is the case for any other page)
|
|
74
|
+
$eq: null
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
]
|
|
63
78
|
}
|
|
64
79
|
]
|
|
65
80
|
};
|
package/dist/server/bootstrap.js
CHANGED
|
@@ -102,89 +102,80 @@ exports.default = async ({ strapi }) => {
|
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
async afterUpdate(event) {
|
|
105
|
-
|
|
105
|
+
await afterUpdate(event === null || event === void 0 ? void 0 : event['result']);
|
|
106
|
+
},
|
|
107
|
+
async afterUpdateMany(event) {
|
|
108
|
+
var _a, _b, _c;
|
|
106
109
|
try {
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
id: data.collectionTypeData[0].id,
|
|
116
|
-
lifecycleState: {
|
|
117
|
-
exit: true
|
|
118
|
-
}
|
|
110
|
+
const pagesToUpdate = (_b = (_a = event.params.where) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b['$in'];
|
|
111
|
+
const pages = (await ((_c = strapi.entityService) === null || _c === void 0 ? void 0 : _c.findMany(constants_1.PAGE_UID, {
|
|
112
|
+
populate: {
|
|
113
|
+
collectionTypeData: true
|
|
114
|
+
},
|
|
115
|
+
filters: {
|
|
116
|
+
id: {
|
|
117
|
+
$in: pagesToUpdate
|
|
119
118
|
}
|
|
120
|
-
}
|
|
119
|
+
}
|
|
120
|
+
})));
|
|
121
|
+
if (pages && pages.length > 0) {
|
|
122
|
+
await Promise.all(pages === null || pages === void 0 ? void 0 : pages.map((p) => afterUpdate(p)));
|
|
121
123
|
}
|
|
122
|
-
// This used to be the way to go. Not sure if the new way works
|
|
123
|
-
// const data = event?.params?.data;
|
|
124
|
-
// if (data.collectionTypeData?.__type && data.collectionTypeData.id) {
|
|
125
|
-
// await strapi.entityService?.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
|
|
126
|
-
// data: {
|
|
127
|
-
// id: data.collectionTypeData.id,
|
|
128
|
-
// hasPage: true,
|
|
129
|
-
// lifecycleState: {
|
|
130
|
-
// exit: true
|
|
131
|
-
// }
|
|
132
|
-
// }
|
|
133
|
-
// });
|
|
134
|
-
// }
|
|
135
124
|
}
|
|
136
125
|
catch (error) {
|
|
137
|
-
console.error('Failed to save hasPage data', error);
|
|
126
|
+
console.error('Failed to save hasPage many data', error);
|
|
138
127
|
}
|
|
139
128
|
},
|
|
140
|
-
// async afterCreate(event) {
|
|
141
|
-
// const data = event?.params?.data;
|
|
142
|
-
// if (data.collectionTypeData?.__type && data.collectionTypeData.id) {
|
|
143
|
-
// await strapi.entityService?.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
|
|
144
|
-
// data: {
|
|
145
|
-
// id: data.collectionTypeData.id,
|
|
146
|
-
// hasPage: true,
|
|
147
|
-
// lifecycleState: {
|
|
148
|
-
// exit: true
|
|
149
|
-
// }
|
|
150
|
-
// }
|
|
151
|
-
// });
|
|
152
|
-
// }
|
|
153
|
-
// },
|
|
154
129
|
async beforeDelete(event) {
|
|
155
|
-
|
|
156
|
-
const originalEntity = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.PAGE_UID, event.params.where.id, {
|
|
157
|
-
populate: {
|
|
158
|
-
collectionTypeData: true
|
|
159
|
-
}
|
|
160
|
-
})));
|
|
161
|
-
if (((_c = (_b = originalEntity === null || originalEntity === void 0 ? void 0 : originalEntity.collectionTypeData) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.__type) && ((_e = (_d = originalEntity === null || originalEntity === void 0 ? void 0 : originalEntity.collectionTypeData) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.id)) {
|
|
162
|
-
await ((_f = strapi.entityService) === null || _f === void 0 ? void 0 : _f.update(originalEntity.collectionTypeData[0].__type, originalEntity.collectionTypeData[0].id, {
|
|
163
|
-
data: {
|
|
164
|
-
id: originalEntity.collectionTypeData[0].id,
|
|
165
|
-
hasPage: false
|
|
166
|
-
}
|
|
167
|
-
}));
|
|
168
|
-
}
|
|
130
|
+
await beforeDelete(event.params.where.id);
|
|
169
131
|
},
|
|
170
132
|
async beforeDeleteMany(event) {
|
|
171
|
-
var _a, _b, _c, _d
|
|
133
|
+
var _a, _b, _c, _d;
|
|
172
134
|
const pagesToDisconnect = (_d = (_c = (_b = (_a = event.params.where) === null || _a === void 0 ? void 0 : _a['$and']) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d['$in'];
|
|
173
135
|
for (const pageId of pagesToDisconnect) {
|
|
174
|
-
|
|
175
|
-
populate: {
|
|
176
|
-
collectionTypeData: true
|
|
177
|
-
}
|
|
178
|
-
})));
|
|
179
|
-
if (((_g = (_f = originalEntity === null || originalEntity === void 0 ? void 0 : originalEntity.collectionTypeData) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.__type) && ((_j = (_h = originalEntity === null || originalEntity === void 0 ? void 0 : originalEntity.collectionTypeData) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.id)) {
|
|
180
|
-
await ((_k = strapi.entityService) === null || _k === void 0 ? void 0 : _k.update(originalEntity.collectionTypeData[0].__type, originalEntity.collectionTypeData[0].id, {
|
|
181
|
-
data: {
|
|
182
|
-
id: originalEntity.collectionTypeData[0].id,
|
|
183
|
-
hasPage: false
|
|
184
|
-
}
|
|
185
|
-
}));
|
|
186
|
-
}
|
|
136
|
+
await beforeDelete(pageId);
|
|
187
137
|
}
|
|
188
138
|
}
|
|
189
139
|
});
|
|
190
140
|
};
|
|
141
|
+
const beforeDelete = async (id) => {
|
|
142
|
+
var _a, _b, _c, _d, _e, _f;
|
|
143
|
+
const originalEntity = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.PAGE_UID, id, {
|
|
144
|
+
populate: {
|
|
145
|
+
collectionTypeData: true
|
|
146
|
+
}
|
|
147
|
+
})));
|
|
148
|
+
if (((_c = (_b = originalEntity === null || originalEntity === void 0 ? void 0 : originalEntity.collectionTypeData) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.__type) && ((_e = (_d = originalEntity === null || originalEntity === void 0 ? void 0 : originalEntity.collectionTypeData) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.id)) {
|
|
149
|
+
await ((_f = strapi.entityService) === null || _f === void 0 ? void 0 : _f.update(originalEntity.collectionTypeData[0].__type, originalEntity.collectionTypeData[0].id, {
|
|
150
|
+
data: {
|
|
151
|
+
id: originalEntity.collectionTypeData[0].id,
|
|
152
|
+
hasPage: false
|
|
153
|
+
}
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const afterUpdate = async (result) => {
|
|
158
|
+
var _a, _b;
|
|
159
|
+
try {
|
|
160
|
+
const hasCollectionTypeRelation = result &&
|
|
161
|
+
((_a = result === null || result === void 0 ? void 0 : result.collectionTypeData) === null || _a === void 0 ? void 0 : _a[0]) &&
|
|
162
|
+
(result === null || result === void 0 ? void 0 : result.collectionTypeData[0].__type) &&
|
|
163
|
+
(result === null || result === void 0 ? void 0 : result.collectionTypeData[0]);
|
|
164
|
+
if (hasCollectionTypeRelation) {
|
|
165
|
+
const isPublished = result.publishedAt !== undefined;
|
|
166
|
+
const pageData = isPublished ? { hasPage: !!result.publishedAt } : {};
|
|
167
|
+
await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(result.collectionTypeData[0].__type, result.collectionTypeData[0].id, {
|
|
168
|
+
data: {
|
|
169
|
+
...pageData,
|
|
170
|
+
id: result.collectionTypeData[0].id,
|
|
171
|
+
lifecycleState: {
|
|
172
|
+
exit: true
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
console.error('Failed to save hasPage data', error);
|
|
180
|
+
}
|
|
181
|
+
};
|