Redux changes and refactoring

This commit is contained in:
Scott E. Graves
2019-06-07 16:32:18 -05:00
parent 5c931bb66d
commit 7f3e90773e
9 changed files with 158 additions and 69 deletions

View File

@@ -7,20 +7,17 @@ import ConfigurationItem from '../../components/ConfigurationItem/ConfigurationI
import Modal from '../../components/UI/Modal/Modal';
import IPCContainer from '../IPCContainer/IPCContainer';
import {displayConfiguration} from '../../redux/actions/mount_actions';
import {notifyError} from '../../redux/actions/error_actions';
const Constants = require('../../constants');
class Configuration extends IPCContainer {
constructor(props) {
super(props);
this.setRequestHandler(Constants.IPC_Get_Config_Template_Reply, this.onGetConfigTemplateReply);
this.setRequestHandler(Constants.IPC_Get_Config_Reply, this.onGetConfigReply);
this.setRequestHandler(Constants.IPC_Set_Config_Values_Reply, this.onSetConfigValuesReply);
this.sendRequest(Constants.IPC_Get_Config_Template, {
Provider: this.props.DisplayConfiguration,
Version: this.props.version,
});
}
state = {
@@ -72,6 +69,13 @@ class Configuration extends IPCContainer {
}
};
componentDidMount() {
this.sendRequest(Constants.IPC_Get_Config_Template, {
Provider: this.props.DisplayConfiguration,
Version: this.props.version,
});
}
createItemList = (config, template) => {
const objectList = [];
const itemList = Object
@@ -142,7 +146,7 @@ class Configuration extends IPCContainer {
OriginalObjectLookup: objectLookupCopy,
});
} else {
this.props.errorHandler(arg.data.Error);
this.props.notifyError(arg.data.Error);
}
};
@@ -157,8 +161,10 @@ class Configuration extends IPCContainer {
});
});
} else {
this.props.errorHandler(arg.data.Error, () => {
this.props.hideConfiguration();
this.props.notifyError(arg.data.Error, false, () => {
if (this.isMounted()) {
this.props.hideConfiguration();
}
});
}
};
@@ -283,6 +289,7 @@ const mapStateToProps = state => {
const mapDispatchToProps = dispatch => {
return {
notifyError: (msg, critical, callback) => dispatch(notifyError(msg, critical, callback)),
hideConfiguration: () => dispatch(displayConfiguration(null)),
}
};

View File

@@ -14,6 +14,7 @@ import {
setMountState,
setProviderState
} from '../../redux/actions/mount_actions';
import {notifyError} from '../../redux/actions/error_actions';
const Constants = require('../../constants');
@@ -101,7 +102,7 @@ class MountItems extends IPCContainer {
handleMountUnMount = (provider, mount, location) => {
if (!location || (location.trim().length === 0)) {
this.props.errorHandler('Mount location is not set');
this.props.notifyError('Mount location is not set');
} else {
let allowAction = true;
if (mount) {
@@ -117,22 +118,22 @@ class MountItems extends IPCContainer {
});
if (!result.Success) {
allowAction = false;
this.props.errorHandler(result.Error.toString());
this.props.notifyError(result.Error.toString());
}
}
} else {
allowAction = false;
if (result.Code === (new Uint32Array([-1]))[0]) {
this.props.errorHandler('Failed to connect to ' + provider + ' daemon');
this.props.notifyError('Failed to connect to ' + provider + ' daemon');
} else if (result.Code === (new Uint32Array([-3]))[0]) {
this.props.errorHandler('Incompatible ' + provider + ' daemon. Please upgrade ' + provider);
this.props.notifyError('Incompatible ' + provider + ' daemon. Please upgrade ' + provider);
} else {
this.props.errorHandler('Version check failed: ' + result.Error);
this.props.notifyError('Version check failed: ' + result.Error);
}
}
} else {
allowAction = false;
this.props.errorHandler(result.Error.toString());
this.props.notifyError(result.Error.toString());
}
}
@@ -201,7 +202,7 @@ class MountItems extends IPCContainer {
this.props.setAutoMountProcessed(true);
} else {
this.props.errorHandler(arg.data.Error);
this.props.notifyError(arg.data.Error);
}
};
@@ -316,6 +317,7 @@ const mapStateToProps = state => {
const mapDispatchToProps = dispatch => {
return {
notifyError: (msg, critical, callback) => dispatch(notifyError(msg, critical, callback)),
setAllowMount: (provider, allow) => dispatch(setAllowMount(provider, allow)),
setAutoMountProcessed: processed => dispatch(setAutoMountProcessed(processed)),
setMounted: (provider, mounted) => dispatch(setMounted(provider, mounted)),