Work in progress on confirmation dialogs displayed when one navigates from a page with unsaved changes.
Optimized imports.
This commit is contained in:
parent
3921a6b2cb
commit
008fd21b51
30 changed files with 324 additions and 231 deletions
|
|
@ -8,13 +8,15 @@ import {
|
|||
Button,
|
||||
ButtonRow,
|
||||
Fieldset,
|
||||
filterData,
|
||||
Form,
|
||||
FormSendMethod,
|
||||
InputField,
|
||||
TableSelect,
|
||||
TableSelectMode,
|
||||
TextArea,
|
||||
withForm
|
||||
withForm,
|
||||
withFormErrorHandlers
|
||||
} from '../lib/form';
|
||||
import axios from '../lib/axios';
|
||||
import {withAsyncErrorHandler, withErrorHandling} from '../lib/error-handling';
|
||||
|
|
@ -73,9 +75,22 @@ export default class CUD extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
submitFormValuesMutator(data) {
|
||||
const params = {};
|
||||
|
||||
for (const spec of data.user_fields) {
|
||||
const fldId = `param_${spec.id}`;
|
||||
params[spec.id] = data[fldId];
|
||||
}
|
||||
|
||||
data.params = params;
|
||||
|
||||
return filterData(data, ['name', 'description', 'report_template', 'params', 'namespace']);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.entity) {
|
||||
this.getFormValuesFromEntity(this.props.entity, ::this.getFormValuesMutator);
|
||||
this.getFormValuesFromEntity(this.props.entity);
|
||||
|
||||
} else {
|
||||
this.populateFormValues({
|
||||
|
|
@ -133,6 +148,7 @@ export default class CUD extends Component {
|
|||
validateNamespace(t, state);
|
||||
}
|
||||
|
||||
@withFormErrorHandlers
|
||||
async submitHandler(submitAndLeave) {
|
||||
const t = this.props.t;
|
||||
|
||||
|
|
@ -153,25 +169,14 @@ export default class CUD extends Component {
|
|||
this.disableForm();
|
||||
this.setFormStatusMessage('info', t('saving'));
|
||||
|
||||
const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url, data => {
|
||||
const params = {};
|
||||
|
||||
for (const spec of data.user_fields) {
|
||||
const fldId = `param_${spec.id}`;
|
||||
params[spec.id] = data[fldId];
|
||||
delete data[fldId];
|
||||
}
|
||||
|
||||
delete data.user_fields;
|
||||
data.params = params;
|
||||
});
|
||||
const submitResult = await this.validateAndSendFormValuesToURL(sendMethod, url);
|
||||
|
||||
if (submitResult) {
|
||||
if (this.props.entity) {
|
||||
if (submitAndLeave) {
|
||||
this.navigateToWithFlashMessage('/reports', 'success', t('Report updated'));
|
||||
} else {
|
||||
await this.getFormValuesFromURL(`rest/reports/${this.props.entity.id}`, ::this.getFormValuesMutator);
|
||||
await this.getFormValuesFromURL(`rest/reports/${this.props.entity.id}`);
|
||||
this.enableForm();
|
||||
this.setFormStatusMessage('success', t('Report updated'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,13 @@ import {
|
|||
Button,
|
||||
ButtonRow,
|
||||
Dropdown,
|
||||
filterData,
|
||||
Form,
|
||||
FormSendMethod,
|
||||
InputField,
|
||||
TextArea,
|
||||
withForm
|
||||
withForm,
|
||||
withFormErrorHandlers
|
||||
} from '../../lib/form';
|
||||
import {withErrorHandling} from '../../lib/error-handling';
|
||||
import {NamespaceSelect, validateNamespace} from '../../lib/namespace';
|
||||
|
|
@ -47,6 +49,10 @@ export default class CUD extends Component {
|
|||
entity: PropTypes.object
|
||||
}
|
||||
|
||||
submitFormValuesMutator(data) {
|
||||
return filterData(data, ['name', 'description', 'mime_type', 'user_fields', 'js', 'hbs', 'namespace']);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.entity) {
|
||||
this.getFormValuesFromEntity(this.props.entity);
|
||||
|
|
@ -246,6 +252,7 @@ export default class CUD extends Component {
|
|||
validateNamespace(t, state);
|
||||
}
|
||||
|
||||
@withFormErrorHandlers
|
||||
async submitHandler(submitAndLeave) {
|
||||
const t = this.props.t;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue