Extract PowerSearchStringTerm

Summary: Project doc: https://docs.google.com/document/d/1miofxds9DJgWScj0zFyBbdpRH5Rj0T9FqiCapof5-vU

Reviewed By: lblasa

Differential Revision: D48601912

fbshipit-source-id: 90f67f1ea19ef6ae8b5d92f26894af2ab20fa821
This commit is contained in:
Andrey Goncharov
2023-08-30 07:26:35 -07:00
committed by Facebook GitHub Bot
parent 380e99400f
commit a9fb5d9863
2 changed files with 49 additions and 19 deletions

View File

@@ -0,0 +1,44 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {Input} from 'antd';
import React from 'react';
type PowerSearchStringTermProps = {
onCancel: () => void;
onChange: (value: string) => void;
};
export const PowerSearchStringTerm: React.FC<PowerSearchStringTermProps> = ({
onCancel,
onChange,
}) => {
return (
<Input
autoFocus
style={{width: 100}}
placeholder="..."
onBlur={(event) => {
const newValue = event.target.value;
if (!newValue) {
onCancel();
return;
}
onChange(newValue);
}}
onKeyDown={(event) => {
if (event.key === 'Enter' || event.key === 'Escape') {
event.currentTarget.blur();
}
}}
/>
);
};

View File

@@ -8,9 +8,10 @@
*/
import {CloseOutlined} from '@ant-design/icons';
import {Button, Input, Space} from 'antd';
import {Button, Space} from 'antd';
import * as React from 'react';
import {FieldConfig, OperatorConfig} from './PowerSearchConfig';
import {PowerSearchStringTerm} from './PowerSearchStringTerm';
export type IncompleteSearchExpressionTerm = {
field: FieldConfig;
@@ -39,29 +40,14 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
{searchValueRenderer === 'button' ? (
<Button>{searchTerm.searchValue ?? '...'}</Button>
) : (
// TODO: Fix width
<Input
autoFocus
style={{width: 100}}
placeholder="..."
onBlur={(event) => {
const newValue = event.target.value;
if (!newValue) {
onCancel();
return;
}
<PowerSearchStringTerm
onCancel={onCancel}
onChange={(newValue) => {
onFinalize({
...searchTerm,
searchValue: newValue,
});
}}
onKeyDown={(event) => {
if (event.key === 'Enter' || event.key === 'Escape') {
event.currentTarget.blur();
}
}}
/>
)}
<Button