mirror of
https://github.com/strapi/strapi.git
synced 2025-08-30 19:56:05 +00:00
First step of ct creation
This commit is contained in:
parent
c52eb01b49
commit
af8b17da1b
@ -18,6 +18,7 @@ const DataManagerProvider = ({ children }) => {
|
||||
isLoading,
|
||||
initialData,
|
||||
modifiedData,
|
||||
newSchema,
|
||||
} = reducerState.toJS();
|
||||
|
||||
const contentTypeMatch = useRouteMatch(
|
||||
@ -60,6 +61,15 @@ const DataManagerProvider = ({ children }) => {
|
||||
getDataRef.current();
|
||||
}, []);
|
||||
|
||||
const createSchema = (data, schemaType, uid) => {
|
||||
dispatch({
|
||||
type: 'CREATE_SCHEMA',
|
||||
data,
|
||||
schemaType,
|
||||
uid,
|
||||
});
|
||||
};
|
||||
|
||||
const setModifiedData = () => {
|
||||
const currentSchemas = isInContentTypeView ? contentTypes : components;
|
||||
const schemaToSet = get(currentSchemas, currentUid, {});
|
||||
@ -70,15 +80,17 @@ const DataManagerProvider = ({ children }) => {
|
||||
});
|
||||
};
|
||||
|
||||
console.log({ contentTypes });
|
||||
console.log({ contentTypes, components });
|
||||
|
||||
return (
|
||||
<DataManagerContext.Provider
|
||||
value={{
|
||||
components,
|
||||
contentTypes,
|
||||
createSchema,
|
||||
initialData,
|
||||
modifiedData,
|
||||
newSchema,
|
||||
setModifiedData,
|
||||
}}
|
||||
>
|
||||
|
@ -6,6 +6,16 @@ const initialState = fromJS({
|
||||
initialData: {},
|
||||
modifiedData: {},
|
||||
isLoading: true,
|
||||
newSchema: {
|
||||
schemaType: '',
|
||||
schema: {},
|
||||
uid: '',
|
||||
},
|
||||
newSchemaClone: {
|
||||
schemaType: '',
|
||||
schema: {},
|
||||
uid: '',
|
||||
},
|
||||
});
|
||||
|
||||
const reducer = (state, action) => {
|
||||
@ -15,6 +25,12 @@ const reducer = (state, action) => {
|
||||
.update('components', () => fromJS(action.components))
|
||||
.update('contentTypes', () => fromJS(action.contentTypes))
|
||||
.update('isLoading', () => false);
|
||||
case 'CREATE_SCHEMA':
|
||||
console.log({ action });
|
||||
return state
|
||||
.updateIn(['newSchema', 'schema'], () => fromJS(action.data))
|
||||
.updateIn(['newSchema', 'uid'], () => fromJS(action.uid))
|
||||
.updateIn(['newSchema', 'schemaType'], () => fromJS(action.schemaType));
|
||||
case 'SET_MODIFIED_DATA':
|
||||
return state
|
||||
.update('initialData', () => OrderedMap(action.schemaToSet))
|
||||
|
@ -22,6 +22,7 @@ import ModalHeader from '../../components/ModalHeader';
|
||||
import HeaderModalNavContainer from '../../components/HeaderModalNavContainer';
|
||||
import HeaderNavLink from '../../components/HeaderNavLink';
|
||||
import forms from './utils/forms';
|
||||
import { createUid } from './utils/createUid';
|
||||
import init from './init';
|
||||
import reducer, { initialState } from './reducer';
|
||||
|
||||
@ -42,7 +43,7 @@ const FormModal = () => {
|
||||
const { formatMessage } = useGlobalContext();
|
||||
const isOpen = !isEmpty(search);
|
||||
const query = useQuery();
|
||||
const { contentTypes, initialData } = useDataManager();
|
||||
const { contentTypes, createSchema, initialData } = useDataManager();
|
||||
const { formErrors, modifiedData } = reducerState.toJS();
|
||||
|
||||
useEffect(() => {
|
||||
@ -89,6 +90,9 @@ const FormModal = () => {
|
||||
const schema = forms.contentType.schema(Object.keys(contentTypes));
|
||||
|
||||
await schema.validate(modifiedData, { abortEarly: false });
|
||||
createSchema(modifiedData, state.modalType, createUid(modifiedData.name));
|
||||
handleToggle();
|
||||
// push({ p})
|
||||
} catch (err) {
|
||||
const errors = getYupInnerErrors(err);
|
||||
// TODO
|
||||
@ -175,6 +179,7 @@ const FormModal = () => {
|
||||
: formatMessage({ id: errorId })
|
||||
}
|
||||
onChange={handleChange}
|
||||
onBlur={() => {}}
|
||||
description={
|
||||
get(input, 'description.id', null)
|
||||
? formatMessage(input.description)
|
||||
|
@ -20,7 +20,7 @@ import Wrapper from './Wrapper';
|
||||
// };
|
||||
|
||||
function LeftMenu() {
|
||||
const { components, contentTypes } = useDataManager();
|
||||
const { components, contentTypes, newSchema } = useDataManager();
|
||||
const { currentEnvironment } = useGlobalContext();
|
||||
const { push } = useHistory();
|
||||
const isProduction = currentEnvironment === 'production';
|
||||
@ -40,7 +40,14 @@ function LeftMenu() {
|
||||
})),
|
||||
obj => obj.title
|
||||
);
|
||||
|
||||
const tempSchemaCT =
|
||||
newSchema.schemaType === 'contentType'
|
||||
? {
|
||||
name: newSchema.uid,
|
||||
title: newSchema.schema.name,
|
||||
to: `/plugins/${pluginId}/content-types/${newSchema.uid}`,
|
||||
}
|
||||
: null;
|
||||
const data = [
|
||||
{
|
||||
name: 'models',
|
||||
@ -62,11 +69,14 @@ function LeftMenu() {
|
||||
},
|
||||
},
|
||||
links: sortBy(
|
||||
Object.keys(contentTypes).map(uid => ({
|
||||
name: uid,
|
||||
title: contentTypes[uid].schema.name,
|
||||
to: `/plugins/${pluginId}/content-types/${uid}`,
|
||||
})),
|
||||
Object.keys(contentTypes)
|
||||
.map(uid => ({
|
||||
name: uid,
|
||||
title: contentTypes[uid].schema.name,
|
||||
to: `/plugins/${pluginId}/content-types/${uid}`,
|
||||
}))
|
||||
.concat(tempSchemaCT)
|
||||
.filter(obj => obj !== null),
|
||||
obj => obj.title
|
||||
),
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user