Make float term editable

Summary: For the purposes of the demo I added power search config for a float field to the summary field

Reviewed By: lblasa

Differential Revision: D49452844

fbshipit-source-id: 26aaadd07a1a8a67dfcf3cb9d8e487f8f4ee2214
This commit is contained in:
Andrey Goncharov
2023-09-20 04:36:57 -07:00
committed by Facebook GitHub Bot
parent 31e93ff3fe
commit e180a1ed4b
3 changed files with 52 additions and 25 deletions

View File

@@ -7,18 +7,23 @@
* @format * @format
*/ */
import {Input} from 'antd'; import {Button, Input} from 'antd';
import React from 'react'; import React from 'react';
type PowerSearchFloatTermProps = { type PowerSearchFloatTermProps = {
onCancel: () => void; onCancel: () => void;
onChange: (value: number) => void; onChange: (value: number) => void;
defaultValue?: number;
}; };
export const PowerSearchFloatTerm: React.FC<PowerSearchFloatTermProps> = ({ export const PowerSearchFloatTerm: React.FC<PowerSearchFloatTermProps> = ({
onCancel, onCancel,
onChange, onChange,
defaultValue,
}) => { }) => {
const [editing, setEditing] = React.useState(!defaultValue);
if (editing) {
return ( return (
<Input <Input
autoFocus autoFocus
@@ -27,6 +32,8 @@ export const PowerSearchFloatTerm: React.FC<PowerSearchFloatTermProps> = ({
onBlur={(event) => { onBlur={(event) => {
const newValue = event.target.value; const newValue = event.target.value;
setEditing(false);
if (!newValue) { if (!newValue) {
onCancel(); onCancel();
return; return;
@@ -42,6 +49,10 @@ export const PowerSearchFloatTerm: React.FC<PowerSearchFloatTermProps> = ({
}} }}
type="number" type="number"
step={0.1} step={0.1}
defaultValue={defaultValue}
/> />
); );
}
return <Button onClick={() => setEditing(true)}>{defaultValue}</Button>;
}; };

View File

@@ -101,6 +101,7 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
searchValue: newValue, searchValue: newValue,
}); });
}} }}
defaultValue={searchTerm.searchValue}
/> />
); );
break; break;
@@ -197,6 +198,21 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
); );
break; break;
} }
case 'FLOAT': {
searchValueComponent = (
<PowerSearchFloatTerm
onCancel={onCancel}
onChange={(newValue) => {
onFinalize({
...searchTerm,
searchValue: newValue,
});
}}
defaultValue={searchTerm.searchValue}
/>
);
break;
}
case 'ENUM': { case 'ENUM': {
searchValueComponent = ( searchValueComponent = (
<PowerSearchEnumTerm <PowerSearchEnumTerm

View File

@@ -73,7 +73,7 @@ export const dataTablePowerSearchOperators = {
key: 'int_less_or_equal', key: 'int_less_or_equal',
valueType: 'INTEGER', valueType: 'INTEGER',
}), }),
float_equals: (precision: number) => ({ float_equals: (precision?: number) => ({
label: '=', label: '=',
key: 'float_equals', key: 'float_equals',
valueType: 'FLOAT', valueType: 'FLOAT',