From e180a1ed4b52dbaefd23a9cabfa06e048ea80b17 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Wed, 20 Sep 2023 04:36:57 -0700 Subject: [PATCH] Make float term editable Summary: For the purposes of the demo I added power search config for a float field to the summary field Reviewed By: lblasa Differential Revision: D49452844 fbshipit-source-id: 26aaadd07a1a8a67dfcf3cb9d8e487f8f4ee2214 --- .../ui/PowerSearch/PowerSearchFloatTerm.tsx | 59 +++++++++++-------- .../src/ui/PowerSearch/PowerSearchTerm.tsx | 16 +++++ .../DataTableDefaultPowerSearchOperators.tsx | 2 +- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchFloatTerm.tsx b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchFloatTerm.tsx index b66516462..69d6d779f 100644 --- a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchFloatTerm.tsx +++ b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchFloatTerm.tsx @@ -7,41 +7,52 @@ * @format */ -import {Input} from 'antd'; +import {Button, Input} from 'antd'; import React from 'react'; type PowerSearchFloatTermProps = { onCancel: () => void; onChange: (value: number) => void; + defaultValue?: number; }; export const PowerSearchFloatTerm: 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; - const normalizedValue = parseFloat(newValue); - onChange(normalizedValue); - }} - onKeyDown={(event) => { - if (event.key === 'Enter' || event.key === 'Escape') { - event.currentTarget.blur(); - } - }} - type="number" - step={0.1} - /> - ); + setEditing(false); + + if (!newValue) { + onCancel(); + return; + } + + const normalizedValue = parseFloat(newValue); + onChange(normalizedValue); + }} + onKeyDown={(event) => { + if (event.key === 'Enter' || event.key === 'Escape') { + event.currentTarget.blur(); + } + }} + type="number" + step={0.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 45facdd6e..684580be8 100644 --- a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx +++ b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx @@ -101,6 +101,7 @@ export const PowerSearchTerm: React.FC = ({ searchValue: newValue, }); }} + defaultValue={searchTerm.searchValue} /> ); break; @@ -197,6 +198,21 @@ export const PowerSearchTerm: React.FC = ({ ); break; } + case 'FLOAT': { + searchValueComponent = ( + { + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + defaultValue={searchTerm.searchValue} + /> + ); + break; + } case 'ENUM': { searchValueComponent = ( ({ + float_equals: (precision?: number) => ({ label: '=', key: 'float_equals', valueType: 'FLOAT',