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:
committed by
Facebook GitHub Bot
parent
31e93ff3fe
commit
e180a1ed4b
@@ -7,41 +7,52 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {Input} from 'antd';
|
||||
import {Button, Input} from 'antd';
|
||||
import React from 'react';
|
||||
|
||||
type PowerSearchFloatTermProps = {
|
||||
onCancel: () => void;
|
||||
onChange: (value: number) => void;
|
||||
defaultValue?: number;
|
||||
};
|
||||
|
||||
export const PowerSearchFloatTerm: React.FC<PowerSearchFloatTermProps> = ({
|
||||
onCancel,
|
||||
onChange,
|
||||
defaultValue,
|
||||
}) => {
|
||||
return (
|
||||
<Input
|
||||
autoFocus
|
||||
style={{width: 100}}
|
||||
placeholder="..."
|
||||
onBlur={(event) => {
|
||||
const newValue = event.target.value;
|
||||
const [editing, setEditing] = React.useState(!defaultValue);
|
||||
|
||||
if (!newValue) {
|
||||
onCancel();
|
||||
return;
|
||||
}
|
||||
if (editing) {
|
||||
return (
|
||||
<Input
|
||||
autoFocus
|
||||
style={{width: 100}}
|
||||
placeholder="..."
|
||||
onBlur={(event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
const normalizedValue = parseFloat(newValue);
|
||||
onChange(normalizedValue);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Enter' || event.key === 'Escape') {
|
||||
event.currentTarget.blur();
|
||||
}
|
||||
}}
|
||||
type="number"
|
||||
step={0.1}
|
||||
/>
|
||||
);
|
||||
setEditing(false);
|
||||
|
||||
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}
|
||||
defaultValue={defaultValue}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <Button onClick={() => setEditing(true)}>{defaultValue}</Button>;
|
||||
};
|
||||
|
||||
@@ -101,6 +101,7 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
|
||||
searchValue: newValue,
|
||||
});
|
||||
}}
|
||||
defaultValue={searchTerm.searchValue}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
@@ -197,6 +198,21 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'FLOAT': {
|
||||
searchValueComponent = (
|
||||
<PowerSearchFloatTerm
|
||||
onCancel={onCancel}
|
||||
onChange={(newValue) => {
|
||||
onFinalize({
|
||||
...searchTerm,
|
||||
searchValue: newValue,
|
||||
});
|
||||
}}
|
||||
defaultValue={searchTerm.searchValue}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'ENUM': {
|
||||
searchValueComponent = (
|
||||
<PowerSearchEnumTerm
|
||||
|
||||
@@ -73,7 +73,7 @@ export const dataTablePowerSearchOperators = {
|
||||
key: 'int_less_or_equal',
|
||||
valueType: 'INTEGER',
|
||||
}),
|
||||
float_equals: (precision: number) => ({
|
||||
float_equals: (precision?: number) => ({
|
||||
label: '=',
|
||||
key: 'float_equals',
|
||||
valueType: 'FLOAT',
|
||||
|
||||
Reference in New Issue
Block a user