Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.

Commit a9702a1

Browse files
authored
fix: allow port input to be empty COMPASS-4607 (#261)
* Update port-input.jsx * Update port-input.jsx * Update port-input.jsx * fix: allow empty port in input
1 parent 7b78dd5 commit a9702a1

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/components/form/port-input.jsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,39 @@ import FormInput from './form-input';
77
class PortInput extends React.PureComponent {
88
static displayName = 'PortInput';
99

10-
static propTypes = { port: PropTypes.number, isPortChanged: PropTypes.bool };
10+
static propTypes = {
11+
port: PropTypes.number // initial port
12+
};
13+
14+
constructor(props) {
15+
super(props);
16+
this.state = { port: props.port };
17+
}
1118

1219
/**
1320
* Changes port.
1421
*
1522
* @param {Object} evt - evt.
1623
*/
1724
onPortChanged(evt) {
18-
Actions.onPortChanged(+evt.target.value);
25+
this.setState({ port: evt.target.value });
26+
Actions.onPortChanged(evt.target.value ? +evt.target.value : 27017);
1927
}
2028

21-
/**
22-
* Gets port.
23-
*
24-
* @returns {Number} port.
25-
*/
26-
getPort() {
27-
if (this.props.isPortChanged === false) {
28-
return 27017;
29+
render() {
30+
if (!this.state) {
31+
return;
2932
}
3033

31-
return +this.props.port;
32-
}
33-
34-
render() {
3534
return (
3635
<FormInput
3736
label="Port"
3837
name="port"
3938
placeholder="27017"
4039
changeHandler={this.onPortChanged.bind(this)}
41-
value={this.getPort()}
40+
value={this.state.port}
4241
type="number"
43-
otherInputAttributes={{min: 1, max: 65536}} />
42+
otherInputAttributes={{ min: 1, max: 65536 }} />
4443
);
4544
}
4645
}

0 commit comments

Comments
 (0)