Skip to content

Commit 9ed0e9e

Browse files
committed
Accept new form of download:upload limit for bwlimit. Fixes #120
1 parent 46983b3 commit 9ed0e9e

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/views/Base/BandwidthStatusCard/BandwidthStatusCard.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ class BandwidthStatusCard extends React.Component {
3636
const {bandwidthText, hasError} = this.state;
3737
if (!hasError) {
3838
const {setBandwidth} = this.props;
39-
if (bandwidthText)
39+
if (bandwidthText) {
4040
setBandwidth(bandwidthText);
41+
this.toggleShowChangeBandwidth();
42+
}
4143
else {
4244
setBandwidth("0M");
4345
}
4446
} else {
45-
toast.error("Error in form");
47+
toast.error("Please check the errors before submitting");
4648
}
4749
};
4850

@@ -53,10 +55,22 @@ class BandwidthStatusCard extends React.Component {
5355
*/
5456
changeBandwidthInput = (e) => {
5557
const inputValue = e.target.value;
56-
const validateInput = validateSizeSuffix(inputValue);
58+
let validateInput = false;
59+
if (inputValue === "") {
60+
validateInput = true;
61+
} else if (inputValue) {
62+
const splitValue = inputValue.split(":");
63+
if(splitValue.length === 1) {
64+
validateInput = validateSizeSuffix(splitValue[0]);
65+
}else if(splitValue.length === 2) {
66+
const validateDownloadLimit = validateSizeSuffix(splitValue[0]);
67+
const validateUploadLimit = validateSizeSuffix(splitValue[1]);
68+
validateInput = validateDownloadLimit && validateUploadLimit;
69+
}
70+
}
5771
this.setState({
5872
bandwidthText: inputValue,
59-
hasError: (inputValue !== "" ? !validateInput : false)
73+
hasError: !validateInput
6074
})
6175
};
6276

@@ -94,15 +108,14 @@ class BandwidthStatusCard extends React.Component {
94108
</p>
95109
<Form onSubmit={this.setBandwidth} className={showChangeBandwidth ? "" : "d-none"}>
96110
<FormGroup row>
97-
<Label for="bandwidthValue" sm={5}>Enter new max speed</Label>
111+
<Label for="bandwidthValue" sm={5}>Enter new max speed (upload:download)</Label>
98112
<Col sm={7}>
99113
<Input type="text" value={bandwidthText}
100114
valid={!hasError} invalid={hasError}
101115
id="bandwidthValue" onChange={this.changeBandwidthInput}>
102116
</Input>
103117
<FormFeedback valid>Keep empty to reset.</FormFeedback>
104-
<FormFeedback>The bandwidth should be of the form 1M|2M|1G|1K|1.1K
105-
etc</FormFeedback>
118+
<FormFeedback>The bandwidth should be of the form 1M|2M|1G|1K|1.1K etc. Can also be specified as (upload:download)</FormFeedback>
106119

107120
</Col>
108121
</FormGroup>

src/views/Base/BandwidthStatusCard/__snapshots__/BandwidthStatusCard.test.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ exports[`Bandwidth Status Card should match snapshot 1`] = `
5454
]
5555
}
5656
>
57-
Enter new max speed
57+
Enter new max speed (upload:download)
5858
</Label>
5959
<Col
6060
sm={7}
@@ -86,7 +86,7 @@ exports[`Bandwidth Status Card should match snapshot 1`] = `
8686
<FormFeedback
8787
tag="div"
8888
>
89-
The bandwidth should be of the form 1M|2M|1G|1K|1.1K etc
89+
The bandwidth should be of the form 1M|2M|1G|1K|1.1K etc. Can also be specified as (upload:download)
9090
</FormFeedback>
9191
</Col>
9292
</FormGroup>

0 commit comments

Comments
 (0)