Redux changes and refactoring

This commit is contained in:
Scott E. Graves
2019-06-07 23:13:05 -05:00
parent 6499ff4f79
commit 4b93c298c2
9 changed files with 75 additions and 45 deletions

View File

@@ -16,9 +16,9 @@ import Text from './components/UI/Text/Text';
import UpgradeIcon from './components/UpgradeIcon/UpgradeIcon';
import UpgradeUI from './components/UpgradeUI/UpgradeUI';
import {setProviderState} from './redux/actions/mount_actions';
import {detectUIUpgrade, loadReleases, setActiveRelease, setDismissUIUpgrade, setReleaseUpgradeAvailable} from './redux/actions/release_version_actions';
import {detectUIUpgrade, loadReleases, setActiveRelease, setDismissUIUpgrade, setInstalledVersion, setReleaseUpgradeAvailable} from './redux/actions/release_version_actions';
import {downloadItem, setAllowDownload} from './redux/actions/download_actions';
import {installDependency, installRelease, installUpgrade} from './redux/actions/install_actions';
import {installDependency, installRelease, installUpgrade, setMissingDependencies} from './redux/actions/install_actions';
import {notifyError} from './redux/actions/error_actions';
const Constants = require('./constants');
@@ -32,11 +32,6 @@ class App extends IPCContainer {
this.setRequestHandler(Constants.IPC_Get_State_Reply, this.onGetStateReply);
}
state = {
MissingDependencies: [],
InstalledVersion: 'none',
};
checkVersionInstalled = () => {
this.props.setAllowDownload(false);
const selectedVersion = this.getSelectedVersion();
@@ -152,11 +147,8 @@ class App extends IPCContainer {
}
this.props.setReleaseUpgradeAvailable(upgradeAvailable);
this.props.setAllowDownload(true);
this.setState({
MissingDependencies: arg.data.Dependencies,
InstalledVersion: installedVersion,
});
this.props.setInstalledVersion(installedVersion);
this.props.setMissingDependencies(arg.data.Dependencies);
};
if (arg.data.Success) {
@@ -258,7 +250,7 @@ class App extends IPCContainer {
};
waitForDependencyInstall = (source, url) => {
const dep = this.state.MissingDependencies.find(d => {
const dep = this.props.MissingDependencies.find(d => {
return d.download === url;
});
@@ -285,10 +277,10 @@ class App extends IPCContainer {
!this.props.MountsBusy &&
!this.props.DownloadActive &&
(selectedVersion !== 'unavailable') &&
(selectedVersion !== this.state.InstalledVersion);
(selectedVersion !== this.props.InstalledVersion);
const missingDependencies = (this.state.MissingDependencies.length > 0);
const allowMount = this.state.InstalledVersion !== 'none' &&
const missingDependencies = (this.props.MissingDependencies.length > 0);
const allowMount = this.props.InstalledVersion !== 'none' &&
!missingDependencies &&
!this.props.InstallActive;
@@ -337,9 +329,7 @@ class App extends IPCContainer {
if (showDependencies) {
dependencyDisplay = (
<Modal>
<DependencyList allowDownload={this.props.DownloadType !== Constants.INSTALL_TYPES.Dependency}
dependencies={this.state.MissingDependencies}
onDownload={this.handleDownloadDependency}/>
<DependencyList onDownload={this.handleDownloadDependency}/>
</Modal>
);
}
@@ -368,11 +358,8 @@ class App extends IPCContainer {
mainContent.push((
<div key={'rvd_' + key++}
style={{height: '32%'}}>
<ReleaseVersionDisplay disabled={this.props.DownloadActive || this.props.InstallActive || this.props.MountsBusy}
downloadClicked={this.handleDownloadRelease}
downloadDisabled={!downloadEnabled}
releaseExtracting={this.props.InstallType === Constants.INSTALL_TYPES.Release}
text={this.state.InstalledVersion + ' [' + this.props.AppPlatform + ']'}/>
<ReleaseVersionDisplay downloadClicked={this.handleDownloadRelease}
downloadDisabled={!downloadEnabled}/>
</div>
));
@@ -381,8 +368,7 @@ class App extends IPCContainer {
<div key={'md_' + key++}>
<MountItems allowConfig={allowConfig}
allowSiaPrime={allowSiaPrime}
noConsoleSupported={noConsoleSupported}
version={this.state.InstalledVersion}/>
noConsoleSupported={noConsoleSupported}/>
</div>
));
}
@@ -440,7 +426,9 @@ const mapStateToProps = state => {
DownloadType: state.download.DownloadType,
InstallActive: state.install.InstallActive,
InstallType: state.install.InstallType,
InstalledVersion: state.relver.InstalledVersion,
LocationsLookup: state.relver.LocationsLookup,
MissingDependencies: state.install.MissingDependencies,
MountsBusy: state.mounts.MountsBusy,
Platform: state.common.Platform,
ProviderState: state.mounts.ProviderState,
@@ -466,6 +454,8 @@ const mapDispatchToProps = dispatch => {
setActiveRelease: (release, version) => dispatch(setActiveRelease(release, version)),
setAllowDownload: allow => dispatch(setAllowDownload(allow)),
setDismissUIUpgrade: dismiss => dispatch(setDismissUIUpgrade(dismiss)),
setInstalledVersion: version => dispatch(setInstalledVersion(version)),
setMissingDependencies: dependencies => dispatch(setMissingDependencies(dependencies)),
setProviderState: (provider, state) => dispatch(setProviderState(provider, state)),
setReleaseUpgradeAvailable: available => dispatch(setReleaseUpgradeAvailable(available)),
};

View File

@@ -1,7 +1,15 @@
import React from 'react';
import './Dependency.css';
import {connect} from 'react-redux';
import * as Constants from '../../../constants';
export default props => {
const mapStateToProps = state => {
return {
AllowDownload: (state.download.DownloadType !== Constants.INSTALL_TYPES.Dependency),
};
};
export default connect(mapStateToProps)(props => {
return (
<div className={'Dependency'}>
<table width="100%">
@@ -11,7 +19,7 @@ export default props => {
<h3>{props.name}</h3>
</td>
<td>
{props.allowDownload ?
{props.AllowDownload ?
<a href={void(0)} className={'DependencyLink'} onClick={()=>{props.onDownload(props.download); return false;}}><u>Install</u></a> :
'Installing...'}
</td>
@@ -20,4 +28,4 @@ export default props => {
</table>
</div>
);
};
});

View File

@@ -1,13 +1,19 @@
import React from 'react';
import './DependencyList.css';
import {connect} from 'react-redux';
import Dependency from './Dependency/Dependency';
import Box from '../UI/Box/Box';
export default props => {
const items = props.dependencies.map((k, i)=> {
const mapStateToProps = state => {
return {
MissingDependencies: state.install.MissingDependencies,
};
};
export default connect(mapStateToProps)(props => {
const items = props.MissingDependencies.map((k, i)=> {
return (
<Dependency allowDownload={props.allowDownload}
download={k.download}
<Dependency download={k.download}
key={i}
name={k.display}
onDownload={props.onDownload}/>
@@ -22,5 +28,4 @@ export default props => {
{items}
</Box>
);
};
});

View File

@@ -11,6 +11,12 @@ import {setActiveRelease} from "../../redux/actions/release_version_actions";
const mapStateToProps = state => {
return {
AppPlatform: state.common.AppPlatform,
DownloadActive: state.download.DownloadActive,
InstallActive: state.install.InstallActive,
InstallType: state.install.InstallType,
InstalledVersion: state.relver.InstalledVersion,
MountsBusy: state.mounts.MountsBusy,
Release: state.relver.Release,
ReleaseUpgradeAvailable: state.relver.ReleaseUpgradeAvailable,
ReleaseVersion: state.relver.Version,
@@ -35,9 +41,13 @@ export default connect(mapStateToProps, mapDispatchToProps)(props => {
props.setActiveRelease(props.Release, parseInt(e.target.value, 10));
};
const text = props.InstalledVersion + ' [' + props.AppPlatform + ']';
const disabled = props.DownloadActive || props.InstallActive || props.MountsBusy;
const releaseExtracting = (props.InstallType === Constants.INSTALL_TYPES.Release);
let optionsDisplay = [];
let key = 0;
if (props.releaseExtracting) {
if (releaseExtracting) {
optionsDisplay.push((
<Text col={dimensions => (dimensions.columns / 3) * 2}
colSpan={'remain'}
@@ -53,7 +63,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(props => {
key={key++}
row={5}
rowSpan={7}
text={props.text}
text={text}
textAlign={'left'}/>
));
} else if (props.downloadDisabled) {
@@ -73,7 +83,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(props => {
key={key++}
row={5}
rowSpan={7}
text={props.text}
text={text}
textAlign={'left'}/>
));
} else {
@@ -97,7 +107,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(props => {
type={'Heading2'}/>
<DropDown changed={handleReleaseChanged}
colSpan={remain=>remain / 3 - 1}
disabled={props.disabled}
disabled={disabled}
items={Constants.RELEASE_TYPES}
row={5}
rowSpan={7}
@@ -116,7 +126,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(props => {
<DropDown changed={handleVersionChanged}
col={dimensions => dimensions.columns / 3}
colSpan={remain=>remain / 2 - 1}
disabled={props.disabled}
disabled={disabled}
items={props.VersionLookup[Constants.RELEASE_TYPES[props.Release]]}
row={5}
rowSpan={7}

View File

@@ -73,7 +73,7 @@ class MountItems extends IPCContainer {
if (!this.state.DisplayRetry) {
this.props.setMountsBusy(true);
this.sendRequest(Constants.IPC_Detect_Mounts, {
Version: this.props.version,
Version: this.props.InstalledVersion,
});
}
};
@@ -108,7 +108,7 @@ class MountItems extends IPCContainer {
if (mount) {
let result = this.sendSyncRequest(Constants.IPC_Check_Daemon_Version, {
Provider: provider,
Version: this.props.version
Version: this.props.InstalledVersion
}).data;
if (result.Success) {
if (result.Valid) {
@@ -146,13 +146,13 @@ class MountItems extends IPCContainer {
Location: location,
NoConsoleSupported: this.props.noConsoleSupported,
Provider: provider,
Version: this.props.version,
Version: this.props.InstalledVersion,
});
} else {
this.sendRequest(Constants.IPC_Unmount_Drive, {
Location: location,
Provider: provider,
Version: this.props.version,
Version: this.props.InstalledVersion,
});
}
}
@@ -309,6 +309,7 @@ class MountItems extends IPCContainer {
const mapStateToProps = state => {
return {
AutoMountProcessed: state.mounts.AutoMountProcessed,
InstalledVersion: state.relver.InstalledVersion,
MountState: state.mounts.MountState,
Platform: state.common.Platform,
ProviderState: state.mounts.ProviderState,

View File

@@ -78,3 +78,4 @@ export const installUpgrade = (source, sha256, signature, skipVerification, comp
export const setInstallActive = createAction('install/setInstallActive');
export const setInstallComplete = createAction('install/setInstallComplete');
export const setMissingDependencies = createAction('install/setMissingDependencies');

View File

@@ -101,6 +101,7 @@ export const setActiveRelease = (release, version) => {
};
export const setDismissUIUpgrade = createAction('relver/setDismissUIUpgrade');
export const setInstalledVersion = createAction('relver/setInstalledVersion');
export const SET_RELEASE_DATA = 'relver/setReleaseData';
export const setReleaseData = (locationsLookup, versionLookup)=> {

View File

@@ -1,10 +1,11 @@
import {createReducer} from 'redux-starter-kit';
import {setInstallActive, setInstallComplete} from '../actions/install_actions';
import {setInstallActive, setInstallComplete, setMissingDependencies} from '../actions/install_actions';
export const installReducer = createReducer({
InstallActive: false,
InstallResult: null,
InstallType: null,
MissingDependencies: [],
}, {
[setInstallActive]: (state, action) => {
return {
@@ -21,5 +22,11 @@ export const installReducer = createReducer({
InstallResult: action.payload,
InstallType: null,
}
},
[setMissingDependencies]: (state, action) => {
return {
...state,
MissingDependencies: action.payload,
}
}
});

View File

@@ -14,6 +14,7 @@ const versionLookup = Constants.RELEASE_TYPES.map(k=> {
});
export const releaseVersionReducer = createReducer({
InstalledVersion: 'none',
LocationsLookup: {},
Release: 2,
ReleaseUpgradeAvailable: false,
@@ -43,6 +44,12 @@ export const releaseVersionReducer = createReducer({
UpgradeDismissed: action.payload,
};
},
[Actions.setInstalledVersion]: (state, action) => {
return {
...state,
InstalledVersion: action.payload,
}
},
[Actions.SET_RELEASE_DATA]: (state, action) => {
return {
...state,