From 8ffdd321b343cbecfdf19a3afae67f6649ba60aa Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 3 May 2021 17:22:31 -0500 Subject: [PATCH] Check for duplicate portals --- src/constants.js | 1 + src/containers/AddEditHost/AddEditHost.js | 23 ++++++++++++++++++----- src/containers/HostList/HostList.js | 6 +----- src/redux/reducers/host_reducer.js | 2 ++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/constants.js b/src/constants.js index e4e68d7..28e36dc 100644 --- a/src/constants.js +++ b/src/constants.js @@ -57,6 +57,7 @@ exports.WINFSP_VERSION_NAMES = [ 'WinFsp 2020.0', 'WinFsp 2020.1', 'WinFsp 2020.2', + 'WinFsp 2021', 'WinFsp 2021 B1', 'WinFsp 2021 B2', 'WinFsp 2021 Beta1', diff --git a/src/containers/AddEditHost/AddEditHost.js b/src/containers/AddEditHost/AddEditHost.js index e5bed23..57c0d02 100644 --- a/src/containers/AddEditHost/AddEditHost.js +++ b/src/containers/AddEditHost/AddEditHost.js @@ -24,13 +24,9 @@ class AddEditHost extends Component { TimeoutMs: 60000, }; - originalState = {}; - componentDidMount() { if (this.props.HostData) { - const state = { ...this.state, ...this.props.HostData }; - this.originalState = { ...state }; - this.setState(state); + this.setState({ ...this.state, ...this.props.HostData }); } } @@ -39,14 +35,29 @@ class AddEditHost extends Component { this.props.notifyError('Host / IP cannot be empty'); return; } + if (this.state.HostNameOrIp.trim().indexOf('/') >= 0) { this.props.notifyError(`Host / IP cannot be contain '/'`); return; } + if (this.state.HostNameOrIp.trim().indexOf(':') >= 0) { this.props.notifyError(`Host / IP cannot be contain ':'`); return; } + + if ( + this.props.HostList.find( + (i) => + (i.HostNameOrIp || '').trim() === this.state.HostNameOrIp && + i.Protocol === this.state.Protocol && + i.ApiPort == this.state.ApiPort + ) + ) { + this.props.notifyError(`Portal already exists`); + return; + } + this.props.completeAddEditHost(this.state); }; @@ -200,6 +211,7 @@ class AddEditHost extends Component { const mapStateToProps = (state) => { return { HostData: state.host.HostData, + HostList: state.host.HostList, }; }; @@ -215,6 +227,7 @@ AddEditHost.propTypes = { Close: PropTypes.func.isRequired, completeAddEditHost: PropTypes.func.isRequired, HostData: PropTypes.object, + HostList: PropTypes.array.isRequired, notifyError: PropTypes.func.isRequired, }; diff --git a/src/containers/HostList/HostList.js b/src/containers/HostList/HostList.js index c012e93..0130cd5 100644 --- a/src/containers/HostList/HostList.js +++ b/src/containers/HostList/HostList.js @@ -23,10 +23,6 @@ class HostList extends Component { componentWillUnmount() {} - checkDuplicates = () => { - return false; - }; - handleAddHost = () => { this.props.addEditHost(this.state.items, (changed, host_data) => { if (changed) { @@ -87,7 +83,7 @@ class HostList extends Component { onDelete={() => this.handleDeleted(index)} allowDelete={this.state.items.length > 1} host_data={v} - host_list={this.state.items} + host_list={this.state.items.filter((i) => i !== v)} /> ); })} diff --git a/src/redux/reducers/host_reducer.js b/src/redux/reducers/host_reducer.js index 9284ff4..c52ebae 100644 --- a/src/redux/reducers/host_reducer.js +++ b/src/redux/reducers/host_reducer.js @@ -6,6 +6,7 @@ export const hostReducer = createReducer( DisplayAddEditHost: false, Edit: false, HostData: {}, + HostList: [], }, { [Actions.DISPLAY_ADD_EDIT_HOST]: (state, action) => { @@ -14,6 +15,7 @@ export const hostReducer = createReducer( DisplayAddEditHost: action.payload.display, Edit: !!action.payload.host_data, HostData: action.payload.host_data || {}, + HostList: action.payload.host_list || [], }; }, }