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
|
* @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,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
const [editing, setEditing] = React.useState(!defaultValue);
|
||||||
<Input
|
|
||||||
autoFocus
|
|
||||||
style={{width: 100}}
|
|
||||||
placeholder="..."
|
|
||||||
onBlur={(event) => {
|
|
||||||
const newValue = event.target.value;
|
|
||||||
|
|
||||||
if (!newValue) {
|
if (editing) {
|
||||||
onCancel();
|
return (
|
||||||
return;
|
<Input
|
||||||
}
|
autoFocus
|
||||||
|
style={{width: 100}}
|
||||||
|
placeholder="..."
|
||||||
|
onBlur={(event) => {
|
||||||
|
const newValue = event.target.value;
|
||||||
|
|
||||||
const normalizedValue = parseFloat(newValue);
|
setEditing(false);
|
||||||
onChange(normalizedValue);
|
|
||||||
}}
|
if (!newValue) {
|
||||||
onKeyDown={(event) => {
|
onCancel();
|
||||||
if (event.key === 'Enter' || event.key === 'Escape') {
|
return;
|
||||||
event.currentTarget.blur();
|
}
|
||||||
}
|
|
||||||
}}
|
const normalizedValue = parseFloat(newValue);
|
||||||
type="number"
|
onChange(normalizedValue);
|
||||||
step={0.1}
|
}}
|
||||||
/>
|
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,
|
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
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
Reference in New Issue
Block a user