@webbio/strapi-plugin-page-builder 0.9.8-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.
@@ -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
- id: result.id,
71
- title: result.title,
72
- publicationState: result?.publishedAt ? 'published' : 'draft',
73
- publishedAt: result?.publishedAt,
74
- href: `/content-manager/collectionType/${uid}/${result.id}`
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
- const { layout, initialData } = form;
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
- Create new page
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 && <CreatePageButton selectedPlatform={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(
@@ -14,7 +14,7 @@ const Wrapper = styled.div<{ small?: boolean }>`
14
14
  position: fixed;
15
15
  top: 64px;
16
16
  left: 0;
17
- z-index: 1000;
17
+ z-index: 4;
18
18
  padding: 0 8px 0 12px;
19
19
  `;
20
20
  }}
@@ -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
 
@@ -172,10 +172,11 @@ const SinglePlatformFilteredSelectField = ({
172
172
  };
173
173
 
174
174
  const CustomOption = (props: OptionProps<CustomReactSelectValue, false>) => {
175
+ console.log('CustomOption', props.data?.publicationState);
175
176
  return (
176
177
  <components.Option {...props}>
177
178
  <S.CustomOption>
178
- <S.CustomOptionStatus publicationState={props.data?.publicationState} />
179
+ {props.data?.publicationState && <S.CustomOptionStatus publicationState={props.data?.publicationState} />}
179
180
  {props.children}
180
181
  </S.CustomOption>
181
182
  </components.Option>
@@ -5,8 +5,8 @@ import { useDefaultPlatformFromLocalStorage } from './useDefaultPlatformFromLoca
5
5
  import { useGetPlatformRelation } from '../../api/platform-relation';
6
6
 
7
7
  const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (platform: Platform) => void) => {
8
- const { onChange, initialData, layout } = form || {};
9
- const { isLoading: isLoadingPlatform, data: selectedPlatform } = useGetPlatformRelation({
8
+ const { onChange, initialData, modifiedData, layout } = form || {};
9
+ const { isLoading: isLoadingPlatform, data: platformRelation } = useGetPlatformRelation({
10
10
  id: initialData?.id,
11
11
  uid: layout.uid
12
12
  });
@@ -15,12 +15,12 @@ const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (pla
15
15
  useDefaultPlatformFromLocalStorage();
16
16
 
17
17
  useEffect(() => {
18
- if (!isLoadingPlatform && !selectedPlatform?.id && defaultPlatform) {
18
+ if (!isLoadingPlatform && !platformRelation?.id && defaultPlatform) {
19
19
  handleSelectPlatform(defaultPlatform);
20
20
  }
21
21
 
22
- if (selectedPlatform?.id && defaultPlatform?.id && selectedPlatform.id !== defaultPlatform.id) {
23
- setDefaultPlatform(selectedPlatform);
22
+ if (platformRelation?.id && defaultPlatform?.id && platformRelation.id !== defaultPlatform.id) {
23
+ setDefaultPlatform(platformRelation);
24
24
  }
25
25
  }, [isLoadingPlatform, defaultPlatform]);
26
26
 
@@ -48,7 +48,11 @@ const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (pla
48
48
  }
49
49
  };
50
50
 
51
- return { defaultPlatform, selectedPlatform, isLoadingPlatform };
51
+ return {
52
+ defaultPlatform,
53
+ selectedPlatform: modifiedData?.platform?.[0]?.id ? modifiedData?.platform?.[0] : platformRelation,
54
+ isLoadingPlatform
55
+ };
52
56
  };
53
57
 
54
58
  export { usePlatformFormData };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.9.8-platform",
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.0.1",
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
- 'pageType.uid': {
61
- $in: permissions
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
  };
@@ -102,89 +102,81 @@ exports.default = async ({ strapi }) => {
102
102
  }
103
103
  },
104
104
  async afterUpdate(event) {
105
- var _a, _b;
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 data = event === null || event === void 0 ? void 0 : event['result'];
108
- const hasCollectionTypeRelation = data && ((_a = data === null || data === void 0 ? void 0 : data.collectionTypeData) === null || _a === void 0 ? void 0 : _a[0]) && (data === null || data === void 0 ? void 0 : data.collectionTypeData[0].__type) && (data === null || data === void 0 ? void 0 : data.collectionTypeData[0]);
109
- if (hasCollectionTypeRelation) {
110
- const isPublished = data.publishedAt !== undefined;
111
- const pageData = isPublished ? { hasPage: !!data.publishedAt } : {};
112
- await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(data.collectionTypeData[0].__type, data.collectionTypeData[0].id, {
113
- data: {
114
- ...pageData,
115
- id: data.collectionTypeData[0].id,
116
- lifecycleState: {
117
- exit: true
118
- }
110
+ // console.log('UPDATEMANY', event.params.where);
111
+ const pagesToUpdate = (_b = (_a = event.params.where) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b['$in'];
112
+ const pages = (await ((_c = strapi.entityService) === null || _c === void 0 ? void 0 : _c.findMany(constants_1.PAGE_UID, {
113
+ populate: {
114
+ collectionTypeData: true
115
+ },
116
+ filters: {
117
+ id: {
118
+ $in: pagesToUpdate
119
119
  }
120
- }));
120
+ }
121
+ })));
122
+ if (pages && pages.length > 0) {
123
+ await Promise.all(pages === null || pages === void 0 ? void 0 : pages.map((p) => afterUpdate(p)));
121
124
  }
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
125
  }
136
126
  catch (error) {
137
- console.error('Failed to save hasPage data', error);
127
+ console.error('Failed to save hasPage many data', error);
138
128
  }
139
129
  },
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
130
  async beforeDelete(event) {
155
- var _a, _b, _c, _d, _e, _f;
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
- }
131
+ await beforeDelete(event.params.where.id);
169
132
  },
170
133
  async beforeDeleteMany(event) {
171
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
134
+ var _a, _b, _c, _d;
172
135
  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
136
  for (const pageId of pagesToDisconnect) {
174
- const originalEntity = (await ((_e = strapi.entityService) === null || _e === void 0 ? void 0 : _e.findOne(constants_1.PAGE_UID, pageId, {
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
- }
137
+ await beforeDelete(pageId);
187
138
  }
188
139
  }
189
140
  });
190
141
  };
142
+ const beforeDelete = async (id) => {
143
+ var _a, _b, _c, _d, _e, _f;
144
+ const originalEntity = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.PAGE_UID, id, {
145
+ populate: {
146
+ collectionTypeData: true
147
+ }
148
+ })));
149
+ 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)) {
150
+ await ((_f = strapi.entityService) === null || _f === void 0 ? void 0 : _f.update(originalEntity.collectionTypeData[0].__type, originalEntity.collectionTypeData[0].id, {
151
+ data: {
152
+ id: originalEntity.collectionTypeData[0].id,
153
+ hasPage: false
154
+ }
155
+ }));
156
+ }
157
+ };
158
+ const afterUpdate = async (result) => {
159
+ var _a, _b;
160
+ try {
161
+ const hasCollectionTypeRelation = result &&
162
+ ((_a = result === null || result === void 0 ? void 0 : result.collectionTypeData) === null || _a === void 0 ? void 0 : _a[0]) &&
163
+ (result === null || result === void 0 ? void 0 : result.collectionTypeData[0].__type) &&
164
+ (result === null || result === void 0 ? void 0 : result.collectionTypeData[0]);
165
+ if (hasCollectionTypeRelation) {
166
+ const isPublished = result.publishedAt !== undefined;
167
+ const pageData = isPublished ? { hasPage: !!result.publishedAt } : {};
168
+ await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(result.collectionTypeData[0].__type, result.collectionTypeData[0].id, {
169
+ data: {
170
+ ...pageData,
171
+ id: result.collectionTypeData[0].id,
172
+ lifecycleState: {
173
+ exit: true
174
+ }
175
+ }
176
+ }));
177
+ }
178
+ }
179
+ catch (error) {
180
+ console.error('Failed to save hasPage data', error);
181
+ }
182
+ };