@webbio/strapi-plugin-page-builder 0.17.0-platform → 0.18.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.
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
 
3
3
  import { useCMEditViewDataManager } from '@strapi/helper-plugin';
4
- import { Flex, Typography, Link } from '@strapi/design-system';
4
+ import { Flex, Link } from '@strapi/design-system';
5
5
  import { Link as LinkIcon } from '@strapi/icons';
6
6
 
7
7
  import { Wrapper } from '../wrapper';
@@ -6,7 +6,7 @@ import { useGetPlatformRelation } from '../../api/platform-relation';
6
6
  import { PLATFORM_UID } from '../../../../shared/utils/constants';
7
7
 
8
8
  const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (platform: Platform) => void) => {
9
- const { onChange, initialData, modifiedData, layout } = form || {};
9
+ const { onChange, initialData, modifiedData, layout, isCreatingEntry } = form || {};
10
10
  const { isLoading: isLoadingPlatform, data: platformRelation } = useGetPlatformRelation({
11
11
  id: initialData?.id,
12
12
  uid: layout.uid
@@ -28,14 +28,28 @@ const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (pla
28
28
  }
29
29
  }, [isLoadingPlatform, defaultPlatform]);
30
30
 
31
- const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
32
- onChange({
33
- target: {
34
- name,
35
- value
31
+ const setFormValue = async (name: string, value?: Record<string, any>[]) => {
32
+ // So let me explain...
33
+ // For some time now Strapi will wait for all form values to be populated before finalizing the form's initialData.
34
+ // In a sense this is a good thing as you now will have all the data you need to operate on.
35
+ // But since we have an onChange with shouldSetInitialValue set to false, we should expect this value to not be in the initialData.
36
+ // Of course this isn't the case and means our platform value will be set too soon and be part of the initialData.
37
+ // On save this will result in no changes being made to the platform field and no platform will be linked.
38
+ // To fix this we need to (any) delay the setting of the platform value until the initialData has been set (as there is no status to check for the finalization of the initialData).
39
+ // Oh yeah, and apparently this only happens when creating a new entry.
40
+ if (isCreatingEntry) {
41
+ await delay(100);
42
+ }
43
+
44
+ onChange(
45
+ {
46
+ target: {
47
+ name,
48
+ value
49
+ }
36
50
  },
37
- shouldSetInitialValue: true
38
- });
51
+ false
52
+ );
39
53
  };
40
54
 
41
55
  const handleSelectPlatform = async (platform: Platform) => {
@@ -44,7 +58,8 @@ const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (pla
44
58
  const formPlatform = {
45
59
  ...platform,
46
60
  label: platform.title,
47
- value: platform.id
61
+ value: platform.id,
62
+ mainField: platform.title
48
63
  };
49
64
  setFormValue('platform', [formPlatform]);
50
65
  } else {
@@ -62,3 +77,7 @@ const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (pla
62
77
  };
63
78
 
64
79
  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.17.0-platform",
3
+ "version": "0.18.0-platform",
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.4",
27
+ "@strapi/helper-plugin": "^4.25.8",
28
28
  "@strapi/icons": "^1.19.0",
29
29
  "@strapi/provider-email-amazon-ses": "^4.16.2",
30
- "@strapi/typescript-utils": "^4.25.4",
31
- "@strapi/utils": "^4.25.4",
30
+ "@strapi/typescript-utils": "^4.25.8",
31
+ "@strapi/utils": "^4.25.8",
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.4",
51
+ "@strapi/strapi": "^4.25.8",
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",
@@ -64,7 +64,6 @@ exports.default = async ({ strapi }) => {
64
64
  async beforeCreate(event) {
65
65
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
66
66
  let { data } = event.params;
67
- console.log('data', event);
68
67
  const collectionTypeId = data === null || data === void 0 ? void 0 : data.collectionTypeId;
69
68
  const pageTypeId = ((_c = (_b = (_a = data === null || data === void 0 ? void 0 : data.pageType) === null || _a === void 0 ? void 0 : _a.connect) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.id) || data.initialPageType;
70
69
  const platformId = (_f = (_e = (_d = data === null || data === void 0 ? void 0 : data.platform) === null || _d === void 0 ? void 0 : _d.connect) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.id;