@webbio/strapi-plugin-page-builder 0.18.0-platform → 1.0.0

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.
@@ -111,7 +111,7 @@ export const getSearchFilteredEntities = async ({
111
111
  title: result?.[mainFieldName],
112
112
  publicationState: getPublicationState(),
113
113
  publishedAt: result?.publishedAt,
114
- href: `/content-manager/collectionType/${uid}/${result.id}`,
114
+ href: `/content-manager/collection-types/${uid}/${result.id}`,
115
115
  subTitle: typeof subTitle === 'string' || typeof subTitle === 'number' ? String(subTitle) : ''
116
116
  };
117
117
  });
@@ -28,7 +28,7 @@ export const CreatePageButton = ({ selectedPlatform, onCreatedPage }: ICreatePag
28
28
  const { locales } = useSelector((state: any) => state.i18n_locales);
29
29
 
30
30
  const { post, get, put } = useFetchClient();
31
- const url = `/content-manager/collectionType/${PAGE_UID}/create`;
31
+ const url = `/content-manager/collection-types/${PAGE_UID}/create`;
32
32
 
33
33
  const handleCreatePage = async (e: React.MouseEvent<HTMLAnchorElement>) => {
34
34
  e.preventDefault();
@@ -10,6 +10,7 @@ import { PAGE_TYPE_PAGE, PAGE_UID } from '../../../../../shared/utils/constants'
10
10
  import { usePlatformFormData } from '../../../utils/hooks/usePlatformFormData';
11
11
  import S from '../Details/styles';
12
12
  import { usePageTypeExists } from '../../../api/page-type-exists';
13
+ import { delay } from '../../../utils/delay';
13
14
 
14
15
  interface CollectionTypeSettingsProps {
15
16
  onlyPlatform?: boolean;
@@ -38,15 +39,26 @@ export const CollectionTypeSettings = ({ onlyPlatform }: CollectionTypeSettingsP
38
39
  }
39
40
  }, [modifiedData.page?.[0]]);
40
41
 
41
- useEffect(() => {
42
- if (isCreatingEntry) {
43
- onChange({
42
+ // Reset page link if creating entry
43
+ // Reason for the delay is explained in usePlatformFormData.ts
44
+ const resetPageLinkIfCreatingEntry = async () => {
45
+ if (!isCreatingEntry || (isCreatingEntry && !initialData.page)) return;
46
+
47
+ await delay(100);
48
+
49
+ onChange(
50
+ {
44
51
  target: {
45
52
  name: 'page',
46
53
  value: null
47
54
  }
48
- });
49
- }
55
+ },
56
+ false
57
+ );
58
+ };
59
+
60
+ useEffect(() => {
61
+ resetPageLinkIfCreatingEntry();
50
62
  }, []);
51
63
 
52
64
  return (
@@ -57,8 +69,8 @@ export const CollectionTypeSettings = ({ onlyPlatform }: CollectionTypeSettingsP
57
69
  {!pageTypeExists && !linkedPage && !isLoadingPageTypeExists && (
58
70
  <S.InfoType variant="pi" textColor="neutral800">
59
71
  Er bestaat nog geen{' '}
60
- <Link to="/content-manager/collectionType/api::page-type.page-type">pagina type</Link> voor dit content
61
- type.
72
+ <Link to="/content-manager/collection-types/api::page-type.page-type">pagina type</Link> voor dit
73
+ content type.
62
74
  </S.InfoType>
63
75
  )}
64
76
  {showCreatePageButton && selectedPlatform && (pageTypeExists || linkedPage) && (
@@ -18,7 +18,7 @@ const useRelationLoad = ({ name, attribute }: IRelationLoadProps) => {
18
18
  const { modifiedData, initialData, slug, layout, allLayoutData, isCreatingEntry, relationLoad } =
19
19
  useCMEditViewDataManager() as any;
20
20
  const { params } =
21
- useRouteMatch<{ origin?: string }>('/content-manager/collectionType/:collectionType/create/clone/:origin') ?? {};
21
+ useRouteMatch<{ origin?: string }>('/content-manager/collection-types/:collectionType/create/clone/:origin') ?? {};
22
22
  const { origin } = params ?? {};
23
23
  const isCloningEntry = Boolean(origin);
24
24
  const entityId = origin || modifiedData.id;
@@ -55,16 +55,6 @@ const PlatformFilteredSelectField = (props: IPlatformFilteredSelectFieldProps) =
55
55
  );
56
56
  };
57
57
 
58
- PlatformFilteredSelectField.defaultProps = {
59
- description: undefined,
60
- disabled: false,
61
- error: undefined,
62
- labelAction: undefined,
63
- placeholder: undefined,
64
- value: '',
65
- required: false
66
- };
67
-
68
58
  export default PlatformFilteredSelectField;
69
59
 
70
60
  const getLocalizedActionLabel = (actionLabel?: JSX.Element, layout?: Record<string, any>): JSX.Element | undefined => {
@@ -1,5 +1,5 @@
1
1
  import { Entity } from '@strapi/types';
2
2
 
3
3
  export function getRelationLink(targetModel: string, id?: Entity.ID) {
4
- return `/content-manager/collectionType/${targetModel}/${id ?? ''}`;
4
+ return `/content-manager/collection-types/${targetModel}/${id ?? ''}`;
5
5
  }
@@ -0,0 +1 @@
1
+ export const delay = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
@@ -4,6 +4,7 @@ import { Platform } from '../../api/platform';
4
4
  import { useDefaultPlatformFromLocalStorage } from './useDefaultPlatformFromLocalStorage';
5
5
  import { useGetPlatformRelation } from '../../api/platform-relation';
6
6
  import { PLATFORM_UID } from '../../../../shared/utils/constants';
7
+ import { delay } from '../delay';
7
8
 
8
9
  const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (platform: Platform) => void) => {
9
10
  const { onChange, initialData, modifiedData, layout, isCreatingEntry } = form || {};
@@ -77,7 +78,3 @@ const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (pla
77
78
  };
78
79
 
79
80
  export { usePlatformFormData };
80
-
81
- function delay(ms: number) {
82
- return new Promise((resolve) => setTimeout(resolve, ms));
83
- }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.18.0-platform",
3
+ "version": "1.0.0",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -24,11 +24,11 @@
24
24
  "@mantine/hooks": "^7.2.2",
25
25
  "@sindresorhus/slugify": "^2.2.1",
26
26
  "@strapi/design-system": "^1.19.0",
27
- "@strapi/helper-plugin": "^4.25.8",
27
+ "@strapi/helper-plugin": "^4.25.22",
28
28
  "@strapi/icons": "^1.19.0",
29
29
  "@strapi/provider-email-amazon-ses": "^4.16.2",
30
- "@strapi/typescript-utils": "^4.25.8",
31
- "@strapi/utils": "^4.25.8",
30
+ "@strapi/typescript-utils": "^4.25.22",
31
+ "@strapi/utils": "^4.25.22",
32
32
  "add": "^2.0.6",
33
33
  "aws-sdk": "^2.1528.0",
34
34
  "fuse.js": "^7.0.0",
@@ -48,7 +48,7 @@
48
48
  "typescript": "5.1.6"
49
49
  },
50
50
  "peerDependencies": {
51
- "@strapi/strapi": "^4.25.8",
51
+ "@strapi/strapi": "^4.25.22",
52
52
  "@webbio/strapi-plugin-slug": "^3.3.2",
53
53
  "react": "^17.0.0 || ^18.0.0",
54
54
  "react-dom": "^17.0.0 || ^18.0.0",
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const filter_underscore_arguments_1 = require("../utils/filter-underscore-arguments");
4
+ const constants_1 = require("../../shared/utils/constants");
5
+ const getPageBySlug = (strapi) => {
6
+ const typeDefs = () => {
7
+ return `
8
+ extend type Page {
9
+ collectionType: GenericMorph
10
+ }
11
+
12
+ type Query {
13
+ getPageBySlug(path: String, _locale: String, _publicationState: PublicationState): PageEntity
14
+ }
15
+
16
+ `;
17
+ };
18
+ const resolvers = (strapi) => {
19
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
20
+ return {
21
+ Query: {
22
+ getPageBySlug: {
23
+ resolve: async (_parent, args, ctx) => {
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
52
+ };
53
+ const result = {
54
+ ...entityResponse.value,
55
+ ...addedAttributes
56
+ };
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;
62
+ }
63
+ else {
64
+ throw new Error(ctx.koaContext.response.message);
65
+ }
66
+ }
67
+ }
68
+ }
69
+ };
70
+ };
71
+ const resolversConfig = {
72
+ 'Query.getPageBySlug': {
73
+ auth: false
74
+ }
75
+ };
76
+ return {
77
+ typeDefs: typeDefs(),
78
+ resolvers: resolvers(strapi),
79
+ resolversConfig
80
+ };
81
+ };
82
+ exports.default = getPageBySlug;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerGraphQLResolvers = void 0;
4
+ const constants_1 = require("../../shared/utils/constants");
5
+ const findPageByPath = (strapi) => {
6
+ const typeDefs = `
7
+ type Query {
8
+ findPageByPath(path: String, locale: I18NLocaleCode): PageEntityResponse
9
+ }
10
+ `;
11
+ const resolvers = (strapi) => {
12
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
13
+ const { toEntityResponse, toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
14
+ return {
15
+ Query: {
16
+ findPageByPath: {
17
+ resolve: async (parent, args, ctx) => {
18
+ const contentType = strapi.getModel(constants_1.PAGE_UID);
19
+ const transformedArgs = transformArgs(args, { contentType });
20
+ const queryResult = await strapi.entityService.findMany(contentType.uid, {
21
+ filters: {
22
+ path: {
23
+ $eq: transformedArgs.path
24
+ }
25
+ },
26
+ locale: transformedArgs.locale
27
+ });
28
+ const result = queryResult === null || queryResult === void 0 ? void 0 : queryResult[0];
29
+ return toEntityResponse(result, {
30
+ args: transformedArgs,
31
+ resourceUID: contentType.uid
32
+ });
33
+ }
34
+ }
35
+ }
36
+ };
37
+ };
38
+ const resolversConfig = {
39
+ 'Query.findPageByPath': {
40
+ auth: false
41
+ }
42
+ };
43
+ return {
44
+ typeDefs,
45
+ resolvers: resolvers(strapi),
46
+ resolversConfig
47
+ };
48
+ };
49
+ const findPagePaths = (strapi) => {
50
+ const typeDefs = `
51
+ type PageByPath {
52
+ id: Int!
53
+ path: String!
54
+ title: String!
55
+ locale: String!
56
+ pageType: ENUM_PAGE_PAGETYPE
57
+ updatedAt: DateTime!
58
+ publishedAt: DateTime!
59
+ }
60
+
61
+ type Query {
62
+ findPagePaths(locale: String, pageType: String = "all"): [PageByPath]
63
+ }
64
+ `;
65
+ const resolvers = (strapi) => {
66
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
67
+ return {
68
+ Query: {
69
+ findPagePaths: {
70
+ resolve: async (parent, args, ctx) => {
71
+ const contentType = strapi.getModel(constants_1.PAGE_UID);
72
+ const transformedArgs = transformArgs(args, { contentType });
73
+ const queryResult = await strapi.entityService.findMany(contentType.uid, {
74
+ populate: '*',
75
+ locale: transformedArgs.locale
76
+ });
77
+ const result = queryResult.filter((page) => page === null || page === void 0 ? void 0 : page.path);
78
+ return result;
79
+ }
80
+ }
81
+ }
82
+ };
83
+ };
84
+ const resolversConfig = {
85
+ 'Query.findPagePaths': {
86
+ auth: false
87
+ }
88
+ };
89
+ return {
90
+ typeDefs,
91
+ resolvers: resolvers(strapi),
92
+ resolversConfig
93
+ };
94
+ };
95
+ const registerGraphQLResolvers = (strapi) => {
96
+ const extensionService = strapi.plugin('graphql').service('extension');
97
+ extensionService.use(findPageByPath(strapi));
98
+ extensionService.use(findPagePaths(strapi));
99
+ };
100
+ exports.registerGraphQLResolvers = registerGraphQLResolvers;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pagination = void 0;
4
+ class Pagination {
5
+ static checkPagination(page, pageSize) {
6
+ const startPage = page === 1 ? 0 : page - 1;
7
+ const start = startPage * pageSize;
8
+ const limit = (startPage + 1) * pageSize;
9
+ return { start, limit };
10
+ }
11
+ static async getPaginationInfo(transformedpageArgs, transformArgs, start, pageSize, entityResponse, uid) {
12
+ var _a;
13
+ const total = await ((_a = strapi === null || strapi === void 0 ? void 0 : strapi.entityService) === null || _a === void 0 ? void 0 : _a.count(uid, {
14
+ filters: {
15
+ ...transformArgs.filters,
16
+ hasPage: { $eq: true },
17
+ page: { ...transformedpageArgs.filters }
18
+ }
19
+ }));
20
+ const pageCount = Math.ceil(total / pageSize);
21
+ const page = Math.floor(start / pageSize) + 1;
22
+ entityResponse.metaInfo = {
23
+ total,
24
+ pageCount,
25
+ page,
26
+ pageSize
27
+ };
28
+ return entityResponse;
29
+ }
30
+ }
31
+ exports.Pagination = Pagination;