Make string term editable
Summary: At the end of the stack we are going to unify two branches of the switch-case in PowerSearchTerm.tsx. Each search term is going to handle the finalized and "editing" mode internally Reviewed By: lblasa Differential Revision: D49451975 fbshipit-source-id: 587ba332d1fbfbaefb368e37965543575e64062f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0540d240c0
commit
09cb48a3e3
@@ -7,18 +7,23 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Input} from 'antd';
|
import {Button, Input} from 'antd';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
type PowerSearchStringTermProps = {
|
type PowerSearchStringTermProps = {
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
onChange: (value: string) => void;
|
onChange: (value: string) => void;
|
||||||
|
defaultValue?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PowerSearchStringTerm: React.FC<PowerSearchStringTermProps> = ({
|
export const PowerSearchStringTerm: React.FC<PowerSearchStringTermProps> = ({
|
||||||
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 PowerSearchStringTerm: React.FC<PowerSearchStringTermProps> = ({
|
|||||||
onBlur={(event) => {
|
onBlur={(event) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
|
|
||||||
|
setEditing(false);
|
||||||
|
|
||||||
if (!newValue) {
|
if (!newValue) {
|
||||||
onCancel();
|
onCancel();
|
||||||
return;
|
return;
|
||||||
@@ -39,6 +46,10 @@ export const PowerSearchStringTerm: React.FC<PowerSearchStringTermProps> = ({
|
|||||||
event.currentTarget.blur();
|
event.currentTarget.blur();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
defaultValue={defaultValue}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Button onClick={() => setEditing(true)}>{defaultValue}</Button>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
|
|||||||
searchValue: newValue,
|
searchValue: newValue,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
defaultValue={searchTerm.searchValue}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@@ -164,6 +165,21 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (searchTerm.operator.valueType) {
|
switch (searchTerm.operator.valueType) {
|
||||||
|
case 'STRING': {
|
||||||
|
searchValueComponent = (
|
||||||
|
<PowerSearchStringTerm
|
||||||
|
onCancel={onCancel}
|
||||||
|
onChange={(newValue) => {
|
||||||
|
onFinalize({
|
||||||
|
...searchTerm,
|
||||||
|
searchValue: newValue,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
defaultValue={searchTerm.searchValue}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'ENUM': {
|
case 'ENUM': {
|
||||||
searchValueComponent = (
|
searchValueComponent = (
|
||||||
<Button>
|
<Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user