@webbio/strapi-plugin-page-builder 0.12.2-platform → 0.12.4-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.
Files changed (172) hide show
  1. package/README.md +166 -166
  2. package/admin/src/api/collection-type.ts +111 -111
  3. package/admin/src/api/entity-relation.ts +42 -42
  4. package/admin/src/api/has-page-relation.ts +37 -37
  5. package/admin/src/api/has-platform-relation.ts +40 -40
  6. package/admin/src/api/page-type-relation.ts +41 -41
  7. package/admin/src/api/platform-page-types.ts +45 -45
  8. package/admin/src/api/platform-relation.ts +42 -42
  9. package/admin/src/api/platform.ts +35 -35
  10. package/admin/src/api/search-filtered-entity.ts +114 -114
  11. package/admin/src/api/template.ts +39 -39
  12. package/admin/src/components/Combobox/index.tsx +83 -83
  13. package/admin/src/components/Combobox/react-select-custom-styles.tsx +121 -121
  14. package/admin/src/components/Combobox/styles.ts +46 -46
  15. package/admin/src/components/ConfirmModal/index.tsx +90 -90
  16. package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +127 -127
  17. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +149 -149
  18. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +19 -19
  19. package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +82 -82
  20. package/admin/src/components/EditView/Details/index.tsx +48 -48
  21. package/admin/src/components/EditView/Details/styles.ts +51 -51
  22. package/admin/src/components/EditView/PageSettings/index.tsx +124 -124
  23. package/admin/src/components/EditView/Platform/platform-select.tsx +30 -30
  24. package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -36
  25. package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +70 -70
  26. package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +41 -41
  27. package/admin/src/components/EditView/index.tsx +35 -35
  28. package/admin/src/components/EditView/page-type-select.tsx +32 -32
  29. package/admin/src/components/EditView/wrapper.tsx +41 -41
  30. package/admin/src/components/GlobalPlatformSelect/index.tsx +40 -40
  31. package/admin/src/components/GlobalPlatformSelect/styles.ts +27 -27
  32. package/admin/src/components/Initializer/index.tsx +24 -24
  33. package/admin/src/components/PageFilters/PageTypeFilter/index.tsx +39 -39
  34. package/admin/src/components/PageFilters/PlatformFilter/index.tsx +32 -32
  35. package/admin/src/components/PageFilters/filters.tsx +189 -189
  36. package/admin/src/components/PageFilters/index.tsx +35 -35
  37. package/admin/src/components/PageTypeEditView/TemplatePlatformSelect/index.tsx +76 -76
  38. package/admin/src/components/PageTypeEditView/index.tsx +53 -53
  39. package/admin/src/components/PlatformFilteredSelectField/InputIcon/index.tsx +23 -23
  40. package/admin/src/components/PlatformFilteredSelectField/Multi/index.tsx +210 -210
  41. package/admin/src/components/PlatformFilteredSelectField/Single/index.tsx +197 -197
  42. package/admin/src/components/PlatformFilteredSelectField/hooks/useRelationLoad.tsx +128 -128
  43. package/admin/src/components/PlatformFilteredSelectField/index.tsx +85 -85
  44. package/admin/src/components/PlatformFilteredSelectField/styles.tsx +77 -77
  45. package/admin/src/components/PlatformFilteredSelectField/utils/get-translations.ts +3 -3
  46. package/admin/src/components/PlatformFilteredSelectField/utils/relation-helper.ts +147 -147
  47. package/admin/src/components/PluginIcon/index.tsx +94 -94
  48. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/RelationInput.tsx +689 -689
  49. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/RelationInputDataManager.tsx +6 -6
  50. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/useRelation.ts +170 -170
  51. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/utils/getRelationLink.ts +5 -5
  52. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/utils/normalizeRelations.ts +52 -52
  53. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/constants/attributes.ts +3 -3
  54. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/useDragAndDrop.ts +253 -253
  55. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/useKeyboardDragAndDrop.ts +96 -96
  56. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/usePrev.ts +11 -11
  57. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/dragAndDrop.ts +8 -8
  58. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/paths.ts +29 -29
  59. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/refs.ts +19 -19
  60. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/translations.ts +3 -3
  61. package/admin/src/components/StrapiCore/content-manager/shared/contracts/collection-types.ts +300 -300
  62. package/admin/src/components/StrapiCore/content-manager/shared/contracts/components.ts +72 -72
  63. package/admin/src/components/StrapiCore/content-manager/shared/contracts/content-types.ts +116 -116
  64. package/admin/src/components/StrapiCore/content-manager/shared/contracts/index.ts +8 -8
  65. package/admin/src/components/StrapiCore/content-manager/shared/contracts/init.ts +22 -22
  66. package/admin/src/components/StrapiCore/content-manager/shared/contracts/relations.ts +80 -80
  67. package/admin/src/components/StrapiCore/content-manager/shared/contracts/review-workflows.ts +88 -88
  68. package/admin/src/components/StrapiCore/content-manager/shared/contracts/single-types.ts +112 -112
  69. package/admin/src/components/StrapiCore/content-manager/shared/contracts/uid.ts +48 -48
  70. package/admin/src/components/StrapiCore/content-manager/shared/index.ts +1 -1
  71. package/admin/src/constants.ts +3 -3
  72. package/admin/src/index.tsx +101 -101
  73. package/admin/src/middlewares/index.tsx +37 -37
  74. package/admin/src/pages/app/index.tsx +14 -14
  75. package/admin/src/pluginId.ts +5 -5
  76. package/admin/src/translations/en.json +9 -9
  77. package/admin/src/translations/nl.json +9 -9
  78. package/admin/src/utils/findDomElement.ts +6 -6
  79. package/admin/src/utils/findElementParent.ts +20 -20
  80. package/admin/src/utils/getObjectFromFormName.ts +42 -42
  81. package/admin/src/utils/getRequestUrl.ts +11 -11
  82. package/admin/src/utils/getTrad.ts +5 -5
  83. package/admin/src/utils/hooks/useDebounce.ts +17 -17
  84. package/admin/src/utils/hooks/useDefaultPlatformFromLocalStorage.ts +61 -61
  85. package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -9
  86. package/admin/src/utils/hooks/useHideOverviewFilterTags.ts +34 -34
  87. package/admin/src/utils/hooks/usePlatformFormData.ts +64 -64
  88. package/admin/src/utils/hooks/usePrevious.ts +12 -12
  89. package/admin/src/utils/sanitizeModules.ts +93 -93
  90. package/custom.d.ts +6 -6
  91. package/dist/package.json +1 -1
  92. package/dist/server/bootstrap/collection-type-lifecycles.js +1 -1
  93. package/dist/server/bootstrap.js +1 -1
  94. package/dist/server/graphql/page-by-path.js +20 -17
  95. package/dist/server/graphql/page-by-slug.js +9 -9
  96. package/dist/server/graphql/pages-by-uid.js +5 -5
  97. package/dist/server/services/private-content/graphql/index.js +27 -27
  98. package/dist/server/services/private-content/graphql/types/index.js +74 -74
  99. package/dist/server/utils/graphql.js +18 -18
  100. package/dist/tsconfig.server.tsbuildinfo +1 -1
  101. package/package.json +78 -78
  102. package/server/bootstrap/collection-type-lifecycles.ts +47 -47
  103. package/server/bootstrap/permissions.ts +161 -161
  104. package/server/bootstrap.ts +261 -261
  105. package/server/config/index.ts +4 -4
  106. package/server/content-types/index.ts +7 -7
  107. package/server/content-types/user-category/schema.json +23 -23
  108. package/server/controllers/collection-types.ts +32 -32
  109. package/server/controllers/index.ts +19 -19
  110. package/server/controllers/page-type.ts +18 -18
  111. package/server/controllers/page.ts +9 -9
  112. package/server/controllers/platform.ts +21 -21
  113. package/server/controllers/private-content.ts +17 -17
  114. package/server/controllers/sitemap.ts +32 -32
  115. package/server/controllers/template.ts +16 -16
  116. package/server/controllers/user-category.ts +3 -3
  117. package/server/destroy.ts +5 -5
  118. package/server/graphql/index.ts +9 -9
  119. package/server/graphql/page-by-path.ts +135 -132
  120. package/server/graphql/page-type.ts +67 -67
  121. package/server/graphql/pages-by-uid.ts +89 -89
  122. package/server/index.ts +23 -23
  123. package/server/middlewares/index.ts +1 -1
  124. package/server/policies/index.ts +5 -5
  125. package/server/policies/isAuthorizedPage.ts +11 -11
  126. package/server/register.ts +22 -22
  127. package/server/routes/index.ts +115 -115
  128. package/server/routes/user-category.ts +3 -3
  129. package/server/schema/page-end.json +96 -96
  130. package/server/schema/page-start.json +87 -87
  131. package/server/schema/page-type-end.json +53 -53
  132. package/server/schema/page-type-start.json +38 -38
  133. package/server/schema/platform-start.json +21 -21
  134. package/server/schema/template-end.json +40 -40
  135. package/server/schema/template-start.json +35 -35
  136. package/server/services/builder.ts +232 -232
  137. package/server/services/collection-types.ts +95 -95
  138. package/server/services/email.ts +127 -127
  139. package/server/services/index.ts +23 -23
  140. package/server/services/page-type.ts +30 -30
  141. package/server/services/page.ts +24 -24
  142. package/server/services/platform.ts +30 -30
  143. package/server/services/private-content/components/admin-email.json +22 -22
  144. package/server/services/private-content/components/email.json +22 -22
  145. package/server/services/private-content/components/platform-email.json +30 -30
  146. package/server/services/private-content/constants/index.ts +13 -13
  147. package/server/services/private-content/graphql/index.ts +88 -88
  148. package/server/services/private-content/graphql/resolvers/findOnePage.ts +40 -40
  149. package/server/services/private-content/graphql/resolvers/findPage.ts +45 -45
  150. package/server/services/private-content/graphql/resolvers/forgot-password.ts +34 -34
  151. package/server/services/private-content/graphql/resolvers/login.ts +56 -56
  152. package/server/services/private-content/graphql/resolvers/register.ts +78 -78
  153. package/server/services/private-content/graphql/resolvers/reset-password.ts +44 -44
  154. package/server/services/private-content/graphql/types/index.ts +96 -96
  155. package/server/services/private-content/index.ts +95 -95
  156. package/server/services/private-content/mail-template/txtMail.email.template.text.ts +6 -6
  157. package/server/services/private-content/page.ts +20 -20
  158. package/server/services/private-content/platform.ts +19 -19
  159. package/server/services/private-content/schemas/index.ts +28 -28
  160. package/server/services/private-content/user.ts +197 -197
  161. package/server/services/sitemap.ts +83 -83
  162. package/server/services/template.ts +13 -13
  163. package/server/services/user-category.ts +3 -3
  164. package/server/utils/filter-underscore-arguments.ts +12 -12
  165. package/server/utils/reload-strapi-on-load.ts +13 -13
  166. package/server/utils/strapi.ts +50 -50
  167. package/shared/utils/constants.ts +8 -8
  168. package/shared/utils/sleep.ts +1 -1
  169. package/strapi-admin.js +3 -3
  170. package/strapi-server.js +3 -3
  171. package/tsconfig.json +20 -20
  172. package/tsconfig.server.json +25 -25
@@ -1,85 +1,85 @@
1
- import React from 'react';
2
- import { useCMEditViewDataManager } from '@strapi/helper-plugin';
3
-
4
- import RelationHelper, { IPlatformFilteredSelectFieldProps } from './utils/relation-helper';
5
- import MultiPlatformFilteredSelectField from './Multi';
6
- import SinglePlatformFilteredSelectField from './Single';
7
- import { useRelationLoad } from './hooks/useRelationLoad';
8
- import { usePlatformFormData } from '../../utils/hooks/usePlatformFormData';
9
-
10
- const PlatformFilteredSelectField = (props: IPlatformFilteredSelectFieldProps) => {
11
- const { name, attribute, labelAction } = props;
12
- const form = useCMEditViewDataManager() as any;
13
- const { modifiedData, layout, allLayoutData } = form;
14
- const { selectedPlatform } = usePlatformFormData(form);
15
- const { relations, isCloningEntry, totalRelations, relationsFromModifiedData } = useRelationLoad(props);
16
- const { targetAttributes } = RelationHelper.getTargetAttributes(name, attribute, modifiedData, layout, allLayoutData);
17
- const toOneRelation = ['oneWay', 'oneToOne', 'manyToOne', 'oneToManyMorph', 'oneToOneMorph'].includes(
18
- targetAttributes?.relation || ''
19
- );
20
- const hiddenId =
21
- attribute?.pluginOptions?.filteredSelect?.hideSameEntity && layout.uid === targetAttributes?.targetModel
22
- ? [modifiedData.id]
23
- : [];
24
-
25
- const correctedLabelAction = getLocalizedActionLabel(labelAction, layout);
26
-
27
- if (toOneRelation) {
28
- return (
29
- <SinglePlatformFilteredSelectField
30
- selectedPlatform={selectedPlatform}
31
- hiddenId={hiddenId}
32
- {...props}
33
- labelAction={correctedLabelAction}
34
- />
35
- );
36
- }
37
-
38
- return (
39
- <MultiPlatformFilteredSelectField
40
- selectedPlatform={selectedPlatform}
41
- relations={relations}
42
- isCloningEntry={isCloningEntry}
43
- totalRelations={totalRelations}
44
- relationsFromModifiedData={relationsFromModifiedData}
45
- hiddenId={hiddenId}
46
- {...props}
47
- labelAction={correctedLabelAction}
48
- />
49
- );
50
- };
51
-
52
- PlatformFilteredSelectField.defaultProps = {
53
- description: undefined,
54
- disabled: false,
55
- error: undefined,
56
- labelAction: undefined,
57
- placeholder: undefined,
58
- value: '',
59
- required: false
60
- };
61
-
62
- export default PlatformFilteredSelectField;
63
-
64
- const getLocalizedActionLabel = (actionLabel?: JSX.Element, layout?: Record<string, any>): JSX.Element | undefined => {
65
- if (!actionLabel) {
66
- return undefined;
67
- }
68
-
69
- if (!layout?.layouts?.edit || layout?.layouts?.edit?.length === 0) {
70
- return actionLabel;
71
- }
72
-
73
- if (layout?.pluginOptions?.i18n?.localized === true) {
74
- for (let index = 0; index < layout?.layouts?.edit.length; index++) {
75
- const element = layout?.layouts?.edit[index];
76
- const foundElement = element.find(
77
- (x: Record<string, any>) => x.fieldSchema?.pluginOptions?.i18n?.localized === true
78
- );
79
-
80
- if (foundElement?.labelAction) {
81
- return foundElement.labelAction;
82
- }
83
- }
84
- }
85
- };
1
+ import React from 'react';
2
+ import { useCMEditViewDataManager } from '@strapi/helper-plugin';
3
+
4
+ import RelationHelper, { IPlatformFilteredSelectFieldProps } from './utils/relation-helper';
5
+ import MultiPlatformFilteredSelectField from './Multi';
6
+ import SinglePlatformFilteredSelectField from './Single';
7
+ import { useRelationLoad } from './hooks/useRelationLoad';
8
+ import { usePlatformFormData } from '../../utils/hooks/usePlatformFormData';
9
+
10
+ const PlatformFilteredSelectField = (props: IPlatformFilteredSelectFieldProps) => {
11
+ const { name, attribute, labelAction } = props;
12
+ const form = useCMEditViewDataManager() as any;
13
+ const { modifiedData, layout, allLayoutData } = form;
14
+ const { selectedPlatform } = usePlatformFormData(form);
15
+ const { relations, isCloningEntry, totalRelations, relationsFromModifiedData } = useRelationLoad(props);
16
+ const { targetAttributes } = RelationHelper.getTargetAttributes(name, attribute, modifiedData, layout, allLayoutData);
17
+ const toOneRelation = ['oneWay', 'oneToOne', 'manyToOne', 'oneToManyMorph', 'oneToOneMorph'].includes(
18
+ targetAttributes?.relation || ''
19
+ );
20
+ const hiddenId =
21
+ attribute?.pluginOptions?.filteredSelect?.hideSameEntity && layout.uid === targetAttributes?.targetModel
22
+ ? [modifiedData.id]
23
+ : [];
24
+
25
+ const correctedLabelAction = getLocalizedActionLabel(labelAction, layout);
26
+
27
+ if (toOneRelation) {
28
+ return (
29
+ <SinglePlatformFilteredSelectField
30
+ selectedPlatform={selectedPlatform}
31
+ hiddenId={hiddenId}
32
+ {...props}
33
+ labelAction={correctedLabelAction}
34
+ />
35
+ );
36
+ }
37
+
38
+ return (
39
+ <MultiPlatformFilteredSelectField
40
+ selectedPlatform={selectedPlatform}
41
+ relations={relations}
42
+ isCloningEntry={isCloningEntry}
43
+ totalRelations={totalRelations}
44
+ relationsFromModifiedData={relationsFromModifiedData}
45
+ hiddenId={hiddenId}
46
+ {...props}
47
+ labelAction={correctedLabelAction}
48
+ />
49
+ );
50
+ };
51
+
52
+ PlatformFilteredSelectField.defaultProps = {
53
+ description: undefined,
54
+ disabled: false,
55
+ error: undefined,
56
+ labelAction: undefined,
57
+ placeholder: undefined,
58
+ value: '',
59
+ required: false
60
+ };
61
+
62
+ export default PlatformFilteredSelectField;
63
+
64
+ const getLocalizedActionLabel = (actionLabel?: JSX.Element, layout?: Record<string, any>): JSX.Element | undefined => {
65
+ if (!actionLabel) {
66
+ return undefined;
67
+ }
68
+
69
+ if (!layout?.layouts?.edit || layout?.layouts?.edit?.length === 0) {
70
+ return actionLabel;
71
+ }
72
+
73
+ if (layout?.pluginOptions?.i18n?.localized === true) {
74
+ for (let index = 0; index < layout?.layouts?.edit.length; index++) {
75
+ const element = layout?.layouts?.edit[index];
76
+ const foundElement = element.find(
77
+ (x: Record<string, any>) => x.fieldSchema?.pluginOptions?.i18n?.localized === true
78
+ );
79
+
80
+ if (foundElement?.labelAction) {
81
+ return foundElement.labelAction;
82
+ }
83
+ }
84
+ }
85
+ };
@@ -1,77 +1,77 @@
1
- import styled, { css } from 'styled-components';
2
- import { Box, Link, Typography } from '@strapi/design-system';
3
-
4
- const EntityLinkWrapper = styled(Typography)`
5
- ${({ _theme }) => css`
6
- margin-top: 4px;
7
- display: flex;
8
- `}
9
- `;
10
-
11
- const EntityLink = styled(Link)`
12
- ${({ _theme }) => css`
13
- span {
14
- line-height: 1.2;
15
- font-size: inherit;
16
- display: flex;
17
- gap: 6px;
18
- align-items: center;
19
- }
20
-
21
- svg {
22
- width: 0.7rem;
23
- height: 0.7rem;
24
- }
25
- `}
26
- `;
27
-
28
- const CustomOption = styled(Box)`
29
- display: flex;
30
- align-items: center;
31
- gap: 8px;
32
- `;
33
-
34
- const CustomOptionStatus = styled(Box)`
35
- background: ${({ theme, publicationState }) =>
36
- publicationState === 'published' ? theme.colors.success600 : theme.colors.secondary600};
37
- width: 6px;
38
- height: 6px;
39
- border-radius: 100px;
40
- `;
41
-
42
- const FieldWrapper = styled(Box)`
43
- display: flex;
44
- gap: 4px;
45
- `;
46
-
47
- const LinkToPage = styled(Link)`
48
- ${({ theme, disabled }) => css`
49
- height: 40px;
50
- width: 40px;
51
- display: flex;
52
- align-items: center;
53
- justify-content: center;
54
- align-self: flex-end;
55
- flex-shrink: 0;
56
- border: ${`1px solid ${theme.colors.neutral200}`};
57
- border-radius: ${theme.borderRadius};
58
- opacity: ${disabled ? 0.5 : 1};
59
- > span {
60
- display: flex;
61
- }
62
-
63
- svg {
64
- width: ${theme.fontSizes[2]};
65
- height: ${theme.fontSizes[2]};
66
- }
67
- `}
68
- `;
69
-
70
- export default {
71
- FieldWrapper,
72
- EntityLinkWrapper,
73
- EntityLink,
74
- CustomOptionStatus,
75
- CustomOption,
76
- LinkToPage
77
- };
1
+ import styled, { css } from 'styled-components';
2
+ import { Box, Link, Typography } from '@strapi/design-system';
3
+
4
+ const EntityLinkWrapper = styled(Typography)`
5
+ ${({ _theme }) => css`
6
+ margin-top: 4px;
7
+ display: flex;
8
+ `}
9
+ `;
10
+
11
+ const EntityLink = styled(Link)`
12
+ ${({ _theme }) => css`
13
+ span {
14
+ line-height: 1.2;
15
+ font-size: inherit;
16
+ display: flex;
17
+ gap: 6px;
18
+ align-items: center;
19
+ }
20
+
21
+ svg {
22
+ width: 0.7rem;
23
+ height: 0.7rem;
24
+ }
25
+ `}
26
+ `;
27
+
28
+ const CustomOption = styled(Box)`
29
+ display: flex;
30
+ align-items: center;
31
+ gap: 8px;
32
+ `;
33
+
34
+ const CustomOptionStatus = styled(Box)`
35
+ background: ${({ theme, publicationState }) =>
36
+ publicationState === 'published' ? theme.colors.success600 : theme.colors.secondary600};
37
+ width: 6px;
38
+ height: 6px;
39
+ border-radius: 100px;
40
+ `;
41
+
42
+ const FieldWrapper = styled(Box)`
43
+ display: flex;
44
+ gap: 4px;
45
+ `;
46
+
47
+ const LinkToPage = styled(Link)`
48
+ ${({ theme, disabled }) => css`
49
+ height: 40px;
50
+ width: 40px;
51
+ display: flex;
52
+ align-items: center;
53
+ justify-content: center;
54
+ align-self: flex-end;
55
+ flex-shrink: 0;
56
+ border: ${`1px solid ${theme.colors.neutral200}`};
57
+ border-radius: ${theme.borderRadius};
58
+ opacity: ${disabled ? 0.5 : 1};
59
+ > span {
60
+ display: flex;
61
+ }
62
+
63
+ svg {
64
+ width: ${theme.fontSizes[2]};
65
+ height: ${theme.fontSizes[2]};
66
+ }
67
+ `}
68
+ `;
69
+
70
+ export default {
71
+ FieldWrapper,
72
+ EntityLinkWrapper,
73
+ EntityLink,
74
+ CustomOptionStatus,
75
+ CustomOption,
76
+ LinkToPage
77
+ };
@@ -1,3 +1,3 @@
1
- const getTranslation = (id: string) => `content-manager.${id}`;
2
-
3
- export { getTranslation };
1
+ const getTranslation = (id: string) => `content-manager.${id}`;
2
+
3
+ export { getTranslation };
@@ -1,147 +1,147 @@
1
- import { IntlFormatters, MessageDescriptor } from '@formatjs/intl';
2
- import get from 'lodash/get';
3
- import { pointPathToGetPath } from '../../../utils/getObjectFromFormName';
4
-
5
- export interface GetTargetAttributesResult {
6
- targetAttributes?: {
7
- relation: string;
8
- relationType: string;
9
- target: string;
10
- targetModel: string;
11
- type: string;
12
- };
13
- targetFieldValue?: any;
14
- targetField: string;
15
- targetFieldName: string;
16
- componentUid?: string;
17
- componentId?: number;
18
- relationMainFieldName?: string;
19
- }
20
-
21
- export interface IPlatformFilteredSelectFieldProps {
22
- intlLabel?: MessageDescriptor & Parameters<IntlFormatters['formatMessage']>;
23
- onChange?: any;
24
- attribute?: {
25
- pluginOptions?: {
26
- filteredSelect?: {
27
- targetField?: string;
28
- customFilters?: Record<string, any>[];
29
- disablePlatformFilter?: boolean;
30
- hideSameEntity?: boolean;
31
- };
32
- };
33
- required?: boolean;
34
- };
35
- name?: string;
36
- description?: MessageDescriptor & Parameters<IntlFormatters['formatMessage']>;
37
- disabled?: boolean;
38
- error?: any;
39
- labelAction?: any;
40
- required?: boolean;
41
- value?: string;
42
- contentTypeUID?: string;
43
- placeholder?: MessageDescriptor & Parameters<IntlFormatters['formatMessage']>;
44
- }
45
-
46
- const RelationHelper = {
47
- getTargetAttributes: (
48
- fieldName?: string,
49
- attribute?: IPlatformFilteredSelectFieldProps['attribute'],
50
- modifiedData?: Record<string, any>,
51
- layout?: Record<string, any>,
52
- allLayoutData?: Record<string, any>
53
- ) => {
54
- const lastFieldName = fieldName?.split('.')?.[fieldName?.split('.')?.length - 1];
55
- const targetField = attribute?.pluginOptions?.filteredSelect?.targetField || fieldName || '';
56
- const targetFieldName = (fieldName || '')?.replace(lastFieldName || '', targetField);
57
-
58
- const component = getComponent(targetFieldName, modifiedData, allLayoutData);
59
- const result: GetTargetAttributesResult = {
60
- targetAttributes: undefined,
61
- targetFieldValue: undefined,
62
- targetField,
63
- componentUid: '',
64
- componentId: undefined,
65
- targetFieldName,
66
- relationMainFieldName: ''
67
- };
68
-
69
- if (component?.uid) {
70
- result.targetAttributes = allLayoutData?.components?.[component.uid]?.attributes?.[targetField];
71
- result.relationMainFieldName = component?.settings?.mainField;
72
- result.targetFieldValue = component?.values?.[targetField];
73
- result.componentUid = component?.uid;
74
- result.componentId = component?.id;
75
- result.targetField = (fieldName || '')?.replace(lastFieldName || '', targetField);
76
- } else {
77
- result.targetAttributes = layout?.attributes?.[targetField];
78
- result.relationMainFieldName = layout?.metadatas?.[targetField]?.list?.mainField?.name;
79
- result.targetFieldValue = modifiedData?.[targetField];
80
- }
81
-
82
- return result;
83
- }
84
- };
85
-
86
- export default RelationHelper;
87
-
88
- interface IComponent {
89
- id: number;
90
- uid: string;
91
- attributes?: Record<string, any>;
92
- metadatas?: Record<string, any>;
93
- settings?: {
94
- mainField?: string;
95
- } & Record<string, any>;
96
- values?: Record<string, any>;
97
- }
98
-
99
- const getComponent = (
100
- targetFieldName?: string,
101
- modifiedData?: Record<string, any>,
102
- allLayoutData?: Record<string, any>
103
- ): IComponent | undefined => {
104
- const path = pointPathToGetPath(targetFieldName);
105
- const keys = (path || '')?.split('.');
106
- // Last key is the target field name, so not a component
107
- keys.pop();
108
- let newPath = '';
109
- const components: any[] = [];
110
-
111
- for (let index = 0; index < keys.length; index++) {
112
- const newPathPart = keys?.[index];
113
- const key = newPathPart.split('[')?.[0];
114
- newPath = [...(newPath || '')?.split('.'), newPathPart].filter(Boolean).join('.');
115
-
116
- const component = get(modifiedData, newPath, true);
117
- const foundRootComponent =
118
- index === 0 ? get(allLayoutData?.contentType?.attributes, newPath.split('[')?.[0]) : undefined;
119
-
120
- if (component?.__component) {
121
- const componentLayout = allLayoutData?.components?.[component.__component];
122
- components.push({ id: component.id, ...componentLayout, values: component });
123
- continue;
124
- }
125
-
126
- if (foundRootComponent?.component) {
127
- const subComponent = allLayoutData?.components?.[foundRootComponent?.component];
128
-
129
- if (subComponent?.uid) {
130
- components.push({ id: component?.id, ...subComponent, values: component });
131
- }
132
- continue;
133
- }
134
-
135
- const lastComponent = components?.at(-1);
136
-
137
- if (lastComponent?.attributes?.[key]?.component) {
138
- const subComponent = allLayoutData?.components?.[lastComponent?.attributes?.[key]?.component];
139
- if (subComponent?.uid) {
140
- components.push({ id: component?.id, ...subComponent, values: component });
141
- }
142
- continue;
143
- }
144
- }
145
-
146
- return components?.at(-1);
147
- };
1
+ import { IntlFormatters, MessageDescriptor } from '@formatjs/intl';
2
+ import get from 'lodash/get';
3
+ import { pointPathToGetPath } from '../../../utils/getObjectFromFormName';
4
+
5
+ export interface GetTargetAttributesResult {
6
+ targetAttributes?: {
7
+ relation: string;
8
+ relationType: string;
9
+ target: string;
10
+ targetModel: string;
11
+ type: string;
12
+ };
13
+ targetFieldValue?: any;
14
+ targetField: string;
15
+ targetFieldName: string;
16
+ componentUid?: string;
17
+ componentId?: number;
18
+ relationMainFieldName?: string;
19
+ }
20
+
21
+ export interface IPlatformFilteredSelectFieldProps {
22
+ intlLabel?: MessageDescriptor & Parameters<IntlFormatters['formatMessage']>;
23
+ onChange?: any;
24
+ attribute?: {
25
+ pluginOptions?: {
26
+ filteredSelect?: {
27
+ targetField?: string;
28
+ customFilters?: Record<string, any>[];
29
+ disablePlatformFilter?: boolean;
30
+ hideSameEntity?: boolean;
31
+ };
32
+ };
33
+ required?: boolean;
34
+ };
35
+ name?: string;
36
+ description?: MessageDescriptor & Parameters<IntlFormatters['formatMessage']>;
37
+ disabled?: boolean;
38
+ error?: any;
39
+ labelAction?: any;
40
+ required?: boolean;
41
+ value?: string;
42
+ contentTypeUID?: string;
43
+ placeholder?: MessageDescriptor & Parameters<IntlFormatters['formatMessage']>;
44
+ }
45
+
46
+ const RelationHelper = {
47
+ getTargetAttributes: (
48
+ fieldName?: string,
49
+ attribute?: IPlatformFilteredSelectFieldProps['attribute'],
50
+ modifiedData?: Record<string, any>,
51
+ layout?: Record<string, any>,
52
+ allLayoutData?: Record<string, any>
53
+ ) => {
54
+ const lastFieldName = fieldName?.split('.')?.[fieldName?.split('.')?.length - 1];
55
+ const targetField = attribute?.pluginOptions?.filteredSelect?.targetField || fieldName || '';
56
+ const targetFieldName = (fieldName || '')?.replace(lastFieldName || '', targetField);
57
+
58
+ const component = getComponent(targetFieldName, modifiedData, allLayoutData);
59
+ const result: GetTargetAttributesResult = {
60
+ targetAttributes: undefined,
61
+ targetFieldValue: undefined,
62
+ targetField,
63
+ componentUid: '',
64
+ componentId: undefined,
65
+ targetFieldName,
66
+ relationMainFieldName: ''
67
+ };
68
+
69
+ if (component?.uid) {
70
+ result.targetAttributes = allLayoutData?.components?.[component.uid]?.attributes?.[targetField];
71
+ result.relationMainFieldName = component?.settings?.mainField;
72
+ result.targetFieldValue = component?.values?.[targetField];
73
+ result.componentUid = component?.uid;
74
+ result.componentId = component?.id;
75
+ result.targetField = (fieldName || '')?.replace(lastFieldName || '', targetField);
76
+ } else {
77
+ result.targetAttributes = layout?.attributes?.[targetField];
78
+ result.relationMainFieldName = layout?.metadatas?.[targetField]?.list?.mainField?.name;
79
+ result.targetFieldValue = modifiedData?.[targetField];
80
+ }
81
+
82
+ return result;
83
+ }
84
+ };
85
+
86
+ export default RelationHelper;
87
+
88
+ interface IComponent {
89
+ id: number;
90
+ uid: string;
91
+ attributes?: Record<string, any>;
92
+ metadatas?: Record<string, any>;
93
+ settings?: {
94
+ mainField?: string;
95
+ } & Record<string, any>;
96
+ values?: Record<string, any>;
97
+ }
98
+
99
+ const getComponent = (
100
+ targetFieldName?: string,
101
+ modifiedData?: Record<string, any>,
102
+ allLayoutData?: Record<string, any>
103
+ ): IComponent | undefined => {
104
+ const path = pointPathToGetPath(targetFieldName);
105
+ const keys = (path || '')?.split('.');
106
+ // Last key is the target field name, so not a component
107
+ keys.pop();
108
+ let newPath = '';
109
+ const components: any[] = [];
110
+
111
+ for (let index = 0; index < keys.length; index++) {
112
+ const newPathPart = keys?.[index];
113
+ const key = newPathPart.split('[')?.[0];
114
+ newPath = [...(newPath || '')?.split('.'), newPathPart].filter(Boolean).join('.');
115
+
116
+ const component = get(modifiedData, newPath, true);
117
+ const foundRootComponent =
118
+ index === 0 ? get(allLayoutData?.contentType?.attributes, newPath.split('[')?.[0]) : undefined;
119
+
120
+ if (component?.__component) {
121
+ const componentLayout = allLayoutData?.components?.[component.__component];
122
+ components.push({ id: component.id, ...componentLayout, values: component });
123
+ continue;
124
+ }
125
+
126
+ if (foundRootComponent?.component) {
127
+ const subComponent = allLayoutData?.components?.[foundRootComponent?.component];
128
+
129
+ if (subComponent?.uid) {
130
+ components.push({ id: component?.id, ...subComponent, values: component });
131
+ }
132
+ continue;
133
+ }
134
+
135
+ const lastComponent = components?.at(-1);
136
+
137
+ if (lastComponent?.attributes?.[key]?.component) {
138
+ const subComponent = allLayoutData?.components?.[lastComponent?.attributes?.[key]?.component];
139
+ if (subComponent?.uid) {
140
+ components.push({ id: component?.id, ...subComponent, values: component });
141
+ }
142
+ continue;
143
+ }
144
+ }
145
+
146
+ return components?.at(-1);
147
+ };