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