@strapi/admin 4.5.2 → 4.5.3

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 (56) hide show
  1. package/admin/src/content-manager/components/Inputs/index.js +5 -19
  2. package/admin/src/content-manager/hooks/useLazyComponents/index.js +44 -0
  3. package/admin/src/content-manager/pages/CollectionTypeRecursivePath/components/ErrorFallback.js +13 -0
  4. package/admin/src/content-manager/pages/CollectionTypeRecursivePath/index.js +2 -1
  5. package/admin/src/content-manager/pages/EditView/GridRow/index.js +62 -0
  6. package/admin/src/content-manager/pages/EditView/index.js +74 -154
  7. package/admin/src/content-manager/pages/EditView/selectors.js +14 -0
  8. package/admin/src/content-manager/pages/EditView/utils/createAttributesLayout.js +11 -6
  9. package/admin/src/content-manager/pages/EditView/utils/getCustomFieldUidsFromLayout.js +18 -0
  10. package/admin/src/content-manager/pages/EditView/utils/index.js +1 -0
  11. package/admin/src/content-manager/pages/EditViewLayoutManager/index.js +1 -1
  12. package/admin/src/core/apis/CustomFields.js +46 -1
  13. package/admin/src/pages/MarketplacePage/components/SortSelect/index.js +20 -0
  14. package/admin/src/translations/en.json +4 -0
  15. package/admin/src/translations/ru.json +789 -489
  16. package/build/{1233.bddaaa76.chunk.js → 1233.80b05d66.chunk.js} +5 -5
  17. package/build/1920.74a262e7.chunk.js +245 -0
  18. package/build/2438.61291207.chunk.js +2183 -0
  19. package/build/2517.9b4940f3.chunk.js +117 -0
  20. package/build/{4306.e62b841c.chunk.js → 4306.f03c2b46.chunk.js} +6 -6
  21. package/build/{805.a1894307.chunk.js → 805.e991a370.chunk.js} +6 -6
  22. package/build/9707.a0cc4ad8.chunk.js +70 -0
  23. package/build/{Admin-authenticatedApp.7484bdf1.chunk.js → Admin-authenticatedApp.1e1d3bdd.chunk.js} +2 -2
  24. package/build/{Admin_marketplace.ff012eb2.chunk.js → Admin_marketplace.8219fda6.chunk.js} +5 -5
  25. package/build/content-manager.01e04e11.chunk.js +1200 -0
  26. package/build/content-type-builder-list-view.4412efc3.chunk.js +201 -0
  27. package/build/{content-type-builder.95b9d6a2.chunk.js → content-type-builder.848a9610.chunk.js} +1 -1
  28. package/build/email-settings-page.d44a57cb.chunk.js +15 -0
  29. package/build/en-json.7dd57947.chunk.js +1 -0
  30. package/build/index.html +1 -1
  31. package/build/main.f31112a5.js +2034 -0
  32. package/build/ru-json.8830286f.chunk.js +1 -0
  33. package/build/{runtime~main.4dc8c7c6.js → runtime~main.f91e75cd.js} +1 -1
  34. package/build/upload-settings.450cab1a.chunk.js +18 -0
  35. package/build/upload.a73936d9.chunk.js +64 -0
  36. package/build/users-advanced-settings-page.dc23bc56.chunk.js +13 -0
  37. package/build/users-email-settings-page.6541d372.chunk.js +28 -0
  38. package/build/users-providers-settings-page.e11a2f64.chunk.js +33 -0
  39. package/build/webhook-edit-page.14ad1e6e.chunk.js +75 -0
  40. package/package.json +9 -9
  41. package/build/1920.208c77f8.chunk.js +0 -245
  42. package/build/2438.afe24949.chunk.js +0 -2525
  43. package/build/2517.5cc235ba.chunk.js +0 -117
  44. package/build/9707.932a3c12.chunk.js +0 -70
  45. package/build/content-manager.577fddcb.chunk.js +0 -1200
  46. package/build/content-type-builder-list-view.95012cf0.chunk.js +0 -201
  47. package/build/email-settings-page.4bb3606f.chunk.js +0 -15
  48. package/build/en-json.4a269f6b.chunk.js +0 -1
  49. package/build/main.23670c4c.js +0 -2026
  50. package/build/ru-json.d7cfc2ff.chunk.js +0 -1
  51. package/build/upload-settings.3010911f.chunk.js +0 -18
  52. package/build/upload.9f19f2e8.chunk.js +0 -64
  53. package/build/users-advanced-settings-page.9df41d67.chunk.js +0 -13
  54. package/build/users-email-settings-page.56d82eaf.chunk.js +0 -28
  55. package/build/users-providers-settings-page.96bb7da0.chunk.js +0 -33
  56. package/build/webhook-edit-page.3285abc4.chunk.js +0 -75
@@ -5,7 +5,7 @@ import get from 'lodash/get';
5
5
  import omit from 'lodash/omit';
6
6
  import take from 'lodash/take';
7
7
  import isEqual from 'react-fast-compare';
8
- import { GenericInput, NotAllowedInput, useLibrary, useCustomFields } from '@strapi/helper-plugin';
8
+ import { GenericInput, NotAllowedInput, useLibrary } from '@strapi/helper-plugin';
9
9
  import { useContentTypeLayout } from '../../hooks';
10
10
  import { getFieldName } from '../../utils';
11
11
  import Wysiwyg from '../Wysiwyg';
@@ -37,11 +37,11 @@ function Inputs({
37
37
  queryInfos,
38
38
  value,
39
39
  size,
40
+ customFieldInputs,
40
41
  }) {
41
42
  const { fields } = useLibrary();
42
43
  const { formatMessage } = useIntl();
43
44
  const { contentType: currentContentTypeLayout } = useContentTypeLayout();
44
- const customFieldsRegistry = useCustomFields();
45
45
 
46
46
  const disabled = useMemo(() => !get(metadatas, 'editable', true), [metadatas]);
47
47
  const { type, customField: customFieldUid } = fieldSchema;
@@ -194,19 +194,6 @@ function Inputs({
194
194
  return minutes % metadatas.step === 0 ? metadatas.step : step;
195
195
  }, [inputType, inputValue, metadatas.step, step]);
196
196
 
197
- // Memoize the component to avoid remounting it and losing state
198
- const CustomFieldInput = useMemo(() => {
199
- if (customFieldUid) {
200
- const customField = customFieldsRegistry.get(customFieldUid);
201
- const CustomFieldInput = React.lazy(customField.components.Input);
202
-
203
- return CustomFieldInput;
204
- }
205
-
206
- // Not a custom field, component won't be used
207
- return null;
208
- }, [customFieldUid, customFieldsRegistry]);
209
-
210
197
  if (visible === false) {
211
198
  return null;
212
199
  }
@@ -268,12 +255,9 @@ function Inputs({
268
255
  media: fields.media,
269
256
  wysiwyg: Wysiwyg,
270
257
  ...fields,
258
+ ...customFieldInputs,
271
259
  };
272
260
 
273
- if (customFieldUid) {
274
- customInputs[customFieldUid] = CustomFieldInput;
275
- }
276
-
277
261
  return (
278
262
  <GenericInput
279
263
  attribute={fieldSchema}
@@ -309,6 +293,7 @@ Inputs.defaultProps = {
309
293
  size: undefined,
310
294
  value: null,
311
295
  queryInfos: {},
296
+ customFieldInputs: {},
312
297
  };
313
298
 
314
299
  Inputs.propTypes = {
@@ -330,6 +315,7 @@ Inputs.propTypes = {
330
315
  defaultParams: PropTypes.object,
331
316
  endPoint: PropTypes.string,
332
317
  }),
318
+ customFieldInputs: PropTypes.object,
333
319
  };
334
320
 
335
321
  const Memoized = memo(Inputs, isEqual);
@@ -0,0 +1,44 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { useCustomFields } from '@strapi/helper-plugin';
3
+
4
+ /**
5
+ * @description
6
+ * A hook to lazy load custom field components
7
+ * @param {Array.<string>} componentUids - The uids to look up components
8
+ * @returns object
9
+ */
10
+ const useLazyComponents = (componentUids) => {
11
+ const [lazyComponentStore, setLazyComponentStore] = useState({});
12
+ const [loading, setLoading] = useState(true);
13
+ const customFieldsRegistry = useCustomFields();
14
+
15
+ useEffect(() => {
16
+ const lazyLoadComponents = async (uids, components) => {
17
+ const modules = await Promise.all(components);
18
+
19
+ uids.forEach((uid, index) => {
20
+ if (!Object.keys(lazyComponentStore).includes(uid)) {
21
+ setLazyComponentStore({ ...lazyComponentStore, [uid]: modules[index].default });
22
+ }
23
+ });
24
+ };
25
+
26
+ if (componentUids.length) {
27
+ const componentPromises = componentUids.map((uid) => {
28
+ const customField = customFieldsRegistry.get(uid);
29
+
30
+ return customField.components.Input();
31
+ });
32
+
33
+ lazyLoadComponents(componentUids, componentPromises);
34
+ }
35
+
36
+ if (componentUids.length === Object.keys(lazyComponentStore).length) {
37
+ setLoading(false);
38
+ }
39
+ }, [componentUids, customFieldsRegistry, loading, lazyComponentStore]);
40
+
41
+ return { isLazyLoading: loading, lazyComponentStore };
42
+ };
43
+
44
+ export default useLazyComponents;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { AnErrorOccurred } from '@strapi/helper-plugin';
3
+ import { Box } from '@strapi/design-system/Box';
4
+
5
+ const ErrorFallback = () => {
6
+ return (
7
+ <Box padding={8}>
8
+ <AnErrorOccurred />
9
+ </Box>
10
+ );
11
+ };
12
+
13
+ export default ErrorFallback;
@@ -3,7 +3,7 @@ import { Switch, Route } from 'react-router-dom';
3
3
  import { ErrorBoundary } from 'react-error-boundary';
4
4
  import { get } from 'lodash';
5
5
  import PropTypes from 'prop-types';
6
- import { ErrorFallback, LoadingIndicatorPage, CheckPagePermissions } from '@strapi/helper-plugin';
6
+ import { LoadingIndicatorPage, CheckPagePermissions } from '@strapi/helper-plugin';
7
7
  import permissions from '../../../permissions';
8
8
  import { ContentTypeLayoutContext } from '../../contexts';
9
9
  import { useFetchContentTypeLayout } from '../../hooks';
@@ -12,6 +12,7 @@ import EditViewLayoutManager from '../EditViewLayoutManager';
12
12
  import EditSettingsView from '../EditSettingsView';
13
13
  import ListViewLayout from '../ListViewLayoutManager';
14
14
  import ListSettingsView from '../ListSettingsView';
15
+ import ErrorFallback from './components/ErrorFallback';
15
16
 
16
17
  const cmPermissions = permissions.contentManager;
17
18
 
@@ -0,0 +1,62 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Grid, GridItem } from '@strapi/design-system/Grid';
4
+ import Inputs from '../../../components/Inputs';
5
+ import FieldComponent from '../../../components/FieldComponent';
6
+
7
+ const GridRow = ({ columns, customFieldInputs }) => {
8
+ return (
9
+ <Grid gap={4}>
10
+ {columns.map(({ fieldSchema, labelAction, metadatas, name, size, queryInfos }) => {
11
+ const isComponent = fieldSchema.type === 'component';
12
+
13
+ if (isComponent) {
14
+ const { component, max, min, repeatable = false, required = false } = fieldSchema;
15
+
16
+ return (
17
+ <GridItem col={size} s={12} xs={12} key={component}>
18
+ <FieldComponent
19
+ componentUid={component}
20
+ labelAction={labelAction}
21
+ isRepeatable={repeatable}
22
+ intlLabel={{
23
+ id: metadatas.label,
24
+ defaultMessage: metadatas.label,
25
+ }}
26
+ max={max}
27
+ min={min}
28
+ name={name}
29
+ required={required}
30
+ />
31
+ </GridItem>
32
+ );
33
+ }
34
+
35
+ return (
36
+ <GridItem col={size} key={name} s={12} xs={12}>
37
+ <Inputs
38
+ size={size}
39
+ fieldSchema={fieldSchema}
40
+ keys={name}
41
+ labelAction={labelAction}
42
+ metadatas={metadatas}
43
+ queryInfos={queryInfos}
44
+ customFieldInputs={customFieldInputs}
45
+ />
46
+ </GridItem>
47
+ );
48
+ })}
49
+ </Grid>
50
+ );
51
+ };
52
+
53
+ GridRow.defaultProps = {
54
+ customFieldInputs: {},
55
+ };
56
+
57
+ GridRow.propTypes = {
58
+ columns: PropTypes.array.isRequired,
59
+ customFieldInputs: PropTypes.object,
60
+ };
61
+
62
+ export default GridRow;
@@ -1,11 +1,11 @@
1
- import React, { Suspense, memo, useCallback, useMemo } from 'react';
1
+ import React, { memo } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import get from 'lodash/get';
3
+ import { useSelector } from 'react-redux';
4
4
  import {
5
5
  CheckPermissions,
6
- LoadingIndicatorPage,
7
6
  useTracking,
8
7
  LinkButton,
8
+ LoadingIndicatorPage,
9
9
  } from '@strapi/helper-plugin';
10
10
  import { useIntl } from 'react-intl';
11
11
  import { ContentLayout } from '@strapi/design-system/Layout';
@@ -18,73 +18,60 @@ import Pencil from '@strapi/icons/Pencil';
18
18
  import { InjectionZone } from '../../../shared/components';
19
19
  import permissions from '../../../permissions';
20
20
  import DynamicZone from '../../components/DynamicZone';
21
- import FieldComponent from '../../components/FieldComponent';
22
- import Inputs from '../../components/Inputs';
21
+
23
22
  import CollectionTypeFormWrapper from '../../components/CollectionTypeFormWrapper';
24
23
  import EditViewDataManagerProvider from '../../components/EditViewDataManagerProvider';
25
24
  import SingleTypeFormWrapper from '../../components/SingleTypeFormWrapper';
26
25
  import { getTrad } from '../../utils';
26
+ import useLazyComponents from '../../hooks/useLazyComponents';
27
27
  import DraftAndPublishBadge from './DraftAndPublishBadge';
28
28
  import Informations from './Informations';
29
29
  import Header from './Header';
30
- import { createAttributesLayout, getFieldsActionMatchingPermissions } from './utils';
30
+ import { getFieldsActionMatchingPermissions } from './utils';
31
31
  import DeleteLink from './DeleteLink';
32
+ import GridRow from './GridRow';
33
+ import { selectCurrentLayout, selectAttributesLayout, selectCustomFieldUids } from './selectors';
32
34
 
33
35
  const cmPermissions = permissions.contentManager;
34
36
  const ctbPermissions = [{ action: 'plugin::content-type-builder.read', subject: null }];
35
37
 
36
38
  /* eslint-disable react/no-array-index-key */
37
- const EditView = ({
38
- allowedActions,
39
- isSingleType,
40
- goBack,
41
- layout,
42
- slug,
43
- id,
44
- origin,
45
- userPermissions,
46
- }) => {
39
+ const EditView = ({ allowedActions, isSingleType, goBack, slug, id, origin, userPermissions }) => {
47
40
  const { trackUsage } = useTracking();
48
41
  const { formatMessage } = useIntl();
42
+
43
+ const { layout, formattedContentTypeLayout, customFieldUids } = useSelector((state) => ({
44
+ layout: selectCurrentLayout(state),
45
+ formattedContentTypeLayout: selectAttributesLayout(state),
46
+ customFieldUids: selectCustomFieldUids(state),
47
+ }));
48
+
49
+ const { isLazyLoading, lazyComponentStore } = useLazyComponents(customFieldUids);
50
+
49
51
  const { createActionAllowedFields, readActionAllowedFields, updateActionAllowedFields } =
50
- useMemo(() => {
51
- return getFieldsActionMatchingPermissions(userPermissions, slug);
52
- }, [userPermissions, slug]);
52
+ getFieldsActionMatchingPermissions(userPermissions, slug);
53
53
 
54
- const configurationPermissions = useMemo(() => {
55
- return isSingleType
56
- ? cmPermissions.singleTypesConfigurations
57
- : cmPermissions.collectionTypesConfigurations;
58
- }, [isSingleType]);
54
+ const configurationPermissions = isSingleType
55
+ ? cmPermissions.singleTypesConfigurations
56
+ : cmPermissions.collectionTypesConfigurations;
59
57
 
60
58
  // // FIXME when changing the routing
61
59
  const configurationsURL = `/content-manager/${
62
60
  isSingleType ? 'singleType' : 'collectionType'
63
61
  }/${slug}/configurations/edit`;
64
- const currentContentTypeLayoutData = get(layout, ['contentType'], {});
65
62
 
66
- const DataManagementWrapper = useMemo(
67
- () => (isSingleType ? SingleTypeFormWrapper : CollectionTypeFormWrapper),
68
- [isSingleType]
69
- );
63
+ const DataManagementWrapper = isSingleType ? SingleTypeFormWrapper : CollectionTypeFormWrapper;
70
64
 
71
65
  // Check if a block is a dynamic zone
72
- const isDynamicZone = useCallback((block) => {
66
+ const isDynamicZone = (block) => {
73
67
  return block.every((subBlock) => {
74
68
  return subBlock.every((obj) => obj.fieldSchema.type === 'dynamiczone');
75
69
  });
76
- }, []);
70
+ };
77
71
 
78
- const formattedContentTypeLayout = useMemo(() => {
79
- if (!currentContentTypeLayoutData.layouts) {
80
- return [];
81
- }
82
-
83
- return createAttributesLayout(
84
- currentContentTypeLayoutData.layouts.edit,
85
- currentContentTypeLayoutData.attributes
86
- );
87
- }, [currentContentTypeLayoutData]);
72
+ if (isLazyLoading) {
73
+ return <LoadingIndicatorPage />;
74
+ }
88
75
 
89
76
  return (
90
77
  <DataManagementWrapper allLayoutData={layout} slug={slug} id={id} origin={origin}>
@@ -132,110 +119,56 @@ const EditView = ({
132
119
  <ContentLayout>
133
120
  <Grid gap={4}>
134
121
  <GridItem col={9} s={12}>
135
- <Suspense fallback={<LoadingIndicatorPage />}>
136
- <Stack spacing={6}>
137
- {formattedContentTypeLayout.map((row, index) => {
138
- if (isDynamicZone(row)) {
139
- const {
140
- 0: {
141
- 0: { name, fieldSchema, metadatas, labelAction },
142
- },
143
- } = row;
144
-
145
- return (
146
- <Box key={index}>
147
- <Grid gap={4}>
148
- <GridItem col={12} s={12} xs={12}>
149
- <DynamicZone
150
- name={name}
151
- fieldSchema={fieldSchema}
152
- labelAction={labelAction}
153
- metadatas={metadatas}
154
- />
155
- </GridItem>
156
- </Grid>
157
- </Box>
158
- );
159
- }
122
+ <Stack spacing={6}>
123
+ {formattedContentTypeLayout.map((row, index) => {
124
+ if (isDynamicZone(row)) {
125
+ const {
126
+ 0: {
127
+ 0: { name, fieldSchema, metadatas, labelAction },
128
+ },
129
+ } = row;
160
130
 
161
131
  return (
162
- <Box
163
- key={index}
164
- hasRadius
165
- background="neutral0"
166
- shadow="tableShadow"
167
- paddingLeft={6}
168
- paddingRight={6}
169
- paddingTop={6}
170
- paddingBottom={6}
171
- borderColor="neutral150"
172
- >
173
- <Stack spacing={6}>
174
- {row.map((grid, gridIndex) => {
175
- return (
176
- <Grid gap={4} key={gridIndex}>
177
- {grid.map(
178
- ({
179
- fieldSchema,
180
- labelAction,
181
- metadatas,
182
- name,
183
- size,
184
- queryInfos,
185
- }) => {
186
- const isComponent = fieldSchema.type === 'component';
187
-
188
- if (isComponent) {
189
- const {
190
- component,
191
- max,
192
- min,
193
- repeatable = false,
194
- required = false,
195
- } = fieldSchema;
196
-
197
- return (
198
- <GridItem col={size} s={12} xs={12} key={component}>
199
- <FieldComponent
200
- componentUid={component}
201
- labelAction={labelAction}
202
- isRepeatable={repeatable}
203
- intlLabel={{
204
- id: metadatas.label,
205
- defaultMessage: metadatas.label,
206
- }}
207
- max={max}
208
- min={min}
209
- name={name}
210
- required={required}
211
- />
212
- </GridItem>
213
- );
214
- }
215
-
216
- return (
217
- <GridItem col={size} key={name} s={12} xs={12}>
218
- <Inputs
219
- size={size}
220
- fieldSchema={fieldSchema}
221
- keys={name}
222
- labelAction={labelAction}
223
- metadatas={metadatas}
224
- queryInfos={queryInfos}
225
- />
226
- </GridItem>
227
- );
228
- }
229
- )}
230
- </Grid>
231
- );
232
- })}
233
- </Stack>
132
+ <Box key={index}>
133
+ <Grid gap={4}>
134
+ <GridItem col={12} s={12} xs={12}>
135
+ <DynamicZone
136
+ name={name}
137
+ fieldSchema={fieldSchema}
138
+ labelAction={labelAction}
139
+ metadatas={metadatas}
140
+ />
141
+ </GridItem>
142
+ </Grid>
234
143
  </Box>
235
144
  );
236
- })}
237
- </Stack>
238
- </Suspense>
145
+ }
146
+
147
+ return (
148
+ <Box
149
+ key={index}
150
+ hasRadius
151
+ background="neutral0"
152
+ shadow="tableShadow"
153
+ paddingLeft={6}
154
+ paddingRight={6}
155
+ paddingTop={6}
156
+ paddingBottom={6}
157
+ borderColor="neutral150"
158
+ >
159
+ <Stack spacing={6}>
160
+ {row.map((grid, gridRowIndex) => (
161
+ <GridRow
162
+ columns={grid}
163
+ customFieldInputs={lazyComponentStore}
164
+ key={gridRowIndex}
165
+ />
166
+ ))}
167
+ </Stack>
168
+ </Box>
169
+ );
170
+ })}
171
+ </Stack>
239
172
  </GridItem>
240
173
  <GridItem col={3} s={12}>
241
174
  <Stack spacing={2}>
@@ -328,16 +261,6 @@ EditView.propTypes = {
328
261
  canCreate: PropTypes.bool.isRequired,
329
262
  canDelete: PropTypes.bool.isRequired,
330
263
  }).isRequired,
331
- layout: PropTypes.shape({
332
- components: PropTypes.object.isRequired,
333
- contentType: PropTypes.shape({
334
- uid: PropTypes.string.isRequired,
335
- settings: PropTypes.object.isRequired,
336
- metadatas: PropTypes.object.isRequired,
337
- options: PropTypes.object.isRequired,
338
- attributes: PropTypes.object.isRequired,
339
- }).isRequired,
340
- }).isRequired,
341
264
  id: PropTypes.string,
342
265
  isSingleType: PropTypes.bool,
343
266
  goBack: PropTypes.func.isRequired,
@@ -346,7 +269,4 @@ EditView.propTypes = {
346
269
  userPermissions: PropTypes.array,
347
270
  };
348
271
 
349
- export { EditView };
350
272
  export default memo(EditView);
351
-
352
- // export default () => 'TODO Edit view';
@@ -0,0 +1,14 @@
1
+ import { createSelector } from 'reselect';
2
+ import { createAttributesLayout, getCustomFieldUidsFromLayout } from './utils';
3
+
4
+ const selectCurrentLayout = (state) => state['content-manager_editViewLayoutManager'].currentLayout;
5
+
6
+ const selectAttributesLayout = createSelector(selectCurrentLayout, (layout) =>
7
+ createAttributesLayout(layout?.contentType ?? {})
8
+ );
9
+
10
+ const selectCustomFieldUids = createSelector(selectCurrentLayout, (layout) =>
11
+ getCustomFieldUidsFromLayout(layout)
12
+ );
13
+
14
+ export { selectCurrentLayout, selectAttributesLayout, selectCustomFieldUids };
@@ -1,14 +1,19 @@
1
1
  import { get, isEmpty } from 'lodash';
2
- // TODO: refacto this file to avoid eslint issues
3
- /* eslint-disable no-restricted-syntax */
4
- /* eslint-disable no-unused-vars */
5
2
 
6
- const createAttributesLayout = (currentLayout, attributes) => {
3
+ const createAttributesLayout = (currentContentTypeLayoutData) => {
4
+ if (!currentContentTypeLayoutData.layouts) {
5
+ return [];
6
+ }
7
+
8
+ const currentLayout = currentContentTypeLayoutData.layouts.edit;
9
+ const attributes = currentContentTypeLayoutData.attributes;
10
+
7
11
  const getType = (name) => get(attributes, [name, 'type'], '');
12
+
8
13
  let currentRowIndex = 0;
9
14
  const newLayout = [];
10
15
 
11
- for (let row of currentLayout) {
16
+ currentLayout.forEach((row) => {
12
17
  const hasDynamicZone = row.some(({ name }) => getType(name) === 'dynamiczone');
13
18
 
14
19
  if (!newLayout[currentRowIndex]) {
@@ -27,7 +32,7 @@ const createAttributesLayout = (currentLayout, attributes) => {
27
32
  } else {
28
33
  newLayout[currentRowIndex].push(row);
29
34
  }
30
- }
35
+ });
31
36
 
32
37
  return newLayout.filter((arr) => arr.length > 0);
33
38
  };
@@ -0,0 +1,18 @@
1
+ const getCustomFieldUidsFromLayout = (layout) => {
2
+ if (!layout) return [];
3
+ // Get all the fields on the content-type and its components
4
+ const allFields = [
5
+ ...layout.contentType.layouts.edit,
6
+ ...Object.values(layout.components).flatMap((component) => component.layouts.edit),
7
+ ].flat();
8
+ // Filter that down to custom fields and map the uids
9
+ const customFieldUids = allFields
10
+ .filter((field) => field.fieldSchema.customField)
11
+ .map((customField) => customField.fieldSchema.customField);
12
+ // Make sure the list is unique
13
+ const uniqueCustomFieldUids = [...new Set(customFieldUids)];
14
+
15
+ return uniqueCustomFieldUids;
16
+ };
17
+
18
+ export default getCustomFieldUidsFromLayout;
@@ -1,3 +1,4 @@
1
1
  // eslint-disable-next-line import/prefer-default-export
2
2
  export { default as createAttributesLayout } from './createAttributesLayout';
3
3
  export { default as getFieldsActionMatchingPermissions } from './getFieldsActionMatchingPermissions';
4
+ export { default as getCustomFieldUidsFromLayout } from './getCustomFieldUidsFromLayout';
@@ -30,7 +30,7 @@ const EditViewLayoutManager = ({ layout, ...rest }) => {
30
30
  return <LoadingIndicatorPage />;
31
31
  }
32
32
 
33
- return <Permissions {...rest} layout={currentLayout} userPermissions={permissions} />;
33
+ return <Permissions {...rest} userPermissions={permissions} />;
34
34
  };
35
35
 
36
36
  EditViewLayoutManager.propTypes = {
@@ -19,6 +19,40 @@ const ALLOWED_TYPES = [
19
19
  'uid',
20
20
  ];
21
21
 
22
+ const ALLOWED_ROOT_LEVEL_OPTIONS = [
23
+ 'min',
24
+ 'minLength',
25
+ 'max',
26
+ 'maxLength',
27
+ 'required',
28
+ 'regex',
29
+ 'enum',
30
+ 'unique',
31
+ 'private',
32
+ 'default',
33
+ ];
34
+
35
+ const optionValidationsReducer = (acc, option) => {
36
+ if (option.items) {
37
+ return option.items.reduce(optionValidationsReducer, acc);
38
+ }
39
+
40
+ if (!option.name) {
41
+ acc.push({
42
+ isValidOptionPath: false,
43
+ errorMessage: "The 'name' property is required on an options object",
44
+ });
45
+ } else {
46
+ acc.push({
47
+ isValidOptionPath:
48
+ ALLOWED_ROOT_LEVEL_OPTIONS.includes(option.name) || option.name.startsWith('options'),
49
+ errorMessage: `'${option.name}' must be prefixed with 'options.'`,
50
+ });
51
+ }
52
+
53
+ return acc;
54
+ };
55
+
22
56
  class CustomFields {
23
57
  constructor() {
24
58
  this.customFields = {};
@@ -32,7 +66,8 @@ class CustomFields {
32
66
  });
33
67
  } else {
34
68
  // Handle individual custom field
35
- const { name, pluginId, type, intlLabel, intlDescription, components } = customFields;
69
+ const { name, pluginId, type, intlLabel, intlDescription, components, options } =
70
+ customFields;
36
71
 
37
72
  // Ensure required attributes are provided
38
73
  invariant(name, 'A name must be provided');
@@ -55,6 +90,16 @@ class CustomFields {
55
90
  `Custom field name: '${name}' is not a valid object key`
56
91
  );
57
92
 
93
+ // Ensure options have valid name paths
94
+ const allFormOptions = [...(options?.base || []), ...(options?.advanced || [])];
95
+
96
+ if (allFormOptions.length) {
97
+ const optionPathValidations = allFormOptions.reduce(optionValidationsReducer, []);
98
+ optionPathValidations.forEach(({ isValidOptionPath, errorMessage }) => {
99
+ invariant(isValidOptionPath, errorMessage);
100
+ });
101
+ }
102
+
58
103
  // When no plugin is specified, default to the global namespace
59
104
  const uid = pluginId ? `plugin::${pluginId}.${name}` : `global::${name}`;
60
105