@webbio/strapi-plugin-page-builder 0.3.1 → 0.3.3

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.
@@ -15,9 +15,9 @@ const QUERY_KEY = 'platforms';
15
15
 
16
16
  const fetchPlatforms = async ({ fetchClient }: any): Promise<Platform[]> => {
17
17
  const { get } = fetchClient;
18
- const result = await get(getRequestUrl(`/platform`));
18
+ const result = await get('/content-manager/collection-types/api::platform.platform');
19
19
 
20
- return result?.data?.map((entity: any) => ({
20
+ return result?.data?.results.map((entity: any) => ({
21
21
  id: entity.id,
22
22
  title: entity.title,
23
23
  pageTypes: entity.pageTypes
@@ -1,4 +1,4 @@
1
- import React, { useEffect } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
 
3
3
  import { useCMEditViewDataManager } from '@strapi/helper-plugin';
4
4
  import { Flex } from '@strapi/design-system';
@@ -8,10 +8,13 @@ import { Wrapper } from '../wrapper';
8
8
  import { CreatePageButton } from './CreatePageButton';
9
9
  import { PAGE_TYPE_PAGE, PAGE_UID } from '../../../../../shared/utils/constants';
10
10
  import S from '../Details/styles';
11
+ import { PlatformSelect } from '../Platform/platform-select';
12
+ import { Platform, useGetPlatforms } from '../../../api/platform';
11
13
 
12
14
  export const CollectionTypeSettings = () => {
13
15
  const { layout, isCreatingEntry, initialData, onChange } = useCMEditViewDataManager() as any;
14
-
16
+ const { data: platforms } = useGetPlatforms({});
17
+ const [selectedPlatform, setSelectedPlatform] = useState<Platform | undefined | null>(initialData?.platform?.[0]);
15
18
  const isUserCreatedContentType = layout.uid.startsWith('api::');
16
19
  const linkedPage = initialData.page?.[0];
17
20
 
@@ -33,26 +36,62 @@ export const CollectionTypeSettings = () => {
33
36
  return null;
34
37
  }
35
38
 
39
+ useEffect(() => {
40
+ setSelectedPlatform(initialData?.platform?.[0]);
41
+ }, [initialData]);
42
+
43
+ const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
44
+ onChange({
45
+ target: {
46
+ name,
47
+ value
48
+ },
49
+ shouldSetInitialValue: true
50
+ });
51
+ };
52
+
53
+ const handleSelectPlatform = async (platformId: string) => {
54
+ const platform = platforms?.find((platform) => platform.id === Number(platformId));
55
+
56
+ if (platform && platform.title) {
57
+ setSelectedPlatform(platform);
58
+ const formPlatform = {
59
+ ...platform,
60
+ label: platform.title,
61
+ value: platform.id
62
+ };
63
+ setFormValue('platform', [formPlatform]);
64
+ } else {
65
+ setFormValue('platform', []);
66
+ setSelectedPlatform(null);
67
+ }
68
+ };
69
+
36
70
  return (
37
- <Wrapper title="Gekoppelde pagina">
38
- <Flex direction="column" gap={4} width="100%" alignItems="start">
39
- {showCreatePageButton && <CreatePageButton />}
71
+ <>
72
+ <Wrapper title="Platform">
73
+ <PlatformSelect platforms={platforms} selectedPlatform={selectedPlatform} onChange={handleSelectPlatform} />
74
+ </Wrapper>
75
+ <Wrapper title="Gekoppelde pagina">
76
+ <Flex direction="column" gap={4} width="100%" alignItems="start">
77
+ {showCreatePageButton && <CreatePageButton />}
40
78
 
41
- {url && (
42
- <Flex direction="column" alignItems="start" width="100%" gap={1}>
43
- <S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
44
- {PAGE_TYPE_PAGE}
45
- </S.SubtleType>
46
- <S.EntityLinkWrapper variant="pi" textColor="neutral800">
47
- <S.EntityLink title={linkedPage.title || '-'} to={url} variant="pi">
48
- <Link />
49
- {linkedPage.title || '-'}
50
- </S.EntityLink>
51
- </S.EntityLinkWrapper>
52
- </Flex>
53
- )}
54
- </Flex>
55
- </Wrapper>
79
+ {url && (
80
+ <Flex direction="column" alignItems="start" width="100%" gap={1}>
81
+ <S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
82
+ {PAGE_TYPE_PAGE}
83
+ </S.SubtleType>
84
+ <S.EntityLinkWrapper variant="pi" textColor="neutral800">
85
+ <S.EntityLink title={linkedPage.title || '-'} to={url} variant="pi">
86
+ <Link />
87
+ {linkedPage.title || '-'}
88
+ </S.EntityLink>
89
+ </S.EntityLinkWrapper>
90
+ </Flex>
91
+ )}
92
+ </Flex>
93
+ </Wrapper>
94
+ </>
56
95
  );
57
96
  };
58
97
 
@@ -3,7 +3,7 @@ import React, { useEffect, useMemo, useState } from 'react';
3
3
  import { useCMEditViewDataManager } from '@strapi/helper-plugin';
4
4
  import { Stack, Flex } from '@strapi/design-system';
5
5
  import { Cog, Cross } from '@strapi/icons';
6
- import { getFetchClient } from '@strapi/helper-plugin';
6
+ import { getFetchClient, useRBACProvider } from '@strapi/helper-plugin';
7
7
  import { TemplateSelect } from '../Template/TemplateSelect';
8
8
  import { PageTypeSelect } from '../page-type-select';
9
9
  import { CollectionTypeSearch } from '../CollectionTypeSearch';
@@ -18,6 +18,7 @@ import getRequestUrl from '../../../utils/getRequestUrl';
18
18
  export const PageSettings = () => {
19
19
  const { isCreatingEntry, initialData, onChange, modifiedData, ...rest } = useCMEditViewDataManager() as any;
20
20
  const { data: allPageTypes } = useGetPageTypes({});
21
+ const { allPermissions } = useRBACProvider();
21
22
  const { data: platforms } = useGetPlatforms({});
22
23
  const [pageTypes, setPageTypes] = useState(allPageTypes);
23
24
  const [selectedPageType, setSelectedPageType] = useState<PageType | undefined | null>(initialData?.initialPageType);
@@ -39,6 +40,18 @@ export const PageSettings = () => {
39
40
  });
40
41
  };
41
42
 
43
+ const getPlatformFromPermissions = () => {
44
+ const checkPagePremissions = allPermissions.filter((permission) => permission.subject === 'api::page.page');
45
+
46
+ const checkedConditions = checkPagePremissions.filter(
47
+ (permission) =>
48
+ permission.action === 'plugin::content-manager.explorer.create' ||
49
+ permission.action === 'plugin::content-manager.explorer.update'
50
+ );
51
+ };
52
+
53
+ getPlatformFromPermissions();
54
+
42
55
  useEffect(() => {
43
56
  setSelectedPageType(initialData?.initialPageType);
44
57
 
@@ -110,7 +123,11 @@ export const PageSettings = () => {
110
123
  const { get } = getFetchClient();
111
124
  const { data: platFormData } = await get(pageTypeUrl);
112
125
 
113
- setPageTypes(platFormData[0].pageTypes);
126
+ const filterPageTypeByPlatform = platFormData[0].pageTypes.filter(
127
+ (data) => allPageTypes?.find((pageData) => pageData.uid === data.uid)
128
+ );
129
+
130
+ setPageTypes(filterPageTypeByPlatform);
114
131
  };
115
132
 
116
133
  return (
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -2,30 +2,83 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const constants_1 = require("../../shared/utils/constants");
4
4
  exports.default = async ({ strapi }) => {
5
- var _a;
5
+ var _a, _b;
6
6
  try {
7
7
  const pageTypes = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_TYPE_UID, {
8
8
  limit: -1
9
9
  })));
10
- const pagePermissions = pageTypes.map((pageType) => {
11
- const name = `page-type-is-${pageType.uid}`;
12
- const displayName = pageType.title;
10
+ const platforms = (await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.findMany(constants_1.PLATFORM_UID, {
11
+ limit: -1
12
+ })));
13
+ const platformPagePermissions = platforms.map((platform) => {
14
+ return pageTypes.map((pageType) => {
15
+ const name = `platform-is-${platform.title}-${pageType.uid}`;
16
+ const displayName = `${platform.title}-${pageType.title}`;
17
+ return {
18
+ plugin: 'page-builder',
19
+ name,
20
+ displayName,
21
+ category: `${platform.title} Page roles`,
22
+ handler: async () => {
23
+ return {
24
+ $and: [
25
+ {
26
+ 'platform.id': {
27
+ $eq: platform.id
28
+ }
29
+ },
30
+ {
31
+ 'pageType.uid': {
32
+ $eq: pageType.uid
33
+ }
34
+ },
35
+ {
36
+ uid: {
37
+ $eq: pageType.uid
38
+ }
39
+ }
40
+ ]
41
+ };
42
+ }
43
+ };
44
+ });
45
+ });
46
+ const pageTypePermissions = pageTypes.map((pageType) => {
47
+ const name = `pageType-permission-${pageType.uid}`;
48
+ const displayName = `pageType ${pageType.title}`;
49
+ return {
50
+ plugin: 'page-builder',
51
+ name,
52
+ displayName,
53
+ category: `Platform pageType roles`,
54
+ handler: async () => {
55
+ return {
56
+ uid: {
57
+ $eq: pageType.uid
58
+ }
59
+ };
60
+ }
61
+ };
62
+ });
63
+ const platformCollectiontypePermissions = platforms.map((platform) => {
64
+ const name = `platform-is-${platform.title}`;
65
+ const displayName = platform.title;
13
66
  return {
14
67
  plugin: 'page-builder',
15
68
  name,
16
69
  displayName,
17
- category: 'Page type',
70
+ category: 'Platform CollectionType roles',
18
71
  handler: async () => {
19
72
  return {
20
73
  $or: [
21
74
  {
22
- 'pageType.uid': {
23
- $eq: pageType.uid
75
+ 'platform.id': {
76
+ $eq: platform.id
24
77
  }
25
78
  },
26
79
  {
27
- uid: {
28
- $eq: pageType.uid
80
+ id: {
81
+ $eq: platform.id
29
82
  }
30
83
  }
31
84
  ]
@@ -33,8 +86,13 @@ exports.default = async ({ strapi }) => {
33
86
  }
34
87
  };
35
88
  });
89
+ const allPermissions = [
90
+ ...platformPagePermissions.flat(),
91
+ ...pageTypePermissions.flat(),
92
+ ...platformCollectiontypePermissions
93
+ ];
36
94
  // @ts-ignore shitty types
37
- await strapi.admin.services.permission.conditionProvider.registerMany(pagePermissions);
95
+ await strapi.admin.services.permission.conditionProvider.registerMany(allPermissions);
38
96
  }
39
97
  catch {
40
98
  console.log('Cannot set page permissions');
@@ -10,7 +10,7 @@ const getPageBySlug = (strapi) => {
10
10
  }
11
11
 
12
12
  type Query {
13
- getPageBySlug(path: String, _locale: String, _publicationState: PublicationState): PageEntity
13
+ getPageBySlug(path: String, _domain: String, _locale: String, _publicationState: PublicationState): PageEntity
14
14
  }
15
15
 
16
16
  `;
@@ -22,45 +22,52 @@ const getPageBySlug = (strapi) => {
22
22
  getPageBySlug: {
23
23
  resolve: async (_parent, args, ctx) => {
24
24
  var _a;
25
- const filteredArgs = {
26
- ...(0, filter_underscore_arguments_1.filterUnderscoreArguments)(args)
27
- };
28
- const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
29
- const getPage = async () => {
30
- var _a, _b, _c;
31
- const transformedArgs = transformArgs(filteredArgs, {
32
- contentType: strapi.contentTypes[constants_1.PAGE_UID],
33
- usePagination: false
34
- });
35
- const results = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_UID, {
36
- filters: transformedArgs,
37
- locale: args._locale,
38
- publicationState: args._publicationState,
39
- populate: '*'
40
- }));
41
- const entityResponse = toEntityResponse((results === null || results === void 0 ? void 0 : results[0]) || {}, {
42
- args: transformedArgs,
43
- resourceUID: constants_1.PAGE_UID
44
- });
45
- if (!(entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) || Object.keys(entityResponse.value).length === 0) {
46
- throw new Error(ctx.koaContext.response.message);
47
- }
48
- 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);
49
- const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter === null || collectionTypeDataFilter === void 0 ? void 0 : collectionTypeDataFilter[0] : null;
50
- const addedAttributes = {
51
- collectionType: collectionType
25
+ try {
26
+ const filteredArgs = {
27
+ ...(0, filter_underscore_arguments_1.filterUnderscoreArguments)(args),
28
+ platform: { domain: args._domain }
52
29
  };
53
- const result = {
54
- ...entityResponse.value,
55
- ...addedAttributes
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;
56
60
  };
57
- return result;
58
- };
59
- const results = await getPage();
60
- if (((_a = Object.values(results)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
61
- return results;
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
+ }
62
68
  }
63
- else {
69
+ catch (error) {
70
+ console.log('Error in getPageBySlug:', error);
64
71
  throw new Error(ctx.koaContext.response.message);
65
72
  }
66
73
  }
@@ -102,7 +102,7 @@ exports.default = {
102
102
  return { uid: constants_1.PLATFORM_UID, contentType };
103
103
  },
104
104
  mergeCollectionTypeWithOld(collectionType, uid) {
105
- var _a, _b;
105
+ var _a, _b, _c, _d, _e, _f;
106
106
  const { pluginOptions: oldPluginOptions, __schema__: oldSchema } = strapi.contentType(uid) || {};
107
107
  const modulesFromConfig = ((_a = oldSchema === null || oldSchema === void 0 ? void 0 : oldSchema.attributes) === null || _a === void 0 ? void 0 : _a.modules) ? this.getConfigModuleComponents() : undefined;
108
108
  return {
@@ -115,9 +115,9 @@ exports.default = {
115
115
  attributes: {
116
116
  ...oldSchema === null || oldSchema === void 0 ? void 0 : oldSchema.attributes,
117
117
  ...collectionType.attributes,
118
- ...(((collectionType.attributes.modules && collectionType.attributes.modules.length > 0) ||
118
+ ...(((((_c = collectionType === null || collectionType === void 0 ? void 0 : collectionType.attributes) === null || _c === void 0 ? void 0 : _c.modules) && ((_e = (_d = collectionType === null || collectionType === void 0 ? void 0 : collectionType.attributes) === null || _d === void 0 ? void 0 : _d.modules) === null || _e === void 0 ? void 0 : _e.length) > 0) ||
119
119
  modulesFromConfig) && {
120
- modules: { ...collectionType.attributes.modules, components: modulesFromConfig }
120
+ modules: { ...(_f = collectionType === null || collectionType === void 0 ? void 0 : collectionType.attributes) === null || _f === void 0 ? void 0 : _f.modules, components: modulesFromConfig }
121
121
  })
122
122
  }
123
123
  };