Make integer term editable
Summary: For the purposes of the demo I added power search config for an integer field to the summary field Reviewed By: lblasa Differential Revision: D49452729 fbshipit-source-id: 78b8fdccfd799a0f71f652d90d10e11db237cbae
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b3fe4c9650
commit
31e93ff3fe
@@ -7,18 +7,23 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {Input} from 'antd';
|
||||
import {Button, Input} from 'antd';
|
||||
import React from 'react';
|
||||
|
||||
type PowerSearchIntegerTermProps = {
|
||||
onCancel: () => void;
|
||||
onChange: (value: number) => void;
|
||||
defaultValue?: number;
|
||||
};
|
||||
|
||||
export const PowerSearchIntegerTerm: React.FC<PowerSearchIntegerTermProps> = ({
|
||||
onCancel,
|
||||
onChange,
|
||||
defaultValue,
|
||||
}) => {
|
||||
const [editing, setEditing] = React.useState(!defaultValue);
|
||||
|
||||
if (editing) {
|
||||
return (
|
||||
<Input
|
||||
autoFocus
|
||||
@@ -36,6 +41,8 @@ export const PowerSearchIntegerTerm: React.FC<PowerSearchIntegerTermProps> = ({
|
||||
onBlur={(event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
setEditing(false);
|
||||
|
||||
if (!newValue) {
|
||||
onCancel();
|
||||
return;
|
||||
@@ -51,6 +58,10 @@ export const PowerSearchIntegerTerm: React.FC<PowerSearchIntegerTermProps> = ({
|
||||
}}
|
||||
type="number"
|
||||
step={1}
|
||||
defaultValue={defaultValue}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <Button onClick={() => setEditing(true)}>{defaultValue}</Button>;
|
||||
};
|
||||
|
||||
@@ -86,6 +86,7 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
|
||||
searchValue: newValue,
|
||||
});
|
||||
}}
|
||||
defaultValue={searchTerm.searchValue}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
@@ -181,6 +182,21 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'INTEGER': {
|
||||
searchValueComponent = (
|
||||
<PowerSearchIntegerTerm
|
||||
onCancel={onCancel}
|
||||
onChange={(newValue) => {
|
||||
onFinalize({
|
||||
...searchTerm,
|
||||
searchValue: newValue,
|
||||
});
|
||||
}}
|
||||
defaultValue={searchTerm.searchValue}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'ENUM': {
|
||||
searchValueComponent = (
|
||||
<PowerSearchEnumTerm
|
||||
|
||||
Reference in New Issue
Block a user