Redux changes and refactoring

This commit is contained in:
Scott E. Graves
2019-06-06 15:52:56 -05:00
parent 6502657e3c
commit 0bbfddc17c
9 changed files with 233 additions and 211 deletions

View File

@@ -18,7 +18,7 @@ class Configuration extends IPCContainer {
this.setRequestHandler(Constants.IPC_Set_Config_Values_Reply, this.onSetConfigValuesReply);
this.sendRequest(Constants.IPC_Get_Config_Template, {
StorageType: this.props.DisplayConfiguration,
Provider: this.props.DisplayConfiguration,
Version: this.props.version,
});
}
@@ -152,7 +152,7 @@ class Configuration extends IPCContainer {
Template: arg.data.Template,
}, ()=> {
this.sendRequest(Constants.IPC_Get_Config, {
StorageType: this.props.DisplayConfiguration,
Provider: this.props.DisplayConfiguration,
Version: this.props.version,
});
});
@@ -192,7 +192,7 @@ class Configuration extends IPCContainer {
this.sendRequest(Constants.IPC_Set_Config_Values, {
Items: changedItems,
StorageType: this.props.DisplayConfiguration,
Provider: this.props.DisplayConfiguration,
Version: this.props.version,
});
});

View File

@@ -6,7 +6,11 @@ import './MountItems.css';
import Modal from '../../components/UI/Modal/Modal';
import MountItem from '../../components/MountItem/MountItem';
import IPCContainer from '../IPCContainer/IPCContainer';
import {displayConfiguration, setAutoMountProcessed, setBusy} from '../../redux/actions/mount_actions';
import {
setAutoMountProcessed,
setBusy,
setProviderState
} from '../../redux/actions/mount_actions';
const Constants = require('../../constants');
@@ -36,15 +40,15 @@ class MountItems extends IPCContainer {
RetryItems: {},
};
cancelRetryMount = (storageType, stateCallback) => {
clearInterval(this.retryIntervals[storageType]);
delete this.retryIntervals[storageType];
cancelRetryMount = (provider, stateCallback) => {
clearInterval(this.retryIntervals[provider]);
delete this.retryIntervals[provider];
if (stateCallback) {
let retryItems = {
...this.state.RetryItems,
};
delete retryItems[storageType];
delete retryItems[provider];
this.setState({
DisplayRetry: Object.keys(retryItems).length > 0,
RetryItems: retryItems,
@@ -58,9 +62,9 @@ class MountItems extends IPCContainer {
};
componentWillUnmount() {
for (const storageType in this.state.RetryItems) {
if (this.state.RetryItems.hasOwnProperty(storageType)) {
this.cancelRetryMount(storageType);
for (const provider in this.state.RetryItems) {
if (this.state.RetryItems.hasOwnProperty(provider)) {
this.cancelRetryMount(provider);
}
}
@@ -76,32 +80,36 @@ class MountItems extends IPCContainer {
}
};
handleBrowseLocation = (storageType, location) => {
handleBrowseLocation = (provider, location) => {
location = this.sendSyncRequest(Constants.IPC_Browse_Directory, {
Title: storageType + ' Mount Location',
Title: provider + ' Mount Location',
Location: location,
});
if (location && (location.length > 0)) {
this.handleMountLocationChanged(storageType, location);
this.handleMountLocationChanged(provider, location);
}
};
handleMountLocationChanged = (storageType, value) => {
if (this.props.Platform === 'win32') {
this.props.changed(storageType, this.state[storageType].DriveLetters[value]);
} else {
this.props.changed(storageType, value);
}
handleMountLocationChanged = (provider, value) => {
const location = (this.props.Platform === 'win32') ?
this.state[provider].DriveLetters[value] :
value;
const state = {
...this.props.ProviderState[provider],
MountLocation: location,
};
this.props.setProviderState(provider, state);
};
handleMountUnMount = (storageType, mount, location) => {
handleMountUnMount = (provider, mount, location) => {
if (!location || (location.trim().length === 0)) {
this.props.errorHandler('Mount location is not set');
} else {
let allowAction = true;
if (mount) {
let result = this.sendSyncRequest(Constants.IPC_Check_Daemon_Version, {
StorageType: storageType,
Provider: provider,
Version: this.props.version
}).data;
if (result.Success) {
@@ -117,7 +125,7 @@ class MountItems extends IPCContainer {
}
} else {
allowAction = false;
this.props.errorHandler("Incompatible " + storageType + " daemon. Please upgrade " + storageType);
this.props.errorHandler("Incompatible " + provider + " daemon. Please upgrade " + provider);
}
} else {
allowAction = false;
@@ -127,26 +135,26 @@ class MountItems extends IPCContainer {
if (allowAction) {
const storageState = {
...this.state[storageType],
...this.state[provider],
AllowMount: false,
};
this.props.setMountsBusy(true);
this.setState({
[storageType]: storageState,
[provider]: storageState,
}, () => {
if (mount) {
this.sendRequest(Constants.IPC_Mount_Drive, {
Location: location,
NoConsoleSupported: this.props.noConsoleSupported,
StorageType: storageType,
Provider: provider,
Version: this.props.version,
});
} else {
this.sendRequest(Constants.IPC_Unmount_Drive, {
Location: location,
StorageType: storageType,
Provider: provider,
Version: this.props.version,
});
}
@@ -172,15 +180,15 @@ class MountItems extends IPCContainer {
this.setState(state, () => {
const updateMountLocation = (data, provider) => {
const providerLower = provider.toLowerCase();
const providerState = this.props.ProviderState[provider];
let location = data.Locations[provider];
if (location.length === 0) {
location = (this.props.Platform === 'win32') ?
this.props[providerLower].MountLocation || data.DriveLetters[provider][0] :
this.props[providerLower].MountLocation;
providerState.MountLocation || data.DriveLetters[provider][0] :
providerState.MountLocation;
}
if (location !== this.props[providerLower].MountLocation) {
this.props.changed(provider, location);
if (location !== providerState.MountLocation) {
this.handleMountLocationChanged(provider, location);
}
};
@@ -197,48 +205,48 @@ class MountItems extends IPCContainer {
onMountDriveReply = (event, arg) => {
const state = {
...this.state[arg.data.StorageType],
...this.state[arg.data.Provider],
Mounted: arg.data.Success,
};
this.setState({
[arg.data.StorageType]: state,
[arg.data.Provider]: state,
}, ()=> {
this.detectMounts();
});
};
onUnmountDriveReply = (event, arg) => {
if (arg && arg.data && !arg.data.Expected && arg.data.Location && this.props[arg.data.StorageType.toLowerCase()].AutoRestart) {
const storageType = arg.data.StorageType;
if (!this.state.RetryItems[storageType]) {
if (arg && arg.data && !arg.data.Expected && arg.data.Location && this.props.ProviderState[arg.data.Provider].AutoRestart) {
const provider = arg.data.Provider;
if (!this.state.RetryItems[provider]) {
let retryItems = {
...this.state.RetryItems
};
retryItems[storageType] = {
retryItems[provider] = {
RetrySeconds: 10,
};
const storageState = {
...this.state[arg.data.StorageType],
...this.state[arg.data.Provider],
AllowMount: false,
Mounted: false,
};
this.setState({
[storageType]: storageState,
[provider]: storageState,
DisplayRetry: true,
RetryItems: retryItems,
}, () => {
this.sendRequest(Constants.IPC_Show_Window);
this.retryIntervals[storageType] = setInterval(() => {
this.retryIntervals[provider] = setInterval(() => {
let retryItems = {
...this.state.RetryItems,
};
const retrySeconds = retryItems[storageType].RetrySeconds - 1;
const retrySeconds = retryItems[provider].RetrySeconds - 1;
if (retrySeconds === 0) {
this.cancelRetryMount(storageType, () => {
this.handleMountUnMount(storageType, true, arg.data.Location);
this.cancelRetryMount(provider, () => {
this.handleMountUnMount(provider, true, arg.data.Location);
});
} else {
retryItems[storageType].RetrySeconds = retrySeconds;
retryItems[provider].RetrySeconds = retrySeconds;
this.setState({
RetryItems: retryItems,
});
@@ -256,11 +264,11 @@ class MountItems extends IPCContainer {
this.props.setAutoMountProcessed(true);
const processAutoMount = (provider) => {
const providerLower = provider.toLowerCase();
if (this.props[providerLower].AutoMount &&
const providerState = this.props.ProviderState[provider];
if (providerState.AutoMount &&
!this.state[provider].Mounted &&
(this.props[providerLower].MountLocation.length > 0)) {
this.handleMountUnMount(provider, true, this.props[providerLower].MountLocation);
(providerState.MountLocation.length > 0)) {
this.handleMountUnMount(provider, true, providerState.MountLocation);
}
};
@@ -275,12 +283,12 @@ class MountItems extends IPCContainer {
if (this.state.DisplayRetry) {
let retryList = [];
let retryListCount = 0;
for (const storageType in this.state.RetryItems) {
if (this.state.RetryItems.hasOwnProperty(storageType)) {
for (const provider in this.state.RetryItems) {
if (this.state.RetryItems.hasOwnProperty(provider)) {
retryListCount++;
retryList.push(<Button
clicked={()=>this.cancelRetryMount(storageType, ()=> this.detectMounts())}
key={'b' + retryListCount}>Cancel {storageType} Remount ({this.state.RetryItems[storageType].RetrySeconds}s)</Button>);
clicked={()=>this.cancelRetryMount(provider, ()=> this.detectMounts())}
key={'b' + retryListCount}>Cancel {provider} Remount ({this.state.RetryItems[provider].RetrySeconds}s)</Button>);
if (retryListCount < Object.keys(this.state.RetryItems).length) {
retryList.push(<div style={{paddingTop: '8px'}} key={'d' + retryListCount}/>);
}
@@ -299,21 +307,15 @@ class MountItems extends IPCContainer {
let items = [];
for (const provider of Constants.PROVIDER_LIST) {
const providerLower = provider.toLowerCase();
items.push((
<MountItem allowConfig={this.props.allowConfig}
allowMount={this.state[provider].AllowMount}
autoMount={this.props[providerLower].AutoMount}
autoMountChanged={(e)=>this.props.autoMountChanged(provider, e)}
autoRestart={this.props[providerLower].AutoRestart}
autoRestartChanged={(e)=>this.props.autoRestartChanged(provider, e)}
browseClicked={this.handleBrowseLocation}
changed={(e) => this.handleMountLocationChanged(provider, e.target.value)}
changed={e => this.handleMountLocationChanged(provider, e.target.value)}
clicked={this.handleMountUnMount}
configClicked={()=>this.props.displayConfiguration(provider)}
items={this.state[provider].DriveLetters}
key={'mi_' + items.length}
location={this.props[providerLower].MountLocation}
provider={provider}
mounted={this.state[provider].Mounted}
title={provider} />
));
@@ -335,14 +337,15 @@ const mapStateToProps = state => {
return {
AutoMountProcessed: state.mounts.AutoMountProcessed,
Platform: state.common.Platform,
ProviderState: state.mounts.ProviderState,
}
};
const mapDispatchToProps = dispatch => {
return {
displayConfiguration: storageType => dispatch(displayConfiguration(storageType)),
setAutoMountProcessed: processed => dispatch(setAutoMountProcessed(processed)),
setMountsBusy: busy => dispatch(setBusy(busy)),
setProviderState: (provider, state) => dispatch(setProviderState(provider, state)),
}
};