Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make number slider more robust against weird input values #4758

Merged
merged 4 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
### Fixed
- Speed up NML import in existing tracings for NMLs with many trees (20,000+). [#4742](https://github.com/scalableminds/webknossos/pull/4742)
- Fixed tree groups when uploading NMLs with multi-component trees. [#4735](https://github.com/scalableminds/webknossos/pull/4735)
- Fixed that invalid number values in slider settings could crash webKnossos. [#4758](https://github.com/scalableminds/webknossos/pull/4758)

### Removed
-
13 changes: 11 additions & 2 deletions frontend/javascripts/oxalis/view/settings/setting_input_views.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { Row, Col, Slider, InputNumber, Switch, Tooltip, Input, Icon, Select } from "antd";
import * as React from "react";
import _ from "lodash";

import type { Vector3, Vector6 } from "oxalis/constants";
import * as Utils from "libs/utils";
Expand All @@ -23,13 +24,21 @@ export class NumberSliderSetting extends React.PureComponent<NumberSliderSetting
};

_onChange = (_value: number) => {
if (this.props.min <= _value && _value <= this.props.max) {
if (this.isValueValid(_value)) {
this.props.onChange(_value);
}
};

isValueValid = (_value: number) =>
_.isNumber(_value) && _value >= this.props.min && _value <= this.props.max;

philippotto marked this conversation as resolved.
Show resolved Hide resolved
render() {
const { value, label, max, min, step, onChange, disabled } = this.props;
const { value: originalValue, label, max, min, step, onChange, disabled } = this.props;

// Validate the provided value. If it's not valid, fallback to the midpoint between min and max.
// This check guards against broken settings which could be introduced before this component
// checked more thoroughly against invalid values.
const value = this.isValueValid(originalValue) ? originalValue : Math.floor((min + max) / 2);

return (
<Row type="flex" align="middle">
Expand Down