@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.
- package/README.md +98 -98
- package/admin/src/api/collection-type.ts +110 -110
- package/admin/src/api/has-page-relation.ts +34 -34
- package/admin/src/api/page-type.ts +31 -31
- package/admin/src/api/template.ts +27 -27
- package/admin/src/components/Combobox/index.tsx +77 -77
- package/admin/src/components/Combobox/react-select-custom-styles.tsx +120 -111
- package/admin/src/components/Combobox/styles.ts +22 -22
- package/admin/src/components/ConfirmModal/index.tsx +90 -90
- package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +124 -124
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +104 -101
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +19 -19
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +74 -74
- package/admin/src/components/EditView/Details/index.tsx +47 -47
- package/admin/src/components/EditView/Details/styles.ts +51 -51
- package/admin/src/components/EditView/PageSettings/index.tsx +104 -104
- package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -36
- package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +69 -69
- package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +38 -38
- package/admin/src/components/EditView/index.tsx +29 -29
- package/admin/src/components/EditView/page-type-select.tsx +32 -32
- package/admin/src/components/EditView/wrapper.tsx +35 -35
- package/admin/src/components/Initializer/index.tsx +24 -24
- package/admin/src/components/PageTypeFilter/index.tsx +17 -17
- package/admin/src/components/PageTypeFilter/page-type-filter.tsx +130 -130
- package/admin/src/components/PluginIcon/index.tsx +12 -12
- package/admin/src/constants.ts +3 -3
- package/admin/src/index.tsx +59 -59
- package/admin/src/middlewares/index.tsx +37 -37
- package/admin/src/pluginId.ts +5 -5
- package/admin/src/translations/en.json +6 -6
- package/admin/src/translations/nl.json +6 -6
- package/admin/src/utils/getRequestUrl.ts +11 -11
- package/admin/src/utils/getTrad.ts +5 -5
- package/admin/src/utils/hooks/useDebounce.ts +17 -17
- package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -9
- package/admin/src/utils/hooks/usePrevious.ts +12 -12
- package/admin/src/utils/sanitizeModules.ts +43 -10
- package/custom.d.ts +5 -5
- package/dist/package.json +9 -9
- package/dist/server/graphql/page-by-slug.js +9 -9
- package/dist/server/graphql/pages-by-uid.js +14 -14
- package/dist/server/services/builder.js +7 -4
- package/dist/server/services/template.js +1 -2
- package/dist/server/utils/graphql.js +18 -18
- package/dist/server/utils/strapi.js +1 -4
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +71 -71
- package/server/bootstrap/collection-type-lifecycles.ts +47 -47
- package/server/bootstrap/permissions.ts +42 -42
- package/server/bootstrap.ts +198 -198
- package/server/config/index.ts +4 -4
- package/server/content-types/index.ts +1 -1
- package/server/controllers/collection-types.ts +27 -27
- package/server/controllers/index.ts +11 -11
- package/server/controllers/page-type.ts +13 -13
- package/server/controllers/page.ts +9 -9
- package/server/controllers/template.ts +16 -16
- package/server/destroy.ts +5 -5
- package/server/graphql/index.ts +9 -9
- package/server/graphql/page-by-slug.ts +98 -98
- package/server/graphql/page-type.ts +67 -67
- package/server/graphql/pages-by-uid.ts +127 -127
- package/server/index.ts +23 -23
- package/server/middlewares/index.ts +1 -1
- package/server/policies/index.ts +1 -1
- package/server/register.ts +15 -15
- package/server/routes/index.ts +58 -58
- package/server/schema/page-end.json +91 -91
- package/server/schema/page-start.json +87 -87
- package/server/schema/page-type-end.json +43 -43
- package/server/schema/page-type-start.json +38 -38
- package/server/schema/template-start.json +35 -35
- package/server/services/builder.ts +137 -134
- package/server/services/collection-types.ts +88 -88
- package/server/services/index.ts +13 -13
- package/server/services/page-type.ts +26 -26
- package/server/services/page.ts +24 -24
- package/server/services/template.ts +13 -14
- package/server/utils/filter-underscore-arguments.ts +12 -12
- package/server/utils/graphql.ts +113 -113
- package/server/utils/paginationValidation.ts +39 -39
- package/server/utils/reload-strapi-on-load.ts +13 -13
- package/server/utils/strapi.ts +45 -49
- package/shared/utils/constants.ts +4 -4
- 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/dist/server/controllers/platform.js +0 -20
- package/dist/server/schema/platform-start.json +0 -31
- package/dist/server/services/platform.js +0 -36
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
{
|
|
2
|
-
"draftAndPublish": false,
|
|
3
|
-
"displayName": "Templates",
|
|
4
|
-
"singularName": "template",
|
|
5
|
-
"pluralName": "templates",
|
|
6
|
-
"description": "",
|
|
7
|
-
"plugin": "page-builder",
|
|
8
|
-
"pluginOptions": {
|
|
9
|
-
"i18n": {
|
|
10
|
-
"localized": true
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"kind": "collectionType",
|
|
14
|
-
"collectionName": "templates",
|
|
15
|
-
"attributes": {
|
|
16
|
-
"title": {
|
|
17
|
-
"type": "string",
|
|
18
|
-
"required": true,
|
|
19
|
-
"pluginOptions": {
|
|
20
|
-
"i18n": {
|
|
21
|
-
"localized": true
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"modules": {
|
|
26
|
-
"type": "dynamiczone",
|
|
27
|
-
"components": [],
|
|
28
|
-
"pluginOptions": {
|
|
29
|
-
"i18n": {
|
|
30
|
-
"localized": true
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"draftAndPublish": false,
|
|
3
|
+
"displayName": "Templates",
|
|
4
|
+
"singularName": "template",
|
|
5
|
+
"pluralName": "templates",
|
|
6
|
+
"description": "",
|
|
7
|
+
"plugin": "page-builder",
|
|
8
|
+
"pluginOptions": {
|
|
9
|
+
"i18n": {
|
|
10
|
+
"localized": true
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"kind": "collectionType",
|
|
14
|
+
"collectionName": "templates",
|
|
15
|
+
"attributes": {
|
|
16
|
+
"title": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"required": true,
|
|
19
|
+
"pluginOptions": {
|
|
20
|
+
"i18n": {
|
|
21
|
+
"localized": true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"modules": {
|
|
26
|
+
"type": "dynamiczone",
|
|
27
|
+
"components": [],
|
|
28
|
+
"pluginOptions": {
|
|
29
|
+
"i18n": {
|
|
30
|
+
"localized": true
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,134 +1,137 @@
|
|
|
1
|
-
import partition from 'lodash/partition';
|
|
2
|
-
import { Common } from '@strapi/strapi';
|
|
3
|
-
|
|
4
|
-
import pageStart from '../schema/page-start.json';
|
|
5
|
-
import pageEnd from '../schema/page-end.json';
|
|
6
|
-
import pluginId from '../../admin/src/pluginId';
|
|
7
|
-
import { PAGE_UID, TEMPLATE_UID, PAGE_TYPE_UID } from '../../shared/utils/constants';
|
|
8
|
-
import { reloadStrapiOnLoad } from '../utils/reload-strapi-on-load';
|
|
9
|
-
import pageTypeStart from '../schema/page-type-start.json';
|
|
10
|
-
import pageTypeEnd from '../schema/page-type-end.json';
|
|
11
|
-
import templateStart from '../schema/template-start.json';
|
|
12
|
-
|
|
13
|
-
const UIDS: Common.UID.ContentType[] = [TEMPLATE_UID, PAGE_TYPE_UID, PAGE_UID];
|
|
14
|
-
|
|
15
|
-
export default {
|
|
16
|
-
async buildContentTypes() {
|
|
17
|
-
this.listenToCreatedContentTypes();
|
|
18
|
-
|
|
19
|
-
await this.createContentTypes();
|
|
20
|
-
|
|
21
|
-
await this.updateContentTypes();
|
|
22
|
-
},
|
|
23
|
-
listenToCreatedContentTypes() {
|
|
24
|
-
strapi.eventHub.on('content-type.create', async (e) => {
|
|
25
|
-
if (e.contentType.uid === PAGE_UID) {
|
|
26
|
-
reloadStrapiOnLoad();
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
async createContentTypes() {
|
|
32
|
-
const newContentTypes = UIDS.filter((c) => !Boolean(strapi.contentType(c)))
|
|
33
|
-
.map((c) => this.getContentType(c)?.create)
|
|
34
|
-
.filter(Boolean);
|
|
35
|
-
|
|
36
|
-
await this.synchronizeContentTypes(newContentTypes);
|
|
37
|
-
},
|
|
38
|
-
async updateContentTypes() {
|
|
39
|
-
const updateContentTypes = UIDS.filter((c) => Boolean(strapi.contentType(c)))
|
|
40
|
-
.map((c) => this.getContentType(c).update)
|
|
41
|
-
.filter(Boolean);
|
|
42
|
-
|
|
43
|
-
await this.synchronizeContentTypes(updateContentTypes);
|
|
44
|
-
},
|
|
45
|
-
async synchronizeContentTypes(contentTypes: { uid: Common.UID.ContentType; contentType: Record<string, any> }[]) {
|
|
46
|
-
const ctb = strapi.service('plugin::content-type-builder.content-types');
|
|
47
|
-
|
|
48
|
-
const [updateTypes, newTypes] = partition(contentTypes, (c) => Boolean(strapi.contentType(c.uid)));
|
|
49
|
-
|
|
50
|
-
if (newTypes.length > 0) {
|
|
51
|
-
console.log(
|
|
52
|
-
'[Plugin Page Builder]: Creating content types',
|
|
53
|
-
newTypes.map((x) => x.uid)
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (updateTypes.length > 0) {
|
|
58
|
-
console.log(
|
|
59
|
-
'[Plugin Page Builder]: Updating content types',
|
|
60
|
-
updateTypes.map((x) => x.uid)
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if ((newTypes || []).length > 0) {
|
|
65
|
-
await ctb.createContentTypes(newTypes.map((c) => ({ contentType: c.contentType, components: [] })));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if ((updateTypes || []).length > 0) {
|
|
69
|
-
for await (const updateType of updateTypes) {
|
|
70
|
-
await ctb.editContentType(updateType.uid, {
|
|
71
|
-
contentType: updateType.contentType,
|
|
72
|
-
components: []
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
getContentType(uid: string) {
|
|
78
|
-
const contentTypes = {
|
|
79
|
-
[PAGE_UID]: {
|
|
80
|
-
create: this.getPageContentType(true),
|
|
81
|
-
update: this.getPageContentType()
|
|
82
|
-
},
|
|
83
|
-
[PAGE_TYPE_UID]: {
|
|
84
|
-
create: this.getPageTypeContentType(true),
|
|
85
|
-
update: this.getPageTypeContentType()
|
|
86
|
-
},
|
|
87
|
-
[TEMPLATE_UID]: {
|
|
88
|
-
create: this.getTemplateContentType(),
|
|
89
|
-
update: this.getTemplateContentType()
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
return contentTypes?.[uid];
|
|
94
|
-
},
|
|
95
|
-
getPageContentType(create?: boolean) {
|
|
96
|
-
const page = create ? pageStart : pageEnd;
|
|
97
|
-
const contentType = this.mergeCollectionTypeWithModules(page, PAGE_UID);
|
|
98
|
-
|
|
99
|
-
return { uid: PAGE_UID, contentType };
|
|
100
|
-
},
|
|
101
|
-
getPageTypeContentType(create?: boolean) {
|
|
102
|
-
const pageType = create ? pageTypeStart : pageTypeEnd;
|
|
103
|
-
const contentType = this.mergeCollectionTypeWithModules(pageType, PAGE_TYPE_UID);
|
|
104
|
-
|
|
105
|
-
return { uid: PAGE_TYPE_UID, contentType };
|
|
106
|
-
},
|
|
107
|
-
getTemplateContentType() {
|
|
108
|
-
const template = templateStart;
|
|
109
|
-
const contentType = this.mergeCollectionTypeWithModules(template, TEMPLATE_UID);
|
|
110
|
-
|
|
111
|
-
return { uid: TEMPLATE_UID, contentType };
|
|
112
|
-
},
|
|
113
|
-
mergeCollectionTypeWithModules(collectionType: Record<string, any>, uid: Common.UID.ContentType) {
|
|
114
|
-
const { pluginOptions: oldPluginOptions, __schema__: oldSchema } = (strapi.contentType(uid) as any) || {};
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
...collectionType,
|
|
119
|
-
displayName: oldSchema?.info?.displayName || collectionType?.displayName,
|
|
120
|
-
pluginOptions: {
|
|
121
|
-
...oldPluginOptions,
|
|
122
|
-
...collectionType?.pluginOptions
|
|
123
|
-
},
|
|
124
|
-
attributes: {
|
|
125
|
-
...oldSchema?.attributes,
|
|
126
|
-
...collectionType.attributes,
|
|
127
|
-
modules
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
1
|
+
import partition from 'lodash/partition';
|
|
2
|
+
import { Common } from '@strapi/strapi';
|
|
3
|
+
|
|
4
|
+
import pageStart from '../schema/page-start.json';
|
|
5
|
+
import pageEnd from '../schema/page-end.json';
|
|
6
|
+
import pluginId from '../../admin/src/pluginId';
|
|
7
|
+
import { PAGE_UID, TEMPLATE_UID, PAGE_TYPE_UID } from '../../shared/utils/constants';
|
|
8
|
+
import { reloadStrapiOnLoad } from '../utils/reload-strapi-on-load';
|
|
9
|
+
import pageTypeStart from '../schema/page-type-start.json';
|
|
10
|
+
import pageTypeEnd from '../schema/page-type-end.json';
|
|
11
|
+
import templateStart from '../schema/template-start.json';
|
|
12
|
+
|
|
13
|
+
const UIDS: Common.UID.ContentType[] = [TEMPLATE_UID, PAGE_TYPE_UID, PAGE_UID];
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
async buildContentTypes() {
|
|
17
|
+
this.listenToCreatedContentTypes();
|
|
18
|
+
|
|
19
|
+
await this.createContentTypes();
|
|
20
|
+
|
|
21
|
+
await this.updateContentTypes();
|
|
22
|
+
},
|
|
23
|
+
listenToCreatedContentTypes() {
|
|
24
|
+
strapi.eventHub.on('content-type.create', async (e) => {
|
|
25
|
+
if (e.contentType.uid === PAGE_UID) {
|
|
26
|
+
reloadStrapiOnLoad();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
async createContentTypes() {
|
|
32
|
+
const newContentTypes = UIDS.filter((c) => !Boolean(strapi.contentType(c)))
|
|
33
|
+
.map((c) => this.getContentType(c)?.create)
|
|
34
|
+
.filter(Boolean);
|
|
35
|
+
|
|
36
|
+
await this.synchronizeContentTypes(newContentTypes);
|
|
37
|
+
},
|
|
38
|
+
async updateContentTypes() {
|
|
39
|
+
const updateContentTypes = UIDS.filter((c) => Boolean(strapi.contentType(c)))
|
|
40
|
+
.map((c) => this.getContentType(c).update)
|
|
41
|
+
.filter(Boolean);
|
|
42
|
+
|
|
43
|
+
await this.synchronizeContentTypes(updateContentTypes);
|
|
44
|
+
},
|
|
45
|
+
async synchronizeContentTypes(contentTypes: { uid: Common.UID.ContentType; contentType: Record<string, any> }[]) {
|
|
46
|
+
const ctb = strapi.service('plugin::content-type-builder.content-types');
|
|
47
|
+
|
|
48
|
+
const [updateTypes, newTypes] = partition(contentTypes, (c) => Boolean(strapi.contentType(c.uid)));
|
|
49
|
+
|
|
50
|
+
if (newTypes.length > 0) {
|
|
51
|
+
console.log(
|
|
52
|
+
'[Plugin Page Builder]: Creating content types',
|
|
53
|
+
newTypes.map((x) => x.uid)
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (updateTypes.length > 0) {
|
|
58
|
+
console.log(
|
|
59
|
+
'[Plugin Page Builder]: Updating content types',
|
|
60
|
+
updateTypes.map((x) => x.uid)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if ((newTypes || []).length > 0) {
|
|
65
|
+
await ctb.createContentTypes(newTypes.map((c) => ({ contentType: c.contentType, components: [] })));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ((updateTypes || []).length > 0) {
|
|
69
|
+
for await (const updateType of updateTypes) {
|
|
70
|
+
await ctb.editContentType(updateType.uid, {
|
|
71
|
+
contentType: updateType.contentType,
|
|
72
|
+
components: []
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
getContentType(uid: string) {
|
|
78
|
+
const contentTypes = {
|
|
79
|
+
[PAGE_UID]: {
|
|
80
|
+
create: this.getPageContentType(true),
|
|
81
|
+
update: this.getPageContentType()
|
|
82
|
+
},
|
|
83
|
+
[PAGE_TYPE_UID]: {
|
|
84
|
+
create: this.getPageTypeContentType(true),
|
|
85
|
+
update: this.getPageTypeContentType()
|
|
86
|
+
},
|
|
87
|
+
[TEMPLATE_UID]: {
|
|
88
|
+
create: this.getTemplateContentType(),
|
|
89
|
+
update: this.getTemplateContentType()
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return contentTypes?.[uid];
|
|
94
|
+
},
|
|
95
|
+
getPageContentType(create?: boolean) {
|
|
96
|
+
const page = create ? pageStart : pageEnd;
|
|
97
|
+
const contentType = this.mergeCollectionTypeWithModules(page, PAGE_UID);
|
|
98
|
+
|
|
99
|
+
return { uid: PAGE_UID, contentType };
|
|
100
|
+
},
|
|
101
|
+
getPageTypeContentType(create?: boolean) {
|
|
102
|
+
const pageType = create ? pageTypeStart : pageTypeEnd;
|
|
103
|
+
const contentType = this.mergeCollectionTypeWithModules(pageType, PAGE_TYPE_UID);
|
|
104
|
+
|
|
105
|
+
return { uid: PAGE_TYPE_UID, contentType };
|
|
106
|
+
},
|
|
107
|
+
getTemplateContentType() {
|
|
108
|
+
const template = templateStart;
|
|
109
|
+
const contentType = this.mergeCollectionTypeWithModules(template, TEMPLATE_UID);
|
|
110
|
+
|
|
111
|
+
return { uid: TEMPLATE_UID, contentType };
|
|
112
|
+
},
|
|
113
|
+
mergeCollectionTypeWithModules(collectionType: Record<string, any>, uid: Common.UID.ContentType) {
|
|
114
|
+
const { pluginOptions: oldPluginOptions, __schema__: oldSchema } = (strapi.contentType(uid) as any) || {};
|
|
115
|
+
const modulesFromConfig = oldSchema?.attributes?.modules ? this.getConfigModuleComponents() : undefined;
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
...collectionType,
|
|
119
|
+
displayName: oldSchema?.info?.displayName || collectionType?.displayName,
|
|
120
|
+
pluginOptions: {
|
|
121
|
+
...oldPluginOptions,
|
|
122
|
+
...collectionType?.pluginOptions
|
|
123
|
+
},
|
|
124
|
+
attributes: {
|
|
125
|
+
...oldSchema?.attributes,
|
|
126
|
+
...collectionType.attributes,
|
|
127
|
+
...(((collectionType?.attributes?.modules && collectionType?.attributes?.modules?.length > 0) ||
|
|
128
|
+
modulesFromConfig) && {
|
|
129
|
+
modules: { ...collectionType?.attributes?.modules, components: modulesFromConfig }
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
getConfigModuleComponents() {
|
|
135
|
+
return ((strapi.config.get(`plugin.${pluginId}`) as Record<string, any>)?.modules || []).filter(Boolean);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import uniqBy from 'lodash/uniqBy';
|
|
2
|
-
import { Common } from '@strapi/strapi';
|
|
3
|
-
|
|
4
|
-
import { IGetTranslationPageLinks } from '../controllers/collection-types';
|
|
5
|
-
import { PAGE_TYPE_UID } from '../../shared/utils/constants';
|
|
6
|
-
|
|
7
|
-
export interface ICollectionTypeGL {
|
|
8
|
-
uid: string;
|
|
9
|
-
type: string;
|
|
10
|
-
inputType: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default {
|
|
14
|
-
async hasPageRelation(uid: string): Promise<{ hasPageRelation: boolean }> {
|
|
15
|
-
const contentType = strapi.contentTypes?.[uid];
|
|
16
|
-
const pageTypesWithUid =
|
|
17
|
-
(await strapi.entityService.findMany(PAGE_TYPE_UID, {
|
|
18
|
-
filters: {
|
|
19
|
-
uid: {
|
|
20
|
-
$eq: uid
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
})) || [];
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
hasPageRelation: Boolean(
|
|
27
|
-
contentType?.attributes?.page &&
|
|
28
|
-
contentType?.attributes?.page?.morphBy === 'collectionTypeData' &&
|
|
29
|
-
(pageTypesWithUid as Record<string, any>[]).length > 0
|
|
30
|
-
)
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
withPageMorph(): ICollectionTypeGL[] {
|
|
34
|
-
const { getTypeName, getFiltersInputTypeName } = strapi.plugin('graphql').service('utils').naming;
|
|
35
|
-
|
|
36
|
-
const collectionTypes = Object.entries(strapi.contentTypes)
|
|
37
|
-
.map((ct) => {
|
|
38
|
-
const uid: string = ct?.[0];
|
|
39
|
-
const contentType = ct?.[1] as Record<string, any>;
|
|
40
|
-
const type = contentType ? getTypeName(contentType) : undefined;
|
|
41
|
-
const hasPageMorph = contentType?.attributes?.page?.morphBy === 'collectionTypeData';
|
|
42
|
-
|
|
43
|
-
if (uid && type && hasPageMorph) {
|
|
44
|
-
return {
|
|
45
|
-
uid,
|
|
46
|
-
type: getTypeName(contentType),
|
|
47
|
-
inputType: getFiltersInputTypeName(contentType)
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
.filter(Boolean) as ICollectionTypeGL[];
|
|
52
|
-
|
|
53
|
-
return collectionTypes;
|
|
54
|
-
},
|
|
55
|
-
async getTranslationPageLinks(uid: Common.UID.ContentType, ids: string[]) {
|
|
56
|
-
try {
|
|
57
|
-
const entities = await strapi.entityService.findMany(uid, {
|
|
58
|
-
filters: {
|
|
59
|
-
id: { $in: ids }
|
|
60
|
-
},
|
|
61
|
-
populate: {
|
|
62
|
-
page: {
|
|
63
|
-
populate: {
|
|
64
|
-
localizations: true
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
} as any);
|
|
69
|
-
|
|
70
|
-
let pages: IGetTranslationPageLinks[] = [];
|
|
71
|
-
|
|
72
|
-
// Get all pages linked to the entity
|
|
73
|
-
entities?.forEach((x: any) => {
|
|
74
|
-
x?.page?.forEach((p: any) => {
|
|
75
|
-
pages.push({ id: p.id, locale: p.locale });
|
|
76
|
-
|
|
77
|
-
p.localizations.forEach((l: any) => {
|
|
78
|
-
pages.push({ id: l.id, locale: l.locale });
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return uniqBy(pages, 'id');
|
|
84
|
-
} catch {
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
1
|
+
import uniqBy from 'lodash/uniqBy';
|
|
2
|
+
import { Common } from '@strapi/strapi';
|
|
3
|
+
|
|
4
|
+
import { IGetTranslationPageLinks } from '../controllers/collection-types';
|
|
5
|
+
import { PAGE_TYPE_UID } from '../../shared/utils/constants';
|
|
6
|
+
|
|
7
|
+
export interface ICollectionTypeGL {
|
|
8
|
+
uid: string;
|
|
9
|
+
type: string;
|
|
10
|
+
inputType: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
async hasPageRelation(uid: string): Promise<{ hasPageRelation: boolean }> {
|
|
15
|
+
const contentType = strapi.contentTypes?.[uid];
|
|
16
|
+
const pageTypesWithUid =
|
|
17
|
+
(await strapi.entityService.findMany(PAGE_TYPE_UID, {
|
|
18
|
+
filters: {
|
|
19
|
+
uid: {
|
|
20
|
+
$eq: uid
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})) || [];
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
hasPageRelation: Boolean(
|
|
27
|
+
contentType?.attributes?.page &&
|
|
28
|
+
contentType?.attributes?.page?.morphBy === 'collectionTypeData' &&
|
|
29
|
+
(pageTypesWithUid as Record<string, any>[]).length > 0
|
|
30
|
+
)
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
withPageMorph(): ICollectionTypeGL[] {
|
|
34
|
+
const { getTypeName, getFiltersInputTypeName } = strapi.plugin('graphql').service('utils').naming;
|
|
35
|
+
|
|
36
|
+
const collectionTypes = Object.entries(strapi.contentTypes)
|
|
37
|
+
.map((ct) => {
|
|
38
|
+
const uid: string = ct?.[0];
|
|
39
|
+
const contentType = ct?.[1] as Record<string, any>;
|
|
40
|
+
const type = contentType ? getTypeName(contentType) : undefined;
|
|
41
|
+
const hasPageMorph = contentType?.attributes?.page?.morphBy === 'collectionTypeData';
|
|
42
|
+
|
|
43
|
+
if (uid && type && hasPageMorph) {
|
|
44
|
+
return {
|
|
45
|
+
uid,
|
|
46
|
+
type: getTypeName(contentType),
|
|
47
|
+
inputType: getFiltersInputTypeName(contentType)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
.filter(Boolean) as ICollectionTypeGL[];
|
|
52
|
+
|
|
53
|
+
return collectionTypes;
|
|
54
|
+
},
|
|
55
|
+
async getTranslationPageLinks(uid: Common.UID.ContentType, ids: string[]) {
|
|
56
|
+
try {
|
|
57
|
+
const entities = await strapi.entityService.findMany(uid, {
|
|
58
|
+
filters: {
|
|
59
|
+
id: { $in: ids }
|
|
60
|
+
},
|
|
61
|
+
populate: {
|
|
62
|
+
page: {
|
|
63
|
+
populate: {
|
|
64
|
+
localizations: true
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} as any);
|
|
69
|
+
|
|
70
|
+
let pages: IGetTranslationPageLinks[] = [];
|
|
71
|
+
|
|
72
|
+
// Get all pages linked to the entity
|
|
73
|
+
entities?.forEach((x: any) => {
|
|
74
|
+
x?.page?.forEach((p: any) => {
|
|
75
|
+
pages.push({ id: p.id, locale: p.locale });
|
|
76
|
+
|
|
77
|
+
p.localizations.forEach((l: any) => {
|
|
78
|
+
pages.push({ id: l.id, locale: l.locale });
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return uniqBy(pages, 'id');
|
|
84
|
+
} catch {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
package/server/services/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import page from './page';
|
|
2
|
-
import builder from './builder';
|
|
3
|
-
import pageType from './page-type';
|
|
4
|
-
import collectionTypes from './collection-types';
|
|
5
|
-
import template from './template';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
page,
|
|
9
|
-
builder,
|
|
10
|
-
'page-type': pageType,
|
|
11
|
-
'collection-types': collectionTypes,
|
|
12
|
-
template
|
|
13
|
-
};
|
|
1
|
+
import page from './page';
|
|
2
|
+
import builder from './builder';
|
|
3
|
+
import pageType from './page-type';
|
|
4
|
+
import collectionTypes from './collection-types';
|
|
5
|
+
import template from './template';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
page,
|
|
9
|
+
builder,
|
|
10
|
+
'page-type': pageType,
|
|
11
|
+
'collection-types': collectionTypes,
|
|
12
|
+
template
|
|
13
|
+
};
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { PAGE_TYPE_UID } from '../../shared/utils/constants';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
async findOneByUid(uid: string) {
|
|
5
|
-
const results = await strapi.entityService?.findMany(PAGE_TYPE_UID, {
|
|
6
|
-
populate: {
|
|
7
|
-
template: {
|
|
8
|
-
populate: {
|
|
9
|
-
modules: true
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
filters: {
|
|
14
|
-
uid
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const result = (results as any[]).length > 0 ? results?.[0] : undefined;
|
|
19
|
-
|
|
20
|
-
if (result) {
|
|
21
|
-
return result;
|
|
22
|
-
} else {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
1
|
+
import { PAGE_TYPE_UID } from '../../shared/utils/constants';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
async findOneByUid(uid: string) {
|
|
5
|
+
const results = await strapi.entityService?.findMany(PAGE_TYPE_UID, {
|
|
6
|
+
populate: {
|
|
7
|
+
template: {
|
|
8
|
+
populate: {
|
|
9
|
+
modules: true
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
filters: {
|
|
14
|
+
uid
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const result = (results as any[]).length > 0 ? results?.[0] : undefined;
|
|
19
|
+
|
|
20
|
+
if (result) {
|
|
21
|
+
return result;
|
|
22
|
+
} else {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
package/server/services/page.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { PAGE_UID } from '../../shared/utils/constants';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
async getPage(id: string) {
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
const page = await strapi.db.query(PAGE_UID).findOne({
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
select: 'id',
|
|
9
|
-
populate: {
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
collectionTypeData: true,
|
|
12
|
-
pageType: true
|
|
13
|
-
},
|
|
14
|
-
where: {
|
|
15
|
-
id
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
pageType: page.pageType,
|
|
21
|
-
collectionTypeData: page.collectionTypeData?.[0] ?? null
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
};
|
|
1
|
+
import { PAGE_UID } from '../../shared/utils/constants';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
async getPage(id: string) {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const page = await strapi.db.query(PAGE_UID).findOne({
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
select: 'id',
|
|
9
|
+
populate: {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
collectionTypeData: true,
|
|
12
|
+
pageType: true
|
|
13
|
+
},
|
|
14
|
+
where: {
|
|
15
|
+
id
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
pageType: page.pageType,
|
|
21
|
+
collectionTypeData: page.collectionTypeData?.[0] ?? null
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { getPopulatedEntity } from '../utils/strapi';
|
|
2
|
-
import { TEMPLATE_UID } from '../../shared/utils/constants';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
async findAll() {
|
|
6
|
-
const foundTemplates = await strapi.entityService.findMany(TEMPLATE_UID);
|
|
7
|
-
|
|
8
|
-
return foundTemplates;
|
|
9
|
-
},
|
|
10
|
-
async findOne(id: number) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
1
|
+
import { getPopulatedEntity } from '../utils/strapi';
|
|
2
|
+
import { TEMPLATE_UID } from '../../shared/utils/constants';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
async findAll() {
|
|
6
|
+
const foundTemplates = await strapi.entityService.findMany(TEMPLATE_UID);
|
|
7
|
+
|
|
8
|
+
return foundTemplates;
|
|
9
|
+
},
|
|
10
|
+
async findOne(id: number) {
|
|
11
|
+
return await getPopulatedEntity(TEMPLATE_UID, id);
|
|
12
|
+
}
|
|
13
|
+
};
|