@akemona-org/strapi-plugin-content-manager 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.
- package/LICENSE +22 -0
- package/README.md +27 -0
- package/admin/src/InjectedComponents/ContentTypeBuilder/ConfigureViewButton/index.js +78 -0
- package/admin/src/assets/images/background_input.svg +1 -0
- package/admin/src/assets/images/icon-cross-blue.svg +1 -0
- package/admin/src/assets/images/icon_remove.svg +19 -0
- package/admin/src/assets/images/logo.svg +1 -0
- package/admin/src/components/AddDropdown/components.js +113 -0
- package/admin/src/components/AddDropdown/index.js +76 -0
- package/admin/src/components/Block/components.js +28 -0
- package/admin/src/components/Block/index.js +45 -0
- package/admin/src/components/ComponentInitializer/P.js +9 -0
- package/admin/src/components/ComponentInitializer/index.js +43 -0
- package/admin/src/components/Container/index.js +7 -0
- package/admin/src/components/CustomInputCheckbox/components.js +77 -0
- package/admin/src/components/CustomInputCheckbox/index.js +53 -0
- package/admin/src/components/CustomTable/ActionCollapse/Delete.js +14 -0
- package/admin/src/components/CustomTable/ActionCollapse/DeleteAll.js +18 -0
- package/admin/src/components/CustomTable/ActionCollapse/Wrapper.js +20 -0
- package/admin/src/components/CustomTable/ActionCollapse/index.js +38 -0
- package/admin/src/components/CustomTable/Headers/Header.js +59 -0
- package/admin/src/components/CustomTable/Headers/Thead.js +35 -0
- package/admin/src/components/CustomTable/Headers/index.js +46 -0
- package/admin/src/components/CustomTable/Row/ActionContainer.js +19 -0
- package/admin/src/components/CustomTable/Row/Cell.js +55 -0
- package/admin/src/components/CustomTable/Row/index.js +112 -0
- package/admin/src/components/CustomTable/index.js +162 -0
- package/admin/src/components/CustomTable/styledComponents.js +85 -0
- package/admin/src/components/DragLayer/index.js +102 -0
- package/admin/src/components/DraggedField/Close/index.js +10 -0
- package/admin/src/components/DraggedField/GrabWrapper.js +38 -0
- package/admin/src/components/DraggedField/Link.js +17 -0
- package/admin/src/components/DraggedField/NameWrapper.js +29 -0
- package/admin/src/components/DraggedField/RemoveWrapper.js +32 -0
- package/admin/src/components/DraggedField/SubWrapper.js +36 -0
- package/admin/src/components/DraggedField/Wrapper.js +134 -0
- package/admin/src/components/DraggedField/index.js +196 -0
- package/admin/src/components/DraggedField/utils/getColor.js +12 -0
- package/admin/src/components/DraggedField/utils/getHeight.js +3 -0
- package/admin/src/components/DraggedFieldWithPreview/Carret.js +24 -0
- package/admin/src/components/DraggedFieldWithPreview/DynamicComponent.js +70 -0
- package/admin/src/components/DraggedFieldWithPreview/DynamicZoneWrapper.js +10 -0
- package/admin/src/components/DraggedFieldWithPreview/Tooltip.js +19 -0
- package/admin/src/components/DraggedFieldWithPreview/Wrapper.js +24 -0
- package/admin/src/components/DraggedFieldWithPreview/index.js +194 -0
- package/admin/src/components/DynamicComponentCard/Wrapper.js +63 -0
- package/admin/src/components/DynamicComponentCard/index.js +49 -0
- package/admin/src/components/DynamicZone/BaselineAlignement.js +11 -0
- package/admin/src/components/DynamicZone/Button.js +31 -0
- package/admin/src/components/DynamicZone/Component/RoundCTA.js +45 -0
- package/admin/src/components/DynamicZone/Component/index.js +79 -0
- package/admin/src/components/DynamicZone/ComponentWrapper.js +44 -0
- package/admin/src/components/DynamicZone/DynamicZoneWrapper.js +12 -0
- package/admin/src/components/DynamicZone/Label.js +42 -0
- package/admin/src/components/DynamicZone/Picker/Category/Banner/Wrapper.js +78 -0
- package/admin/src/components/DynamicZone/Picker/Category/Banner/index.js +33 -0
- package/admin/src/components/DynamicZone/Picker/Category/index.js +53 -0
- package/admin/src/components/DynamicZone/Picker/Wrapper.js +32 -0
- package/admin/src/components/DynamicZone/Picker/index.js +88 -0
- package/admin/src/components/DynamicZone/Wrapper.js +34 -0
- package/admin/src/components/DynamicZone/index.js +238 -0
- package/admin/src/components/DynamicZone/utils/connect.js +12 -0
- package/admin/src/components/DynamicZone/utils/select.js +49 -0
- package/admin/src/components/FieldComponent/ComponentIcon.js +44 -0
- package/admin/src/components/FieldComponent/EmptyComponent.js +19 -0
- package/admin/src/components/FieldComponent/Label.js +10 -0
- package/admin/src/components/FieldComponent/ResetComponent.js +41 -0
- package/admin/src/components/FieldComponent/Wrapper.js +18 -0
- package/admin/src/components/FieldComponent/index.js +171 -0
- package/admin/src/components/FieldComponent/utils/connect.js +12 -0
- package/admin/src/components/FieldComponent/utils/select.js +123 -0
- package/admin/src/components/FieldsReorder/Item.js +249 -0
- package/admin/src/components/FieldsReorder/components.js +8 -0
- package/admin/src/components/FieldsReorder/index.js +102 -0
- package/admin/src/components/FilterOptionsCTA/index.js +14 -0
- package/admin/src/components/FilterPicker/components.js +56 -0
- package/admin/src/components/FilterPicker/index.js +258 -0
- package/admin/src/components/FilterPicker/init.js +25 -0
- package/admin/src/components/FilterPicker/reducer.js +58 -0
- package/admin/src/components/FilterPickerOption/Input.js +58 -0
- package/admin/src/components/FilterPickerOption/Option.js +18 -0
- package/admin/src/components/FilterPickerOption/components.js +60 -0
- package/admin/src/components/FilterPickerOption/index.js +101 -0
- package/admin/src/components/FormTitle/index.js +26 -0
- package/admin/src/components/FormWrapper/index.js +20 -0
- package/admin/src/components/InputJSON/components.js +30 -0
- package/admin/src/components/InputJSON/index.js +184 -0
- package/admin/src/components/InputJSON/jsonlint.js +424 -0
- package/admin/src/components/InputJSONWithErrors/Wrapper.js +32 -0
- package/admin/src/components/InputJSONWithErrors/index.js +168 -0
- package/admin/src/components/InputUID/InputUID.js +26 -0
- package/admin/src/components/InputUID/Options/Option.js +22 -0
- package/admin/src/components/InputUID/Options/OptionsTitle.js +12 -0
- package/admin/src/components/InputUID/Options/RightOptionLabel.js +10 -0
- package/admin/src/components/InputUID/Options/index.js +34 -0
- package/admin/src/components/InputUID/Options/wrapper.js +13 -0
- package/admin/src/components/InputUID/RegenerateButton.js +18 -0
- package/admin/src/components/InputUID/RightContent.js +14 -0
- package/admin/src/components/InputUID/RightContentLabel.js +10 -0
- package/admin/src/components/InputUID/RightLabel.js +42 -0
- package/admin/src/components/InputUID/SubLabel.js +9 -0
- package/admin/src/components/InputUID/Wrapper.js +8 -0
- package/admin/src/components/InputUID/index.js +325 -0
- package/admin/src/components/InputUID/regex.js +3 -0
- package/admin/src/components/Inputs/index.js +283 -0
- package/admin/src/components/Inputs/utils/VALIDATIONS_TO_OMIT.js +12 -0
- package/admin/src/components/Inputs/utils/connect.js +12 -0
- package/admin/src/components/Inputs/utils/generateOptions.js +19 -0
- package/admin/src/components/Inputs/utils/getInputType.js +44 -0
- package/admin/src/components/Inputs/utils/getStep.js +15 -0
- package/admin/src/components/Inputs/utils/index.js +6 -0
- package/admin/src/components/Inputs/utils/select.js +38 -0
- package/admin/src/components/LayoutTitle/index.js +19 -0
- package/admin/src/components/MediaPreviewList/StyledMediaPreviewList.js +171 -0
- package/admin/src/components/MediaPreviewList/index.js +110 -0
- package/admin/src/components/NonRepeatableComponent/index.js +73 -0
- package/admin/src/components/NonRepeatableWrapper/index.js +73 -0
- package/admin/src/components/PlusButton/index.js +52 -0
- package/admin/src/components/PopupForm/index.js +93 -0
- package/admin/src/components/PreviewCarret/components.js +27 -0
- package/admin/src/components/PreviewCarret/index.js +22 -0
- package/admin/src/components/PreviewWysiwyg/Wrapper.js +133 -0
- package/admin/src/components/PreviewWysiwyg/index.js +34 -0
- package/admin/src/components/PreviewWysiwyg/utils/mdRenderer.js +72 -0
- package/admin/src/components/PreviewWysiwyg/utils/satinizeHtml.js +16 -0
- package/admin/src/components/RelationPreviewList/CountWrapper.js +7 -0
- package/admin/src/components/RelationPreviewList/RelationPreviewTooltip.js +117 -0
- package/admin/src/components/RelationPreviewList/index.js +111 -0
- package/admin/src/components/RepeatableComponent/AddFieldButton.js +64 -0
- package/admin/src/components/RepeatableComponent/Banner.js +112 -0
- package/admin/src/components/RepeatableComponent/BannerWrapper.js +194 -0
- package/admin/src/components/RepeatableComponent/CarretTop.js +14 -0
- package/admin/src/components/RepeatableComponent/DraggedItem/index.js +245 -0
- package/admin/src/components/RepeatableComponent/DraggedItem/utils/connect.js +11 -0
- package/admin/src/components/RepeatableComponent/DraggedItem/utils/index.js +2 -0
- package/admin/src/components/RepeatableComponent/DraggedItem/utils/select.js +30 -0
- package/admin/src/components/RepeatableComponent/EmptyComponent.js +27 -0
- package/admin/src/components/RepeatableComponent/FormWrapper.js +27 -0
- package/admin/src/components/RepeatableComponent/index.js +187 -0
- package/admin/src/components/RepeatableComponent/reducer.js +73 -0
- package/admin/src/components/RepeatableComponent/utils/connect.js +11 -0
- package/admin/src/components/RepeatableComponent/utils/select.js +12 -0
- package/admin/src/components/Search/index.js +88 -0
- package/admin/src/components/SectionTitle/Title.js +11 -0
- package/admin/src/components/SectionTitle/index.js +29 -0
- package/admin/src/components/SelectMany/ListItem.js +107 -0
- package/admin/src/components/SelectMany/Relation.js +106 -0
- package/admin/src/components/SelectMany/components.js +153 -0
- package/admin/src/components/SelectMany/index.js +159 -0
- package/admin/src/components/SelectOne/SingleValue.js +58 -0
- package/admin/src/components/SelectOne/index.js +71 -0
- package/admin/src/components/SelectWrapper/ClearIndicator.js +15 -0
- package/admin/src/components/SelectWrapper/IndicatorSeparator.js +3 -0
- package/admin/src/components/SelectWrapper/Option.js +76 -0
- package/admin/src/components/SelectWrapper/components.js +14 -0
- package/admin/src/components/SelectWrapper/index.js +393 -0
- package/admin/src/components/SelectWrapper/utils/connect.js +12 -0
- package/admin/src/components/SelectWrapper/utils/index.js +3 -0
- package/admin/src/components/SelectWrapper/utils/select.js +45 -0
- package/admin/src/components/SelectWrapper/utils/styles.js +105 -0
- package/admin/src/components/Separator/index.js +9 -0
- package/admin/src/components/SettingFormWrapper/index.js +9 -0
- package/admin/src/components/SettingsViewWrapper/index.js +283 -0
- package/admin/src/components/SortWrapper/index.js +9 -0
- package/admin/src/components/SortableList/Item.js +126 -0
- package/admin/src/components/SortableList/index.js +60 -0
- package/admin/src/components/State/Wrapper.js +30 -0
- package/admin/src/components/State/index.js +26 -0
- package/admin/src/components/Truncate/index.js +5 -0
- package/admin/src/components/Truncated/index.js +10 -0
- package/admin/src/components/Wysiwyg/EditorWrapper.js +122 -0
- package/admin/src/components/Wysiwyg/MediaLib.js +71 -0
- package/admin/src/components/Wysiwyg/PreviewControlWrapper.js +30 -0
- package/admin/src/components/Wysiwyg/SelectWrapper.js +24 -0
- package/admin/src/components/Wysiwyg/ToggleModeWrapper.js +30 -0
- package/admin/src/components/Wysiwyg/constants.js +98 -0
- package/admin/src/components/Wysiwyg/customSelect.js +39 -0
- package/admin/src/components/Wysiwyg/helpers.js +116 -0
- package/admin/src/components/Wysiwyg/index.js +819 -0
- package/admin/src/components/Wysiwyg/previewControl.js +29 -0
- package/admin/src/components/Wysiwyg/toggleMode.js +44 -0
- package/admin/src/components/Wysiwyg/utils.js +70 -0
- package/admin/src/components/WysiwygBottomControls/components.js +44 -0
- package/admin/src/components/WysiwygBottomControls/index.js +33 -0
- package/admin/src/components/WysiwygDropUpload/Label.js +16 -0
- package/admin/src/components/WysiwygDropUpload/index.js +18 -0
- package/admin/src/components/WysiwygEditor/index.js +26 -0
- package/admin/src/components/WysiwygInlineControls/Button.js +77 -0
- package/admin/src/components/WysiwygInlineControls/StyledButton.js +54 -0
- package/admin/src/components/WysiwygInlineControls/Wrapper.js +25 -0
- package/admin/src/components/WysiwygInlineControls/index.js +66 -0
- package/admin/src/components/WysiwygWithErrors/Wrapper.js +38 -0
- package/admin/src/components/WysiwygWithErrors/index.js +158 -0
- package/admin/src/containers/CollectionTypeFormWrapper/index.js +376 -0
- package/admin/src/containers/CollectionTypeFormWrapper/utils/getRequestUrl.js +5 -0
- package/admin/src/containers/CollectionTypeFormWrapper/utils/index.js +2 -0
- package/admin/src/containers/CollectionTypeRecursivePath/index.js +125 -0
- package/admin/src/containers/ComponentSetttingsView/index.js +55 -0
- package/admin/src/containers/EditSettingsView/index.js +408 -0
- package/admin/src/containers/EditSettingsView/init.js +18 -0
- package/admin/src/containers/EditSettingsView/reducer.js +126 -0
- package/admin/src/containers/EditSettingsView/utils/createPossibleMainFieldsForModelsAndComponents.js +26 -0
- package/admin/src/containers/EditSettingsView/utils/getInputProps.js +30 -0
- package/admin/src/containers/EditSettingsView/utils/index.js +2 -0
- package/admin/src/containers/EditSettingsView/utils/layout.js +98 -0
- package/admin/src/containers/EditView/DeleteLink/index.js +94 -0
- package/admin/src/containers/EditView/DeleteLink/utils/connect.js +12 -0
- package/admin/src/containers/EditView/DeleteLink/utils/index.js +2 -0
- package/admin/src/containers/EditView/DeleteLink/utils/select.js +21 -0
- package/admin/src/containers/EditView/Header/index.js +258 -0
- package/admin/src/containers/EditView/Header/utils/connect.js +12 -0
- package/admin/src/containers/EditView/Header/utils/getDraftRelations.js +62 -0
- package/admin/src/containers/EditView/Header/utils/index.js +3 -0
- package/admin/src/containers/EditView/Header/utils/select.js +31 -0
- package/admin/src/containers/EditView/InformationCard.js +100 -0
- package/admin/src/containers/EditView/components.js +74 -0
- package/admin/src/containers/EditView/index.js +297 -0
- package/admin/src/containers/EditView/utils/createAttributesLayout.js +39 -0
- package/admin/src/containers/EditView/utils/getFieldsActionMatchingPermissions.js +23 -0
- package/admin/src/containers/EditView/utils/index.js +3 -0
- package/admin/src/containers/EditViewDataManagerProvider/index.js +519 -0
- package/admin/src/containers/EditViewDataManagerProvider/reducer.js +218 -0
- package/admin/src/containers/EditViewDataManagerProvider/utils/cleanData.js +88 -0
- package/admin/src/containers/EditViewDataManagerProvider/utils/getYupInnerErrors.js +17 -0
- package/admin/src/containers/EditViewDataManagerProvider/utils/index.js +3 -0
- package/admin/src/containers/EditViewDataManagerProvider/utils/schema.js +368 -0
- package/admin/src/containers/EditViewLayoutManager/Permissions.js +30 -0
- package/admin/src/containers/EditViewLayoutManager/actions.js +9 -0
- package/admin/src/containers/EditViewLayoutManager/constants.js +2 -0
- package/admin/src/containers/EditViewLayoutManager/index.js +44 -0
- package/admin/src/containers/EditViewLayoutManager/reducer.js +30 -0
- package/admin/src/containers/EditViewLayoutManager/selectors.js +5 -0
- package/admin/src/containers/LayoutDndProvider/index.js +75 -0
- package/admin/src/containers/ListSettingsView/DragWrapper.js +21 -0
- package/admin/src/containers/ListSettingsView/DropdownButton.js +8 -0
- package/admin/src/containers/ListSettingsView/Label.js +91 -0
- package/admin/src/containers/ListSettingsView/MenuDropdown.js +41 -0
- package/admin/src/containers/ListSettingsView/Toggle.js +51 -0
- package/admin/src/containers/ListSettingsView/forms.json +64 -0
- package/admin/src/containers/ListSettingsView/index.js +298 -0
- package/admin/src/containers/ListSettingsView/init.js +11 -0
- package/admin/src/containers/ListSettingsView/reducer.js +77 -0
- package/admin/src/containers/ListView/FieldPicker/ConfigureLink/StyledLink.js +28 -0
- package/admin/src/containers/ListView/FieldPicker/ConfigureLink/Wrapper.js +8 -0
- package/admin/src/containers/ListView/FieldPicker/ConfigureLink/index.js +29 -0
- package/admin/src/containers/ListView/FieldPicker/Field/Wrapper.js +15 -0
- package/admin/src/containers/ListView/FieldPicker/Field/index.js +24 -0
- package/admin/src/containers/ListView/FieldPicker/Fields/Wrapper.js +18 -0
- package/admin/src/containers/ListView/FieldPicker/Fields/index.js +27 -0
- package/admin/src/containers/ListView/FieldPicker/Header/Reset.js +8 -0
- package/admin/src/containers/ListView/FieldPicker/Header/index.js +42 -0
- package/admin/src/containers/ListView/FieldPicker/Wrapper.js +9 -0
- package/admin/src/containers/ListView/FieldPicker/index.js +46 -0
- package/admin/src/containers/ListView/Filter.js +83 -0
- package/admin/src/containers/ListView/Footer.js +60 -0
- package/admin/src/containers/ListView/actions.js +91 -0
- package/admin/src/containers/ListView/components.js +138 -0
- package/admin/src/containers/ListView/constants.js +16 -0
- package/admin/src/containers/ListView/index.js +573 -0
- package/admin/src/containers/ListView/reducer.js +182 -0
- package/admin/src/containers/ListView/selectors.js +24 -0
- package/admin/src/containers/ListView/utils/buildQueryString.js +26 -0
- package/admin/src/containers/ListView/utils/createPluginsFilter.js +13 -0
- package/admin/src/containers/ListView/utils/getAllAllowedHeaders.js +17 -0
- package/admin/src/containers/ListView/utils/getFirstSortableHeader.js +14 -0
- package/admin/src/containers/ListView/utils/index.js +3 -0
- package/admin/src/containers/ListViewLayoutManager/Permissions.js +29 -0
- package/admin/src/containers/ListViewLayoutManager/index.js +60 -0
- package/admin/src/containers/ListViewProvider/index.js +16 -0
- package/admin/src/containers/Main/actions.js +13 -0
- package/admin/src/containers/Main/constants.js +3 -0
- package/admin/src/containers/Main/index.js +100 -0
- package/admin/src/containers/Main/reducer.js +37 -0
- package/admin/src/containers/Main/selectors.js +20 -0
- package/admin/src/containers/RBACManager/actions.js +14 -0
- package/admin/src/containers/RBACManager/constants.js +2 -0
- package/admin/src/containers/RBACManager/reducer.js +32 -0
- package/admin/src/containers/RBACManager/useSyncRbac.js +28 -0
- package/admin/src/containers/SingleTypeFormWrapper/index.js +317 -0
- package/admin/src/containers/SingleTypeFormWrapper/utils/getRequestUrl.js +5 -0
- package/admin/src/containers/SingleTypeFormWrapper/utils/index.js +2 -0
- package/admin/src/containers/SingleTypeRecursivePath/index.js +84 -0
- package/admin/src/containers/WysiwygProvider/index.js +16 -0
- package/admin/src/contexts/ContentTypeLayout.js +5 -0
- package/admin/src/contexts/LayoutDnd.js +5 -0
- package/admin/src/contexts/ListView.js +5 -0
- package/admin/src/contexts/Wysiwyg.js +5 -0
- package/admin/src/contexts/index.js +4 -0
- package/admin/src/hooks/index.js +6 -0
- package/admin/src/hooks/useContentTypeLayout/index.js +19 -0
- package/admin/src/hooks/useFetchContentTypeLayout/index.js +83 -0
- package/admin/src/hooks/useFetchContentTypeLayout/reducer.js +56 -0
- package/admin/src/hooks/useFetchContentTypeLayout/utils/formatLayouts.js +235 -0
- package/admin/src/hooks/useFindRedirectionLink/index.js +14 -0
- package/admin/src/hooks/useFindRedirectionLink/selectors.js +7 -0
- package/admin/src/hooks/useFindRedirectionLink/utils/getRedirectionLink.js +45 -0
- package/admin/src/hooks/useLayoutDnd.js +6 -0
- package/admin/src/hooks/useListView.js +6 -0
- package/admin/src/hooks/useWysiwyg.js +6 -0
- package/admin/src/icons/Bold/index.js +22 -0
- package/admin/src/icons/Code/index.js +13 -0
- package/admin/src/icons/Cross/index.js +33 -0
- package/admin/src/icons/Italic/index.js +23 -0
- package/admin/src/icons/Link/index.js +21 -0
- package/admin/src/icons/Media/index.js +14 -0
- package/admin/src/icons/Na/index.js +58 -0
- package/admin/src/icons/Ol/index.js +13 -0
- package/admin/src/icons/Quote/index.js +13 -0
- package/admin/src/icons/Striked/index.js +24 -0
- package/admin/src/icons/Ul/index.js +15 -0
- package/admin/src/icons/Underline/index.js +22 -0
- package/admin/src/index.js +52 -0
- package/admin/src/lifecycles.js +19 -0
- package/admin/src/permissions.js +27 -0
- package/admin/src/pluginId.js +5 -0
- package/admin/src/reducers.js +16 -0
- package/admin/src/selectors.js +6 -0
- package/admin/src/sharedReducers/crudReducer/actions.js +44 -0
- package/admin/src/sharedReducers/crudReducer/constants.js +7 -0
- package/admin/src/sharedReducers/crudReducer/reducer.js +75 -0
- package/admin/src/sharedReducers/crudReducer/selectors.js +5 -0
- package/admin/src/testUtils/data.js +305 -0
- package/admin/src/testUtils/index.js +4 -0
- package/admin/src/translations/ar.json +94 -0
- package/admin/src/translations/cs.json +130 -0
- package/admin/src/translations/de.json +177 -0
- package/admin/src/translations/dk.json +180 -0
- package/admin/src/translations/en.json +177 -0
- package/admin/src/translations/es.json +177 -0
- package/admin/src/translations/fr.json +162 -0
- package/admin/src/translations/id.json +175 -0
- package/admin/src/translations/index.js +53 -0
- package/admin/src/translations/it.json +177 -0
- package/admin/src/translations/ja.json +94 -0
- package/admin/src/translations/ko.json +110 -0
- package/admin/src/translations/ms.json +148 -0
- package/admin/src/translations/nl.json +94 -0
- package/admin/src/translations/pl.json +142 -0
- package/admin/src/translations/pt-BR.json +94 -0
- package/admin/src/translations/pt.json +94 -0
- package/admin/src/translations/ru.json +177 -0
- package/admin/src/translations/sk.json +172 -0
- package/admin/src/translations/th.json +155 -0
- package/admin/src/translations/tr.json +177 -0
- package/admin/src/translations/uk.json +148 -0
- package/admin/src/translations/vi.json +110 -0
- package/admin/src/translations/zh-Hans.json +177 -0
- package/admin/src/translations/zh.json +94 -0
- package/admin/src/utils/ItemTypes.js +7 -0
- package/admin/src/utils/checkIfAttributeIsDisplayable.js +13 -0
- package/admin/src/utils/createDefaultForm.js +50 -0
- package/admin/src/utils/dateFormats.js +18 -0
- package/admin/src/utils/formatFiltersFromQuery.js +55 -0
- package/admin/src/utils/formatFiltersToQuery.js +27 -0
- package/admin/src/utils/formatLayoutToApi.js +44 -0
- package/admin/src/utils/generatePermissionsObject.js +20 -0
- package/admin/src/utils/getComponents.js +50 -0
- package/admin/src/utils/getDisplayedValue.js +61 -0
- package/admin/src/utils/getFieldName.js +6 -0
- package/admin/src/utils/getMaxTempKey.js +12 -0
- package/admin/src/utils/getRequestUrl.js +5 -0
- package/admin/src/utils/getTrad.js +5 -0
- package/admin/src/utils/index.js +17 -0
- package/admin/src/utils/mergeMetasWithSchema.js +20 -0
- package/admin/src/utils/removeKeyInObject.js +45 -0
- package/admin/src/utils/removePasswordFieldsFromData.js +54 -0
- package/config/admin.json +5 -0
- package/config/functions/bootstrap.js +9 -0
- package/config/policies/has-draft-and-publish.js +19 -0
- package/config/policies/hasPermissions.js +34 -0
- package/config/policies/routing.js +27 -0
- package/config/routes.json +275 -0
- package/controllers/collection-types.js +282 -0
- package/controllers/components.js +66 -0
- package/controllers/content-types.js +112 -0
- package/controllers/relations.js +63 -0
- package/controllers/single-types.js +170 -0
- package/controllers/uid.js +41 -0
- package/controllers/validation/index.js +104 -0
- package/controllers/validation/model-configuration.js +114 -0
- package/oas.yml +757 -0
- package/package.json +77 -0
- package/services/components.js +92 -0
- package/services/configuration.js +79 -0
- package/services/content-types.js +73 -0
- package/services/data-mapper.js +98 -0
- package/services/entity-manager.js +140 -0
- package/services/metrics.js +34 -0
- package/services/permission-checker.js +69 -0
- package/services/permission.js +95 -0
- package/services/uid.js +63 -0
- package/services/utils/configuration/attributes.js +175 -0
- package/services/utils/configuration/index.js +43 -0
- package/services/utils/configuration/layouts.js +185 -0
- package/services/utils/configuration/metadatas.js +142 -0
- package/services/utils/configuration/settings.js +52 -0
- package/services/utils/store.js +93 -0
- package/utils/index.js +16 -0
- package/utils/pick-writable-attributes.js +6 -0
- package/utils/wrap-bad-request.js +15 -0
- package/validation/policies/hasPermissions.js +17 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useHistory } from 'react-router-dom';
|
|
3
|
+
import { get } from 'lodash';
|
|
4
|
+
import {
|
|
5
|
+
request,
|
|
6
|
+
useGlobalContext,
|
|
7
|
+
formatComponentData,
|
|
8
|
+
useQueryParams,
|
|
9
|
+
} from 'strapi-helper-plugin';
|
|
10
|
+
import { useSelector, useDispatch } from 'react-redux';
|
|
11
|
+
import PropTypes from 'prop-types';
|
|
12
|
+
import { createDefaultForm, getTrad, removePasswordFieldsFromData } from '../../utils';
|
|
13
|
+
import {
|
|
14
|
+
getData,
|
|
15
|
+
getDataSucceeded,
|
|
16
|
+
initForm,
|
|
17
|
+
resetProps,
|
|
18
|
+
setDataStructures,
|
|
19
|
+
setStatus,
|
|
20
|
+
submitSucceeded,
|
|
21
|
+
} from '../../sharedReducers/crudReducer/actions';
|
|
22
|
+
import selectCrudReducer from '../../sharedReducers/crudReducer/selectors';
|
|
23
|
+
import { getRequestUrl } from './utils';
|
|
24
|
+
import buildQueryString from '../ListView/utils/buildQueryString';
|
|
25
|
+
|
|
26
|
+
// This container is used to handle the CRUD
|
|
27
|
+
const SingleTypeFormWrapper = ({ allLayoutData, children, slug }) => {
|
|
28
|
+
const { emitEvent } = useGlobalContext();
|
|
29
|
+
const { push } = useHistory();
|
|
30
|
+
const emitEventRef = useRef(emitEvent);
|
|
31
|
+
const [isCreatingEntry, setIsCreatingEntry] = useState(true);
|
|
32
|
+
const [{ query, rawQuery }] = useQueryParams();
|
|
33
|
+
const searchToSend = buildQueryString(query);
|
|
34
|
+
|
|
35
|
+
const dispatch = useDispatch();
|
|
36
|
+
const {
|
|
37
|
+
componentsDataStructure,
|
|
38
|
+
contentTypeDataStructure,
|
|
39
|
+
data,
|
|
40
|
+
isLoading,
|
|
41
|
+
status,
|
|
42
|
+
} = useSelector(selectCrudReducer);
|
|
43
|
+
|
|
44
|
+
const cleanReceivedData = useCallback(
|
|
45
|
+
data => {
|
|
46
|
+
const cleaned = removePasswordFieldsFromData(
|
|
47
|
+
data,
|
|
48
|
+
allLayoutData.contentType,
|
|
49
|
+
allLayoutData.components
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
// This is needed in order to add a unique id for the repeatable components, in order to make the reorder easier
|
|
53
|
+
return formatComponentData(cleaned, allLayoutData.contentType, allLayoutData.components);
|
|
54
|
+
},
|
|
55
|
+
[allLayoutData]
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
return () => {
|
|
60
|
+
dispatch(resetProps());
|
|
61
|
+
};
|
|
62
|
+
}, [dispatch]);
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const componentsDataStructure = Object.keys(allLayoutData.components).reduce((acc, current) => {
|
|
66
|
+
const defaultComponentForm = createDefaultForm(
|
|
67
|
+
get(allLayoutData, ['components', current, 'attributes'], {}),
|
|
68
|
+
allLayoutData.components
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
acc[current] = formatComponentData(
|
|
72
|
+
defaultComponentForm,
|
|
73
|
+
allLayoutData.components[current],
|
|
74
|
+
allLayoutData.components
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return acc;
|
|
78
|
+
}, {});
|
|
79
|
+
|
|
80
|
+
const contentTypeDataStructure = createDefaultForm(
|
|
81
|
+
allLayoutData.contentType.attributes,
|
|
82
|
+
allLayoutData.components
|
|
83
|
+
);
|
|
84
|
+
const contentTypeDataStructureFormatted = formatComponentData(
|
|
85
|
+
contentTypeDataStructure,
|
|
86
|
+
allLayoutData.contentType,
|
|
87
|
+
allLayoutData.components
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
dispatch(setDataStructures(componentsDataStructure, contentTypeDataStructureFormatted));
|
|
91
|
+
}, [allLayoutData, dispatch]);
|
|
92
|
+
|
|
93
|
+
// Check if creation mode or editing mode
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
const abortController = new AbortController();
|
|
96
|
+
const { signal } = abortController;
|
|
97
|
+
|
|
98
|
+
const fetchData = async signal => {
|
|
99
|
+
dispatch(getData());
|
|
100
|
+
|
|
101
|
+
setIsCreatingEntry(true);
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
const data = await request(getRequestUrl(`${slug}${searchToSend}`), {
|
|
105
|
+
method: 'GET',
|
|
106
|
+
signal,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
dispatch(getDataSucceeded(cleanReceivedData(data)));
|
|
110
|
+
|
|
111
|
+
setIsCreatingEntry(false);
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (err.name === 'AbortError') {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const responseStatus = get(err, 'response.status', null);
|
|
118
|
+
|
|
119
|
+
// Creating a single type
|
|
120
|
+
if (responseStatus === 404) {
|
|
121
|
+
dispatch(initForm(rawQuery, true));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (responseStatus === 403) {
|
|
125
|
+
strapi.notification.info(getTrad('permissions.not-allowed.update'));
|
|
126
|
+
|
|
127
|
+
push('/');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
fetchData(signal);
|
|
133
|
+
|
|
134
|
+
return () => abortController.abort();
|
|
135
|
+
}, [cleanReceivedData, push, slug, dispatch, searchToSend, rawQuery]);
|
|
136
|
+
|
|
137
|
+
const displayErrors = useCallback(err => {
|
|
138
|
+
const errorPayload = err.response.payload;
|
|
139
|
+
console.error(errorPayload);
|
|
140
|
+
|
|
141
|
+
let errorMessage = get(errorPayload, ['message'], 'Bad Request');
|
|
142
|
+
|
|
143
|
+
// TODO handle errors correctly when back-end ready
|
|
144
|
+
if (Array.isArray(errorMessage)) {
|
|
145
|
+
errorMessage = get(errorMessage, ['0', 'messages', '0', 'id']);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (typeof errorMessage === 'string') {
|
|
149
|
+
strapi.notification.error(errorMessage);
|
|
150
|
+
}
|
|
151
|
+
}, []);
|
|
152
|
+
|
|
153
|
+
const onDelete = useCallback(
|
|
154
|
+
async trackerProperty => {
|
|
155
|
+
try {
|
|
156
|
+
emitEventRef.current('willDeleteEntry', trackerProperty);
|
|
157
|
+
|
|
158
|
+
const response = await request(getRequestUrl(`${slug}`), {
|
|
159
|
+
method: 'DELETE',
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
strapi.notification.success(getTrad('success.record.delete'));
|
|
163
|
+
|
|
164
|
+
emitEventRef.current('didDeleteEntry', trackerProperty);
|
|
165
|
+
|
|
166
|
+
return Promise.resolve(response);
|
|
167
|
+
} catch (err) {
|
|
168
|
+
emitEventRef.current('didNotDeleteEntry', { error: err, ...trackerProperty });
|
|
169
|
+
|
|
170
|
+
return Promise.reject(err);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
[slug]
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const onDeleteSucceeded = useCallback(() => {
|
|
177
|
+
setIsCreatingEntry(true);
|
|
178
|
+
|
|
179
|
+
dispatch(initForm(rawQuery, true));
|
|
180
|
+
}, [dispatch, rawQuery]);
|
|
181
|
+
|
|
182
|
+
const onPost = useCallback(
|
|
183
|
+
async (body, trackerProperty) => {
|
|
184
|
+
const endPoint = getRequestUrl(`${slug}${rawQuery}`);
|
|
185
|
+
|
|
186
|
+
try {
|
|
187
|
+
dispatch(setStatus('submit-pending'));
|
|
188
|
+
|
|
189
|
+
const response = await request(endPoint, { method: 'PUT', body });
|
|
190
|
+
|
|
191
|
+
emitEventRef.current('didCreateEntry', trackerProperty);
|
|
192
|
+
strapi.notification.toggle({
|
|
193
|
+
type: 'success',
|
|
194
|
+
message: { id: getTrad('success.record.save') },
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
dispatch(submitSucceeded(cleanReceivedData(response)));
|
|
198
|
+
setIsCreatingEntry(false);
|
|
199
|
+
|
|
200
|
+
dispatch(setStatus('resolved'));
|
|
201
|
+
} catch (err) {
|
|
202
|
+
emitEventRef.current('didNotCreateEntry', { error: err, trackerProperty });
|
|
203
|
+
|
|
204
|
+
displayErrors(err);
|
|
205
|
+
|
|
206
|
+
dispatch(setStatus('resolved'));
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
[cleanReceivedData, displayErrors, slug, dispatch, rawQuery]
|
|
210
|
+
);
|
|
211
|
+
const onPublish = useCallback(async () => {
|
|
212
|
+
try {
|
|
213
|
+
emitEventRef.current('willPublishEntry');
|
|
214
|
+
const endPoint = getRequestUrl(`${slug}/actions/publish${searchToSend}`);
|
|
215
|
+
|
|
216
|
+
dispatch(setStatus('publish-pending'));
|
|
217
|
+
|
|
218
|
+
const data = await request(endPoint, { method: 'POST' });
|
|
219
|
+
|
|
220
|
+
emitEventRef.current('didPublishEntry');
|
|
221
|
+
strapi.notification.toggle({
|
|
222
|
+
type: 'success',
|
|
223
|
+
message: { id: getTrad('success.record.publish') },
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
dispatch(submitSucceeded(cleanReceivedData(data)));
|
|
227
|
+
|
|
228
|
+
dispatch(setStatus('resolved'));
|
|
229
|
+
} catch (err) {
|
|
230
|
+
displayErrors(err);
|
|
231
|
+
|
|
232
|
+
dispatch(setStatus('resolved'));
|
|
233
|
+
}
|
|
234
|
+
}, [cleanReceivedData, displayErrors, slug, searchToSend, dispatch]);
|
|
235
|
+
|
|
236
|
+
const onPut = useCallback(
|
|
237
|
+
async (body, trackerProperty) => {
|
|
238
|
+
const endPoint = getRequestUrl(`${slug}${rawQuery}`);
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
emitEventRef.current('willEditEntry', trackerProperty);
|
|
242
|
+
|
|
243
|
+
dispatch(setStatus('submit-pending'));
|
|
244
|
+
|
|
245
|
+
const response = await request(endPoint, { method: 'PUT', body });
|
|
246
|
+
|
|
247
|
+
strapi.notification.toggle({
|
|
248
|
+
type: 'success',
|
|
249
|
+
message: { id: getTrad('success.record.save') },
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
emitEventRef.current('didEditEntry', { trackerProperty });
|
|
253
|
+
|
|
254
|
+
dispatch(submitSucceeded(cleanReceivedData(response)));
|
|
255
|
+
|
|
256
|
+
dispatch(setStatus('resolved'));
|
|
257
|
+
} catch (err) {
|
|
258
|
+
displayErrors(err);
|
|
259
|
+
|
|
260
|
+
emitEventRef.current('didNotEditEntry', { error: err, trackerProperty });
|
|
261
|
+
|
|
262
|
+
dispatch(setStatus('resolved'));
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
[cleanReceivedData, displayErrors, slug, dispatch, rawQuery]
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
// The publish and unpublish method could be refactored but let's leave the duplication for now
|
|
269
|
+
const onUnpublish = useCallback(async () => {
|
|
270
|
+
const endPoint = getRequestUrl(`${slug}/actions/unpublish${searchToSend}`);
|
|
271
|
+
|
|
272
|
+
dispatch(setStatus('unpublish-pending'));
|
|
273
|
+
|
|
274
|
+
try {
|
|
275
|
+
emitEventRef.current('willUnpublishEntry');
|
|
276
|
+
|
|
277
|
+
const response = await request(endPoint, { method: 'POST' });
|
|
278
|
+
|
|
279
|
+
emitEventRef.current('didUnpublishEntry');
|
|
280
|
+
strapi.notification.success(getTrad('success.record.unpublish'));
|
|
281
|
+
|
|
282
|
+
dispatch(submitSucceeded(cleanReceivedData(response)));
|
|
283
|
+
|
|
284
|
+
dispatch(setStatus('resolved'));
|
|
285
|
+
} catch (err) {
|
|
286
|
+
dispatch(setStatus('resolved'));
|
|
287
|
+
displayErrors(err);
|
|
288
|
+
}
|
|
289
|
+
}, [cleanReceivedData, displayErrors, slug, dispatch, searchToSend]);
|
|
290
|
+
|
|
291
|
+
return children({
|
|
292
|
+
componentsDataStructure,
|
|
293
|
+
contentTypeDataStructure,
|
|
294
|
+
data,
|
|
295
|
+
isCreatingEntry,
|
|
296
|
+
isLoadingForData: isLoading,
|
|
297
|
+
onDelete,
|
|
298
|
+
onDeleteSucceeded,
|
|
299
|
+
onPost,
|
|
300
|
+
onPublish,
|
|
301
|
+
onPut,
|
|
302
|
+
onUnpublish,
|
|
303
|
+
redirectionLink: '/',
|
|
304
|
+
status,
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
SingleTypeFormWrapper.propTypes = {
|
|
309
|
+
allLayoutData: PropTypes.shape({
|
|
310
|
+
components: PropTypes.object.isRequired,
|
|
311
|
+
contentType: PropTypes.object.isRequired,
|
|
312
|
+
}).isRequired,
|
|
313
|
+
children: PropTypes.func.isRequired,
|
|
314
|
+
slug: PropTypes.string.isRequired,
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export default memo(SingleTypeFormWrapper);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React, { memo, useMemo } from 'react';
|
|
2
|
+
import { Switch, Route } from 'react-router-dom';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { LoadingIndicatorPage, CheckPagePermissions } from 'strapi-helper-plugin';
|
|
5
|
+
import pluginPermissions from '../../permissions';
|
|
6
|
+
import { ContentTypeLayoutContext } from '../../contexts';
|
|
7
|
+
import { useFetchContentTypeLayout } from '../../hooks';
|
|
8
|
+
import { formatLayoutToApi } from '../../utils';
|
|
9
|
+
import EditViewLayoutManager from '../EditViewLayoutManager';
|
|
10
|
+
import EditSettingsView from '../EditSettingsView';
|
|
11
|
+
|
|
12
|
+
const SingleTypeRecursivePath = ({
|
|
13
|
+
match: {
|
|
14
|
+
params: { slug },
|
|
15
|
+
url,
|
|
16
|
+
},
|
|
17
|
+
}) => {
|
|
18
|
+
const { isLoading, layout, updateLayout } = useFetchContentTypeLayout(slug);
|
|
19
|
+
|
|
20
|
+
const { rawContentTypeLayout, rawComponentsLayouts } = useMemo(() => {
|
|
21
|
+
let rawComponentsLayouts = {};
|
|
22
|
+
let rawContentTypeLayout = {};
|
|
23
|
+
|
|
24
|
+
if (layout.contentType) {
|
|
25
|
+
rawContentTypeLayout = formatLayoutToApi(layout.contentType);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (layout.components) {
|
|
29
|
+
rawComponentsLayouts = Object.keys(layout.components).reduce((acc, current) => {
|
|
30
|
+
acc[current] = formatLayoutToApi(layout.components[current]);
|
|
31
|
+
|
|
32
|
+
return acc;
|
|
33
|
+
}, {});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { rawContentTypeLayout, rawComponentsLayouts };
|
|
37
|
+
}, [layout]);
|
|
38
|
+
|
|
39
|
+
if (isLoading) {
|
|
40
|
+
return <LoadingIndicatorPage />;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<ContentTypeLayoutContext.Provider value={layout}>
|
|
45
|
+
<Switch>
|
|
46
|
+
<Route path={`${url}/configurations/edit`}>
|
|
47
|
+
<CheckPagePermissions permissions={pluginPermissions.singleTypesConfigurations}>
|
|
48
|
+
<EditSettingsView
|
|
49
|
+
components={rawComponentsLayouts}
|
|
50
|
+
isContentTypeView
|
|
51
|
+
mainLayout={rawContentTypeLayout}
|
|
52
|
+
slug={slug}
|
|
53
|
+
updateLayout={updateLayout}
|
|
54
|
+
/>
|
|
55
|
+
</CheckPagePermissions>
|
|
56
|
+
</Route>
|
|
57
|
+
<Route
|
|
58
|
+
path={url}
|
|
59
|
+
render={({ location: { state }, history: { goBack } }) => {
|
|
60
|
+
return (
|
|
61
|
+
<EditViewLayoutManager
|
|
62
|
+
layout={layout}
|
|
63
|
+
slug={slug}
|
|
64
|
+
isSingleType
|
|
65
|
+
state={state}
|
|
66
|
+
goBack={goBack}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
</Switch>
|
|
72
|
+
</ContentTypeLayoutContext.Provider>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
SingleTypeRecursivePath.propTypes = {
|
|
77
|
+
match: PropTypes.shape({
|
|
78
|
+
url: PropTypes.string.isRequired,
|
|
79
|
+
params: PropTypes.shape({
|
|
80
|
+
slug: PropTypes.string.isRequired,
|
|
81
|
+
}).isRequired,
|
|
82
|
+
}).isRequired,
|
|
83
|
+
};
|
|
84
|
+
export default memo(SingleTypeRecursivePath);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import WysiwygContext from '../../contexts/Wysiwyg';
|
|
5
|
+
|
|
6
|
+
function WysiwygProvider({ children, ...rest }) {
|
|
7
|
+
return (
|
|
8
|
+
<WysiwygContext.Provider value={rest}>{children}</WysiwygContext.Provider>
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
WysiwygProvider.propTypes = {
|
|
13
|
+
children: PropTypes.node.isRequired,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default WysiwygProvider;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as useContentTypeLayout } from './useContentTypeLayout';
|
|
2
|
+
export { default as useFetchContentTypeLayout } from './useFetchContentTypeLayout';
|
|
3
|
+
export { default as useFindRedirectionLink } from './useFindRedirectionLink';
|
|
4
|
+
export { default as useLayoutDnd } from './useLayoutDnd';
|
|
5
|
+
export { default as useListView } from './useListView';
|
|
6
|
+
export { default as useWysiwyg } from './useWysiwyg';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { get } from 'lodash';
|
|
3
|
+
import { useSelector } from 'react-redux';
|
|
4
|
+
import selectLayout from '../../containers/EditViewLayoutManager/selectors';
|
|
5
|
+
|
|
6
|
+
const useContentTypeLayout = () => {
|
|
7
|
+
const currentLayout = useSelector(selectLayout);
|
|
8
|
+
|
|
9
|
+
const getComponentLayout = useCallback(
|
|
10
|
+
componentUid => {
|
|
11
|
+
return get(currentLayout, ['components', componentUid], {});
|
|
12
|
+
},
|
|
13
|
+
[currentLayout]
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
return { ...currentLayout, getComponentLayout };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default useContentTypeLayout;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useReducer, useRef } from 'react';
|
|
2
|
+
import { useSelector, shallowEqual } from 'react-redux';
|
|
3
|
+
import { request } from 'strapi-helper-plugin';
|
|
4
|
+
import formatLayouts from './utils/formatLayouts';
|
|
5
|
+
import reducer, { initialState } from './reducer';
|
|
6
|
+
import { makeSelectModelAndComponentSchemas } from '../../containers/Main/selectors';
|
|
7
|
+
|
|
8
|
+
const useFetchContentTypeLayout = contentTypeUID => {
|
|
9
|
+
const [{ error, isLoading, layout, layouts }, dispatch] = useReducer(reducer, initialState);
|
|
10
|
+
const schemasSelector = useMemo(makeSelectModelAndComponentSchemas, []);
|
|
11
|
+
const { schemas } = useSelector(state => schemasSelector(state), shallowEqual);
|
|
12
|
+
const isMounted = useRef(true);
|
|
13
|
+
|
|
14
|
+
const getData = useCallback(
|
|
15
|
+
async (uid, abortSignal = false) => {
|
|
16
|
+
let signal = abortSignal || new AbortController().signal;
|
|
17
|
+
|
|
18
|
+
if (layouts[uid]) {
|
|
19
|
+
dispatch({ type: 'SET_LAYOUT_FROM_STATE', uid });
|
|
20
|
+
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
dispatch({ type: 'GET_DATA' });
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const { data } = await request(`/content-manager/content-types/${uid}/configuration`, {
|
|
27
|
+
method: 'GET',
|
|
28
|
+
signal,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
dispatch({
|
|
32
|
+
type: 'GET_DATA_SUCCEEDED',
|
|
33
|
+
data: formatLayouts(data, schemas),
|
|
34
|
+
});
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (isMounted.current) {
|
|
37
|
+
console.error(error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (isMounted.current && error.name !== 'AbortError') {
|
|
41
|
+
dispatch({ type: 'GET_DATA_ERROR', error });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
[layouts, schemas]
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
return () => {
|
|
50
|
+
isMounted.current = false;
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const abortController = new AbortController();
|
|
56
|
+
const { signal } = abortController;
|
|
57
|
+
|
|
58
|
+
getData(contentTypeUID, signal);
|
|
59
|
+
|
|
60
|
+
return () => {
|
|
61
|
+
abortController.abort();
|
|
62
|
+
};
|
|
63
|
+
}, [contentTypeUID, getData]);
|
|
64
|
+
|
|
65
|
+
const updateLayout = useCallback(
|
|
66
|
+
newLayout => {
|
|
67
|
+
dispatch({
|
|
68
|
+
type: 'UPDATE_LAYOUT',
|
|
69
|
+
newLayout: formatLayouts({ contentType: newLayout, components: {} }, schemas),
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
[schemas]
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
error,
|
|
77
|
+
isLoading,
|
|
78
|
+
layout,
|
|
79
|
+
updateLayout,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default useFetchContentTypeLayout;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* eslint-disable consistent-return */
|
|
2
|
+
import produce from 'immer';
|
|
3
|
+
|
|
4
|
+
export const initialState = {
|
|
5
|
+
error: null,
|
|
6
|
+
isLoading: true,
|
|
7
|
+
layout: {},
|
|
8
|
+
layouts: {},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const reducer = (state, action) =>
|
|
12
|
+
produce(state, draftState => {
|
|
13
|
+
switch (action.type) {
|
|
14
|
+
case 'GET_DATA': {
|
|
15
|
+
draftState.isLoading = true;
|
|
16
|
+
draftState.error = null;
|
|
17
|
+
draftState.layout = {};
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
case 'GET_DATA_SUCCEEDED': {
|
|
21
|
+
const contentTypeUid = action.data.contentType.uid;
|
|
22
|
+
|
|
23
|
+
draftState.layout = action.data;
|
|
24
|
+
draftState.layouts[contentTypeUid] = action.data;
|
|
25
|
+
draftState.isLoading = false;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case 'GET_DATA_ERROR': {
|
|
29
|
+
draftState.isLoading = false;
|
|
30
|
+
draftState.error = action.error;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case 'SET_LAYOUT_FROM_STATE': {
|
|
34
|
+
draftState.error = null;
|
|
35
|
+
draftState.layout = state.layouts[action.uid];
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case 'UPDATE_LAYOUT': {
|
|
39
|
+
const oldLayout = state.layout;
|
|
40
|
+
|
|
41
|
+
draftState.layout = {
|
|
42
|
+
...oldLayout,
|
|
43
|
+
contentType: { uid: oldLayout.contentType.uid, ...action.newLayout.contentType },
|
|
44
|
+
};
|
|
45
|
+
draftState.layouts[oldLayout.contentType.uid] = {
|
|
46
|
+
...oldLayout,
|
|
47
|
+
contentType: { uid: oldLayout.contentType.uid, ...action.newLayout.contentType },
|
|
48
|
+
};
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
default:
|
|
52
|
+
return draftState;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export default reducer;
|