Skip to content

Commit

Permalink
Corrected #1658
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Aug 24, 2022
1 parent f27aab9 commit 3a6c46d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src-rx/src/components/JsonConfig.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ class JsonConfig extends Router {
return null;
}
return <ConfirmDialog
title={I18n.t('Please confirm')}
text={I18n.t('Some data are not stored. Discard?')}
ok={I18n.t('Discard')}
cancel={I18n.t('Cancel')}
title={I18n.t('ra_Please confirm')}
text={I18n.t('ra_Some data are not stored. Discard?')}
ok={I18n.t('ra_Discard')}
cancel={I18n.t('ra_Cancel')}
onClose={isYes =>
this.setState({ confirmDialog: false }, () => isYes && Router.doNavigate(null))}
/>;
Expand All @@ -303,7 +303,7 @@ class JsonConfig extends Router {
return null;
} else {
return <ConfirmDialog
title={I18n.t('Please confirm')}
title={I18n.t('ra_Please confirm')}
text={typeof this.state.saveConfigDialog === 'string' ? this.state.saveConfigDialog : I18n.t('Save configuration?')}
ok={I18n.t('ra_Save')}
cancel={I18n.t('ra_Cancel')}
Expand Down
30 changes: 23 additions & 7 deletions src-rx/src/components/JsonConfigComponent/ConfigGeneric.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class ConfigGeneric extends Component {

this.isError = {};

if (this.props.schema) {
if (this.props.custom) {
this.defaultValue = this.props.schema.defaultFunc ? this.executeCustom(this.props.schema.defaultFunc, this.props.schema.default, this.props.data, this.props.instanceObj, this.props.arrayIndex, this.props.globalData) : this.props.schema.default;
if (props.schema) {
if (props.custom) {
this.defaultValue = props.schema.defaultFunc ? this.executeCustom(props.schema.defaultFunc, props.schema.default, props.data, props.instanceObj, props.arrayIndex, props.globalData) : props.schema.default;
} else {
this.defaultValue = this.props.schema.defaultFunc ? this.execute(this.props.schema.defaultFunc, this.props.schema.default, this.props.data, this.props.arrayIndex, this.props.globalData) : this.props.schema.default;
this.defaultValue = props.schema.defaultFunc ? this.execute(props.schema.defaultFunc, props.schema.default, props.data, props.arrayIndex, props.globalData) : props.schema.default;
}
}

Expand All @@ -52,7 +52,7 @@ class ConfigGeneric extends Component {
setTimeout(() => {
if (this.props.custom) {
this.props.onChange(this.props.attr, this.defaultValue, () =>
this.props.forceUpdate([this.props.attr], this.props.data));
setTimeout(() => this.props.forceUpdate([this.props.attr], this.props.data), 100));
//this.onChange(this.props.attr, this.defaultValue);
} else {
ConfigGeneric.setValue(this.props.data, this.props.attr, this.defaultValue);
Expand Down Expand Up @@ -218,10 +218,26 @@ class ConfigGeneric extends Component {
}

ConfigGeneric.setValue(data, this.state.confirmAttr, this.state.confirmNewValue);
this.setState({confirmDialog: false, confirmDepAttr: null, confirmDepNewValue: null, confirmNewValue: null, confirmAttr: null, confirmOldValue: null, confirmData: null}, () =>
this.setState({
confirmDialog: false,
confirmDepAttr: null,
confirmDepNewValue: null,
confirmNewValue: null,
confirmAttr: null,
confirmOldValue: null,
confirmData: null,
}, () =>
this.props.onChange(data));
} else {
this.setState({confirmDialog: false, confirmDepAttr: null, confirmDepNewValue: null, confirmNewValue: null, confirmAttr: null, confirmOldValue: null, confirmData: null});
this.setState({
confirmDialog: false,
confirmDepAttr: null,
confirmDepNewValue: null,
confirmNewValue: null,
confirmAttr: null,
confirmOldValue: null,
confirmData: null,
});
}
})
}
Expand Down
39 changes: 28 additions & 11 deletions src-rx/src/components/Object/ObjectCustomEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const styles = theme => ({
maxWidth: 800,
display: 'inline-block',
verticalAlign: 'top',
paddingTop: 16,
},

accordionOdd: {
Expand Down Expand Up @@ -286,7 +287,7 @@ class ObjectCustomEditor extends Component {
}

getDefaultValues(instance, obj) {
const defaultValues = {enabled: false};
const defaultValues = { enabled: false };
const adapter = instance.split('.')[0];

if (this.jsonConfigs[adapter] && !this.jsonConfigs[adapter].disabled) {
Expand Down Expand Up @@ -438,10 +439,18 @@ class ObjectCustomEditor extends Component {
}
(window._localStorage || window.localStorage).setItem('App.customsExpanded', JSON.stringify(expanded));
pos === -1 && (window._localStorage || window.localStorage).setItem('App.customsLastExpanded', instance);
this.setState({expanded});
this.setState({ expanded });
}}
>
<AccordionSummary expandIcon={<ExpandMoreIcon />} data-id={ instance } className={i % 2 ? (enabled ? this.props.classes.accordionHeaderEnabledOdd : this.props.classes.accordionHeaderOdd) : (enabled ? this.props.classes.accordionHeaderEnabledEven : this.props.classes.accordionHeaderEven)}>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
data-id={instance}
className={i % 2 ?
(enabled ? this.props.classes.accordionHeaderEnabledOdd : this.props.classes.accordionHeaderOdd)
:
(enabled ? this.props.classes.accordionHeaderEnabledEven : this.props.classes.accordionHeaderEven)
}
>
<img src={ icon } className={ this.props.classes.headingIcon } alt="" />
<Typography className={ this.props.classes.heading }>{ this.props.t('Settings %s', instance)}</Typography>
<div className={ clsx(this.props.classes.titleEnabled, 'titleEnabled', enabled ? this.props.classes.enabledVisible : this.props.classes.enabledInvisible) }>{
Expand All @@ -457,7 +466,8 @@ class ObjectCustomEditor extends Component {
checked={ !!enabled }
disabled={disabled}
onChange={e => {
const newValues = JSON.parse(JSON.stringify(this.state.newValues));
this.cachedNewValues = this.cachedNewValues || this.state.newValues;
const newValues = JSON.parse(JSON.stringify(this.cachedNewValues));

newValues[instance] = newValues[instance] || {};
if (isIndeterminate || e.target.checked) {
Expand All @@ -469,8 +479,11 @@ class ObjectCustomEditor extends Component {
delete newValues[instance];
}
}
this.setState({newValues, hasChanges: this.isChanged(newValues)}, () =>
this.props.onChange && this.props.onChange(this.state.hasChanges));
this.cachedNewValues = newValues;
this.setState({ newValues, hasChanges: this.isChanged(newValues) }, () => {
this.cachedNewValues = null;
this.props.onChange && this.props.onChange(this.state.hasChanges);
});
}}/>}
label={this.props.t('Enabled')}
/>
Expand All @@ -495,8 +508,9 @@ class ObjectCustomEditor extends Component {
onError={error =>
this.setState({error}, () => this.props.onError && this.props.onError(error))}
onValueChange={(attr, value) => {
console.log(attr + ' => ' + value);
const newValues = JSON.parse(JSON.stringify(this.state.newValues));
this.cachedNewValues = this.cachedNewValues || this.state.newValues;
console.log(`${attr} => ${value}`);
const newValues = JSON.parse(JSON.stringify(this.cachedNewValues));
newValues[instance] = newValues[instance] || {};
if (JSON.stringify(ConfigGeneric.getValue(this.commonConfig[instance], attr)) === JSON.stringify(value)) {
ConfigGeneric.setValue(newValues[instance], attr, null);
Expand All @@ -506,8 +520,11 @@ class ObjectCustomEditor extends Component {
} else {
ConfigGeneric.setValue(newValues[instance], attr, value);
}
this.setState({ newValues, hasChanges: this.isChanged(newValues) }, () =>
this.props.onChange && this.props.onChange(this.state.hasChanges));
this.cachedNewValues = newValues;
this.setState({ newValues, hasChanges: this.isChanged(newValues) }, () => {
this.cachedNewValues = null;
this.props.onChange && this.props.onChange(this.state.hasChanges);
});
}}
/> : null}

Expand Down Expand Up @@ -698,7 +715,7 @@ class ObjectCustomEditor extends Component {

this.saveOneState([...this.props.objectIDs], () => {
this.changedItems = [];
this.newValues = {};
this.cachedNewValues = {};
this.commonConfig = this.getCommonConfig();
this.setState({ confirmed: false, hasChanges: false, newValues: {}}, () => {
this.props.reportChangedIds(this.changedIds);
Expand Down

0 comments on commit 3a6c46d

Please sign in to comment.