From 09cb48a3e35e1ea9139d7ef1fde41220708f7bc5 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Wed, 20 Sep 2023 04:36:57 -0700 Subject: [PATCH] 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 --- .../ui/PowerSearch/PowerSearchStringTerm.tsx | 53 +++++++++++-------- .../src/ui/PowerSearch/PowerSearchTerm.tsx | 16 ++++++ 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchStringTerm.tsx b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchStringTerm.tsx index 4c3ef860f..32d237ab4 100644 --- a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchStringTerm.tsx +++ b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchStringTerm.tsx @@ -7,38 +7,49 @@ * @format */ -import {Input} from 'antd'; +import {Button, Input} from 'antd'; import React from 'react'; type PowerSearchStringTermProps = { onCancel: () => void; onChange: (value: string) => void; + defaultValue?: string; }; export const PowerSearchStringTerm: React.FC = ({ onCancel, onChange, + defaultValue, }) => { - return ( - { - const newValue = event.target.value; + const [editing, setEditing] = React.useState(!defaultValue); - if (!newValue) { - onCancel(); - return; - } + if (editing) { + return ( + { + const newValue = event.target.value; - onChange(newValue); - }} - onKeyDown={(event) => { - if (event.key === 'Enter' || event.key === 'Escape') { - event.currentTarget.blur(); - } - }} - /> - ); + setEditing(false); + + if (!newValue) { + onCancel(); + return; + } + + onChange(newValue); + }} + onKeyDown={(event) => { + if (event.key === 'Enter' || event.key === 'Escape') { + event.currentTarget.blur(); + } + }} + defaultValue={defaultValue} + /> + ); + } + + return ; }; diff --git a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx index b00b5601c..3df20f1ff 100644 --- a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx +++ b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx @@ -57,6 +57,7 @@ export const PowerSearchTerm: React.FC = ({ searchValue: newValue, }); }} + defaultValue={searchTerm.searchValue} /> ); break; @@ -164,6 +165,21 @@ export const PowerSearchTerm: React.FC = ({ } } else { switch (searchTerm.operator.valueType) { + case 'STRING': { + searchValueComponent = ( + { + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + defaultValue={searchTerm.searchValue} + /> + ); + break; + } case 'ENUM': { searchValueComponent = (