Support float operator type
Summary: Project doc: https://docs.google.com/document/d/1miofxds9DJgWScj0zFyBbdpRH5Rj0T9FqiCapof5-vU Reviewed By: lblasa Differential Revision: D48605219 fbshipit-source-id: 9b919fe59278f77cdbbc036948eb04d585b25baa
This commit is contained in:
committed by
Facebook GitHub Bot
parent
143dce85f1
commit
9bca358ab2
@@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {Input} from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
type PowerSearchFloatTermProps = {
|
||||||
|
onCancel: () => void;
|
||||||
|
onChange: (value: number) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const PowerSearchFloatTerm: React.FC<PowerSearchFloatTermProps> = ({
|
||||||
|
onCancel,
|
||||||
|
onChange,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<Input
|
||||||
|
autoFocus
|
||||||
|
style={{width: 100}}
|
||||||
|
placeholder="..."
|
||||||
|
onBlur={(event) => {
|
||||||
|
const newValue = event.target.value;
|
||||||
|
|
||||||
|
if (!newValue) {
|
||||||
|
onCancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedValue = parseFloat(newValue);
|
||||||
|
onChange(normalizedValue);
|
||||||
|
}}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === 'Enter' || event.key === 'Escape') {
|
||||||
|
event.currentTarget.blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
type="number"
|
||||||
|
step={0.1}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -11,6 +11,7 @@ import {CloseOutlined} from '@ant-design/icons';
|
|||||||
import {Button, Space} from 'antd';
|
import {Button, Space} from 'antd';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {FieldConfig, OperatorConfig} from './PowerSearchConfig';
|
import {FieldConfig, OperatorConfig} from './PowerSearchConfig';
|
||||||
|
import {PowerSearchFloatTerm} from './PowerSearchFloatTerm';
|
||||||
import {PowerSearchIntegerTerm} from './PowerSearchIntegerTerm';
|
import {PowerSearchIntegerTerm} from './PowerSearchIntegerTerm';
|
||||||
import {PowerSearchStringTerm} from './PowerSearchStringTerm';
|
import {PowerSearchStringTerm} from './PowerSearchStringTerm';
|
||||||
|
|
||||||
@@ -64,6 +65,20 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'FLOAT': {
|
||||||
|
searchValueInputComponent = (
|
||||||
|
<PowerSearchFloatTerm
|
||||||
|
onCancel={onCancel}
|
||||||
|
onChange={(newValue) => {
|
||||||
|
onFinalize({
|
||||||
|
...searchTerm,
|
||||||
|
searchValue: newValue,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
console.error(
|
console.error(
|
||||||
'PowerSearchTerm -> unknownoperator.valueType',
|
'PowerSearchTerm -> unknownoperator.valueType',
|
||||||
|
|||||||
Reference in New Issue
Block a user