Check for duplicate portals

This commit is contained in:
2021-05-03 17:22:31 -05:00
parent 33145ef629
commit 8ffdd321b3
4 changed files with 22 additions and 10 deletions

View File

@@ -57,6 +57,7 @@ exports.WINFSP_VERSION_NAMES = [
'WinFsp 2020.0', 'WinFsp 2020.0',
'WinFsp 2020.1', 'WinFsp 2020.1',
'WinFsp 2020.2', 'WinFsp 2020.2',
'WinFsp 2021',
'WinFsp 2021 B1', 'WinFsp 2021 B1',
'WinFsp 2021 B2', 'WinFsp 2021 B2',
'WinFsp 2021 Beta1', 'WinFsp 2021 Beta1',

View File

@@ -24,13 +24,9 @@ class AddEditHost extends Component {
TimeoutMs: 60000, TimeoutMs: 60000,
}; };
originalState = {};
componentDidMount() { componentDidMount() {
if (this.props.HostData) { if (this.props.HostData) {
const state = { ...this.state, ...this.props.HostData }; this.setState({ ...this.state, ...this.props.HostData });
this.originalState = { ...state };
this.setState(state);
} }
} }
@@ -39,14 +35,29 @@ class AddEditHost extends Component {
this.props.notifyError('Host / IP cannot be empty'); this.props.notifyError('Host / IP cannot be empty');
return; return;
} }
if (this.state.HostNameOrIp.trim().indexOf('/') >= 0) { if (this.state.HostNameOrIp.trim().indexOf('/') >= 0) {
this.props.notifyError(`Host / IP cannot be contain '/'`); this.props.notifyError(`Host / IP cannot be contain '/'`);
return; return;
} }
if (this.state.HostNameOrIp.trim().indexOf(':') >= 0) { if (this.state.HostNameOrIp.trim().indexOf(':') >= 0) {
this.props.notifyError(`Host / IP cannot be contain ':'`); this.props.notifyError(`Host / IP cannot be contain ':'`);
return; 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); this.props.completeAddEditHost(this.state);
}; };
@@ -200,6 +211,7 @@ class AddEditHost extends Component {
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
return { return {
HostData: state.host.HostData, HostData: state.host.HostData,
HostList: state.host.HostList,
}; };
}; };
@@ -215,6 +227,7 @@ AddEditHost.propTypes = {
Close: PropTypes.func.isRequired, Close: PropTypes.func.isRequired,
completeAddEditHost: PropTypes.func.isRequired, completeAddEditHost: PropTypes.func.isRequired,
HostData: PropTypes.object, HostData: PropTypes.object,
HostList: PropTypes.array.isRequired,
notifyError: PropTypes.func.isRequired, notifyError: PropTypes.func.isRequired,
}; };

View File

@@ -23,10 +23,6 @@ class HostList extends Component {
componentWillUnmount() {} componentWillUnmount() {}
checkDuplicates = () => {
return false;
};
handleAddHost = () => { handleAddHost = () => {
this.props.addEditHost(this.state.items, (changed, host_data) => { this.props.addEditHost(this.state.items, (changed, host_data) => {
if (changed) { if (changed) {
@@ -87,7 +83,7 @@ class HostList extends Component {
onDelete={() => this.handleDeleted(index)} onDelete={() => this.handleDeleted(index)}
allowDelete={this.state.items.length > 1} allowDelete={this.state.items.length > 1}
host_data={v} host_data={v}
host_list={this.state.items} host_list={this.state.items.filter((i) => i !== v)}
/> />
); );
})} })}

View File

@@ -6,6 +6,7 @@ export const hostReducer = createReducer(
DisplayAddEditHost: false, DisplayAddEditHost: false,
Edit: false, Edit: false,
HostData: {}, HostData: {},
HostList: [],
}, },
{ {
[Actions.DISPLAY_ADD_EDIT_HOST]: (state, action) => { [Actions.DISPLAY_ADD_EDIT_HOST]: (state, action) => {
@@ -14,6 +15,7 @@ export const hostReducer = createReducer(
DisplayAddEditHost: action.payload.display, DisplayAddEditHost: action.payload.display,
Edit: !!action.payload.host_data, Edit: !!action.payload.host_data,
HostData: action.payload.host_data || {}, HostData: action.payload.host_data || {},
HostList: action.payload.host_list || [],
}; };
}, },
} }