@webbio/strapi-plugin-page-builder 0.5.1-platform → 0.7.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/has-page-relation.ts +1 -1
- package/admin/src/api/has-platform-relation.ts +1 -1
- package/admin/src/api/page.ts +94 -0
- package/admin/src/api/platform-page-types.ts +17 -19
- package/admin/src/api/platform.ts +2 -2
- package/admin/src/api/template.ts +10 -7
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +6 -2
- package/admin/src/components/EditView/Details/index.tsx +1 -1
- package/admin/src/components/EditView/PageSettings/index.tsx +1 -1
- package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +3 -2
- package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +5 -2
- package/admin/src/components/EditView/page-type-select.tsx +1 -1
- package/admin/src/components/EditView/wrapper.tsx +13 -7
- package/admin/src/components/GlobalPlatformSelect/index.tsx +0 -1
- package/admin/src/components/PageFilters/PageTypeFilter/index.tsx +1 -1
- package/admin/src/components/PageFilters/filters.tsx +1 -1
- package/admin/src/components/PageFilters/index.tsx +6 -1
- package/admin/src/components/PageTypeEditView/PageByPlatformSelect/index.tsx +112 -0
- package/admin/src/components/PageTypeEditView/TemplatePlatformSelect/index.tsx +55 -0
- package/admin/src/components/PageTypeEditView/index.tsx +28 -0
- package/admin/src/index.tsx +5 -0
- package/admin/src/utils/hooks/useDefaultPlatformFromLocalStorage.ts +36 -6
- package/admin/src/utils/hooks/usePlatformFormData.ts +1 -0
- package/dist/package.json +1 -1
- package/dist/server/controllers/page-type.js +6 -2
- package/dist/server/routes/index.js +1 -1
- package/dist/server/schema/page-type-end.json +15 -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 +4 -3
- package/dist/server/services/page-type.js +7 -3
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/server/controllers/page-type.ts +6 -1
- package/server/routes/index.ts +1 -1
- package/server/schema/page-type-end.json +15 -5
- package/server/schema/platform-start.json +0 -10
- package/server/schema/template-end.json +40 -0
- package/server/services/builder.ts +4 -3
- package/server/services/page-type.ts +7 -3
- package/admin/src/api/page-type.ts +0 -32
|
@@ -1,29 +1,59 @@
|
|
|
1
|
-
import { useLocalStorage } from '@mantine/hooks';
|
|
2
|
-
import { Platform, useGetPlatforms } from '../../api/platform';
|
|
3
1
|
import { useEffect } from 'react';
|
|
2
|
+
import remove from 'lodash/remove';
|
|
3
|
+
|
|
4
|
+
import { useLocalStorage, useSessionStorage } from '@mantine/hooks';
|
|
5
|
+
|
|
6
|
+
import { Platform, useGetPlatforms } from '../../api/platform';
|
|
4
7
|
|
|
5
8
|
const useDefaultPlatformFromLocalStorage = () => {
|
|
6
9
|
const { data: platforms, isLoading } = useGetPlatforms({});
|
|
7
|
-
|
|
10
|
+
// Set multiple platforms in local storage. When a new tab is opened, the first platform from the array will be selected.
|
|
11
|
+
const [platformsFromState, setPlatformsFromState] = useLocalStorage<Platform[] | undefined>({
|
|
12
|
+
key: 'selectedPlatforms',
|
|
13
|
+
defaultValue: undefined,
|
|
14
|
+
getInitialValueInEffect: false
|
|
15
|
+
});
|
|
16
|
+
const selectedPlatformFromState = platformsFromState?.[0];
|
|
17
|
+
|
|
18
|
+
// Session storage is used to keep the state of the current tab.
|
|
19
|
+
const [selectedPlatform, setSelectedPlatform] = useSessionStorage<Platform | undefined>({
|
|
8
20
|
key: 'selectedPlatform',
|
|
9
21
|
defaultValue: undefined,
|
|
10
22
|
getInitialValueInEffect: false
|
|
11
23
|
});
|
|
12
24
|
|
|
25
|
+
// When a new platform is selected, it is added as first element to the array of platforms in local storage.
|
|
26
|
+
// This makes sure that when a new tab is opened, the most recent platform will be selected.
|
|
13
27
|
useEffect(() => {
|
|
14
|
-
|
|
28
|
+
const platformArray: Platform[] = platformsFromState || [];
|
|
29
|
+
remove(platformArray, (p) => p.id === selectedPlatform?.id);
|
|
30
|
+
|
|
31
|
+
if (selectedPlatform) {
|
|
32
|
+
platformArray.unshift(selectedPlatform);
|
|
33
|
+
}
|
|
34
|
+
setPlatformsFromState(platformArray);
|
|
35
|
+
}, [selectedPlatform]);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
// If there are no platforms in local storage, select the first platform from the list.
|
|
15
39
|
if (
|
|
16
40
|
!isLoading &&
|
|
17
41
|
platforms?.[0]?.title &&
|
|
18
|
-
(!selectedPlatform?.id || !platforms.find((platform) => platform.id ===
|
|
42
|
+
(!selectedPlatform?.id || !platforms.find((platform) => platform.id === selectedPlatformFromState?.id))
|
|
19
43
|
) {
|
|
20
44
|
setSelectedPlatform(platforms[0]);
|
|
21
45
|
}
|
|
22
46
|
|
|
47
|
+
// If there are no platforms in local storage and no platforms are returned from the API, set the selected platform to undefined.
|
|
23
48
|
if (!isLoading && (platforms || []).length === 0) {
|
|
24
49
|
setSelectedPlatform(undefined);
|
|
25
50
|
}
|
|
26
|
-
|
|
51
|
+
|
|
52
|
+
// If there is no selected platform in the session storage, set it to the selected platform from local storage.
|
|
53
|
+
if (!isLoading && selectedPlatformFromState?.id && !selectedPlatform) {
|
|
54
|
+
setSelectedPlatform(selectedPlatformFromState);
|
|
55
|
+
}
|
|
56
|
+
}, [isLoading, selectedPlatformFromState, platforms]);
|
|
27
57
|
|
|
28
58
|
return { selectedPlatform, setSelectedPlatform, platforms };
|
|
29
59
|
};
|
|
@@ -6,6 +6,7 @@ import { useGetPlatformRelation } from '../../api/platform-relation';
|
|
|
6
6
|
const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (platform: Platform) => void) => {
|
|
7
7
|
const { onChange, initialData, layout } = form || {};
|
|
8
8
|
const { isLoading } = useGetPlatformRelation({ id: initialData?.id, uid: layout.uid });
|
|
9
|
+
|
|
9
10
|
const { selectedPlatform: defaultPlatform, setSelectedPlatform: setDefaultPlatform } =
|
|
10
11
|
useDefaultPlatformFromLocalStorage();
|
|
11
12
|
|
package/dist/package.json
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = {
|
|
4
4
|
async findOneByUid(ctx) {
|
|
5
|
-
var _a;
|
|
5
|
+
var _a, _b;
|
|
6
6
|
const uid = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.uid;
|
|
7
|
+
const platformId = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _b === void 0 ? void 0 : _b.platformId;
|
|
7
8
|
if (!uid) {
|
|
8
9
|
return ctx.badRequest('uid is missing.');
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
if (!platformId) {
|
|
12
|
+
return ctx.badRequest('PlatformId is missing.');
|
|
13
|
+
}
|
|
14
|
+
return await strapi.service('plugin::page-builder.page-type').findOneByUid(uid, platformId);
|
|
11
15
|
}
|
|
12
16
|
};
|
|
@@ -25,6 +25,21 @@
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
+
"template": {
|
|
29
|
+
"type": "relation",
|
|
30
|
+
"relation": "oneToOne",
|
|
31
|
+
"target": "api::template.template"
|
|
32
|
+
},
|
|
33
|
+
"platform": {
|
|
34
|
+
"type": "relation",
|
|
35
|
+
"relation": "oneToOne",
|
|
36
|
+
"target": "api::platform.platform"
|
|
37
|
+
},
|
|
38
|
+
"defaultParent": {
|
|
39
|
+
"type": "relation",
|
|
40
|
+
"relation": "oneToOne",
|
|
41
|
+
"target": "api::page.page"
|
|
42
|
+
},
|
|
28
43
|
"modules": {
|
|
29
44
|
"type": "dynamiczone",
|
|
30
45
|
"components": [],
|
|
@@ -33,11 +48,6 @@
|
|
|
33
48
|
"localized": true
|
|
34
49
|
}
|
|
35
50
|
}
|
|
36
|
-
},
|
|
37
|
-
"template": {
|
|
38
|
-
"type": "relation",
|
|
39
|
-
"relation": "oneToOne",
|
|
40
|
-
"target": "api::template.template"
|
|
41
51
|
}
|
|
42
52
|
}
|
|
43
53
|
}
|
|
@@ -16,16 +16,6 @@
|
|
|
16
16
|
},
|
|
17
17
|
"domain": {
|
|
18
18
|
"type": "string"
|
|
19
|
-
},
|
|
20
|
-
"template": {
|
|
21
|
-
"type": "relation",
|
|
22
|
-
"relation": "oneToMany",
|
|
23
|
-
"target": "api::template.template"
|
|
24
|
-
},
|
|
25
|
-
"pageTypes": {
|
|
26
|
-
"type": "relation",
|
|
27
|
-
"relation": "oneToMany",
|
|
28
|
-
"target": "api::page-type.page-type"
|
|
29
19
|
}
|
|
30
20
|
}
|
|
31
21
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
"platform": {
|
|
26
|
+
"type": "relation",
|
|
27
|
+
"relation": "oneToOne",
|
|
28
|
+
"target": "api::platform.platform"
|
|
29
|
+
},
|
|
30
|
+
"modules": {
|
|
31
|
+
"type": "dynamiczone",
|
|
32
|
+
"components": [],
|
|
33
|
+
"pluginOptions": {
|
|
34
|
+
"i18n": {
|
|
35
|
+
"localized": true
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -12,6 +12,7 @@ const reload_strapi_on_load_1 = require("../utils/reload-strapi-on-load");
|
|
|
12
12
|
const page_type_start_json_1 = __importDefault(require("../schema/page-type-start.json"));
|
|
13
13
|
const page_type_end_json_1 = __importDefault(require("../schema/page-type-end.json"));
|
|
14
14
|
const template_start_json_1 = __importDefault(require("../schema/template-start.json"));
|
|
15
|
+
const template_end_json_1 = __importDefault(require("../schema/template-end.json"));
|
|
15
16
|
const platform_start_json_1 = __importDefault(require("../schema/platform-start.json"));
|
|
16
17
|
const UIDS = [constants_1.TEMPLATE_UID, constants_1.PAGE_TYPE_UID, constants_1.PLATFORM_UID, constants_1.PAGE_UID];
|
|
17
18
|
exports.default = {
|
|
@@ -71,7 +72,7 @@ exports.default = {
|
|
|
71
72
|
update: this.getPageTypeContentType()
|
|
72
73
|
},
|
|
73
74
|
[constants_1.TEMPLATE_UID]: {
|
|
74
|
-
create: this.getTemplateContentType(),
|
|
75
|
+
create: this.getTemplateContentType(true),
|
|
75
76
|
update: this.getTemplateContentType()
|
|
76
77
|
},
|
|
77
78
|
[constants_1.PLATFORM_UID]: {
|
|
@@ -91,8 +92,8 @@ exports.default = {
|
|
|
91
92
|
const contentType = this.mergeCollectionTypeWithOld(pageType, constants_1.PAGE_TYPE_UID);
|
|
92
93
|
return { uid: constants_1.PAGE_TYPE_UID, contentType };
|
|
93
94
|
},
|
|
94
|
-
getTemplateContentType() {
|
|
95
|
-
const template = template_start_json_1.default;
|
|
95
|
+
getTemplateContentType(create) {
|
|
96
|
+
const template = create ? template_start_json_1.default : template_end_json_1.default;
|
|
96
97
|
const contentType = this.mergeCollectionTypeWithOld(template, constants_1.TEMPLATE_UID);
|
|
97
98
|
return { uid: constants_1.TEMPLATE_UID, contentType };
|
|
98
99
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const constants_1 = require("../../shared/utils/constants");
|
|
4
4
|
exports.default = {
|
|
5
|
-
async findOneByUid(uid) {
|
|
5
|
+
async findOneByUid(uid, platformId) {
|
|
6
6
|
var _a;
|
|
7
7
|
const results = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_TYPE_UID, {
|
|
8
8
|
populate: {
|
|
@@ -10,10 +10,14 @@ exports.default = {
|
|
|
10
10
|
populate: {
|
|
11
11
|
modules: true
|
|
12
12
|
}
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
defaultParent: true
|
|
14
15
|
},
|
|
15
16
|
filters: {
|
|
16
|
-
uid
|
|
17
|
+
uid,
|
|
18
|
+
platform: {
|
|
19
|
+
id: platformId
|
|
20
|
+
}
|
|
17
21
|
}
|
|
18
22
|
}));
|
|
19
23
|
const result = results.length > 0 ? results === null || results === void 0 ? void 0 : results[0] : undefined;
|