Commit e8550ccd authored by Viacheslav Pavlov's avatar Viacheslav Pavlov
Browse files

Update core filters

parent dc04be56
......@@ -3,11 +3,10 @@
* Defined in OpenAPI as '#/definitions/DateFilter'
*/
class DateFilter {
public between: Date[];
public ge: Date;
public gt: Date;
public le: Date;
public lt: Date;
public ge?: Date;
public gt?: Date;
public le?: Date;
public lt?: Date;
}
......
......@@ -3,12 +3,11 @@
* Defined in Swagger as '#/definitions/NumberFilter«double»'
*/
class NumberFilter {
public between: number[];
public eq: number;
public ge: number;
public gt: number;
public le: number;
public lt: number;
public eq?: number;
public ge?: number;
public gt?: number;
public le?: number;
public lt?: number;
}
......
......@@ -3,6 +3,8 @@ import { Field } from 'redux-form';
import TextField from '@material-ui/core/TextField';
import NumberFilterModel from 'model/NumberFilter';
interface INumberFilterInternal extends React.ClassAttributes<any> {
name: string;
input: any;
......@@ -10,56 +12,49 @@ interface INumberFilterInternal extends React.ClassAttributes<any> {
label: string;
}
// The operations of NumberFilter supported
const opGe = 'ge';
const opLe = 'le';
class NumberFilterInternal extends React.Component<INumberFilterInternal, any> {
private constructor(props, context) {
super(props, context);
const { value } = props.input;
let textA = value[opGe] && value[opGe] || '';
let textB = value[opLe] && value[opLe] || '';
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];
textB = sorted[1];
textA = sorted[0] === 0 ? '0' : sorted[0];
textB = sorted[1] === 0 ? '0' : sorted[1];
}
// console.log('Constructor', textA, textB);
this.state = { textA, textB };
}
public componentWillReceiveProps(nextProps) {
const { value } = nextProps.input;
const textA = value[opGe] && value[opGe] || '';
const textB = value[opLe] && value[opLe] || '';
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 });
}
private report(valueA, valueB) {
private report(filter: NumberFilterModel) {
const { input } = this.props;
if (valueA || valueB) {
const r = { ge: null, le: null };
r[opGe] = valueA && +valueA || undefined;
r[opLe] = valueB && +valueB || undefined;
console.log('Reporting', r);
input.onChange(r);
if (filter) {
console.log('Reporting', filter);
input.onChange(filter);
} else {
input.onChange(null);
}
}
private textAChange = (event) => {
this.setState({ ...this.state, textA: event.target.value });
this.report(event.target.value, this.state.textB);
this.setState({textA: event.target.value , textB: this.state.textB});
this.report({ge: event.target.value, le: this.state.textB});
}
private textBChange = (event) => {
this.setState({ ...this.state, textB: event.target.value });
this.report(this.state.textA, event.target.value);
this.setState({ textA: this.state.textA, textB: event.target.value });
this.report({ge: this.state.textA, le: event.target.value});
}
public render() {
......@@ -88,7 +83,7 @@ interface INumberFilter extends React.ClassAttributes<any> {
label: string;
}
// NumberFilter supports between [a,b], eq, ge, gt, le, lt
// NumberFilter supports eq, ge, gt, le, lt
class NumberFilter extends React.Component<INumberFilter, any> {
public constructor(props: any) {
......
Supports Markdown
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