@webbio/strapi-plugin-page-builder 0.9.9-platform → 0.10.0-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 +3 -2
- package/dist/package.json +2 -2
- package/dist/server/bootstrap/permissions.js +18 -3
- package/dist/server/bootstrap.js +62 -70
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/bootstrap/permissions.ts +16 -3
- package/server/bootstrap.ts +67 -80
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webbio/strapi-plugin-page-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-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,3 +1,4 @@
|
|
|
1
|
+
import uniq from 'lodash/uniq';
|
|
1
2
|
import { Strapi } from '@strapi/strapi';
|
|
2
3
|
import { PLATFORM_UID } from '../../shared/utils/constants';
|
|
3
4
|
|
|
@@ -54,6 +55,8 @@ export default async ({ strapi }: { strapi: Strapi }) => {
|
|
|
54
55
|
}
|
|
55
56
|
});
|
|
56
57
|
|
|
58
|
+
const uniquePermissions = uniq(permissions);
|
|
59
|
+
|
|
57
60
|
return {
|
|
58
61
|
$and: [
|
|
59
62
|
{
|
|
@@ -62,9 +65,19 @@ export default async ({ strapi }: { strapi: Strapi }) => {
|
|
|
62
65
|
}
|
|
63
66
|
},
|
|
64
67
|
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
$or: [
|
|
69
|
+
{
|
|
70
|
+
'pageType.uid': {
|
|
71
|
+
$in: uniquePermissions
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
'pageType.uid': {
|
|
76
|
+
// This means there is no pageType (which is the case for any other page)
|
|
77
|
+
$eq: null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
]
|
|
68
81
|
}
|
|
69
82
|
]
|
|
70
83
|
};
|
package/server/bootstrap.ts
CHANGED
|
@@ -137,100 +137,87 @@ export default async ({ strapi }: { strapi: Strapi }) => {
|
|
|
137
137
|
}
|
|
138
138
|
},
|
|
139
139
|
async afterUpdate(event) {
|
|
140
|
+
await afterUpdate(event?.['result']);
|
|
141
|
+
},
|
|
142
|
+
async afterUpdateMany(event) {
|
|
140
143
|
try {
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
data: {
|
|
151
|
-
...pageData,
|
|
152
|
-
id: data.collectionTypeData[0].id,
|
|
153
|
-
lifecycleState: {
|
|
154
|
-
exit: true
|
|
155
|
-
}
|
|
144
|
+
// console.log('UPDATEMANY', event.params.where);
|
|
145
|
+
const pagesToUpdate = event.params.where?.id?.['$in'];
|
|
146
|
+
const pages: Record<string, any>[] | undefined = (await strapi.entityService?.findMany(PAGE_UID, {
|
|
147
|
+
populate: {
|
|
148
|
+
collectionTypeData: true
|
|
149
|
+
},
|
|
150
|
+
filters: {
|
|
151
|
+
id: {
|
|
152
|
+
$in: pagesToUpdate
|
|
156
153
|
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
154
|
+
}
|
|
155
|
+
})) as any;
|
|
159
156
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// await strapi.entityService?.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
|
|
164
|
-
// data: {
|
|
165
|
-
// id: data.collectionTypeData.id,
|
|
166
|
-
// hasPage: true,
|
|
167
|
-
// lifecycleState: {
|
|
168
|
-
// exit: true
|
|
169
|
-
// }
|
|
170
|
-
// }
|
|
171
|
-
// });
|
|
172
|
-
// }
|
|
157
|
+
if (pages && pages.length > 0) {
|
|
158
|
+
await Promise.all(pages?.map((p) => afterUpdate(p)));
|
|
159
|
+
}
|
|
173
160
|
} catch (error) {
|
|
174
|
-
console.error('Failed to save hasPage data', error);
|
|
161
|
+
console.error('Failed to save hasPage many data', error);
|
|
175
162
|
}
|
|
176
163
|
},
|
|
177
|
-
// async afterCreate(event) {
|
|
178
|
-
// const data = event?.params?.data;
|
|
179
|
-
// if (data.collectionTypeData?.__type && data.collectionTypeData.id) {
|
|
180
|
-
// await strapi.entityService?.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
|
|
181
|
-
// data: {
|
|
182
|
-
// id: data.collectionTypeData.id,
|
|
183
|
-
// hasPage: true,
|
|
184
|
-
// lifecycleState: {
|
|
185
|
-
// exit: true
|
|
186
|
-
// }
|
|
187
|
-
// }
|
|
188
|
-
// });
|
|
189
|
-
// }
|
|
190
|
-
// },
|
|
191
164
|
async beforeDelete(event) {
|
|
192
|
-
|
|
193
|
-
populate: {
|
|
194
|
-
collectionTypeData: true
|
|
195
|
-
}
|
|
196
|
-
})) as Record<string, any> | undefined;
|
|
197
|
-
|
|
198
|
-
if (originalEntity?.collectionTypeData?.[0]?.__type && originalEntity?.collectionTypeData?.[0]?.id) {
|
|
199
|
-
await strapi.entityService?.update(
|
|
200
|
-
originalEntity.collectionTypeData[0].__type,
|
|
201
|
-
originalEntity.collectionTypeData[0].id,
|
|
202
|
-
{
|
|
203
|
-
data: {
|
|
204
|
-
id: originalEntity.collectionTypeData[0].id,
|
|
205
|
-
hasPage: false
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
);
|
|
209
|
-
}
|
|
165
|
+
await beforeDelete(event.params.where.id);
|
|
210
166
|
},
|
|
211
167
|
async beforeDeleteMany(event) {
|
|
212
168
|
const pagesToDisconnect = event.params.where?.['$and']?.[0]?.id?.['$in'];
|
|
213
169
|
|
|
214
170
|
for (const pageId of pagesToDisconnect) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
171
|
+
await beforeDelete(pageId);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
};
|
|
220
176
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
177
|
+
const beforeDelete = async (id: number) => {
|
|
178
|
+
const originalEntity = (await strapi.entityService?.findOne(PAGE_UID, id, {
|
|
179
|
+
populate: {
|
|
180
|
+
collectionTypeData: true
|
|
181
|
+
}
|
|
182
|
+
})) as Record<string, any> | undefined;
|
|
183
|
+
|
|
184
|
+
if (originalEntity?.collectionTypeData?.[0]?.__type && originalEntity?.collectionTypeData?.[0]?.id) {
|
|
185
|
+
await strapi.entityService?.update(
|
|
186
|
+
originalEntity.collectionTypeData[0].__type,
|
|
187
|
+
originalEntity.collectionTypeData[0].id,
|
|
188
|
+
{
|
|
189
|
+
data: {
|
|
190
|
+
id: originalEntity.collectionTypeData[0].id,
|
|
191
|
+
hasPage: false
|
|
232
192
|
}
|
|
233
193
|
}
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const afterUpdate = async (result: Record<string, any>) => {
|
|
199
|
+
try {
|
|
200
|
+
const hasCollectionTypeRelation =
|
|
201
|
+
result &&
|
|
202
|
+
result?.collectionTypeData?.[0] &&
|
|
203
|
+
result?.collectionTypeData[0].__type &&
|
|
204
|
+
result?.collectionTypeData[0];
|
|
205
|
+
|
|
206
|
+
if (hasCollectionTypeRelation) {
|
|
207
|
+
const isPublished = result.publishedAt !== undefined;
|
|
208
|
+
const pageData = isPublished ? { hasPage: !!result.publishedAt } : {};
|
|
209
|
+
|
|
210
|
+
await strapi.entityService?.update(result.collectionTypeData[0].__type, result.collectionTypeData[0].id, {
|
|
211
|
+
data: {
|
|
212
|
+
...pageData,
|
|
213
|
+
id: result.collectionTypeData[0].id,
|
|
214
|
+
lifecycleState: {
|
|
215
|
+
exit: true
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
234
219
|
}
|
|
235
|
-
})
|
|
220
|
+
} catch (error) {
|
|
221
|
+
console.error('Failed to save hasPage data', error);
|
|
222
|
+
}
|
|
236
223
|
};
|