From 31e93ff3fe1975b8564a2053e8b12600ecfa20b1 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Wed, 20 Sep 2023 04:36:57 -0700 Subject: [PATCH] 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 --- .../ui/PowerSearch/PowerSearchIntegerTerm.tsx | 73 +++++++++++-------- .../src/ui/PowerSearch/PowerSearchTerm.tsx | 16 ++++ 2 files changed, 58 insertions(+), 31 deletions(-) diff --git a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchIntegerTerm.tsx b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchIntegerTerm.tsx index 96757e3e9..3edf7f50a 100644 --- a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchIntegerTerm.tsx +++ b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchIntegerTerm.tsx @@ -7,50 +7,61 @@ * @format */ -import {Input} from 'antd'; +import {Button, Input} from 'antd'; import React from 'react'; type PowerSearchIntegerTermProps = { onCancel: () => void; onChange: (value: number) => void; + defaultValue?: number; }; export const PowerSearchIntegerTerm: React.FC = ({ onCancel, onChange, + defaultValue, }) => { - return ( - { - const newValue = event.target.value; + const [editing, setEditing] = React.useState(!defaultValue); - const normalizedValue = parseInt(newValue, 10); + if (editing) { + return ( + { + const newValue = event.target.value; - if (normalizedValue.toString() !== newValue) { - event.target.value = normalizedValue.toString(); - } - }} - onBlur={(event) => { - const newValue = event.target.value; + const normalizedValue = parseInt(newValue, 10); - if (!newValue) { - onCancel(); - return; - } + if (normalizedValue.toString() !== newValue) { + event.target.value = normalizedValue.toString(); + } + }} + onBlur={(event) => { + const newValue = event.target.value; - const normalizedValue = parseInt(newValue, 10); - onChange(normalizedValue); - }} - onKeyDown={(event) => { - if (event.key === 'Enter' || event.key === 'Escape') { - event.currentTarget.blur(); - } - }} - type="number" - step={1} - /> - ); + setEditing(false); + + if (!newValue) { + onCancel(); + return; + } + + const normalizedValue = parseInt(newValue, 10); + onChange(normalizedValue); + }} + onKeyDown={(event) => { + if (event.key === 'Enter' || event.key === 'Escape') { + event.currentTarget.blur(); + } + }} + type="number" + step={1} + defaultValue={defaultValue} + /> + ); + } + + return ; }; diff --git a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx index e8a9b10ed..45facdd6e 100644 --- a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx +++ b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx @@ -86,6 +86,7 @@ export const PowerSearchTerm: React.FC = ({ searchValue: newValue, }); }} + defaultValue={searchTerm.searchValue} /> ); break; @@ -181,6 +182,21 @@ export const PowerSearchTerm: React.FC = ({ ); break; } + case 'INTEGER': { + searchValueComponent = ( + { + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + defaultValue={searchTerm.searchValue} + /> + ); + break; + } case 'ENUM': { searchValueComponent = (