Add float_equals operator
Summary: Doc: https://docs.google.com/document/d/1miofxds9DJgWScj0zFyBbdpRH5Rj0T9FqiCapof5-vU/edit#heading=h.pg8svtdjlx7 Reviewed By: antonk52 Differential Revision: D49230150 fbshipit-source-id: 976055a555d02ea61e29b4f2e939c9c89e44fd49
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a0f02c57e4
commit
51073bc665
@@ -12,10 +12,11 @@
|
|||||||
export type SimpleFilterValueType =
|
export type SimpleFilterValueType =
|
||||||
| 'NO_VALUE'
|
| 'NO_VALUE'
|
||||||
| 'INTEGER'
|
| 'INTEGER'
|
||||||
| 'FLOAT'
|
|
||||||
| 'STRING'
|
| 'STRING'
|
||||||
| 'STRING_SET';
|
| 'STRING_SET';
|
||||||
|
|
||||||
|
export type FloatFilterValueType = 'FLOAT';
|
||||||
|
|
||||||
export type EnumFilterValueType = 'ENUM' | 'ENUM_SET';
|
export type EnumFilterValueType = 'ENUM' | 'ENUM_SET';
|
||||||
|
|
||||||
export type AbsoluteDateFilterValueType = 'ABSOLUTE_DATE';
|
export type AbsoluteDateFilterValueType = 'ABSOLUTE_DATE';
|
||||||
@@ -26,6 +27,13 @@ export type SimpleOperatorConfig = {
|
|||||||
label: string;
|
label: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type FloatOperatorConfig = {
|
||||||
|
valueType: FloatFilterValueType;
|
||||||
|
key: string;
|
||||||
|
label: string;
|
||||||
|
precision?: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type EnumOperatorConfig = {
|
export type EnumOperatorConfig = {
|
||||||
valueType: EnumFilterValueType;
|
valueType: EnumFilterValueType;
|
||||||
key: string;
|
key: string;
|
||||||
@@ -44,6 +52,7 @@ export type AbsoluteDateOperatorConfig = {
|
|||||||
|
|
||||||
export type OperatorConfig =
|
export type OperatorConfig =
|
||||||
| SimpleOperatorConfig
|
| SimpleOperatorConfig
|
||||||
|
| FloatOperatorConfig
|
||||||
| EnumOperatorConfig
|
| EnumOperatorConfig
|
||||||
| AbsoluteDateOperatorConfig;
|
| AbsoluteDateOperatorConfig;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {OperatorConfig} from '../PowerSearch';
|
import {OperatorConfig} from '../PowerSearch';
|
||||||
|
import {FloatOperatorConfig} from '../PowerSearch/PowerSearchConfig';
|
||||||
|
|
||||||
export type PowerSearchOperatorProcessor = (
|
export type PowerSearchOperatorProcessor = (
|
||||||
powerSearchOperatorConfig: OperatorConfig,
|
powerSearchOperatorConfig: OperatorConfig,
|
||||||
@@ -71,6 +72,12 @@ export const dataTablePowerSearchOperators = {
|
|||||||
key: 'int_less_or_equal',
|
key: 'int_less_or_equal',
|
||||||
valueType: 'INTEGER',
|
valueType: 'INTEGER',
|
||||||
}),
|
}),
|
||||||
|
float_equals: (precision: number) => ({
|
||||||
|
label: '=',
|
||||||
|
key: 'float_equals',
|
||||||
|
valueType: 'FLOAT',
|
||||||
|
precision,
|
||||||
|
}),
|
||||||
float_greater_than: () => ({
|
float_greater_than: () => ({
|
||||||
label: '>',
|
label: '>',
|
||||||
key: 'float_greater_than',
|
key: 'float_greater_than',
|
||||||
@@ -165,6 +172,10 @@ export const dataTablePowerSearchOperatorProcessorConfig = {
|
|||||||
value < searchValue,
|
value < searchValue,
|
||||||
int_less_or_equal: (_operator, searchValue: number, value: number) =>
|
int_less_or_equal: (_operator, searchValue: number, value: number) =>
|
||||||
value <= searchValue,
|
value <= searchValue,
|
||||||
|
float_equals: (operator, searchValue: number, value: number) => {
|
||||||
|
const precision = (operator as FloatOperatorConfig).precision ?? 0.01;
|
||||||
|
return value <= searchValue + precision && value >= searchValue - precision;
|
||||||
|
},
|
||||||
float_greater_than: (_operator, searchValue: number, value: number) =>
|
float_greater_than: (_operator, searchValue: number, value: number) =>
|
||||||
value > searchValue,
|
value > searchValue,
|
||||||
float_greater_or_equal: (_operator, searchValue: number, value: number) =>
|
float_greater_or_equal: (_operator, searchValue: number, value: number) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user