From c9ab951e849fc790af1c8b4095e6c9be9bd017e5 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Wed, 30 Aug 2023 07:26:35 -0700 Subject: [PATCH] Extract PowerSearchTerm Summary: Project doc: https://docs.google.com/document/d/1miofxds9DJgWScj0zFyBbdpRH5Rj0T9FqiCapof5-vU Reviewed By: lblasa Differential Revision: D48599166 fbshipit-source-id: 13b447b55408a8673928489312c4d22cf864c232 --- ...rSearchTypes.tsx => PowerSearchConfig.tsx} | 0 .../PowerSearch/PowerSearchExampleConfig.tsx | 2 +- .../src/ui/PowerSearch/PowerSearchTerm.tsx | 74 ++++++++++++++ .../src/ui/PowerSearch/index.tsx | 99 ++++++------------- 4 files changed, 105 insertions(+), 70 deletions(-) rename desktop/flipper-plugin/src/ui/PowerSearch/{PowerSearchTypes.tsx => PowerSearchConfig.tsx} (100%) create mode 100644 desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx diff --git a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTypes.tsx b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchConfig.tsx similarity index 100% rename from desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTypes.tsx rename to desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchConfig.tsx diff --git a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchExampleConfig.tsx b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchExampleConfig.tsx index b2a58bf80..851e97f01 100644 --- a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchExampleConfig.tsx +++ b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchExampleConfig.tsx @@ -7,7 +7,7 @@ * @format */ -import {OperatorConfig, PowerSearchConfig} from './PowerSearchTypes'; +import {OperatorConfig, PowerSearchConfig} from './PowerSearchConfig'; const MyStatusEnum = { NEEDS_REVIEW: 'Needs review', diff --git a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx new file mode 100644 index 000000000..8b403b9ca --- /dev/null +++ b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx @@ -0,0 +1,74 @@ +/** + * 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 {CloseOutlined} from '@ant-design/icons'; +import {Button, Input, Space} from 'antd'; +import * as React from 'react'; +import {FieldConfig, OperatorConfig} from './PowerSearchConfig'; + +export type SearchExpressionTerm = { + field: FieldConfig; + operator: OperatorConfig; + searchValue?: string; +}; + +type PowerSearchTermProps = { + searchTerm: SearchExpressionTerm; + searchValueRenderer: 'input' | 'button'; + onCancel: () => void; + onFinalize: (completeSearchTerm: Required) => void; +}; + +export const PowerSearchTerm: React.FC = ({ + searchTerm, + searchValueRenderer, + onCancel, + onFinalize, +}) => { + return ( + + + + {searchValueRenderer === 'button' ? ( + + ) : ( + // TODO: Fix width + { + const newValue = event.target.value; + + if (!newValue) { + onCancel(); + return; + } + + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + onKeyDown={(event) => { + if (event.key === 'Enter' || event.key === 'Escape') { + event.currentTarget.blur(); + } + }} + /> + )} + - - {lastSearchTermHasSearchValue || !isLastTerm ? ( - - ) : ( - // TODO: Fix width - { - const newValue = event.target.value; - - if (!newValue) { - setSearchExpression((prevSearchExpression) => { - return prevSearchExpression.slice(0, -1); - }); - return; - } - - setSearchExpression((prevSearchExpression) => { - return [ - ...prevSearchExpression.slice(0, -1), - { - ...prevSearchExpression[ - prevSearchExpression.length - 1 - ], - searchValue: newValue, - }, - ]; - }); - searchTermFinderRef.current?.focus(); - }} - onKeyDown={(event) => { - if (event.key === 'Enter' || event.key === 'Escape') { - event.currentTarget.blur(); - } - }} - /> - )} -