mirror of
https://github.com/strapi/strapi.git
synced 2025-08-05 07:16:02 +00:00
Use crudReducer in components settings
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
e535136fa6
commit
42d711299c
@ -5,11 +5,11 @@ import { useSelector } from 'react-redux';
|
|||||||
import { getRequestUrl, mergeMetasWithSchema } from '../../utils';
|
import { getRequestUrl, mergeMetasWithSchema } from '../../utils';
|
||||||
import { makeSelectModelAndComponentSchemas } from '../Main/selectors';
|
import { makeSelectModelAndComponentSchemas } from '../Main/selectors';
|
||||||
import pluginPermissions from '../../permissions';
|
import pluginPermissions from '../../permissions';
|
||||||
|
import { crudInitialState, crudReducer } from '../../sharedReducers';
|
||||||
import EditSettingsView from '../EditSettingsView';
|
import EditSettingsView from '../EditSettingsView';
|
||||||
import reducer, { initialState } from './reducer';
|
|
||||||
|
|
||||||
const ComponentSettingsView = () => {
|
const ComponentSettingsView = () => {
|
||||||
const [{ isLoading, layout }, dispatch] = useReducer(reducer, initialState);
|
const [{ isLoading, data: layout }, dispatch] = useReducer(crudReducer, crudInitialState);
|
||||||
const schemasSelector = useMemo(makeSelectModelAndComponentSchemas, []);
|
const schemasSelector = useMemo(makeSelectModelAndComponentSchemas, []);
|
||||||
const { schemas } = useSelector(state => schemasSelector(state), []);
|
const { schemas } = useSelector(state => schemasSelector(state), []);
|
||||||
const { uid } = useParams();
|
const { uid } = useParams();
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
/* eslint-disable consistent-return */
|
|
||||||
import produce from 'immer';
|
|
||||||
|
|
||||||
export const initialState = {
|
|
||||||
error: null,
|
|
||||||
isLoading: true,
|
|
||||||
layout: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
const reducer = (state, action) =>
|
|
||||||
produce(state, draftState => {
|
|
||||||
switch (action.type) {
|
|
||||||
case 'GET_DATA': {
|
|
||||||
draftState.isLoading = true;
|
|
||||||
draftState.error = null;
|
|
||||||
draftState.layout = {};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'GET_DATA_SUCCEEDED': {
|
|
||||||
draftState.layout = action.data;
|
|
||||||
draftState.isLoading = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'GET_DATA_ERROR': {
|
|
||||||
draftState.isLoading = false;
|
|
||||||
draftState.error = action.error;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
return draftState;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default reducer;
|
|
@ -31,9 +31,7 @@ const reducer = (state, action) => {
|
|||||||
.insert(action.hoverRowIndex, state.getIn([...layoutPathEdit, action.dragRowIndex]));
|
.insert(action.hoverRowIndex, state.getIn([...layoutPathEdit, action.dragRowIndex]));
|
||||||
});
|
});
|
||||||
case 'ON_ADD_DATA': {
|
case 'ON_ADD_DATA': {
|
||||||
const size = getInputSize(
|
const size = getInputSize(state.getIn(['modifiedData', 'attributes', action.name, 'type']));
|
||||||
state.getIn(['modifiedData', 'schema', 'attributes', action.name, 'type'])
|
|
||||||
);
|
|
||||||
|
|
||||||
const listSize = state.getIn(layoutPathEdit).size;
|
const listSize = state.getIn(layoutPathEdit).size;
|
||||||
const newList = state.getIn(layoutPathEdit).updateIn([listSize - 1, 'rowContent'], list => {
|
const newList = state.getIn(layoutPathEdit).updateIn([listSize - 1, 'rowContent'], list => {
|
||||||
|
@ -4,11 +4,8 @@ const mergeMetasWithSchema = (data, schemas, mainSchemaKey) => {
|
|||||||
const findSchema = refUid => schemas.find(obj => obj.uid === refUid);
|
const findSchema = refUid => schemas.find(obj => obj.uid === refUid);
|
||||||
const merged = Object.assign({}, data);
|
const merged = Object.assign({}, data);
|
||||||
const mainUID = data[mainSchemaKey].uid;
|
const mainUID = data[mainSchemaKey].uid;
|
||||||
// const contentTypeUid = data.contentType ? data.contentType.uid : data.component.uid;
|
|
||||||
const mainSchema = findSchema(mainUID);
|
const mainSchema = findSchema(mainUID);
|
||||||
// const contentTypeSchema = findSchema(contentTypeUid);
|
|
||||||
|
|
||||||
// set(merged, ['contentType'], { ...data.contentType, ...contentTypeSchema });
|
|
||||||
set(merged, [mainSchemaKey], { ...data[mainSchemaKey], ...mainSchema });
|
set(merged, [mainSchemaKey], { ...data[mainSchemaKey], ...mainSchema });
|
||||||
|
|
||||||
Object.keys(data.components).forEach(compoUID => {
|
Object.keys(data.components).forEach(compoUID => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user