mirror of
https://github.com/strapi/strapi.git
synced 2026-01-06 12:13:52 +00:00
Use layout from the core_store instead of fetching it
This commit is contained in:
parent
5e9490e207
commit
8bb43c9e6b
@ -73,7 +73,8 @@ class Edit extends React.PureComponent {
|
||||
}
|
||||
|
||||
setLayout = (props) => {
|
||||
const currentLayout = get(props.layout, [props.modelName, 'attributes']);
|
||||
// const currentLayout = get(props.layout, [props.modelName, 'attributes']);
|
||||
const currentLayout = get(props.layout, ['attributes']);
|
||||
const displayedFields = merge(this.getUploadRelations(props), get(currentLayout), omit(props.schema.fields, 'id'));
|
||||
|
||||
this.setState({ currentLayout, displayedFields });
|
||||
|
||||
@ -11,8 +11,6 @@ import {
|
||||
CHANGE_DATA,
|
||||
GET_DATA,
|
||||
GET_DATA_SUCCEEDED,
|
||||
GET_LAYOUT,
|
||||
GET_LAYOUT_SUCCEEDED,
|
||||
INIT_MODEL_PROPS,
|
||||
ON_CANCEL,
|
||||
RESET_PROPS,
|
||||
@ -50,20 +48,6 @@ export function getDataSucceeded(id, data, pluginHeaderTitle) {
|
||||
};
|
||||
}
|
||||
|
||||
export function getLayout(source) {
|
||||
return {
|
||||
type: GET_LAYOUT,
|
||||
source,
|
||||
};
|
||||
}
|
||||
|
||||
export function getLayoutSucceeded(layout) {
|
||||
return {
|
||||
type: GET_LAYOUT_SUCCEEDED,
|
||||
layout,
|
||||
};
|
||||
}
|
||||
|
||||
export function initModelProps(modelName, isCreating, source, attributes) {
|
||||
const formValidations = getValidationsFromForm(
|
||||
Object.keys(attributes).map(attr => ({ name: attr, validations: get(attributes, attr, {}) })),
|
||||
|
||||
@ -7,8 +7,6 @@
|
||||
export const CHANGE_DATA = 'ContentManager/EditPage/CHANGE_DATA';
|
||||
export const GET_DATA = 'ContentManager/EditPage/GET_DATA';
|
||||
export const GET_DATA_SUCCEEDED = 'ContentManager/EditPage/GET_DATA_SUCCEEDED';
|
||||
export const GET_LAYOUT = 'ContentManager/EditPage/GET_LAYOUT';
|
||||
export const GET_LAYOUT_SUCCEEDED = 'ContentManager/EditPage/GET_LAYOUT_SUCCEEDED';
|
||||
export const INIT_MODEL_PROPS = 'ContentManager/EditPage/INIT_MODEL_PROPS';
|
||||
export const ON_CANCEL = 'ContentManager/EditPage/ON_CANCEL';
|
||||
export const RESET_PROPS = 'ContentManager/EditPage/RESET_PROPS';
|
||||
|
||||
@ -39,7 +39,6 @@ import { checkFormValidity } from 'utils/formValidations';
|
||||
import {
|
||||
changeData,
|
||||
getData,
|
||||
getLayout,
|
||||
initModelProps,
|
||||
onCancel,
|
||||
resetProps,
|
||||
@ -62,8 +61,6 @@ export class EditPage extends React.Component {
|
||||
if (!this.isCreating()) {
|
||||
const mainField = get(this.getModel(), 'info.mainField') || this.getModel().primaryKey;
|
||||
this.props.getData(this.props.match.params.id, this.getSource(), mainField);
|
||||
} else {
|
||||
this.props.getLayout(this.getSource());
|
||||
}
|
||||
|
||||
// Get all relations made with the upload plugin
|
||||
@ -120,7 +117,7 @@ export class EditPage extends React.Component {
|
||||
*
|
||||
*/
|
||||
getLayout = () => (
|
||||
bindLayout.call(this, get(this.props.editPage, ['layout', this.getModelName()], {}))
|
||||
bindLayout.call(this, get(this.props.schema, ['layout', this.getModelName()], {}))
|
||||
)
|
||||
|
||||
/**
|
||||
@ -282,7 +279,7 @@ export class EditPage extends React.Component {
|
||||
);
|
||||
|
||||
showLoaders = () => {
|
||||
const { editPage: { isLoading, layout } } = this.props;
|
||||
const { editPage: { isLoading }, schema: { layout } } = this.props;
|
||||
|
||||
return isLoading && !this.isCreating() || isLoading && get(layout, this.getModelName()) === undefined;
|
||||
}
|
||||
@ -372,7 +369,6 @@ EditPage.propTypes = {
|
||||
changeData: PropTypes.func.isRequired,
|
||||
editPage: PropTypes.object.isRequired,
|
||||
getData: PropTypes.func.isRequired,
|
||||
getLayout: PropTypes.func.isRequired,
|
||||
history: PropTypes.object.isRequired,
|
||||
initModelProps: PropTypes.func.isRequired,
|
||||
location: PropTypes.object.isRequired,
|
||||
@ -390,7 +386,6 @@ function mapDispatchToProps(dispatch) {
|
||||
{
|
||||
changeData,
|
||||
getData,
|
||||
getLayout,
|
||||
initModelProps,
|
||||
onCancel,
|
||||
resetProps,
|
||||
|
||||
@ -8,7 +8,6 @@ import { fromJS, Map, List } from 'immutable';
|
||||
import {
|
||||
CHANGE_DATA,
|
||||
GET_DATA_SUCCEEDED,
|
||||
GET_LAYOUT_SUCCEEDED,
|
||||
INIT_MODEL_PROPS,
|
||||
ON_CANCEL,
|
||||
RESET_PROPS,
|
||||
@ -28,7 +27,6 @@ const initialState = fromJS({
|
||||
id: '',
|
||||
initialRecord: Map({}),
|
||||
isLoading: true,
|
||||
layout: fromJS({}),
|
||||
modelName: '',
|
||||
pluginHeaderTitle: 'New Entry',
|
||||
record: Map({}),
|
||||
@ -49,10 +47,6 @@ function editPageReducer(state = initialState, action) {
|
||||
.update('initialRecord', () => Map(action.data))
|
||||
.update('pluginHeaderTitle', () => action.pluginHeaderTitle)
|
||||
.update('record', () => Map(action.data));
|
||||
case GET_LAYOUT_SUCCEEDED:
|
||||
return state
|
||||
.update('isLoading', () => false)
|
||||
.updateIn(['layout', state.get('modelName')], () => Map(action.layout));
|
||||
case INIT_MODEL_PROPS:
|
||||
return state
|
||||
.update('formValidations', () => List(action.formValidations))
|
||||
@ -67,7 +61,7 @@ function editPageReducer(state = initialState, action) {
|
||||
.update('record', () => state.get('initialRecord'))
|
||||
.update('resetProps', (v) => v = !v);
|
||||
case RESET_PROPS:
|
||||
return initialState.update('layout', () => state.get('layout'));
|
||||
return initialState;
|
||||
case SET_FILE_RELATIONS:
|
||||
return state.set('fileRelations', List(action.fileRelations));
|
||||
case SET_FORM_ERRORS:
|
||||
|
||||
@ -19,13 +19,12 @@ import templateObject from 'utils/templateObject';
|
||||
|
||||
import {
|
||||
getDataSucceeded,
|
||||
getLayoutSucceeded,
|
||||
setFormErrors,
|
||||
setLoader,
|
||||
submitSuccess,
|
||||
unsetLoader,
|
||||
} from './actions';
|
||||
import { GET_DATA, GET_LAYOUT, SUBMIT } from './constants';
|
||||
import { GET_DATA, SUBMIT } from './constants';
|
||||
import {
|
||||
makeSelectFileRelations,
|
||||
makeSelectIsCreating,
|
||||
@ -38,9 +37,8 @@ function* dataGet(action) {
|
||||
try {
|
||||
const modelName = yield select(makeSelectModelName());
|
||||
const params = { source: action.source };
|
||||
const [response, layout] = yield [
|
||||
const [response] = yield [
|
||||
call(request, `/content-manager/explorer/${modelName}/${action.id}`, { method: 'GET', params }),
|
||||
call(request, '/content-manager/layout', { method: 'GET', params }),
|
||||
];
|
||||
const pluginHeaderTitle = yield call(templateObject, { mainField: action.mainField }, response);
|
||||
|
||||
@ -58,22 +56,11 @@ function* dataGet(action) {
|
||||
}
|
||||
|
||||
yield put(getDataSucceeded(action.id, response, pluginHeaderTitle.mainField));
|
||||
yield put(getLayoutSucceeded(layout));
|
||||
} catch(err) {
|
||||
strapi.notification.error('content-manager.error.record.fetch');
|
||||
}
|
||||
}
|
||||
|
||||
function* layoutGet(action) {
|
||||
try {
|
||||
const params = { source: action.source };
|
||||
const response = yield call(request, '/content-manager/layout', { method: 'GET', params });
|
||||
yield put(getLayoutSucceeded(response));
|
||||
} catch(err) {
|
||||
strapi.notification('notification.error');
|
||||
}
|
||||
}
|
||||
|
||||
export function* submit() {
|
||||
const currentModelName = yield select(makeSelectModelName());
|
||||
const fileRelations = yield select(makeSelectFileRelations());
|
||||
@ -170,7 +157,6 @@ export function* submit() {
|
||||
|
||||
function* defaultSaga() {
|
||||
const loadDataWatcher = yield fork(takeLatest, GET_DATA, dataGet);
|
||||
yield fork(takeLatest, GET_LAYOUT, layoutGet);
|
||||
yield fork(takeLatest, SUBMIT, submit);
|
||||
|
||||
yield take(LOCATION_CHANGE);
|
||||
|
||||
@ -1,13 +1,5 @@
|
||||
{
|
||||
"routes": [
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/layout",
|
||||
"handler": "ContentManager.layout",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/models",
|
||||
|
||||
@ -7,12 +7,6 @@ const _ = require('lodash');
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
layout: async (ctx) => {
|
||||
const {source} = ctx.query;
|
||||
|
||||
return ctx.send(_.get(strapi.plugins, [source, 'config', 'layout'], {}));
|
||||
},
|
||||
|
||||
models: async ctx => {
|
||||
const pluginsStore = strapi.store({
|
||||
environment: '',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user