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
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Input} from 'antd';
|
import {Button, Input} from 'antd';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
type PowerSearchIntegerTermProps = {
|
type PowerSearchIntegerTermProps = {
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
onChange: (value: number) => void;
|
onChange: (value: number) => void;
|
||||||
|
defaultValue?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PowerSearchIntegerTerm: React.FC<PowerSearchIntegerTermProps> = ({
|
export const PowerSearchIntegerTerm: React.FC<PowerSearchIntegerTermProps> = ({
|
||||||
onCancel,
|
onCancel,
|
||||||
onChange,
|
onChange,
|
||||||
|
defaultValue,
|
||||||
}) => {
|
}) => {
|
||||||
|
const [editing, setEditing] = React.useState(!defaultValue);
|
||||||
|
|
||||||
|
if (editing) {
|
||||||
return (
|
return (
|
||||||
<Input
|
<Input
|
||||||
autoFocus
|
autoFocus
|
||||||
@@ -36,6 +41,8 @@ export const PowerSearchIntegerTerm: React.FC<PowerSearchIntegerTermProps> = ({
|
|||||||
onBlur={(event) => {
|
onBlur={(event) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
|
|
||||||
|
setEditing(false);
|
||||||
|
|
||||||
if (!newValue) {
|
if (!newValue) {
|
||||||
onCancel();
|
onCancel();
|
||||||
return;
|
return;
|
||||||
@@ -51,6 +58,10 @@ export const PowerSearchIntegerTerm: React.FC<PowerSearchIntegerTermProps> = ({
|
|||||||
}}
|
}}
|
||||||
type="number"
|
type="number"
|
||||||
step={1}
|
step={1}
|
||||||
|
defaultValue={defaultValue}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Button onClick={() => setEditing(true)}>{defaultValue}</Button>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
|
|||||||
searchValue: newValue,
|
searchValue: newValue,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
defaultValue={searchTerm.searchValue}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@@ -181,6 +182,21 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'INTEGER': {
|
||||||
|
searchValueComponent = (
|
||||||
|
<PowerSearchIntegerTerm
|
||||||
|
onCancel={onCancel}
|
||||||
|
onChange={(newValue) => {
|
||||||
|
onFinalize({
|
||||||
|
...searchTerm,
|
||||||
|
searchValue: newValue,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
defaultValue={searchTerm.searchValue}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'ENUM': {
|
case 'ENUM': {
|
||||||
searchValueComponent = (
|
searchValueComponent = (
|
||||||
<PowerSearchEnumTerm
|
<PowerSearchEnumTerm
|
||||||
|
|||||||
Reference in New Issue
Block a user