mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 15:19:00 +00:00
Add loading view to editpage
This commit is contained in:
parent
915d419a59
commit
4268f788c9
@ -17,6 +17,7 @@ import cn from 'classnames';
|
|||||||
// ./node_modules/strapi-helper-plugin/lib/src
|
// ./node_modules/strapi-helper-plugin/lib/src
|
||||||
// or strapi/packages/strapi-helper-plugin/lib/src
|
// or strapi/packages/strapi-helper-plugin/lib/src
|
||||||
import BackHeader from 'components/BackHeader';
|
import BackHeader from 'components/BackHeader';
|
||||||
|
import LoadingIndicator from 'components/LoadingIndicator';
|
||||||
import PluginHeader from 'components/PluginHeader';
|
import PluginHeader from 'components/PluginHeader';
|
||||||
|
|
||||||
// Plugin's components
|
// Plugin's components
|
||||||
@ -108,7 +109,7 @@ export class EditPage extends React.Component {
|
|||||||
* @return {[type]} [description]
|
* @return {[type]} [description]
|
||||||
*/
|
*/
|
||||||
getLayout = () => (
|
getLayout = () => (
|
||||||
bindLayout.call(this, this.props.editPage.layout)
|
bindLayout.call(this, get(this.props.editPage, ['layout', this.getModelName()], {}))
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -150,6 +151,14 @@ export class EditPage extends React.Component {
|
|||||||
get(this.props.schema, ['plugins', this.getSource(), this.getModelName()])
|
get(this.props.schema, ['plugins', this.getSource(), this.getModelName()])
|
||||||
: get(this.props.schema, [this.getModelName()]);
|
: get(this.props.schema, [this.getModelName()]);
|
||||||
|
|
||||||
|
getPluginHeaderTitle = () => {
|
||||||
|
if (this.isCreating()) {
|
||||||
|
return toString(this.props.editPage.pluginHeaderTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.props.match.params.id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the model's source
|
* Retrieve the model's source
|
||||||
* @return {String}
|
* @return {String}
|
||||||
@ -236,6 +245,7 @@ export class EditPage extends React.Component {
|
|||||||
kind: 'secondary',
|
kind: 'secondary',
|
||||||
onClick: this.props.onCancel,
|
onClick: this.props.onCancel,
|
||||||
type: 'button',
|
type: 'button',
|
||||||
|
disabled: this.showLoaders(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
kind: 'primary',
|
kind: 'primary',
|
||||||
@ -244,10 +254,17 @@ export class EditPage extends React.Component {
|
|||||||
type: 'submit',
|
type: 'submit',
|
||||||
loader: this.props.editPage.showLoader,
|
loader: this.props.editPage.showLoader,
|
||||||
style: this.props.editPage.showLoader ? { marginRight: '18px' } : {},
|
style: this.props.editPage.showLoader ? { marginRight: '18px' } : {},
|
||||||
|
disabled: this.showLoaders(),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
showLoaders = () => {
|
||||||
|
const { editPage: { isLoading, layout } } = this.props;
|
||||||
|
|
||||||
|
return isLoading && !this.isCreating() || isLoading && get(layout, this.getModelName()) === undefined;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { editPage } = this.props;
|
const { editPage } = this.props;
|
||||||
|
|
||||||
@ -258,24 +275,28 @@ export class EditPage extends React.Component {
|
|||||||
<div className={cn('container-fluid', styles.containerFluid)}>
|
<div className={cn('container-fluid', styles.containerFluid)}>
|
||||||
<PluginHeader
|
<PluginHeader
|
||||||
actions={this.pluginHeaderActions()}
|
actions={this.pluginHeaderActions()}
|
||||||
title={{ id: toString(editPage.pluginHeaderTitle) }}
|
title={{ id: this.getPluginHeaderTitle() }}
|
||||||
/>
|
/>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className={this.isRelationComponentNull() ? 'col-lg-12' : 'col-lg-9'}>
|
<div className={this.isRelationComponentNull() ? 'col-lg-12' : 'col-lg-9'}>
|
||||||
<div className={styles.main_wrapper}>
|
<div className={styles.main_wrapper}>
|
||||||
<Edit
|
{this.showLoaders() ? (
|
||||||
attributes={this.getModelAttributes()}
|
<LoadingIndicator />
|
||||||
didCheckErrors={editPage.didCheckErrors}
|
) : (
|
||||||
formValidations={editPage.formValidations}
|
<Edit
|
||||||
formErrors={editPage.formErrors}
|
attributes={this.getModelAttributes()}
|
||||||
layout={this.getLayout()}
|
didCheckErrors={editPage.didCheckErrors}
|
||||||
modelName={this.getModelName()}
|
formValidations={editPage.formValidations}
|
||||||
onBlur={this.handleBlur}
|
formErrors={editPage.formErrors}
|
||||||
onChange={this.handleChange}
|
layout={this.getLayout()}
|
||||||
record={editPage.record}
|
modelName={this.getModelName()}
|
||||||
resetProps={editPage.resetProps}
|
onBlur={this.handleBlur}
|
||||||
schema={this.getSchema()}
|
onChange={this.handleChange}
|
||||||
/>
|
record={editPage.record}
|
||||||
|
resetProps={editPage.resetProps}
|
||||||
|
schema={this.getSchema()}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{!this.isRelationComponentNull() && (
|
{!this.isRelationComponentNull() && (
|
||||||
@ -360,3 +381,5 @@ export default compose(
|
|||||||
withSaga,
|
withSaga,
|
||||||
withConnect,
|
withConnect,
|
||||||
)(EditPage);
|
)(EditPage);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,8 @@ const initialState = fromJS({
|
|||||||
isCreating: false,
|
isCreating: false,
|
||||||
id: '',
|
id: '',
|
||||||
initialRecord: Map({}),
|
initialRecord: Map({}),
|
||||||
layout: Map({}),
|
isLoading: true,
|
||||||
|
layout: fromJS({}),
|
||||||
modelName: '',
|
modelName: '',
|
||||||
pluginHeaderTitle: 'New Entry',
|
pluginHeaderTitle: 'New Entry',
|
||||||
record: Map({}),
|
record: Map({}),
|
||||||
@ -44,11 +45,14 @@ function editPageReducer(state = initialState, action) {
|
|||||||
case GET_DATA_SUCCEEDED:
|
case GET_DATA_SUCCEEDED:
|
||||||
return state
|
return state
|
||||||
.update('id', () => action.id)
|
.update('id', () => action.id)
|
||||||
|
.update('isLoading', () => false)
|
||||||
.update('initialRecord', () => Map(action.data))
|
.update('initialRecord', () => Map(action.data))
|
||||||
.update('pluginHeaderTitle', () => action.pluginHeaderTitle)
|
.update('pluginHeaderTitle', () => action.pluginHeaderTitle)
|
||||||
.update('record', () => Map(action.data));
|
.update('record', () => Map(action.data));
|
||||||
case GET_LAYOUT_SUCCEEDED:
|
case GET_LAYOUT_SUCCEEDED:
|
||||||
return state.update('layout', () => Map(action.layout));
|
return state
|
||||||
|
.update('isLoading', () => false)
|
||||||
|
.updateIn(['layout', state.get('modelName')], () => Map(action.layout));
|
||||||
case INIT_MODEL_PROPS:
|
case INIT_MODEL_PROPS:
|
||||||
return state
|
return state
|
||||||
.update('formValidations', () => List(action.formValidations))
|
.update('formValidations', () => List(action.formValidations))
|
||||||
@ -63,7 +67,7 @@ function editPageReducer(state = initialState, action) {
|
|||||||
.update('record', () => state.get('initialRecord'))
|
.update('record', () => state.get('initialRecord'))
|
||||||
.update('resetProps', (v) => v = !v);
|
.update('resetProps', (v) => v = !v);
|
||||||
case RESET_PROPS:
|
case RESET_PROPS:
|
||||||
return initialState;
|
return initialState.update('layout', () => state.get('layout'));
|
||||||
case SET_FILE_RELATIONS:
|
case SET_FILE_RELATIONS:
|
||||||
return state.set('fileRelations', List(action.fileRelations));
|
return state.set('fileRelations', List(action.fileRelations));
|
||||||
case SET_FORM_ERRORS:
|
case SET_FORM_ERRORS:
|
||||||
|
|||||||
@ -99,6 +99,7 @@ export function* dataDelete({ id, modelName, source }) {
|
|||||||
export function* dataDeleteAll({ entriesToDelete, model, source }) {
|
export function* dataDeleteAll({ entriesToDelete, model, source }) {
|
||||||
try {
|
try {
|
||||||
const params = Object.assign(entriesToDelete, source !== undefined ? { source } : {});
|
const params = Object.assign(entriesToDelete, source !== undefined ? { source } : {});
|
||||||
|
|
||||||
yield call(request, `/content-manager/explorer/deleteAll/${model}`, {
|
yield call(request, `/content-manager/explorer/deleteAll/${model}`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
params,
|
params,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user