mirror of
https://github.com/strapi/strapi.git
synced 2025-11-11 07:39:16 +00:00
Fix relation modal for content types and nested compos
This commit is contained in:
parent
b01c930c0f
commit
03840542f7
@ -138,6 +138,8 @@ const DataManagerProvider = ({ children }) => {
|
|||||||
return <Redirect to={`/plugins/${pluginId}/content-types/${firstCTUid}`} />;
|
return <Redirect to={`/plugins/${pluginId}/content-types/${firstCTUid}`} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log({ modifiedData });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataManagerContext.Provider
|
<DataManagerContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import React, { useEffect, useReducer, useRef, useState } from 'react';
|
import React, { useEffect, useReducer, useRef, useState } from 'react';
|
||||||
// import PropTypes from 'prop-types';
|
|
||||||
import {
|
import {
|
||||||
ButtonModal,
|
ButtonModal,
|
||||||
HeaderModal,
|
HeaderModal,
|
||||||
@ -53,12 +52,10 @@ const FormModal = () => {
|
|||||||
const { formatMessage } = useGlobalContext();
|
const { formatMessage } = useGlobalContext();
|
||||||
const query = useQuery();
|
const query = useQuery();
|
||||||
const attributeOptionRef = useRef();
|
const attributeOptionRef = useRef();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
addAttribute,
|
addAttribute,
|
||||||
contentTypes,
|
contentTypes,
|
||||||
createSchema,
|
createSchema,
|
||||||
initialData,
|
|
||||||
modifiedData: allDataSchema,
|
modifiedData: allDataSchema,
|
||||||
sortedContentTypesList,
|
sortedContentTypesList,
|
||||||
} = useDataManager();
|
} = useDataManager();
|
||||||
@ -105,8 +102,6 @@ const FormModal = () => {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [search]);
|
}, [search]);
|
||||||
|
|
||||||
const displayedAttributes = getAttributes(state.forTarget);
|
|
||||||
|
|
||||||
const form = get(forms, [state.modalType, 'form', state.settingType], () => ({
|
const form = get(forms, [state.modalType, 'form', state.settingType], () => ({
|
||||||
items: [],
|
items: [],
|
||||||
}));
|
}));
|
||||||
@ -117,7 +112,6 @@ const FormModal = () => {
|
|||||||
const isCreating = state.actionType === 'create';
|
const isCreating = state.actionType === 'create';
|
||||||
const isOpen = !isEmpty(search);
|
const isOpen = !isEmpty(search);
|
||||||
const isPickingAttribute = state.modalType === 'chooseAttribute';
|
const isPickingAttribute = state.modalType === 'chooseAttribute';
|
||||||
const name = get(initialData, ['schema', 'name'], '');
|
|
||||||
const uid = createUid(modifiedData.name || '');
|
const uid = createUid(modifiedData.name || '');
|
||||||
|
|
||||||
let headerId = isCreating
|
let headerId = isCreating
|
||||||
@ -128,23 +122,26 @@ const FormModal = () => {
|
|||||||
headerId = null;
|
headerId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const modalBodyStyle = isPickingAttribute
|
|
||||||
? { paddingTop: '0.5rem', paddingBottom: '3rem' }
|
|
||||||
: {};
|
|
||||||
|
|
||||||
const checkFormValidity = async () => {
|
const checkFormValidity = async () => {
|
||||||
let schema;
|
let schema;
|
||||||
|
|
||||||
if (state.modalType === 'contentType') {
|
if (state.modalType === 'contentType') {
|
||||||
schema = forms[state.modalType].schema(Object.keys(contentTypes));
|
schema = forms[state.modalType].schema(Object.keys(contentTypes));
|
||||||
} else if (state.modalType === 'attribute') {
|
} else if (
|
||||||
|
state.modalType === 'attribute' &&
|
||||||
|
state.forTarget !== 'components' &&
|
||||||
|
state.forTarget !== 'component'
|
||||||
|
) {
|
||||||
schema = forms[state.modalType].schema(
|
schema = forms[state.modalType].schema(
|
||||||
allDataSchema,
|
allDataSchema,
|
||||||
modifiedData.type,
|
modifiedData.type,
|
||||||
modifiedData
|
modifiedData
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
// TODO validate component schema
|
||||||
console.log('Will do something');
|
console.log('Will do something');
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await schema.validate(modifiedData, { abortEarly: false });
|
await schema.validate(modifiedData, { abortEarly: false });
|
||||||
@ -286,6 +283,14 @@ const FormModal = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Display data
|
||||||
|
const displayedAttributes = getAttributes(state.forTarget);
|
||||||
|
|
||||||
|
// Styles
|
||||||
|
const modalBodyStyle = isPickingAttribute
|
||||||
|
? { paddingTop: '0.5rem', paddingBottom: '3rem' }
|
||||||
|
: {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
@ -416,7 +421,7 @@ const FormModal = () => {
|
|||||||
return (
|
return (
|
||||||
<RelationForm
|
<RelationForm
|
||||||
key="relation"
|
key="relation"
|
||||||
mainBoxHeader={name}
|
mainBoxHeader={state.headerDisplayName}
|
||||||
modifiedData={modifiedData}
|
modifiedData={modifiedData}
|
||||||
naturePickerType={state.forTarget}
|
naturePickerType={state.forTarget}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const getAttributes = () => {
|
const getAttributes = (dataTarget = '') => {
|
||||||
const defaultAttributes = [
|
const defaultAttributes = [
|
||||||
[
|
[
|
||||||
'text',
|
'text',
|
||||||
@ -14,10 +14,16 @@ const getAttributes = () => {
|
|||||||
// 'uid',
|
// 'uid',
|
||||||
'relation',
|
'relation',
|
||||||
],
|
],
|
||||||
['component', 'dynamiczone'],
|
['component'],
|
||||||
];
|
];
|
||||||
|
|
||||||
return defaultAttributes;
|
const items = defaultAttributes.slice();
|
||||||
|
|
||||||
|
if (dataTarget !== 'component' && dataTarget !== 'components') {
|
||||||
|
items[1].push('dynamiczone');
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default getAttributes;
|
export default getAttributes;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user