From 761675253ef9ddfb2342990632a833111c201be7 Mon Sep 17 00:00:00 2001 From: soupette Date: Mon, 24 Feb 2020 08:38:09 +0100 Subject: [PATCH 1/4] Fix delete uid field by removing all field attached to it Signed-off-by: soupette --- .../containers/DataManagerProvider/reducer.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/reducer.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/reducer.js index 5c31f7226d..5814388b20 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/reducer.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/reducer.js @@ -391,18 +391,15 @@ const reducer = (state, action) => { } } - const attributes = state.getIn(['modifiedData', mainDataKey, 'schema', 'attributes']).toJS(); - const uidField = Object.entries(attributes).find( - ([, value]) => attributeToRemoveName === value.targetField - ); + return state.removeIn(pathToAttributeToRemove).updateIn([...pathToAttributes], attributes => { + return attributes.keySeq().reduce((acc, current) => { + if (acc.getIn([current, 'targetField']) === attributeToRemoveName) { + return acc.removeIn([current, 'targetField']); + } - if (uidField) { - return state - .removeIn(pathToAttributeToRemove) - .removeIn([...pathToAttributes, uidField[0], 'targetField']); - } - - return state.removeIn(pathToAttributeToRemove); + return acc; + }, attributes); + }); } case 'SET_MODIFIED_DATA': { let newState = state From 7ab7ebda51446f0c5bc9ed819381dc63f3ebeb9f Mon Sep 17 00:00:00 2001 From: soupette Date: Mon, 24 Feb 2020 08:53:34 +0100 Subject: [PATCH 2/4] Fix loading state and ctb setup Signed-off-by: soupette --- .../containers/DataManagerProvider/index.js | 89 +++++-------------- 1 file changed, 23 insertions(+), 66 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js index 19fbee0932..19efcce911 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js @@ -7,12 +7,7 @@ import { useGlobalContext, PopUpWarning, } from 'strapi-helper-plugin'; -import { - useHistory, - useLocation, - useRouteMatch, - Redirect, -} from 'react-router-dom'; +import { useHistory, useLocation, useRouteMatch, Redirect } from 'react-router-dom'; import DataManagerContext from '../../contexts/DataManagerContext'; import getTrad from '../../utils/getTrad'; import makeUnique from '../../utils/makeUnique'; @@ -55,21 +50,17 @@ const DataManagerProvider = ({ allIcons, children }) => { } = reducerState.toJS(); const { pathname } = useLocation(); const { push } = useHistory(); - const contentTypeMatch = useRouteMatch( - `/plugins/${pluginId}/content-types/:uid` - ); + const contentTypeMatch = useRouteMatch(`/plugins/${pluginId}/content-types/:uid`); const componentMatch = useRouteMatch( `/plugins/${pluginId}/component-categories/:categoryUid/:componentUid` ); + const formatMessageRef = useRef(); formatMessageRef.current = formatMessage; - const isInDevelopmentMode = - currentEnvironment === 'development' && autoReload; + const isInDevelopmentMode = currentEnvironment === 'development' && autoReload; const isInContentTypeView = contentTypeMatch !== null; - const firstKeyToMainSchema = isInContentTypeView - ? 'contentType' - : 'component'; + const firstKeyToMainSchema = isInContentTypeView ? 'contentType' : 'component'; const currentUid = isInContentTypeView ? get(contentTypeMatch, 'params.uid', null) : get(componentMatch, 'params.componentUid', null); @@ -80,10 +71,7 @@ const DataManagerProvider = ({ allIcons, children }) => { getDataRef.current = async () => { try { - const [ - { data: componentsArray }, - { data: contentTypesArray }, - ] = await Promise.all( + const [{ data: componentsArray }, { data: contentTypesArray }] = await Promise.all( ['components', 'content-types'].map(endPoint => { return request(`/${pluginId}/${endPoint}`, { method: 'GET', @@ -118,11 +106,11 @@ const DataManagerProvider = ({ allIcons, children }) => { useEffect(() => { // We need to set the modifiedData after the data has been retrieved // and also on pathname change - if (!isLoading) { + if (!isLoading && currentUid) { setModifiedData(); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isLoading, pathname]); + }, [isLoading, pathname, currentUid]); useEffect(() => { if (currentEnvironment === 'development' && !autoReload) { @@ -135,8 +123,7 @@ const DataManagerProvider = ({ allIcons, children }) => { }, [autoReload, currentEnvironment]); const didModifiedComponents = - getCreatedAndModifiedComponents(modifiedData.components || {}, components) - .length > 0; + getCreatedAndModifiedComponents(modifiedData.components || {}, components).length > 0; const addAttribute = ( attributeToSet, @@ -158,10 +145,7 @@ const DataManagerProvider = ({ allIcons, children }) => { }); }; - const addCreatedComponentToDynamicZone = ( - dynamicZoneTarget, - componentsToAdd - ) => { + const addCreatedComponentToDynamicZone = (dynamicZoneTarget, componentsToAdd) => { dispatch({ type: 'ADD_CREATED_COMPONENT_TO_DYNAMIC_ZONE', dynamicZoneTarget, @@ -181,10 +165,7 @@ const DataManagerProvider = ({ allIcons, children }) => { componentCategory, shouldAddComponentToData = false ) => { - const type = - schemaType === 'contentType' - ? 'CREATE_SCHEMA' - : 'CREATE_COMPONENT_SCHEMA'; + const type = schemaType === 'contentType' ? 'CREATE_SCHEMA' : 'CREATE_COMPONENT_SCHEMA'; dispatch({ type, @@ -204,15 +185,9 @@ const DataManagerProvider = ({ allIcons, children }) => { }); }; - const removeAttribute = ( - mainDataKey, - attributeToRemoveName, - componentUid = '' - ) => { + const removeAttribute = (mainDataKey, attributeToRemoveName, componentUid = '') => { const type = - mainDataKey === 'components' - ? 'REMOVE_FIELD_FROM_DISPLAYED_COMPONENT' - : 'REMOVE_FIELD'; + mainDataKey === 'components' ? 'REMOVE_FIELD_FROM_DISPLAYED_COMPONENT' : 'REMOVE_FIELD'; if (mainDataKey === 'contentType') { emitEvent('willDeleteFieldOfContentType'); @@ -253,17 +228,11 @@ const DataManagerProvider = ({ allIcons, children }) => { const deleteData = async () => { try { const requestURL = `/${pluginId}/${endPoint}/${currentUid}`; - const isTemporary = get( - modifiedData, - [firstKeyToMainSchema, 'isTemporary'], - false - ); + const isTemporary = get(modifiedData, [firstKeyToMainSchema, 'isTemporary'], false); const userConfirm = window.confirm( formatMessage({ id: getTrad( - `popUpWarning.bodyMessage.${ - isInContentTypeView ? 'contentType' : 'component' - }.delete` + `popUpWarning.bodyMessage.${isInContentTypeView ? 'contentType' : 'component'}.delete` ), }) ); @@ -338,9 +307,7 @@ const DataManagerProvider = ({ allIcons, children }) => { const getAllNestedComponents = () => { const appNestedCompo = retrieveNestedComponents(components); - const editingDataNestedCompos = retrieveNestedComponents( - modifiedData.components || {} - ); + const editingDataNestedCompos = retrieveNestedComponents(modifiedData.components || {}); return makeUnique([...editingDataNestedCompos, ...appNestedCompo]); }; @@ -370,10 +337,7 @@ const DataManagerProvider = ({ allIcons, children }) => { isInContentTypeView ); - const dataShape = orderAllDataAttributesWithImmutable( - newSchemaToSet, - isInContentTypeView - ); + const dataShape = orderAllDataAttributesWithImmutable(newSchemaToSet, isInContentTypeView); // This prevents from losing the created content type or component when clicking on the link from the left menu const hasJustCreatedSchema = @@ -401,11 +365,7 @@ const DataManagerProvider = ({ allIcons, children }) => { const submitData = async additionalContentTypeData => { try { - const isCreating = get( - modifiedData, - [firstKeyToMainSchema, 'isTemporary'], - false - ); + const isCreating = get(modifiedData, [firstKeyToMainSchema, 'isTemporary'], false); const body = { components: getComponentsToPost( modifiedData.components, @@ -505,14 +465,11 @@ const DataManagerProvider = ({ allIcons, children }) => { value={{ addAttribute, addCreatedComponentToDynamicZone, - allComponentsCategories: retrieveSpecificInfoFromComponents( - components, - ['category'] - ), - allComponentsIconAlreadyTaken: retrieveSpecificInfoFromComponents( - components, - ['schema', 'icon'] - ), + allComponentsCategories: retrieveSpecificInfoFromComponents(components, ['category']), + allComponentsIconAlreadyTaken: retrieveSpecificInfoFromComponents(components, [ + 'schema', + 'icon', + ]), allIcons, changeDynamicZoneComponents, components, From e2322871527fd87caa0f03c12bd7e66d93d58c58 Mon Sep 17 00:00:00 2001 From: soupette Date: Mon, 24 Feb 2020 09:42:35 +0100 Subject: [PATCH 3/4] fix links to ctm Signed-off-by: soupette --- .../admin/src/containers/ListView/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/ListView/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/ListView/index.js index 0c5cd47780..b699d34262 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/ListView/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/ListView/index.js @@ -257,8 +257,9 @@ const ListView = () => { }; const goToCMSettingsPage = () => { const endPoint = isInContentTypeView - ? `/plugins/content-manager/${targetUid}/ctm-configurations/edit-settings/content-types` + ? `/plugins/content-manager/${contentTypeKind}/${targetUid}/ctm-configurations/edit-settings/content-types` : `/plugins/content-manager/ctm-configurations/edit-settings/components/${targetUid}/`; + push(endPoint); }; From 2f3bbcb2dbb6016a5e2fbc61a045badeca72d47c Mon Sep 17 00:00:00 2001 From: soupette Date: Mon, 24 Feb 2020 10:05:15 +0100 Subject: [PATCH 4/4] Fix timestamp dipslay Signed-off-by: soupette --- .../admin/src/translations/en.json | 1 + .../admin/src/utils/getAttributeDisplayedType.js | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json b/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json index ad543a955e..0da3f498a7 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json +++ b/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json @@ -28,6 +28,7 @@ "attribute.text.description": "Small or long text like title or description", "attribute.text": "Text", "attribute.time": "Time", + "attribute.timestamp": "Timestamp", "attribute.uid.description": "Unique identifier", "attribute.uid": "Uid", "button.attributes.add.another": "Add another field", diff --git a/packages/strapi-plugin-content-type-builder/admin/src/utils/getAttributeDisplayedType.js b/packages/strapi-plugin-content-type-builder/admin/src/utils/getAttributeDisplayedType.js index 4a9a04403f..94652913a7 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/utils/getAttributeDisplayedType.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/utils/getAttributeDisplayedType.js @@ -5,6 +5,7 @@ const getAttributeDisplayedType = type => { case 'date': case 'datetime': case 'time': + case 'timestamp': displayedType = 'date'; break; case 'integer':