mirror of
https://github.com/strapi/strapi.git
synced 2025-11-16 10:07:55 +00:00
Merge pull request #5299 from strapi/single-types/uid-ctb-fixes
CTB small fixes
This commit is contained in:
commit
0ce196b6a3
@ -7,12 +7,7 @@ import {
|
|||||||
useGlobalContext,
|
useGlobalContext,
|
||||||
PopUpWarning,
|
PopUpWarning,
|
||||||
} from 'strapi-helper-plugin';
|
} from 'strapi-helper-plugin';
|
||||||
import {
|
import { useHistory, useLocation, useRouteMatch, Redirect } from 'react-router-dom';
|
||||||
useHistory,
|
|
||||||
useLocation,
|
|
||||||
useRouteMatch,
|
|
||||||
Redirect,
|
|
||||||
} from 'react-router-dom';
|
|
||||||
import DataManagerContext from '../../contexts/DataManagerContext';
|
import DataManagerContext from '../../contexts/DataManagerContext';
|
||||||
import getTrad from '../../utils/getTrad';
|
import getTrad from '../../utils/getTrad';
|
||||||
import makeUnique from '../../utils/makeUnique';
|
import makeUnique from '../../utils/makeUnique';
|
||||||
@ -55,21 +50,17 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
} = reducerState.toJS();
|
} = reducerState.toJS();
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
const { push } = useHistory();
|
const { push } = useHistory();
|
||||||
const contentTypeMatch = useRouteMatch(
|
const contentTypeMatch = useRouteMatch(`/plugins/${pluginId}/content-types/:uid`);
|
||||||
`/plugins/${pluginId}/content-types/:uid`
|
|
||||||
);
|
|
||||||
const componentMatch = useRouteMatch(
|
const componentMatch = useRouteMatch(
|
||||||
`/plugins/${pluginId}/component-categories/:categoryUid/:componentUid`
|
`/plugins/${pluginId}/component-categories/:categoryUid/:componentUid`
|
||||||
);
|
);
|
||||||
|
|
||||||
const formatMessageRef = useRef();
|
const formatMessageRef = useRef();
|
||||||
formatMessageRef.current = formatMessage;
|
formatMessageRef.current = formatMessage;
|
||||||
const isInDevelopmentMode =
|
const isInDevelopmentMode = currentEnvironment === 'development' && autoReload;
|
||||||
currentEnvironment === 'development' && autoReload;
|
|
||||||
|
|
||||||
const isInContentTypeView = contentTypeMatch !== null;
|
const isInContentTypeView = contentTypeMatch !== null;
|
||||||
const firstKeyToMainSchema = isInContentTypeView
|
const firstKeyToMainSchema = isInContentTypeView ? 'contentType' : 'component';
|
||||||
? 'contentType'
|
|
||||||
: 'component';
|
|
||||||
const currentUid = isInContentTypeView
|
const currentUid = isInContentTypeView
|
||||||
? get(contentTypeMatch, 'params.uid', null)
|
? get(contentTypeMatch, 'params.uid', null)
|
||||||
: get(componentMatch, 'params.componentUid', null);
|
: get(componentMatch, 'params.componentUid', null);
|
||||||
@ -80,10 +71,7 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
|
|
||||||
getDataRef.current = async () => {
|
getDataRef.current = async () => {
|
||||||
try {
|
try {
|
||||||
const [
|
const [{ data: componentsArray }, { data: contentTypesArray }] = await Promise.all(
|
||||||
{ data: componentsArray },
|
|
||||||
{ data: contentTypesArray },
|
|
||||||
] = await Promise.all(
|
|
||||||
['components', 'content-types'].map(endPoint => {
|
['components', 'content-types'].map(endPoint => {
|
||||||
return request(`/${pluginId}/${endPoint}`, {
|
return request(`/${pluginId}/${endPoint}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -118,11 +106,11 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// We need to set the modifiedData after the data has been retrieved
|
// We need to set the modifiedData after the data has been retrieved
|
||||||
// and also on pathname change
|
// and also on pathname change
|
||||||
if (!isLoading) {
|
if (!isLoading && currentUid) {
|
||||||
setModifiedData();
|
setModifiedData();
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [isLoading, pathname]);
|
}, [isLoading, pathname, currentUid]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentEnvironment === 'development' && !autoReload) {
|
if (currentEnvironment === 'development' && !autoReload) {
|
||||||
@ -135,8 +123,7 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
}, [autoReload, currentEnvironment]);
|
}, [autoReload, currentEnvironment]);
|
||||||
|
|
||||||
const didModifiedComponents =
|
const didModifiedComponents =
|
||||||
getCreatedAndModifiedComponents(modifiedData.components || {}, components)
|
getCreatedAndModifiedComponents(modifiedData.components || {}, components).length > 0;
|
||||||
.length > 0;
|
|
||||||
|
|
||||||
const addAttribute = (
|
const addAttribute = (
|
||||||
attributeToSet,
|
attributeToSet,
|
||||||
@ -158,10 +145,7 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const addCreatedComponentToDynamicZone = (
|
const addCreatedComponentToDynamicZone = (dynamicZoneTarget, componentsToAdd) => {
|
||||||
dynamicZoneTarget,
|
|
||||||
componentsToAdd
|
|
||||||
) => {
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'ADD_CREATED_COMPONENT_TO_DYNAMIC_ZONE',
|
type: 'ADD_CREATED_COMPONENT_TO_DYNAMIC_ZONE',
|
||||||
dynamicZoneTarget,
|
dynamicZoneTarget,
|
||||||
@ -181,10 +165,7 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
componentCategory,
|
componentCategory,
|
||||||
shouldAddComponentToData = false
|
shouldAddComponentToData = false
|
||||||
) => {
|
) => {
|
||||||
const type =
|
const type = schemaType === 'contentType' ? 'CREATE_SCHEMA' : 'CREATE_COMPONENT_SCHEMA';
|
||||||
schemaType === 'contentType'
|
|
||||||
? 'CREATE_SCHEMA'
|
|
||||||
: 'CREATE_COMPONENT_SCHEMA';
|
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type,
|
type,
|
||||||
@ -204,15 +185,9 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeAttribute = (
|
const removeAttribute = (mainDataKey, attributeToRemoveName, componentUid = '') => {
|
||||||
mainDataKey,
|
|
||||||
attributeToRemoveName,
|
|
||||||
componentUid = ''
|
|
||||||
) => {
|
|
||||||
const type =
|
const type =
|
||||||
mainDataKey === 'components'
|
mainDataKey === 'components' ? 'REMOVE_FIELD_FROM_DISPLAYED_COMPONENT' : 'REMOVE_FIELD';
|
||||||
? 'REMOVE_FIELD_FROM_DISPLAYED_COMPONENT'
|
|
||||||
: 'REMOVE_FIELD';
|
|
||||||
|
|
||||||
if (mainDataKey === 'contentType') {
|
if (mainDataKey === 'contentType') {
|
||||||
emitEvent('willDeleteFieldOfContentType');
|
emitEvent('willDeleteFieldOfContentType');
|
||||||
@ -253,17 +228,11 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
const deleteData = async () => {
|
const deleteData = async () => {
|
||||||
try {
|
try {
|
||||||
const requestURL = `/${pluginId}/${endPoint}/${currentUid}`;
|
const requestURL = `/${pluginId}/${endPoint}/${currentUid}`;
|
||||||
const isTemporary = get(
|
const isTemporary = get(modifiedData, [firstKeyToMainSchema, 'isTemporary'], false);
|
||||||
modifiedData,
|
|
||||||
[firstKeyToMainSchema, 'isTemporary'],
|
|
||||||
false
|
|
||||||
);
|
|
||||||
const userConfirm = window.confirm(
|
const userConfirm = window.confirm(
|
||||||
formatMessage({
|
formatMessage({
|
||||||
id: getTrad(
|
id: getTrad(
|
||||||
`popUpWarning.bodyMessage.${
|
`popUpWarning.bodyMessage.${isInContentTypeView ? 'contentType' : 'component'}.delete`
|
||||||
isInContentTypeView ? 'contentType' : 'component'
|
|
||||||
}.delete`
|
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -338,9 +307,7 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
|
|
||||||
const getAllNestedComponents = () => {
|
const getAllNestedComponents = () => {
|
||||||
const appNestedCompo = retrieveNestedComponents(components);
|
const appNestedCompo = retrieveNestedComponents(components);
|
||||||
const editingDataNestedCompos = retrieveNestedComponents(
|
const editingDataNestedCompos = retrieveNestedComponents(modifiedData.components || {});
|
||||||
modifiedData.components || {}
|
|
||||||
);
|
|
||||||
|
|
||||||
return makeUnique([...editingDataNestedCompos, ...appNestedCompo]);
|
return makeUnique([...editingDataNestedCompos, ...appNestedCompo]);
|
||||||
};
|
};
|
||||||
@ -370,10 +337,7 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
isInContentTypeView
|
isInContentTypeView
|
||||||
);
|
);
|
||||||
|
|
||||||
const dataShape = orderAllDataAttributesWithImmutable(
|
const dataShape = orderAllDataAttributesWithImmutable(newSchemaToSet, isInContentTypeView);
|
||||||
newSchemaToSet,
|
|
||||||
isInContentTypeView
|
|
||||||
);
|
|
||||||
|
|
||||||
// This prevents from losing the created content type or component when clicking on the link from the left menu
|
// This prevents from losing the created content type or component when clicking on the link from the left menu
|
||||||
const hasJustCreatedSchema =
|
const hasJustCreatedSchema =
|
||||||
@ -401,11 +365,7 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
|
|
||||||
const submitData = async additionalContentTypeData => {
|
const submitData = async additionalContentTypeData => {
|
||||||
try {
|
try {
|
||||||
const isCreating = get(
|
const isCreating = get(modifiedData, [firstKeyToMainSchema, 'isTemporary'], false);
|
||||||
modifiedData,
|
|
||||||
[firstKeyToMainSchema, 'isTemporary'],
|
|
||||||
false
|
|
||||||
);
|
|
||||||
const body = {
|
const body = {
|
||||||
components: getComponentsToPost(
|
components: getComponentsToPost(
|
||||||
modifiedData.components,
|
modifiedData.components,
|
||||||
@ -505,14 +465,11 @@ const DataManagerProvider = ({ allIcons, children }) => {
|
|||||||
value={{
|
value={{
|
||||||
addAttribute,
|
addAttribute,
|
||||||
addCreatedComponentToDynamicZone,
|
addCreatedComponentToDynamicZone,
|
||||||
allComponentsCategories: retrieveSpecificInfoFromComponents(
|
allComponentsCategories: retrieveSpecificInfoFromComponents(components, ['category']),
|
||||||
components,
|
allComponentsIconAlreadyTaken: retrieveSpecificInfoFromComponents(components, [
|
||||||
['category']
|
'schema',
|
||||||
),
|
'icon',
|
||||||
allComponentsIconAlreadyTaken: retrieveSpecificInfoFromComponents(
|
]),
|
||||||
components,
|
|
||||||
['schema', 'icon']
|
|
||||||
),
|
|
||||||
allIcons,
|
allIcons,
|
||||||
changeDynamicZoneComponents,
|
changeDynamicZoneComponents,
|
||||||
components,
|
components,
|
||||||
|
|||||||
@ -391,18 +391,15 @@ const reducer = (state, action) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const attributes = state.getIn(['modifiedData', mainDataKey, 'schema', 'attributes']).toJS();
|
return state.removeIn(pathToAttributeToRemove).updateIn([...pathToAttributes], attributes => {
|
||||||
const uidField = Object.entries(attributes).find(
|
return attributes.keySeq().reduce((acc, current) => {
|
||||||
([, value]) => attributeToRemoveName === value.targetField
|
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': {
|
case 'SET_MODIFIED_DATA': {
|
||||||
let newState = state
|
let newState = state
|
||||||
|
|||||||
@ -257,8 +257,9 @@ const ListView = () => {
|
|||||||
};
|
};
|
||||||
const goToCMSettingsPage = () => {
|
const goToCMSettingsPage = () => {
|
||||||
const endPoint = isInContentTypeView
|
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}/`;
|
: `/plugins/content-manager/ctm-configurations/edit-settings/components/${targetUid}/`;
|
||||||
|
|
||||||
push(endPoint);
|
push(endPoint);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@
|
|||||||
"attribute.text.description": "Small or long text like title or description",
|
"attribute.text.description": "Small or long text like title or description",
|
||||||
"attribute.text": "Text",
|
"attribute.text": "Text",
|
||||||
"attribute.time": "Time",
|
"attribute.time": "Time",
|
||||||
|
"attribute.timestamp": "Timestamp",
|
||||||
"attribute.uid.description": "Unique identifier",
|
"attribute.uid.description": "Unique identifier",
|
||||||
"attribute.uid": "Uid",
|
"attribute.uid": "Uid",
|
||||||
"button.attributes.add.another": "Add another field",
|
"button.attributes.add.another": "Add another field",
|
||||||
|
|||||||
@ -5,6 +5,7 @@ const getAttributeDisplayedType = type => {
|
|||||||
case 'date':
|
case 'date':
|
||||||
case 'datetime':
|
case 'datetime':
|
||||||
case 'time':
|
case 'time':
|
||||||
|
case 'timestamp':
|
||||||
displayedType = 'date';
|
displayedType = 'date';
|
||||||
break;
|
break;
|
||||||
case 'integer':
|
case 'integer':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user