Commit 1fbae9b8 authored by Matija Obreza's avatar Matija Obreza
Browse files

Fix: swap ge/le if necessary

parent 560111dc
......@@ -14,29 +14,30 @@ interface INumberFilterInternal extends React.ClassAttributes<any> {
t: any;
}
// Utility to place ge/le in the right order
function swapIfNecessary(props) {
const { value }: { value: NumberFilterModel } = props.input;
let textA = value && value.ge !== null ? value.ge : '';
let textB = value && value.le !== null ? value.le : '';
if (textA && textB) {
const sorted = [+textA, +textB].sort((a, b) => a - b);
textA = sorted[0] === 0 ? '0' : sorted[0];
textB = sorted[1] === 0 ? '0' : sorted[1];
// console.log('SwapIfNecessary', sorted, textA, textB);
}
return { textA, textB };
}
class NumberFilterInternal extends React.Component<INumberFilterInternal, any> {
private constructor(props, context) {
super(props, context);
const { value }: { value: NumberFilterModel } = props.input;
let textA = value && value.ge !== null ? value.ge : '';
let textB = value && value.le !== null ? value.le : '';
if (textA && textB) {
const sorted = [ +textA, +textB ].sort((a, b) => b - a);
textA = sorted[0] === 0 ? '0' : sorted[0];
textB = sorted[1] === 0 ? '0' : sorted[1];
}
// console.log('Constructor', textA, textB);
this.state = { textA, textB };
this.state = swapIfNecessary(props);
}
public componentWillReceiveProps(nextProps) {
const { value }: { value: NumberFilterModel } = nextProps.input;
const textA = value && value.ge !== null ? value.ge : '';
const textB = value && value.le !== null ? value.le : '';
// console.log('receive props', textA, textB);
this.setState({ textA, textB });
this.setState(swapIfNecessary(nextProps));
}
private report(filter: NumberFilterModel) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment