mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 01:47:13 +00:00 
			
		
		
		
	Rename CM hook
Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
		
							parent
							
								
									9096a86b91
								
							
						
					
					
						commit
						ff8069a1c8
					
				| @ -1,14 +1,14 @@ | ||||
| import React from 'react'; | ||||
| import PropTypes from 'prop-types'; | ||||
| import { FormattedMessage } from 'react-intl'; | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { getTrad } from '../../utils'; | ||||
| import NonRepeatableWrapper from '../NonRepeatableWrapper'; | ||||
| import PlusButton from '../PlusButton'; | ||||
| import P from './P'; | ||||
| 
 | ||||
| const ComponentInitializer = ({ componentUid, isReadOnly, name }) => { | ||||
|   const { addNonRepeatableComponentToField } = useContentManagerEditViewDataManager(); | ||||
|   const { addNonRepeatableComponentToField } = useCMEditViewDataManager(); | ||||
| 
 | ||||
|   return ( | ||||
|     <NonRepeatableWrapper | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| import { useMemo } from 'react'; | ||||
| import { get } from 'lodash'; | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| 
 | ||||
| function useSelect(name) { | ||||
|   const { | ||||
| @ -14,7 +14,7 @@ function useSelect(name) { | ||||
|     removeComponentFromDynamicZone, | ||||
|     readActionAllowedFields, | ||||
|     updateActionAllowedFields, | ||||
|   } = useContentManagerEditViewDataManager(); | ||||
|   } = useCMEditViewDataManager(); | ||||
| 
 | ||||
|   const dynamicDisplayedComponents = useMemo( | ||||
|     () => get(modifiedData, [name], []).map(data => data.__component), | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| import { useMemo } from 'react'; | ||||
| import { get, take } from 'lodash'; | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| 
 | ||||
| import { getFieldName } from '../../../utils'; | ||||
| import { useContentTypeLayout } from '../../../hooks'; | ||||
| @ -13,7 +13,7 @@ function useSelect({ isFromDynamicZone, name }) { | ||||
|     removeComponentFromField, | ||||
|     readActionAllowedFields, | ||||
|     updateActionAllowedFields, | ||||
|   } = useContentManagerEditViewDataManager(); | ||||
|   } = useCMEditViewDataManager(); | ||||
|   const { contentType } = useContentTypeLayout(); | ||||
| 
 | ||||
|   // This is used for the readonly mode when updating an entry
 | ||||
|  | ||||
| @ -8,7 +8,7 @@ import styled from 'styled-components'; | ||||
| import { | ||||
|   LabelIconWrapper, | ||||
|   LoadingIndicator, | ||||
|   useContentManagerEditViewDataManager, | ||||
|   useCMEditViewDataManager, | ||||
| } from '@strapi/helper-plugin'; | ||||
| import { useIntl } from 'react-intl'; | ||||
| import get from 'lodash/get'; | ||||
| @ -52,7 +52,7 @@ const InputUID = ({ | ||||
|   editable, | ||||
|   ...inputProps | ||||
| }) => { | ||||
|   const { modifiedData, initialData, layout } = useContentManagerEditViewDataManager(); | ||||
|   const { modifiedData, initialData, layout } = useCMEditViewDataManager(); | ||||
|   const [isLoading, setIsLoading] = useState(false); | ||||
|   const [availability, setAvailability] = useState(null); | ||||
|   const [isSuggestionOpen, setIsSuggestionOpen] = useState(true); | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| import { useMemo } from 'react'; | ||||
| import { get } from 'lodash'; | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| 
 | ||||
| function useSelect(keys) { | ||||
|   const { | ||||
| @ -12,7 +12,7 @@ function useSelect(keys) { | ||||
|     readActionAllowedFields, | ||||
|     shouldNotRunValidations, | ||||
|     updateActionAllowedFields, | ||||
|   } = useContentManagerEditViewDataManager(); | ||||
|   } = useCMEditViewDataManager(); | ||||
| 
 | ||||
|   const allowedFields = useMemo(() => { | ||||
|     return isCreatingEntry ? createActionAllowedFields : updateActionAllowedFields; | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| import { useMemo } from 'react'; | ||||
| import { get, toString } from 'lodash'; | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| 
 | ||||
| function useSelect({ schema, componentFieldName }) { | ||||
|   const { | ||||
| @ -9,7 +9,7 @@ function useSelect({ schema, componentFieldName }) { | ||||
|     moveComponentField, | ||||
|     removeRepeatableField, | ||||
|     triggerFormValidation, | ||||
|   } = useContentManagerEditViewDataManager(); | ||||
|   } = useCMEditViewDataManager(); | ||||
| 
 | ||||
|   const mainField = useMemo(() => get(schema, ['settings', 'mainField'], 'id'), [schema]); | ||||
|   const displayedValue = toString( | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| 
 | ||||
| function useSelect() { | ||||
|   const { addRepeatableComponentToField, formErrors } = useContentManagerEditViewDataManager(); | ||||
|   const { addRepeatableComponentToField, formErrors } = useCMEditViewDataManager(); | ||||
| 
 | ||||
|   return { | ||||
|     addRepeatableComponentToField, | ||||
|  | ||||
| @ -7,7 +7,7 @@ import { | ||||
|   DropdownIndicator, | ||||
|   LabelIconWrapper, | ||||
|   NotAllowedInput, | ||||
|   useContentManagerEditViewDataManager, | ||||
|   useCMEditViewDataManager, | ||||
|   useQueryParams, | ||||
| } from '@strapi/helper-plugin'; | ||||
| import { Flex, Text, Padded } from '@buffetjs/core'; | ||||
| @ -69,7 +69,7 @@ function SelectWrapper({ | ||||
|     moveRelation, | ||||
|     onChange, | ||||
|     onRemoveRelation, | ||||
|   } = useContentManagerEditViewDataManager(); | ||||
|   } = useCMEditViewDataManager(); | ||||
|   const { pathname } = useLocation(); | ||||
| 
 | ||||
|   const value = get(modifiedData, name, null); | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| import { useMemo } from 'react'; | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| 
 | ||||
| function useSelect({ isUserAllowedToEditField, isUserAllowedToReadField, name }) { | ||||
|   const { | ||||
| @ -7,7 +7,7 @@ function useSelect({ isUserAllowedToEditField, isUserAllowedToReadField, name }) | ||||
|     createActionAllowedFields, | ||||
|     readActionAllowedFields, | ||||
|     updateActionAllowedFields, | ||||
|   } = useContentManagerEditViewDataManager(); | ||||
|   } = useCMEditViewDataManager(); | ||||
| 
 | ||||
|   const isFieldAllowed = useMemo(() => { | ||||
|     if (isUserAllowedToEditField === true) { | ||||
|  | ||||
| @ -1,8 +1,8 @@ | ||||
| import { isEmpty } from 'lodash'; | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| 
 | ||||
| function useSelect() { | ||||
|   const { hasDraftAndPublish, modifiedData } = useContentManagerEditViewDataManager(); | ||||
|   const { hasDraftAndPublish, modifiedData } = useCMEditViewDataManager(); | ||||
| 
 | ||||
|   let trackerProperty = {}; | ||||
| 
 | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| 
 | ||||
| function useSelect() { | ||||
|   const { initialData, hasDraftAndPublish } = useContentManagerEditViewDataManager(); | ||||
|   const { initialData, hasDraftAndPublish } = useCMEditViewDataManager(); | ||||
| 
 | ||||
|   const isPublished = initialData.published_at !== undefined && initialData.published_at !== null; | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| 
 | ||||
| function useSelect() { | ||||
|   const { | ||||
| @ -12,7 +12,7 @@ function useSelect() { | ||||
|     modifiedData, | ||||
|     onPublish, | ||||
|     onUnpublish, | ||||
|   } = useContentManagerEditViewDataManager(); | ||||
|   } = useCMEditViewDataManager(); | ||||
| 
 | ||||
|   return { | ||||
|     componentLayouts: allLayoutData.components, | ||||
|  | ||||
| @ -4,7 +4,7 @@ import { get, isEmpty } from 'lodash'; | ||||
| import moment from 'moment'; | ||||
| import styled from 'styled-components'; | ||||
| import { useIntl } from 'react-intl'; | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { InjectionZone } from '../../../shared/components'; | ||||
| import { SubWrapper, StatusWrapper } from './components'; | ||||
| import { getTrad } from '../../utils'; | ||||
| @ -14,7 +14,7 @@ const BaselineAlignment = styled.div` | ||||
| `;
 | ||||
| 
 | ||||
| const InformationCard = () => { | ||||
|   const { initialData, hasDraftAndPublish, layout } = useContentManagerEditViewDataManager(); | ||||
|   const { initialData, hasDraftAndPublish, layout } = useCMEditViewDataManager(); | ||||
|   const { formatMessage } = useIntl(); | ||||
| 
 | ||||
|   const updatedAtName = useMemo( | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| import React, { useRef } from 'react'; | ||||
| import { useIntl } from 'react-intl'; | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { Box } from '@strapi/parts/Box'; | ||||
| import { Divider } from '@strapi/parts/Divider'; | ||||
| import { TableLabel, Text } from '@strapi/parts/Text'; | ||||
| @ -11,7 +11,7 @@ import getUnits from './utils/getUnits'; | ||||
| 
 | ||||
| const Informations = () => { | ||||
|   const { formatMessage, formatRelativeTime } = useIntl(); | ||||
|   const { initialData, isCreatingEntry } = useContentManagerEditViewDataManager(); | ||||
|   const { initialData, isCreatingEntry } = useCMEditViewDataManager(); | ||||
| 
 | ||||
|   // TODO if timestamps are still configurable in the V4
 | ||||
|   const updatedAt = 'updated_at'; | ||||
|  | ||||
| @ -7,12 +7,12 @@ | ||||
| import React from 'react'; | ||||
| import { render } from '@testing-library/react'; | ||||
| import { IntlProvider } from 'react-intl'; | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import Theme from '../../../../../components/Theme'; | ||||
| import Informations from '../index'; | ||||
| 
 | ||||
| jest.mock('@strapi/helper-plugin', () => ({ | ||||
|   useContentManagerEditViewDataManager: jest.fn(), | ||||
|   useCMEditViewDataManager: jest.fn(), | ||||
| })); | ||||
| 
 | ||||
| const makeApp = () => { | ||||
| @ -41,7 +41,7 @@ describe('CONTENT MANAGER | EditView | Header', () => { | ||||
|   }); | ||||
| 
 | ||||
|   it('renders and matches the snaphsot', () => { | ||||
|     useContentManagerEditViewDataManager.mockImplementationOnce(() => ({ | ||||
|     useCMEditViewDataManager.mockImplementationOnce(() => ({ | ||||
|       initialData: {}, | ||||
|       isCreatingEntry: true, | ||||
|     })); | ||||
|  | ||||
| @ -1,8 +1,8 @@ | ||||
| import { useContext } from 'react'; | ||||
| import ContentManagerEditViewDataManagerContext from '../../contexts/ContentManagerEditViewDataManagerContext'; | ||||
| 
 | ||||
| const useContentManagerEditViewDataManager = () => { | ||||
| const useCMEditViewDataManager = () => { | ||||
|   return useContext(ContentManagerEditViewDataManagerContext); | ||||
| }; | ||||
| 
 | ||||
| export default useContentManagerEditViewDataManager; | ||||
| export default useCMEditViewDataManager; | ||||
| @ -1,18 +1,18 @@ | ||||
| <!--- useContentManagerEditViewDataManager.stories.mdx ---> | ||||
| <!--- useCMEditViewDataManager.stories.mdx ---> | ||||
| 
 | ||||
| import { Meta, ArgsTable, Canvas, Story } from '@storybook/addon-docs'; | ||||
| import { Main, Row, Button } from '@strapi/parts'; | ||||
| 
 | ||||
| <Meta title="content-manager/hooks/useContentManagerEditViewDataManager" /> | ||||
| <Meta title="content-manager/hooks/useCMEditViewDataManager" /> | ||||
| 
 | ||||
| # useContentManagerEditViewDataManager | ||||
| # useCMEditViewDataManager | ||||
| 
 | ||||
| Hook that manages the content manager edit view. Use this hooks when you want to inject a component into the | ||||
| 
 | ||||
| ## Usage | ||||
| 
 | ||||
| ```js | ||||
| import { useContentManagerEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager } from '@strapi/helper-plugin'; | ||||
| 
 | ||||
| const MyCompo = () => { | ||||
|   const { | ||||
| @ -47,7 +47,7 @@ const MyCompo = () => { | ||||
|     removeComponentFromDynamicZone: () => {}, | ||||
|     removeComponentFromField: () => {}, | ||||
|     removeRepeatableField: () => {}, | ||||
|   } = useContentManagerEditViewDataManager() | ||||
|   } = useCMEditViewDataManager() | ||||
| 
 | ||||
|   return null | ||||
| } | ||||
| @ -205,6 +205,6 @@ export { default as RemoveRoundedButton } from './icons/RemoveRoundedButton'; | ||||
| 
 | ||||
| // content-manager
 | ||||
| export { default as ContentManagerEditViewDataManagerContext } from './content-manager/contexts/ContentManagerEditViewDataManagerContext'; | ||||
| export { default as useContentManagerEditViewDataManager } from './content-manager/hooks/useContentManagerEditViewDataManager'; | ||||
| export { default as useCMEditViewDataManager } from './content-manager/hooks/useCMEditViewDataManager'; | ||||
| export { getType }; | ||||
| export { getOtherInfos }; | ||||
|  | ||||
| @ -12,7 +12,7 @@ import { Row } from '@strapi/parts/Row'; | ||||
| import { Stack } from '@strapi/parts/Stack'; | ||||
| import AlertWarningIcon from '@strapi/icons/AlertWarningIcon'; | ||||
| import Duplicate from '@strapi/icons/Duplicate'; | ||||
| import { useContentManagerEditViewDataManager, useNotification } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager, useNotification } from '@strapi/helper-plugin'; | ||||
| import { axiosInstance, getTrad } from '../../../utils'; | ||||
| import { cleanData, generateOptions } from './utils'; | ||||
| 
 | ||||
| @ -41,7 +41,7 @@ const Content = ({ appLocales, currentLocale, localizations, readPermissions }) | ||||
|   const toggleNotification = useNotification(); | ||||
|   const { formatMessage } = useIntl(); | ||||
|   const dispatch = useDispatch(); | ||||
|   const { allLayoutData, slug } = useContentManagerEditViewDataManager(); | ||||
|   const { allLayoutData, slug } = useCMEditViewDataManager(); | ||||
|   const [isLoading, setIsLoading] = useState(false); | ||||
|   const [isOpen, setIsOpen] = useState(false); | ||||
|   const [value, setValue] = useState(options[0]?.value || ''); | ||||
|  | ||||
| @ -3,19 +3,13 @@ import get from 'lodash/get'; | ||||
| import has from 'lodash/has'; | ||||
| import { useSelector } from 'react-redux'; | ||||
| import { useParams } from 'react-router-dom'; | ||||
| import { useContentManagerEditViewDataManager, useQueryParams } from '@strapi/helper-plugin'; | ||||
| import { useCMEditViewDataManager, useQueryParams } from '@strapi/helper-plugin'; | ||||
| import selectI18NLocales from '../../selectors/selectI18nLocales'; | ||||
| import useContentTypePermissions from '../../hooks/useContentTypePermissions'; | ||||
| import CMEditViewLocalePicker from './CMEditViewLocalePicker'; | ||||
| 
 | ||||
| const CMEditViewInjectedComponents = () => { | ||||
|   const { | ||||
|     layout, | ||||
|     modifiedData, | ||||
|     initialData, | ||||
|     slug, | ||||
|     isSingleType, | ||||
|   } = useContentManagerEditViewDataManager(); | ||||
|   const { layout, modifiedData, initialData, slug, isSingleType } = useCMEditViewDataManager(); | ||||
|   const { createPermissions, readPermissions } = useContentTypePermissions(slug); | ||||
|   const locales = useSelector(selectI18NLocales); | ||||
|   const params = useParams(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 soupette
						soupette