@strapi/admin 4.4.3 → 4.5.0-beta.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.
Files changed (132) hide show
  1. package/admin/src/content-manager/components/CollectionTypeFormWrapper/index.js +35 -1
  2. package/admin/src/content-manager/components/DynamicTable/CellContent/RelationMultiple/index.js +11 -7
  3. package/admin/src/content-manager/components/DynamicTable/CellContent/index.js +6 -5
  4. package/admin/src/content-manager/components/DynamicTable/TableRows/index.js +5 -0
  5. package/admin/src/content-manager/components/DynamicTable/index.js +1 -1
  6. package/admin/src/content-manager/components/EditViewDataManagerProvider/index.js +73 -20
  7. package/admin/src/content-manager/components/EditViewDataManagerProvider/reducer.js +166 -26
  8. package/admin/src/content-manager/components/EditViewDataManagerProvider/utils/cleanData.js +17 -1
  9. package/admin/src/content-manager/components/Inputs/index.js +12 -4
  10. package/admin/src/content-manager/components/NonRepeatableComponent/index.js +2 -0
  11. package/admin/src/content-manager/components/RelationInput/RelationInput.js +427 -0
  12. package/admin/src/content-manager/components/{SelectWrapper → RelationInput/components}/Option.js +15 -25
  13. package/admin/src/content-manager/components/RelationInput/components/Relation.js +48 -0
  14. package/admin/src/content-manager/components/RelationInput/components/RelationItem.js +52 -0
  15. package/admin/src/content-manager/components/RelationInput/components/RelationList.js +52 -0
  16. package/admin/src/content-manager/components/RelationInput/constants.js +1 -0
  17. package/admin/src/content-manager/components/RelationInput/index.js +1 -0
  18. package/admin/src/content-manager/components/RelationInputDataManager/RelationInputDataManager.js +261 -0
  19. package/admin/src/content-manager/components/RelationInputDataManager/constants.js +8 -0
  20. package/admin/src/content-manager/components/RelationInputDataManager/index.js +1 -0
  21. package/admin/src/content-manager/components/{SelectWrapper → RelationInputDataManager}/utils/connect.js +0 -1
  22. package/admin/src/content-manager/components/RelationInputDataManager/utils/getRelationLink.js +5 -0
  23. package/admin/src/content-manager/components/RelationInputDataManager/utils/index.js +4 -0
  24. package/admin/src/content-manager/components/RelationInputDataManager/utils/normalizeRelations.js +65 -0
  25. package/admin/src/content-manager/components/RelationInputDataManager/utils/normalizeSearchResults.js +12 -0
  26. package/admin/src/content-manager/components/RelationInputDataManager/utils/select.js +98 -0
  27. package/admin/src/content-manager/components/RepeatableComponent/DraggedItem/index.js +5 -0
  28. package/admin/src/content-manager/components/SingleTypeFormWrapper/index.js +42 -2
  29. package/admin/src/content-manager/hooks/useFetchContentTypeLayout/utils/formatLayouts.js +7 -69
  30. package/admin/src/content-manager/hooks/useRelation/index.js +1 -0
  31. package/admin/src/content-manager/hooks/useRelation/useRelation.js +81 -0
  32. package/admin/src/content-manager/pages/EditSettingsView/components/DisplayedFields.js +4 -4
  33. package/admin/src/content-manager/pages/EditSettingsView/index.js +21 -49
  34. package/admin/src/content-manager/pages/EditSettingsView/reducer.js +0 -25
  35. package/admin/src/content-manager/pages/EditView/Header/index.js +121 -140
  36. package/admin/src/content-manager/pages/EditView/Header/utils/index.js +0 -1
  37. package/admin/src/content-manager/pages/EditView/Header/utils/select.js +4 -2
  38. package/admin/src/content-manager/pages/EditView/index.js +12 -65
  39. package/admin/src/content-manager/pages/ListView/FieldPicker/index.js +0 -1
  40. package/admin/src/content-manager/pages/ListView/index.js +0 -1
  41. package/admin/src/content-manager/pages/ListViewLayoutManager/index.js +0 -1
  42. package/admin/src/content-manager/utils/formatLayoutToApi.js +1 -3
  43. package/admin/src/pages/HomePage/SocialLinks.js +1 -1
  44. package/admin/src/translations/ar.json +0 -1
  45. package/admin/src/translations/ca.json +1 -8
  46. package/admin/src/translations/cs.json +0 -2
  47. package/admin/src/translations/de.json +4 -12
  48. package/admin/src/translations/dk.json +3 -11
  49. package/admin/src/translations/en.json +4 -11
  50. package/admin/src/translations/es.json +156 -168
  51. package/admin/src/translations/fr.json +3 -11
  52. package/admin/src/translations/gu.json +608 -617
  53. package/admin/src/translations/hi.json +689 -698
  54. package/admin/src/translations/hu.json +2 -10
  55. package/admin/src/translations/id.json +2 -10
  56. package/admin/src/translations/it.json +2 -10
  57. package/admin/src/translations/ja.json +2 -11
  58. package/admin/src/translations/ko.json +2 -11
  59. package/admin/src/translations/ml.json +689 -698
  60. package/admin/src/translations/ms.json +0 -2
  61. package/admin/src/translations/nl.json +3 -11
  62. package/admin/src/translations/pl.json +2 -11
  63. package/admin/src/translations/pt-BR.json +3 -11
  64. package/admin/src/translations/pt.json +0 -1
  65. package/admin/src/translations/ru.json +489 -501
  66. package/admin/src/translations/sa.json +85 -93
  67. package/admin/src/translations/sk.json +3 -10
  68. package/admin/src/translations/sv.json +3 -9
  69. package/admin/src/translations/th.json +0 -2
  70. package/admin/src/translations/tr.json +0 -1
  71. package/admin/src/translations/uk.json +0 -2
  72. package/admin/src/translations/vi.json +0 -1
  73. package/admin/src/translations/zh-Hans.json +4 -13
  74. package/admin/src/translations/zh.json +3 -11
  75. package/build/{8773.51992277.chunk.js → 1939.e3c87653.chunk.js} +50 -50
  76. package/build/8738.a30a2160.chunk.js +461 -0
  77. package/build/962.8651ba3f.chunk.js +184 -0
  78. package/build/Admin-authenticatedApp.883449a5.chunk.js +80 -0
  79. package/build/{Admin_homePage.6d5e3236.chunk.js → Admin_homePage.4b2be829.chunk.js} +1 -1
  80. package/build/{ar-json.d4cb26d9.chunk.js → ar-json.3489463d.chunk.js} +1 -1
  81. package/build/{ca-json.d16c1d28.chunk.js → ca-json.82df6eab.chunk.js} +1 -1
  82. package/build/content-manager.933dc286.chunk.js +1201 -0
  83. package/build/{cs-json.c8f28ba8.chunk.js → cs-json.ce49da5c.chunk.js} +1 -1
  84. package/build/{de-json.a9b514dc.chunk.js → de-json.0ad554eb.chunk.js} +1 -1
  85. package/build/{dk-json.09e8d145.chunk.js → dk-json.e195ea1a.chunk.js} +1 -1
  86. package/build/{en-json.e936d40e.chunk.js → en-json.1889403c.chunk.js} +1 -1
  87. package/build/{es-json.3a9c7c09.chunk.js → es-json.09f80f6e.chunk.js} +1 -1
  88. package/build/{fr-json.4ed1fc2c.chunk.js → fr-json.606d056b.chunk.js} +1 -1
  89. package/build/{gu-json.d8311297.chunk.js → gu-json.9881264f.chunk.js} +1 -1
  90. package/build/{hi-json.0edb8d29.chunk.js → hi-json.83dcf48f.chunk.js} +1 -1
  91. package/build/{hu-json.7855529a.chunk.js → hu-json.6f328bce.chunk.js} +1 -1
  92. package/build/{id-json.df9618f2.chunk.js → id-json.1f3c4303.chunk.js} +1 -1
  93. package/build/index.html +1 -1
  94. package/build/{it-json.a21bf078.chunk.js → it-json.494ac432.chunk.js} +1 -1
  95. package/build/{ja-json.7b0d9067.chunk.js → ja-json.6f262117.chunk.js} +1 -1
  96. package/build/{ko-json.983c1f8f.chunk.js → ko-json.36dc3b9a.chunk.js} +1 -1
  97. package/build/main.63e7ea0a.js +9338 -0
  98. package/build/{ml-json.8dd021c8.chunk.js → ml-json.9566bf9a.chunk.js} +1 -1
  99. package/build/{ms-json.836ed013.chunk.js → ms-json.ed51e902.chunk.js} +1 -1
  100. package/build/{nl-json.29d2eb37.chunk.js → nl-json.94c3a289.chunk.js} +1 -1
  101. package/build/{pl-json.1f04f00c.chunk.js → pl-json.ccc6ef23.chunk.js} +1 -1
  102. package/build/{pt-BR-json.b4bc8efe.chunk.js → pt-BR-json.744f024d.chunk.js} +1 -1
  103. package/build/{pt-json.c23020ab.chunk.js → pt-json.3161ca22.chunk.js} +1 -1
  104. package/build/{ru-json.7ab40ccf.chunk.js → ru-json.d22ea13c.chunk.js} +1 -1
  105. package/build/{runtime~main.7faf633a.js → runtime~main.3a5e1b07.js} +1 -1
  106. package/build/{sa-json.c5a9f4ea.chunk.js → sa-json.8fb1c04d.chunk.js} +1 -1
  107. package/build/{sk-json.e4c24c4e.chunk.js → sk-json.6c7335d4.chunk.js} +1 -1
  108. package/build/{sv-json.c3f471ae.chunk.js → sv-json.2e589a7d.chunk.js} +1 -1
  109. package/build/{th-json.a59ffb32.chunk.js → th-json.72e8de3d.chunk.js} +1 -1
  110. package/build/{tr-json.276e59fe.chunk.js → tr-json.9c44ea0c.chunk.js} +1 -1
  111. package/build/{uk-json.5b5b9c27.chunk.js → uk-json.c4cd2e24.chunk.js} +1 -1
  112. package/build/{upload-translation-en-json.004a86c1.chunk.js → upload-translation-en-json.86da7b0a.chunk.js} +1 -1
  113. package/build/{vi-json.bf3424be.chunk.js → vi-json.f7890025.chunk.js} +1 -1
  114. package/build/{zh-Hans-json.9c99f8d4.chunk.js → zh-Hans-json.a4d7dc69.chunk.js} +1 -1
  115. package/build/{zh-json.451a0271.chunk.js → zh-json.66aa2ae1.chunk.js} +1 -1
  116. package/package.json +7 -7
  117. package/admin/src/content-manager/components/SelectMany/ListItem.js +0 -102
  118. package/admin/src/content-manager/components/SelectMany/index.js +0 -148
  119. package/admin/src/content-manager/components/SelectOne/SingleValue.js +0 -67
  120. package/admin/src/content-manager/components/SelectOne/index.js +0 -97
  121. package/admin/src/content-manager/components/SelectWrapper/Label.js +0 -60
  122. package/admin/src/content-manager/components/SelectWrapper/index.js +0 -356
  123. package/admin/src/content-manager/components/SelectWrapper/utils/index.js +0 -2
  124. package/admin/src/content-manager/components/SelectWrapper/utils/select.js +0 -45
  125. package/admin/src/content-manager/pages/EditSettingsView/components/RelationalFieldButton.js +0 -135
  126. package/admin/src/content-manager/pages/EditSettingsView/components/RelationalFields.js +0 -103
  127. package/admin/src/content-manager/pages/EditView/Header/utils/getDraftRelations.js +0 -62
  128. package/build/1669.d1b29c28.chunk.js +0 -1
  129. package/build/524.8a540ac1.chunk.js +0 -644
  130. package/build/Admin-authenticatedApp.88fa40ac.chunk.js +0 -80
  131. package/build/content-manager.8bddf2e6.chunk.js +0 -1178
  132. package/build/main.6650d2e7.js +0 -9338
@@ -1,67 +0,0 @@
1
- import React from 'react';
2
- import { components } from 'react-select';
3
- import PropTypes from 'prop-types';
4
- import styled from 'styled-components';
5
- import { useIntl } from 'react-intl';
6
- import { pxToRem } from '@strapi/helper-plugin';
7
- import { Flex } from '@strapi/design-system/Flex';
8
- import { Typography } from '@strapi/design-system/Typography';
9
- import get from 'lodash/get';
10
- import has from 'lodash/has';
11
- import isEmpty from 'lodash/isEmpty';
12
- import { getTrad } from '../../utils';
13
-
14
- const StyledBullet = styled.div`
15
- flex-shrink: 0;
16
- width: ${pxToRem(6)};
17
- height: ${pxToRem(6)};
18
- margin-right: ${({ theme }) => theme.spaces[2]};
19
- background-color: ${({ theme, isDraft }) =>
20
- theme.colors[isDraft ? 'secondary600' : 'success600']};
21
- border-radius: 50%;
22
- cursor: pointer;
23
- `;
24
-
25
- const SingleValue = (props) => {
26
- const { formatMessage } = useIntl();
27
- const Component = components.SingleValue;
28
- const hasDraftAndPublish = has(get(props, 'data.value'), 'publishedAt');
29
- const isDraft = isEmpty(get(props, 'data.value.publishedAt'));
30
-
31
- if (hasDraftAndPublish) {
32
- const draftMessage = {
33
- id: getTrad('components.Select.draft-info-title'),
34
- defaultMessage: 'State: Draft',
35
- };
36
- const publishedMessage = {
37
- id: getTrad('components.Select.publish-info-title'),
38
- defaultMessage: 'State: Published',
39
- };
40
- const title = isDraft ? formatMessage(draftMessage) : formatMessage(publishedMessage);
41
-
42
- return (
43
- <Component {...props}>
44
- <Flex>
45
- <StyledBullet title={title} isDraft={isDraft} />
46
- <Typography ellipsis>{props.data.label ?? '-'}</Typography>
47
- </Flex>
48
- </Component>
49
- );
50
- }
51
-
52
- return <Component {...props}>{props.data.label ?? '-'}</Component>;
53
- };
54
-
55
- SingleValue.propTypes = {
56
- data: PropTypes.object.isRequired,
57
- selectProps: PropTypes.shape({
58
- mainField: PropTypes.shape({
59
- name: PropTypes.string.isRequired,
60
- schema: PropTypes.shape({
61
- type: PropTypes.string.isRequired,
62
- }).isRequired,
63
- }).isRequired,
64
- }).isRequired,
65
- };
66
-
67
- export default SingleValue;
@@ -1,97 +0,0 @@
1
- import React, { memo } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { useIntl } from 'react-intl';
4
- import { Stack } from '@strapi/design-system/Stack';
5
- import { Typography } from '@strapi/design-system/Typography';
6
- import get from 'lodash/get';
7
- import isNull from 'lodash/isNull';
8
- import { ReactSelect as Select } from '@strapi/helper-plugin';
9
- import SingleValue from './SingleValue';
10
-
11
- function SelectOne({
12
- components,
13
- mainField,
14
- name,
15
- isDisabled,
16
- isLoading,
17
- loadingMessage,
18
- onChange,
19
- onInputChange,
20
- onMenuClose,
21
- onMenuOpen,
22
- onMenuScrollToBottom,
23
- options,
24
- placeholder,
25
- value,
26
- description,
27
- }) {
28
- const { formatMessage } = useIntl();
29
-
30
- return (
31
- <Stack spacing={1}>
32
- <Select
33
- components={{
34
- ...components,
35
- SingleValue,
36
- }}
37
- id={name}
38
- isClearable
39
- isDisabled={isDisabled}
40
- isLoading={isLoading}
41
- loadingMessage={loadingMessage}
42
- mainField={mainField}
43
- options={options}
44
- onChange={onChange}
45
- onInputChange={onInputChange}
46
- onMenuClose={onMenuClose}
47
- onMenuOpen={onMenuOpen}
48
- onMenuScrollToBottom={onMenuScrollToBottom}
49
- placeholder={formatMessage(
50
- placeholder || { id: 'global.select', defaultMessage: 'Select...' }
51
- )}
52
- value={isNull(value) ? null : { label: get(value, [mainField.name], ''), value }}
53
- />
54
-
55
- {description && (
56
- <Typography variant="pi" textColor="neutral600">
57
- {description}
58
- </Typography>
59
- )}
60
- </Stack>
61
- );
62
- }
63
-
64
- SelectOne.defaultProps = {
65
- description: '',
66
- components: {},
67
- placeholder: null,
68
- value: null,
69
- };
70
-
71
- SelectOne.propTypes = {
72
- components: PropTypes.object,
73
- isDisabled: PropTypes.bool.isRequired,
74
- isLoading: PropTypes.bool.isRequired,
75
- loadingMessage: PropTypes.func.isRequired,
76
- mainField: PropTypes.shape({
77
- name: PropTypes.string.isRequired,
78
- schema: PropTypes.shape({
79
- type: PropTypes.string.isRequired,
80
- }).isRequired,
81
- }).isRequired,
82
- name: PropTypes.string.isRequired,
83
- onChange: PropTypes.func.isRequired,
84
- onInputChange: PropTypes.func.isRequired,
85
- onMenuClose: PropTypes.func.isRequired,
86
- onMenuOpen: PropTypes.func.isRequired,
87
- onMenuScrollToBottom: PropTypes.func.isRequired,
88
- options: PropTypes.array.isRequired,
89
- placeholder: PropTypes.shape({
90
- id: PropTypes.string.isRequired,
91
- defaultMessage: PropTypes.string.isRequired,
92
- }),
93
- value: PropTypes.object,
94
- description: PropTypes.string,
95
- };
96
-
97
- export default memo(SelectOne);
@@ -1,60 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { useIntl } from 'react-intl';
4
- import styled from 'styled-components';
5
- import { Box } from '@strapi/design-system/Box';
6
- import { Flex } from '@strapi/design-system/Flex';
7
- import { Typography } from '@strapi/design-system/Typography';
8
-
9
- const LabelAction = styled(Box)`
10
- svg path {
11
- fill: ${({ theme }) => theme.colors.neutral500};
12
- }
13
- `;
14
-
15
- const Label = ({ intlLabel, id, labelAction, link, name, numberOfEntries, isSingle }) => {
16
- const { formatMessage } = useIntl();
17
- const label = intlLabel?.id ? formatMessage(intlLabel) : name;
18
-
19
- return (
20
- <Flex justifyContent="space-between">
21
- <Flex>
22
- <Typography
23
- textColor="neutral800"
24
- htmlFor={id || name}
25
- variant="pi"
26
- fontWeight="bold"
27
- as="label"
28
- >
29
- {label}
30
- {!isSingle && <>&nbsp;({numberOfEntries})</>}
31
- </Typography>
32
- {labelAction && <LabelAction paddingLeft={1}>{labelAction}</LabelAction>}
33
- </Flex>
34
- {link}
35
- </Flex>
36
- );
37
- };
38
-
39
- Label.defaultProps = {
40
- id: undefined,
41
- labelAction: undefined,
42
- link: null,
43
- numberOfEntries: 0,
44
- };
45
-
46
- Label.propTypes = {
47
- id: PropTypes.string,
48
- intlLabel: PropTypes.shape({
49
- id: PropTypes.string.isRequired,
50
- defaultMessage: PropTypes.string.isRequired,
51
- values: PropTypes.object,
52
- }).isRequired,
53
- isSingle: PropTypes.bool.isRequired,
54
- labelAction: PropTypes.element,
55
- link: PropTypes.element,
56
- name: PropTypes.string.isRequired,
57
- numberOfEntries: PropTypes.number,
58
- };
59
-
60
- export default Label;
@@ -1,356 +0,0 @@
1
- import React, { useCallback, useState, useEffect, useMemo, memo } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { useIntl } from 'react-intl';
4
- import { useLocation } from 'react-router-dom';
5
- import { Stack } from '@strapi/design-system/Stack';
6
- import findIndex from 'lodash/findIndex';
7
- import get from 'lodash/get';
8
- import isArray from 'lodash/isArray';
9
- import isEmpty from 'lodash/isEmpty';
10
- import set from 'lodash/set';
11
- import {
12
- NotAllowedInput,
13
- useCMEditViewDataManager,
14
- useQueryParams,
15
- Link,
16
- } from '@strapi/helper-plugin';
17
- import { stringify } from 'qs';
18
- import axios from 'axios';
19
- import { axiosInstance } from '../../../core/utils';
20
- import { getTrad } from '../../utils';
21
- import Label from './Label';
22
- import SelectOne from '../SelectOne';
23
- import SelectMany from '../SelectMany';
24
- import Option from './Option';
25
- import { connect, select } from './utils';
26
-
27
- const initialPaginationState = {
28
- contains: '',
29
- limit: 20,
30
- start: 0,
31
- };
32
-
33
- const buildParams = (query, paramsToKeep) => {
34
- if (!paramsToKeep) {
35
- return {};
36
- }
37
-
38
- return paramsToKeep.reduce((acc, current) => {
39
- const value = get(query, current, null);
40
-
41
- if (value) {
42
- set(acc, current, value);
43
- }
44
-
45
- return acc;
46
- }, {});
47
- };
48
- function SelectWrapper({
49
- description,
50
- editable,
51
- labelAction,
52
- intlLabel,
53
- isCreatingEntry,
54
- isFieldAllowed,
55
- isFieldReadable,
56
- mainField,
57
- name,
58
- relationType,
59
- targetModel,
60
- placeholder,
61
- queryInfos,
62
- }) {
63
- const { formatMessage } = useIntl();
64
- const [{ query }] = useQueryParams();
65
- // Disable the input in case of a polymorphic relation
66
- const isMorph = useMemo(() => relationType.toLowerCase().includes('morph'), [relationType]);
67
- const { addRelation, modifiedData, moveRelation, onChange, onRemoveRelation } =
68
- useCMEditViewDataManager();
69
- const { pathname } = useLocation();
70
-
71
- const value = get(modifiedData, name, null);
72
- const [state, setState] = useState(initialPaginationState);
73
- const [options, setOptions] = useState([]);
74
- const [isLoading, setIsLoading] = useState(false);
75
- const [isOpen, setIsOpen] = useState(false);
76
-
77
- const filteredOptions = useMemo(() => {
78
- return options.filter((option) => {
79
- if (!isEmpty(value)) {
80
- // SelectMany
81
- if (Array.isArray(value)) {
82
- return findIndex(value, (o) => o.id === option.value.id) === -1;
83
- }
84
-
85
- // SelectOne
86
- return get(value, 'id', '') !== option.value.id;
87
- }
88
-
89
- return true;
90
- });
91
- }, [options, value]);
92
-
93
- const { endPoint, containsKey, defaultParams, shouldDisplayRelationLink, paramsToKeep } =
94
- queryInfos;
95
-
96
- const isSingle = ['oneWay', 'oneToOne', 'manyToOne', 'oneToManyMorph', 'oneToOneMorph'].includes(
97
- relationType
98
- );
99
-
100
- const idsToOmit = useMemo(() => {
101
- if (!value) {
102
- return [];
103
- }
104
-
105
- if (isSingle) {
106
- return [value.id];
107
- }
108
-
109
- return value.map((val) => val.id);
110
- }, [isSingle, value]);
111
-
112
- const getData = useCallback(
113
- async (source) => {
114
- // Currently polymorphic relations are not handled
115
- if (isMorph) {
116
- setIsLoading(false);
117
-
118
- return;
119
- }
120
-
121
- if (!isFieldAllowed) {
122
- setIsLoading(false);
123
-
124
- return;
125
- }
126
-
127
- setIsLoading(true);
128
-
129
- const params = { limit: state.limit, ...defaultParams, start: state.start };
130
-
131
- if (state.contains) {
132
- params[`filters[${containsKey}][$containsi]`] = state.contains;
133
- }
134
-
135
- try {
136
- const { data } = await axiosInstance.post(
137
- endPoint,
138
- { idsToOmit },
139
- { params, cancelToken: source.token }
140
- );
141
-
142
- const formattedData = data.map((obj) => {
143
- return { value: obj, label: obj[mainField.name] };
144
- });
145
-
146
- setOptions((prevState) =>
147
- prevState.concat(formattedData).filter((obj, index) => {
148
- const objIndex = prevState.findIndex((el) => el.value.id === obj.value.id);
149
-
150
- if (objIndex === -1) {
151
- return true;
152
- }
153
-
154
- return prevState.findIndex((el) => el.value.id === obj.value.id) === index;
155
- })
156
- );
157
- setIsLoading(false);
158
- } catch (err) {
159
- // Silent
160
- setIsLoading(false);
161
- }
162
- },
163
- [
164
- containsKey,
165
- defaultParams,
166
- endPoint,
167
- idsToOmit,
168
- isFieldAllowed,
169
- isMorph,
170
- mainField.name,
171
- state.contains,
172
- state.limit,
173
- state.start,
174
- ]
175
- );
176
-
177
- useEffect(() => {
178
- const CancelToken = axios.CancelToken;
179
- const source = CancelToken.source();
180
-
181
- if (isOpen) {
182
- getData(source);
183
- }
184
-
185
- return () => source.cancel('Operation canceled by the user.');
186
- }, [getData, isOpen]);
187
-
188
- const handleInputChange = (inputValue, { action }) => {
189
- if (action === 'input-change') {
190
- setState((prevState) => {
191
- if (prevState.contains === inputValue) {
192
- return prevState;
193
- }
194
-
195
- return { ...prevState, contains: inputValue, start: 0 };
196
- });
197
- }
198
-
199
- return inputValue;
200
- };
201
-
202
- const handleMenuScrollToBottom = () => {
203
- setState((prevState) => ({
204
- ...prevState,
205
- start: prevState.start + 20,
206
- }));
207
- };
208
-
209
- const handleMenuClose = () => {
210
- setState(initialPaginationState);
211
- setIsOpen(false);
212
- };
213
-
214
- const handleChange = (value) => {
215
- onChange({ target: { name, value: value ? value.value : value } });
216
- };
217
-
218
- const handleAddRelation = (value) => {
219
- if (!isEmpty(value)) {
220
- addRelation({ target: { name, value } });
221
- }
222
- };
223
-
224
- const handleMenuOpen = () => {
225
- setIsOpen(true);
226
- };
227
-
228
- const to = `/content-manager/collectionType/${targetModel}/${value ? value.id : null}`;
229
-
230
- const searchToPersist = stringify(buildParams(query, paramsToKeep), { encode: false });
231
-
232
- let link = null;
233
-
234
- if (isSingle && value && shouldDisplayRelationLink) {
235
- link = (
236
- <Link to={{ pathname: to, state: { from: pathname }, search: searchToPersist }}>
237
- {formatMessage({ id: getTrad('containers.Edit.seeDetails'), defaultMessage: 'Details' })}
238
- </Link>
239
- );
240
- }
241
-
242
- const Component = isSingle ? SelectOne : SelectMany;
243
- const associationsLength = isArray(value) ? value.length : 0;
244
-
245
- const isDisabled = useMemo(() => {
246
- if (isMorph) {
247
- return true;
248
- }
249
-
250
- if (!isCreatingEntry) {
251
- return (!isFieldAllowed && isFieldReadable) || !editable;
252
- }
253
-
254
- return !editable;
255
- }, [isMorph, isCreatingEntry, editable, isFieldAllowed, isFieldReadable]);
256
-
257
- if (!isFieldAllowed && isCreatingEntry) {
258
- return <NotAllowedInput intlLabel={intlLabel} labelAction={labelAction} />;
259
- }
260
-
261
- if (!isCreatingEntry && !isFieldAllowed && !isFieldReadable) {
262
- return <NotAllowedInput intlLabel={intlLabel} labelAction={labelAction} />;
263
- }
264
-
265
- return (
266
- <Stack spacing={1}>
267
- <Label
268
- intlLabel={intlLabel}
269
- isSingle={isSingle}
270
- labelAction={labelAction}
271
- link={link}
272
- name={name}
273
- numberOfEntries={associationsLength}
274
- />
275
- <Component
276
- addRelation={handleAddRelation}
277
- components={{
278
- Option,
279
- }}
280
- displayNavigationLink={shouldDisplayRelationLink}
281
- id={name}
282
- isDisabled={isDisabled}
283
- isLoading={isLoading}
284
- isClearable
285
- loadingMessage={() =>
286
- formatMessage({
287
- id: getTrad('DynamicTable.relation-loading'),
288
- defaultMessage: 'Relations are loading',
289
- })
290
- }
291
- mainField={mainField}
292
- move={moveRelation}
293
- name={name}
294
- options={filteredOptions}
295
- onChange={handleChange}
296
- onInputChange={handleInputChange}
297
- onMenuClose={handleMenuClose}
298
- onMenuOpen={handleMenuOpen}
299
- onMenuScrollToBottom={handleMenuScrollToBottom}
300
- onRemove={onRemoveRelation}
301
- placeholder={placeholder}
302
- searchToPersist={searchToPersist}
303
- targetModel={targetModel}
304
- value={value}
305
- description={description}
306
- />
307
- </Stack>
308
- );
309
- }
310
-
311
- SelectWrapper.defaultProps = {
312
- editable: true,
313
- description: '',
314
- labelAction: null,
315
- isFieldAllowed: true,
316
- placeholder: null,
317
- };
318
-
319
- SelectWrapper.propTypes = {
320
- editable: PropTypes.bool,
321
- description: PropTypes.string,
322
- intlLabel: PropTypes.shape({
323
- id: PropTypes.string.isRequired,
324
- defaultMessage: PropTypes.string.isRequired,
325
- values: PropTypes.object,
326
- }).isRequired,
327
- labelAction: PropTypes.element,
328
- isCreatingEntry: PropTypes.bool.isRequired,
329
- isFieldAllowed: PropTypes.bool,
330
- isFieldReadable: PropTypes.bool.isRequired,
331
- mainField: PropTypes.shape({
332
- name: PropTypes.string.isRequired,
333
- schema: PropTypes.shape({
334
- type: PropTypes.string.isRequired,
335
- }).isRequired,
336
- }).isRequired,
337
- name: PropTypes.string.isRequired,
338
- placeholder: PropTypes.shape({
339
- id: PropTypes.string.isRequired,
340
- defaultMessage: PropTypes.string.isRequired,
341
- values: PropTypes.object,
342
- }),
343
- relationType: PropTypes.string.isRequired,
344
- targetModel: PropTypes.string.isRequired,
345
- queryInfos: PropTypes.shape({
346
- containsKey: PropTypes.string.isRequired,
347
- defaultParams: PropTypes.object,
348
- endPoint: PropTypes.string.isRequired,
349
- shouldDisplayRelationLink: PropTypes.bool.isRequired,
350
- paramsToKeep: PropTypes.array,
351
- }).isRequired,
352
- };
353
-
354
- const Memoized = memo(SelectWrapper);
355
-
356
- export default connect(Memoized, select);
@@ -1,2 +0,0 @@
1
- export { default as connect } from './connect';
2
- export { default as select } from './select';
@@ -1,45 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { useCMEditViewDataManager } from '@strapi/helper-plugin';
3
-
4
- function useSelect({ isUserAllowedToEditField, isUserAllowedToReadField, name }) {
5
- const {
6
- isCreatingEntry,
7
- createActionAllowedFields,
8
- readActionAllowedFields,
9
- updateActionAllowedFields,
10
- } = useCMEditViewDataManager();
11
-
12
- const isFieldAllowed = useMemo(() => {
13
- if (isUserAllowedToEditField === true) {
14
- return true;
15
- }
16
-
17
- const allowedFields = isCreatingEntry ? createActionAllowedFields : updateActionAllowedFields;
18
-
19
- return allowedFields.includes(name);
20
- }, [
21
- isCreatingEntry,
22
- createActionAllowedFields,
23
- name,
24
- isUserAllowedToEditField,
25
- updateActionAllowedFields,
26
- ]);
27
-
28
- const isFieldReadable = useMemo(() => {
29
- if (isUserAllowedToReadField) {
30
- return true;
31
- }
32
-
33
- const allowedFields = isCreatingEntry ? [] : readActionAllowedFields;
34
-
35
- return allowedFields.includes(name);
36
- }, [isCreatingEntry, isUserAllowedToReadField, name, readActionAllowedFields]);
37
-
38
- return {
39
- isCreatingEntry,
40
- isFieldAllowed,
41
- isFieldReadable,
42
- };
43
- }
44
-
45
- export default useSelect;