@akemona-org/strapi-plugin-content-type-builder 3.7.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 (223) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -0
  3. package/admin/src/InjectedComponents/ContentManager/EditSettingViewButton.js +76 -0
  4. package/admin/src/InjectedComponents/ContentManager/EditViewLink.js +44 -0
  5. package/admin/src/assets/images/logo.svg +1 -0
  6. package/admin/src/components/AllowedTypesSelect/MenuList.js +115 -0
  7. package/admin/src/components/AllowedTypesSelect/Text.js +26 -0
  8. package/admin/src/components/AllowedTypesSelect/index.js +55 -0
  9. package/admin/src/components/AttributeOption/Button.js +50 -0
  10. package/admin/src/components/AttributeOption/Card.js +26 -0
  11. package/admin/src/components/AttributeOption/index.js +127 -0
  12. package/admin/src/components/BooleanBox/CT.js +21 -0
  13. package/admin/src/components/BooleanBox/Enumeration.js +10 -0
  14. package/admin/src/components/BooleanBox/EnumerationWrapper.js +14 -0
  15. package/admin/src/components/BooleanBox/Label.js +9 -0
  16. package/admin/src/components/BooleanBox/ST.js +21 -0
  17. package/admin/src/components/BooleanBox/Wrapper.js +75 -0
  18. package/admin/src/components/BooleanBox/icons/CTSelected.js +136 -0
  19. package/admin/src/components/BooleanBox/icons/CTUnselected.js +136 -0
  20. package/admin/src/components/BooleanBox/icons/STSelected.js +80 -0
  21. package/admin/src/components/BooleanBox/icons/STUnselected.js +76 -0
  22. package/admin/src/components/BooleanBox/index.js +103 -0
  23. package/admin/src/components/CheckboxWithDescription/Wrapper.js +12 -0
  24. package/admin/src/components/CheckboxWithDescription/index.js +40 -0
  25. package/admin/src/components/ComponentCard/Close.js +12 -0
  26. package/admin/src/components/ComponentCard/Wrapper.js +84 -0
  27. package/admin/src/components/ComponentCard/index.js +62 -0
  28. package/admin/src/components/ComponentIconPicker/Cell.js +40 -0
  29. package/admin/src/components/ComponentIconPicker/CellRenderer.js +36 -0
  30. package/admin/src/components/ComponentIconPicker/Search.js +12 -0
  31. package/admin/src/components/ComponentIconPicker/SearchWrapper.js +34 -0
  32. package/admin/src/components/ComponentIconPicker/Wrapper.js +60 -0
  33. package/admin/src/components/ComponentIconPicker/index.js +143 -0
  34. package/admin/src/components/ComponentList/index.js +78 -0
  35. package/admin/src/components/ComponentSelect/Category.js +20 -0
  36. package/admin/src/components/ComponentSelect/CategoryName.js +11 -0
  37. package/admin/src/components/ComponentSelect/MenuList.js +110 -0
  38. package/admin/src/components/ComponentSelect/MultipleMenuList.js +271 -0
  39. package/admin/src/components/ComponentSelect/Value.js +83 -0
  40. package/admin/src/components/ComponentSelect/index.js +83 -0
  41. package/admin/src/components/ComponentSelect/utils/HasSomeSubArray.js +5 -0
  42. package/admin/src/components/ComponentSelect/utils/hasSubArray.js +5 -0
  43. package/admin/src/components/CreatableSelect/index.js +58 -0
  44. package/admin/src/components/CustomCheckbox/StyledCustomCheckbox.js +25 -0
  45. package/admin/src/components/CustomCheckbox/index.js +71 -0
  46. package/admin/src/components/CustomLink/P.js +17 -0
  47. package/admin/src/components/CustomLink/StyledCustomLink.js +20 -0
  48. package/admin/src/components/CustomLink/index.js +31 -0
  49. package/admin/src/components/DynamicZoneList/ComponentButton.js +39 -0
  50. package/admin/src/components/DynamicZoneList/index.js +124 -0
  51. package/admin/src/components/HeaderModalNavContainer/index.js +25 -0
  52. package/admin/src/components/HeaderNavLink/Wrapper.js +21 -0
  53. package/admin/src/components/HeaderNavLink/index.js +50 -0
  54. package/admin/src/components/List/List.js +131 -0
  55. package/admin/src/components/List/index.js +295 -0
  56. package/admin/src/components/ListButton/index.js +9 -0
  57. package/admin/src/components/ListHeader/Title.js +19 -0
  58. package/admin/src/components/ListHeader/Wrapper.js +24 -0
  59. package/admin/src/components/ListHeader/index.js +37 -0
  60. package/admin/src/components/ListRow/Wrapper.js +76 -0
  61. package/admin/src/components/ListRow/index.js +334 -0
  62. package/admin/src/components/ModalHeader/ComponentIcon.js +21 -0
  63. package/admin/src/components/ModalHeader/ComponentInfos.js +22 -0
  64. package/admin/src/components/ModalHeader/ComponentInfosWrapper.js +9 -0
  65. package/admin/src/components/ModalHeader/DropdownInfos.js +50 -0
  66. package/admin/src/components/ModalHeader/Icon.js +26 -0
  67. package/admin/src/components/ModalHeader/IconWrapper.js +11 -0
  68. package/admin/src/components/ModalHeader/Item.js +19 -0
  69. package/admin/src/components/ModalHeader/Menu.js +8 -0
  70. package/admin/src/components/ModalHeader/Toggle.js +14 -0
  71. package/admin/src/components/ModalHeader/Wrapper.js +12 -0
  72. package/admin/src/components/ModalHeader/index.js +105 -0
  73. package/admin/src/components/RelationForm/Wrapper.js +9 -0
  74. package/admin/src/components/RelationForm/index.js +66 -0
  75. package/admin/src/components/RelationFormBox/Wrapper.js +34 -0
  76. package/admin/src/components/RelationFormBox/index.js +85 -0
  77. package/admin/src/components/RelationFormNaturePicker/Wrapper.js +53 -0
  78. package/admin/src/components/RelationFormNaturePicker/index.js +112 -0
  79. package/admin/src/components/RelationTargetPicker/Item.js +62 -0
  80. package/admin/src/components/RelationTargetPicker/Wrapper.js +89 -0
  81. package/admin/src/components/RelationTargetPicker/index.js +88 -0
  82. package/admin/src/components/SelectCheckbox/index.js +8 -0
  83. package/admin/src/components/SelectMenuSubUl/ToggleUl.js +23 -0
  84. package/admin/src/components/SelectMenuSubUl/index.js +23 -0
  85. package/admin/src/components/SelectMenuUl/index.js +66 -0
  86. package/admin/src/components/Td/index.js +37 -0
  87. package/admin/src/components/UpperFirst/index.js +14 -0
  88. package/admin/src/components/WrapperSelect/index.js +89 -0
  89. package/admin/src/containers/App/Wrapper.js +14 -0
  90. package/admin/src/containers/App/index.js +39 -0
  91. package/admin/src/containers/App/utils/icons.json +962 -0
  92. package/admin/src/containers/DataManagerProvider/constants.js +15 -0
  93. package/admin/src/containers/DataManagerProvider/index.js +610 -0
  94. package/admin/src/containers/DataManagerProvider/reducer.js +461 -0
  95. package/admin/src/containers/DataManagerProvider/selectors.js +25 -0
  96. package/admin/src/containers/DataManagerProvider/utils/cleanData.js +167 -0
  97. package/admin/src/containers/DataManagerProvider/utils/createDataObject.js +8 -0
  98. package/admin/src/containers/DataManagerProvider/utils/createModifiedDataSchema.js +91 -0
  99. package/admin/src/containers/DataManagerProvider/utils/retrieveComponentsFromSchema.js +55 -0
  100. package/admin/src/containers/DataManagerProvider/utils/retrieveComponentsThatHaveComponents.js +35 -0
  101. package/admin/src/containers/DataManagerProvider/utils/retrieveNestedComponents.js +34 -0
  102. package/admin/src/containers/DataManagerProvider/utils/retrieveSpecificInfoFromComponents.js +12 -0
  103. package/admin/src/containers/FormModal/CustomButton.js +12 -0
  104. package/admin/src/containers/FormModal/attributes/advancedForm.js +269 -0
  105. package/admin/src/containers/FormModal/attributes/attributeOptions.js +99 -0
  106. package/admin/src/containers/FormModal/attributes/baseForm.js +322 -0
  107. package/admin/src/containers/FormModal/attributes/commonBaseForm.js +7 -0
  108. package/admin/src/containers/FormModal/attributes/form.js +9 -0
  109. package/admin/src/containers/FormModal/attributes/index.js +4 -0
  110. package/admin/src/containers/FormModal/attributes/nameField.js +19 -0
  111. package/admin/src/containers/FormModal/attributes/types.js +309 -0
  112. package/admin/src/containers/FormModal/attributes/uiHelpers.js +11 -0
  113. package/admin/src/containers/FormModal/attributes/validation/common.js +151 -0
  114. package/admin/src/containers/FormModal/category/createCategorySchema.js +28 -0
  115. package/admin/src/containers/FormModal/category/form.js +27 -0
  116. package/admin/src/containers/FormModal/category/index.js +3 -0
  117. package/admin/src/containers/FormModal/category/regex.js +3 -0
  118. package/admin/src/containers/FormModal/component/componentField.js +25 -0
  119. package/admin/src/containers/FormModal/component/createComponentSchema.js +49 -0
  120. package/admin/src/containers/FormModal/component/form.js +67 -0
  121. package/admin/src/containers/FormModal/component/index.js +4 -0
  122. package/admin/src/containers/FormModal/constants.js +11 -0
  123. package/admin/src/containers/FormModal/contentType/createContentTypeSchema.js +44 -0
  124. package/admin/src/containers/FormModal/contentType/form.js +116 -0
  125. package/admin/src/containers/FormModal/contentType/index.js +2 -0
  126. package/admin/src/containers/FormModal/dynamicZone/form.js +45 -0
  127. package/admin/src/containers/FormModal/dynamicZone/index.js +2 -0
  128. package/admin/src/containers/FormModal/forms/index.js +164 -0
  129. package/admin/src/containers/FormModal/index.js +1552 -0
  130. package/admin/src/containers/FormModal/reducer.js +293 -0
  131. package/admin/src/containers/FormModal/selectors.js +24 -0
  132. package/admin/src/containers/FormModal/utils/canEditContentType.js +19 -0
  133. package/admin/src/containers/FormModal/utils/createHeadersArray.js +37 -0
  134. package/admin/src/containers/FormModal/utils/createHeadersObjectFromArray.js +27 -0
  135. package/admin/src/containers/FormModal/utils/createUid.js +17 -0
  136. package/admin/src/containers/FormModal/utils/getAttributesToDisplay.js +35 -0
  137. package/admin/src/containers/FormModal/utils/getModalTitleSubHeader.js +25 -0
  138. package/admin/src/containers/FormModal/utils/getNextSearch.js +17 -0
  139. package/admin/src/containers/FormModal/utils/index.js +6 -0
  140. package/admin/src/containers/FormModal/utils/relations.js +9 -0
  141. package/admin/src/containers/FormModal/utils/staticData.js +43 -0
  142. package/admin/src/containers/Initializer/index.js +26 -0
  143. package/admin/src/containers/LeftMenu/Wrapper.js +14 -0
  144. package/admin/src/containers/LeftMenu/index.js +220 -0
  145. package/admin/src/containers/ListView/Wrapper.js +16 -0
  146. package/admin/src/containers/ListView/index.js +322 -0
  147. package/admin/src/containers/NotFoundPage/index.js +20 -0
  148. package/admin/src/containers/RecursivePath/index.js +22 -0
  149. package/admin/src/contexts/DataManagerContext.js +5 -0
  150. package/admin/src/contexts/ListViewContext.js +5 -0
  151. package/admin/src/hooks/useDataManager.js +6 -0
  152. package/admin/src/hooks/useListView.js +6 -0
  153. package/admin/src/icons/Curve.js +26 -0
  154. package/admin/src/icons/ManyToMany.js +98 -0
  155. package/admin/src/icons/ManyToOne.js +64 -0
  156. package/admin/src/icons/ManyWay.js +36 -0
  157. package/admin/src/icons/OneToMany.js +65 -0
  158. package/admin/src/icons/OneToOne.js +47 -0
  159. package/admin/src/icons/OneWay.js +38 -0
  160. package/admin/src/index.js +83 -0
  161. package/admin/src/lifecycles.js +13 -0
  162. package/admin/src/permissions.js +9 -0
  163. package/admin/src/pluginId.js +5 -0
  164. package/admin/src/reducers.js +10 -0
  165. package/admin/src/translations/ar.json +48 -0
  166. package/admin/src/translations/cs.json +151 -0
  167. package/admin/src/translations/de.json +187 -0
  168. package/admin/src/translations/dk.json +181 -0
  169. package/admin/src/translations/en.json +188 -0
  170. package/admin/src/translations/es.json +188 -0
  171. package/admin/src/translations/fr.json +87 -0
  172. package/admin/src/translations/id.json +187 -0
  173. package/admin/src/translations/index.js +51 -0
  174. package/admin/src/translations/it.json +187 -0
  175. package/admin/src/translations/ja.json +50 -0
  176. package/admin/src/translations/ko.json +57 -0
  177. package/admin/src/translations/ms.json +179 -0
  178. package/admin/src/translations/nl.json +171 -0
  179. package/admin/src/translations/pl.json +152 -0
  180. package/admin/src/translations/pt-BR.json +51 -0
  181. package/admin/src/translations/pt.json +51 -0
  182. package/admin/src/translations/ru.json +188 -0
  183. package/admin/src/translations/sk.json +186 -0
  184. package/admin/src/translations/th.json +181 -0
  185. package/admin/src/translations/tr.json +51 -0
  186. package/admin/src/translations/uk.json +180 -0
  187. package/admin/src/translations/zh-Hans.json +188 -0
  188. package/admin/src/translations/zh.json +178 -0
  189. package/admin/src/utils/convertAttrObjToArray.js +7 -0
  190. package/admin/src/utils/formAPI.js +112 -0
  191. package/admin/src/utils/getAttributeDisplayedType.js +31 -0
  192. package/admin/src/utils/getComponents.js +31 -0
  193. package/admin/src/utils/getTrad.js +5 -0
  194. package/admin/src/utils/makeSearch.js +15 -0
  195. package/admin/src/utils/makeUnique.js +3 -0
  196. package/config/functions/bootstrap.js +14 -0
  197. package/config/routes.json +144 -0
  198. package/controllers/Builder.js +7 -0
  199. package/controllers/ComponentCategories.js +43 -0
  200. package/controllers/Components.js +152 -0
  201. package/controllers/Connections.js +9 -0
  202. package/controllers/ContentTypes.js +143 -0
  203. package/controllers/validation/common.js +118 -0
  204. package/controllers/validation/component-category.js +21 -0
  205. package/controllers/validation/component.js +89 -0
  206. package/controllers/validation/content-type.js +161 -0
  207. package/controllers/validation/data-transform.js +32 -0
  208. package/controllers/validation/model-schema.js +91 -0
  209. package/controllers/validation/relations.js +56 -0
  210. package/controllers/validation/types.js +277 -0
  211. package/package.json +63 -0
  212. package/services/Builder.js +7 -0
  213. package/services/ComponentCategories.js +88 -0
  214. package/services/Components.js +103 -0
  215. package/services/ContentTypes.js +263 -0
  216. package/services/api-handler.js +158 -0
  217. package/services/constants.js +59 -0
  218. package/services/schema-builder/component-builder.js +137 -0
  219. package/services/schema-builder/content-type-builder.js +256 -0
  220. package/services/schema-builder/index.js +196 -0
  221. package/services/schema-builder/schema-handler.js +297 -0
  222. package/utils/attributes.js +154 -0
  223. package/utils/helpers.js +31 -0
@@ -0,0 +1,66 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { get, isEmpty } from 'lodash';
4
+ import { useGlobalContext } from 'strapi-helper-plugin';
5
+ import RelationFormBox from '../RelationFormBox';
6
+ import RelationFormNaturePicker from '../RelationFormNaturePicker';
7
+ import Wrapper from './Wrapper';
8
+
9
+ const RelationForm = ({
10
+ errors,
11
+ mainBoxHeader,
12
+ modifiedData,
13
+ naturePickerType,
14
+ onChange,
15
+ }) => {
16
+ const { formatMessage } = useGlobalContext();
17
+ const getError = name => {
18
+ const errorId = get(errors, [name, 'id'], null);
19
+
20
+ return isEmpty(errorId) ? null : formatMessage({ id: errorId });
21
+ };
22
+
23
+ return (
24
+ <Wrapper>
25
+ <RelationFormBox
26
+ isMain
27
+ header={mainBoxHeader}
28
+ error={getError('name')}
29
+ name="name"
30
+ onChange={onChange}
31
+ value={get(modifiedData, 'name', '')}
32
+ />
33
+ <RelationFormNaturePicker
34
+ oneThatIsCreatingARelationWithAnother={mainBoxHeader}
35
+ target={modifiedData.target}
36
+ nature={modifiedData.nature}
37
+ naturePickerType={naturePickerType}
38
+ onChange={onChange}
39
+ />
40
+ <RelationFormBox
41
+ disabled={['oneWay', 'manyWay'].includes(modifiedData.nature)}
42
+ error={getError('targetAttribute')}
43
+ name="targetAttribute"
44
+ onChange={onChange}
45
+ oneThatIsCreatingARelationWithAnother={mainBoxHeader}
46
+ target={modifiedData.target}
47
+ value={get(modifiedData, 'targetAttribute', '')}
48
+ />
49
+ </Wrapper>
50
+ );
51
+ };
52
+
53
+ RelationForm.defaultProps = {
54
+ errors: {},
55
+ modifiedData: {},
56
+ };
57
+
58
+ RelationForm.propTypes = {
59
+ errors: PropTypes.object,
60
+ mainBoxHeader: PropTypes.string.isRequired,
61
+ modifiedData: PropTypes.object,
62
+ naturePickerType: PropTypes.string.isRequired,
63
+ onChange: PropTypes.func.isRequired,
64
+ };
65
+
66
+ export default RelationForm;
@@ -0,0 +1,34 @@
1
+ import styled from 'styled-components';
2
+
3
+ import { colors } from 'strapi-helper-plugin';
4
+
5
+ const Wrapper = styled.div`
6
+ width: 22rem;
7
+ height: 13.8rem;
8
+ flex-shrink: 0;
9
+ background-color: ${colors.relations.boxBkgd};
10
+ box-shadow: 0 1px 2px ${colors.relations.boxShadow};
11
+ border-radius: 2px;
12
+ .box-header {
13
+ height: 3.6rem;
14
+ line-height: 3.6rem;
15
+ text-transform: capitalize;
16
+ background-color: ${colors.relations.headerBkgd};
17
+ &,
18
+ .dropdown-toggle p {
19
+ text-align: center;
20
+ font-size: 1.4rem;
21
+ font-weight: 700;
22
+ }
23
+ i,
24
+ svg {
25
+ margin-right: 8px;
26
+ }
27
+ }
28
+ .box-body {
29
+ padding: 0 15px;
30
+ padding-top: 1rem;
31
+ }
32
+ `;
33
+
34
+ export default Wrapper;
@@ -0,0 +1,85 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Inputs } from '@buffetjs/custom';
4
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5
+ import { useGlobalContext } from 'strapi-helper-plugin';
6
+ import getTrad from '../../utils/getTrad';
7
+ import RelationTargetPicker from '../RelationTargetPicker';
8
+ import Wrapper from './Wrapper';
9
+
10
+ const RelationFormBox = ({
11
+ disabled,
12
+ error,
13
+ header,
14
+ isMain,
15
+ name,
16
+ onChange,
17
+ oneThatIsCreatingARelationWithAnother,
18
+ target,
19
+ value,
20
+ }) => {
21
+ const { formatMessage } = useGlobalContext();
22
+
23
+ return (
24
+ <Wrapper>
25
+ <div className="box-header">
26
+ {isMain ? (
27
+ <p>
28
+ <FontAwesomeIcon
29
+ icon={['far', 'caret-square-right']}
30
+ style={{ fontSize: 12, marginTop: '-3px' }}
31
+ />
32
+ {header}
33
+ </p>
34
+ ) : (
35
+ <RelationTargetPicker
36
+ target={target}
37
+ onChange={onChange}
38
+ oneThatIsCreatingARelationWithAnother={
39
+ oneThatIsCreatingARelationWithAnother
40
+ }
41
+ />
42
+ )}
43
+ </div>
44
+ <div className="box-body">
45
+ <Inputs
46
+ autoFocus={isMain}
47
+ disabled={disabled}
48
+ label={formatMessage({
49
+ id: getTrad('form.attribute.item.defineRelation.fieldName'),
50
+ })}
51
+ error={error}
52
+ type="text"
53
+ onChange={onChange}
54
+ name={name}
55
+ value={value}
56
+ />
57
+ </div>
58
+ </Wrapper>
59
+ );
60
+ };
61
+
62
+ RelationFormBox.defaultProps = {
63
+ disabled: false,
64
+ error: null,
65
+ header: null,
66
+ isMain: false,
67
+ onChange: () => {},
68
+ oneThatIsCreatingARelationWithAnother: null,
69
+ target: null,
70
+ value: '',
71
+ };
72
+
73
+ RelationFormBox.propTypes = {
74
+ disabled: PropTypes.bool,
75
+ error: PropTypes.string,
76
+ header: PropTypes.string,
77
+ isMain: PropTypes.bool,
78
+ name: PropTypes.string.isRequired,
79
+ onChange: PropTypes.func,
80
+ oneThatIsCreatingARelationWithAnother: PropTypes.string,
81
+ target: PropTypes.string,
82
+ value: PropTypes.string,
83
+ };
84
+
85
+ export default RelationFormBox;
@@ -0,0 +1,53 @@
1
+ import styled from 'styled-components';
2
+
3
+ import { colors } from 'strapi-helper-plugin';
4
+
5
+ const StyledRelationNaturePicker = styled.div`
6
+ position: relative;
7
+ width: 100%;
8
+ .nature-container {
9
+ position: absolute;
10
+ bottom: 0;
11
+ left: 0;
12
+ width: 100%;
13
+ height: fit-content;
14
+ &::before {
15
+ content: '';
16
+ position: absolute;
17
+ top: 2.2rem;
18
+ height: 1px;
19
+ width: 100%;
20
+ background-color: ${colors.relations.border};
21
+ z-index: 0;
22
+ }
23
+ .nature-buttons {
24
+ position: relative;
25
+ width: fit-content;
26
+ display: block;
27
+ margin: 0 auto;
28
+ z-index: 1;
29
+ }
30
+ .nature-txt {
31
+ padding: 0 1rem;
32
+ font-size: 1.3rem;
33
+ text-align: center;
34
+ margin-top: 6px;
35
+ margin-bottom: 2px;
36
+ span {
37
+ &:first-of-type,
38
+ &:nth-of-type(3) {
39
+ text-transform: capitalize;
40
+ }
41
+ &:nth-of-type(2) {
42
+ color: ${colors.relations.border};
43
+ }
44
+ }
45
+ }
46
+ svg {
47
+ margin: 0 1rem;
48
+ cursor: pointer;
49
+ }
50
+ }
51
+ `;
52
+
53
+ export default StyledRelationNaturePicker;
@@ -0,0 +1,112 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { FormattedMessage } from 'react-intl';
4
+ import { get, truncate } from 'lodash';
5
+ import pluralize from 'pluralize';
6
+ import useDataManager from '../../hooks/useDataManager';
7
+ import ManyToMany from '../../icons/ManyToMany';
8
+ import ManyToOne from '../../icons/ManyToOne';
9
+ import ManyWay from '../../icons/ManyWay';
10
+ import OneToMany from '../../icons/OneToMany';
11
+ import OneToOne from '../../icons/OneToOne';
12
+ import OneWay from '../../icons/OneWay';
13
+ import getTrad from '../../utils/getTrad';
14
+ import Wrapper from './Wrapper';
15
+
16
+ const relations = {
17
+ oneWay: OneWay,
18
+ oneToOne: OneToOne,
19
+ oneToMany: OneToMany,
20
+ manyToOne: ManyToOne,
21
+ manyToMany: ManyToMany,
22
+ manyWay: ManyWay,
23
+ };
24
+
25
+ const RelationFormNaturePicker = ({
26
+ nature,
27
+ naturePickerType,
28
+ onChange,
29
+ oneThatIsCreatingARelationWithAnother,
30
+ target,
31
+ }) => {
32
+ const { contentTypes, modifiedData } = useDataManager();
33
+ const ctRelations = ['oneWay', 'oneToOne', 'oneToMany', 'manyToOne', 'manyToMany', 'manyWay'];
34
+ const componentRelations = ['oneWay', 'manyWay'];
35
+ const dataType =
36
+ naturePickerType === 'contentType'
37
+ ? get(modifiedData, [naturePickerType, 'schema', 'kind'], '')
38
+ : naturePickerType;
39
+ const relationsType = dataType === 'collectionType' ? ctRelations : componentRelations;
40
+
41
+ const areDisplayedNamesInverted = nature === 'manyToOne';
42
+ const targetLabel = get(contentTypes, [target, 'schema', 'name'], 'unknown');
43
+ const leftTarget = areDisplayedNamesInverted
44
+ ? targetLabel
45
+ : oneThatIsCreatingARelationWithAnother;
46
+ const rightTarget = areDisplayedNamesInverted
47
+ ? oneThatIsCreatingARelationWithAnother
48
+ : targetLabel;
49
+ const leftDisplayedValue = pluralize(leftTarget, nature === 'manyToMany' ? 2 : 1);
50
+ const restrictedRelations = get(contentTypes, [target, 'schema', 'restrictRelationsTo'], null);
51
+
52
+ const rightDisplayedValue = pluralize(
53
+ rightTarget,
54
+ ['manyToMany', 'oneToMany', 'manyToOne', 'manyWay'].includes(nature) ? 2 : 1
55
+ );
56
+
57
+ return (
58
+ <Wrapper>
59
+ <div className="nature-container">
60
+ <div className="nature-buttons">
61
+ {relationsType.map(relationNature => {
62
+ const Asset = relations[relationNature];
63
+ const isEnabled =
64
+ restrictedRelations === null || restrictedRelations.includes(relationNature);
65
+
66
+ return (
67
+ <Asset
68
+ key={relationNature}
69
+ isSelected={nature === relationNature}
70
+ style={{ cursor: isEnabled ? 'pointer' : 'not-allowed' }}
71
+ onClick={() => {
72
+ if (isEnabled) {
73
+ onChange({
74
+ target: {
75
+ name: 'nature',
76
+ value: relationNature,
77
+ targetContentType: target,
78
+ oneThatIsCreatingARelationWithAnother,
79
+ type: 'relation',
80
+ },
81
+ });
82
+ }
83
+ }}
84
+ />
85
+ );
86
+ })}
87
+ </div>
88
+ <div className="nature-txt">
89
+ <span>{truncate(leftDisplayedValue, { length: 24 })}</span>
90
+ &nbsp;
91
+ <FormattedMessage id={getTrad(`relation.${nature}`)} />
92
+ &nbsp;
93
+ <span>{truncate(rightDisplayedValue, { length: 24 })}</span>
94
+ </div>
95
+ </div>
96
+ </Wrapper>
97
+ );
98
+ };
99
+
100
+ RelationFormNaturePicker.defaultProps = {
101
+ nature: 'oneWay',
102
+ };
103
+
104
+ RelationFormNaturePicker.propTypes = {
105
+ nature: PropTypes.string,
106
+ naturePickerType: PropTypes.string.isRequired,
107
+ onChange: PropTypes.func.isRequired,
108
+ oneThatIsCreatingARelationWithAnother: PropTypes.string.isRequired,
109
+ target: PropTypes.string.isRequired,
110
+ };
111
+
112
+ export default RelationFormNaturePicker;
@@ -0,0 +1,62 @@
1
+ import React, { memo } from 'react';
2
+ import { DropdownItem } from 'reactstrap';
3
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4
+ import PropTypes from 'prop-types';
5
+ import { Text } from '@buffetjs/core';
6
+
7
+ const Item = ({
8
+ onChange,
9
+ oneThatIsCreatingARelationWithAnother,
10
+ plugin,
11
+ restrictRelationsTo,
12
+ title,
13
+ uid,
14
+ }) => {
15
+ const handleChange = () => {
16
+ const selectedContentTypeFriendlyName = plugin ? `${plugin}_${title}` : title;
17
+
18
+ onChange({
19
+ target: {
20
+ name: 'target',
21
+ value: uid,
22
+ type: 'relation',
23
+ oneThatIsCreatingARelationWithAnother,
24
+ selectedContentTypeFriendlyName,
25
+ targetContentTypeAllowedRelations: restrictRelationsTo,
26
+ },
27
+ });
28
+ };
29
+
30
+ return (
31
+ <DropdownItem key={uid} onClick={handleChange}>
32
+ <p>
33
+ <FontAwesomeIcon
34
+ icon={['far', 'caret-square-right']}
35
+ style={{ fontSize: 12, marginTop: '-3px' }}
36
+ />
37
+ {title}
38
+ {plugin && (
39
+ <Text as="span" fontStyle="italic" textTransform="none" color="rgba(50,55,64,0.75)">
40
+ &nbsp; (from: {plugin})
41
+ </Text>
42
+ )}
43
+ </p>
44
+ </DropdownItem>
45
+ );
46
+ };
47
+
48
+ Item.defaultProps = {
49
+ plugin: null,
50
+ restrictRelationsTo: null,
51
+ };
52
+
53
+ Item.propTypes = {
54
+ onChange: PropTypes.func.isRequired,
55
+ oneThatIsCreatingARelationWithAnother: PropTypes.string.isRequired,
56
+ plugin: PropTypes.string,
57
+ restrictRelationsTo: PropTypes.array,
58
+ title: PropTypes.string.isRequired,
59
+ uid: PropTypes.string.isRequired,
60
+ };
61
+
62
+ export default memo(Item);
@@ -0,0 +1,89 @@
1
+ import styled from 'styled-components';
2
+
3
+ const Wrapper = styled.div`
4
+ > div {
5
+ width: 100%;
6
+ > button {
7
+ position: relative;
8
+ width: 100%;
9
+ font-size: 1.4rem;
10
+ line-height: 3.6rem;
11
+ background-color: transparent;
12
+ border: none;
13
+ cursor: pointer;
14
+ text-transform: capitalize;
15
+ color: black;
16
+ &:focus,
17
+ &:active,
18
+ &:hover,
19
+ &:visited {
20
+ background-color: transparent !important;
21
+ box-shadow: none;
22
+ color: black;
23
+ }
24
+ &:after {
25
+ position: absolute;
26
+ top: calc(50% - 0.1rem);
27
+ right: 1.5rem;
28
+ }
29
+ > p {
30
+ margin-top: -1px;
31
+ margin-bottom: 0;
32
+ padding: 0 20px 0 10px;
33
+ white-space: nowrap;
34
+ overflow: hidden;
35
+ text-overflow: ellipsis;
36
+ > i,
37
+ > svg {
38
+ margin-right: 8px;
39
+ }
40
+ span {
41
+ font-style: italic;
42
+ font-weight: 500;
43
+ }
44
+ }
45
+ }
46
+ /* Dropdown List */
47
+ > button + div {
48
+ max-width: 100%;
49
+ max-height: 180px;
50
+ width: 100%;
51
+ margin-top: -4px;
52
+ padding: 0;
53
+ border-radius: 0;
54
+ overflow: scroll;
55
+ > button {
56
+ height: 3.6rem;
57
+ border-bottom: 1px solid #f6f6f6;
58
+ font-size: 1.3rem;
59
+ font-family: Lato;
60
+ font-weight: 400;
61
+ text-transform: capitalize;
62
+ -webkit-font-smoothing: antialiased;
63
+ cursor: pointer;
64
+ &:focus,
65
+ &:active {
66
+ outline: 0;
67
+ background-color: rgb(255, 255, 255) !important;
68
+ color: rgba(50, 55, 64, 0.75);
69
+ }
70
+ > p {
71
+ color: rgba(50, 55, 64, 0.75);
72
+ line-height: 3rem;
73
+ white-space: nowrap;
74
+ overflow: hidden;
75
+ text-overflow: ellipsis;
76
+ i,
77
+ svg {
78
+ margin-right: 10px;
79
+ }
80
+ span {
81
+ font-style: italic;
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ `;
88
+
89
+ export default Wrapper;
@@ -0,0 +1,88 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4
+ import { get } from 'lodash';
5
+ import { Dropdown, DropdownToggle, DropdownMenu } from 'reactstrap';
6
+
7
+ import useDataManager from '../../hooks/useDataManager';
8
+ import Item from './Item';
9
+ import Wrapper from './Wrapper';
10
+
11
+ const RelationTargetPicker = ({ onChange, oneThatIsCreatingARelationWithAnother, target }) => {
12
+ const [isOpen, setIsOpen] = useState(false);
13
+ const { contentTypes, sortedContentTypesList } = useDataManager();
14
+ const allowedContentTypesForRelation = useMemo(
15
+ () =>
16
+ sortedContentTypesList
17
+ .filter(obj => obj.kind === 'collectionType')
18
+ .filter(
19
+ obj =>
20
+ obj.restrictRelationsTo === null ||
21
+ (Array.isArray(obj.restrictRelationsTo) && obj.restrictRelationsTo.length > 0)
22
+ ),
23
+ [sortedContentTypesList]
24
+ );
25
+
26
+ const pluginInfo = useMemo(() => {
27
+ const plugin = get(contentTypes, [target, 'plugin'], null);
28
+
29
+ if (plugin) {
30
+ return (
31
+ <span style={{ fontStyle: 'italic', textTransform: 'none' }}>&nbsp; (from: {plugin})</span>
32
+ );
33
+ }
34
+
35
+ return null;
36
+ }, [contentTypes, target]);
37
+
38
+ const targetFriendlyName = useMemo(() => {
39
+ const name = get(contentTypes, [target, 'schema', 'name'], 'error');
40
+
41
+ return name;
42
+ }, [contentTypes, target]);
43
+
44
+ return (
45
+ <Wrapper>
46
+ <Dropdown
47
+ isOpen={isOpen}
48
+ toggle={() => {
49
+ setIsOpen(!isOpen);
50
+ }}
51
+ >
52
+ <DropdownToggle caret>
53
+ <p>
54
+ <FontAwesomeIcon
55
+ icon={['far', 'caret-square-right']}
56
+ style={{ fontSize: 12, marginTop: '-3px' }}
57
+ />
58
+ {targetFriendlyName}
59
+ {pluginInfo}
60
+ </p>
61
+ </DropdownToggle>
62
+ <DropdownMenu style={{ paddingTop: '3px' }}>
63
+ {allowedContentTypesForRelation.map(({ uid, title, restrictRelationsTo, plugin }) => {
64
+ return (
65
+ <Item
66
+ key={uid}
67
+ uid={uid}
68
+ title={title}
69
+ restrictRelationsTo={restrictRelationsTo}
70
+ plugin={plugin}
71
+ onChange={onChange}
72
+ oneThatIsCreatingARelationWithAnother={oneThatIsCreatingARelationWithAnother}
73
+ />
74
+ );
75
+ })}
76
+ </DropdownMenu>
77
+ </Dropdown>
78
+ </Wrapper>
79
+ );
80
+ };
81
+
82
+ RelationTargetPicker.propTypes = {
83
+ onChange: PropTypes.func.isRequired,
84
+ oneThatIsCreatingARelationWithAnother: PropTypes.string.isRequired,
85
+ target: PropTypes.string.isRequired,
86
+ };
87
+
88
+ export default RelationTargetPicker;
@@ -0,0 +1,8 @@
1
+ import styled from 'styled-components';
2
+ import { Checkbox } from '@buffetjs/styles';
3
+
4
+ const SelectCheckbox = styled(Checkbox)`
5
+ margin-right: 10px;
6
+ `;
7
+
8
+ export default SelectCheckbox;
@@ -0,0 +1,23 @@
1
+ import { Collapse } from 'reactstrap';
2
+ import styled from 'styled-components';
3
+
4
+ const ToggleUl = styled(Collapse)`
5
+ padding: 0 15px;
6
+ background-color: #fff;
7
+ list-style: none;
8
+ font-size: 13px;
9
+ > li {
10
+ label {
11
+ cursor: pointer;
12
+ }
13
+
14
+ .check-wrapper {
15
+ z-index: 9;
16
+ > input {
17
+ z-index: 1;
18
+ }
19
+ }
20
+ }
21
+ `;
22
+
23
+ export default ToggleUl;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ToggleUl from './ToggleUl';
4
+
5
+ const SubUl = ({ children, isOpen }) => {
6
+ return (
7
+ <ToggleUl tag="ul" isOpen={isOpen}>
8
+ {children}
9
+ </ToggleUl>
10
+ );
11
+ };
12
+
13
+ SubUl.defaultProps = {
14
+ children: null,
15
+ isOpen: false,
16
+ };
17
+
18
+ SubUl.propTypes = {
19
+ children: PropTypes.node,
20
+ isOpen: PropTypes.bool,
21
+ };
22
+
23
+ export default SubUl;