@webbio/strapi-plugin-page-builder 0.17.1-platform → 0.18.1-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';
@@ -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 (
@@ -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 => {
@@ -0,0 +1 @@
1
+ export const delay = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
@@ -4,9 +4,10 @@ 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
- const { onChange, initialData, modifiedData, layout } = form || {};
10
+ const { onChange, initialData, modifiedData, layout, isCreatingEntry } = form || {};
10
11
  const { isLoading: isLoadingPlatform, data: platformRelation } = useGetPlatformRelation({
11
12
  id: initialData?.id,
12
13
  uid: layout.uid
@@ -28,14 +29,28 @@ const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (pla
28
29
  }
29
30
  }, [isLoadingPlatform, defaultPlatform]);
30
31
 
31
- const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
32
- onChange({
33
- target: {
34
- name,
35
- value
32
+ const setFormValue = async (name: string, value?: Record<string, any>[]) => {
33
+ // So let me explain...
34
+ // For some time now Strapi will wait for all form values to be populated before finalizing the form's initialData.
35
+ // In a sense this is a good thing as you now will have all the data you need to operate on.
36
+ // But since we have an onChange with shouldSetInitialValue set to false, we should expect this value to not be in the initialData.
37
+ // Of course this isn't the case and means our platform value will be set too soon and be part of the initialData.
38
+ // On save this will result in no changes being made to the platform field and no platform will be linked.
39
+ // 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).
40
+ // Oh yeah, and apparently this only happens when creating a new entry.
41
+ if (isCreatingEntry) {
42
+ await delay(100);
43
+ }
44
+
45
+ onChange(
46
+ {
47
+ target: {
48
+ name,
49
+ value
50
+ }
36
51
  },
37
- shouldSetInitialValue: true
38
- });
52
+ false
53
+ );
39
54
  };
40
55
 
41
56
  const handleSelectPlatform = async (platform: Platform) => {
@@ -44,7 +59,8 @@ const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (pla
44
59
  const formPlatform = {
45
60
  ...platform,
46
61
  label: platform.title,
47
- value: platform.id
62
+ value: platform.id,
63
+ mainField: platform.title
48
64
  };
49
65
  setFormValue('platform', [formPlatform]);
50
66
  } else {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.17.1-platform",
3
+ "version": "0.18.1-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",