-
Notifications
You must be signed in to change notification settings - Fork 955
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Project doc: https://docs.google.com/document/d/1miofxds9DJgWScj0zFyBbdpRH5Rj0T9FqiCapof5-vU Reviewed By: lblasa Differential Revision: D48648499 fbshipit-source-id: ee24ae15c1e6533398db0af79597388e473f97e7
- Loading branch information
1 parent
e514778
commit 2affcbd
Showing
4 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchEnumSetTerm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* 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 {Select} from 'antd'; | ||
import React from 'react'; | ||
|
||
type PowerSearchEnumSetTermProps = { | ||
onCancel: () => void; | ||
onChange: (value: string[]) => void; | ||
enumLabels: {[key: string]: string}; | ||
}; | ||
|
||
export const PowerSearchEnumSetTerm: React.FC<PowerSearchEnumSetTermProps> = ({ | ||
onCancel, | ||
onChange, | ||
enumLabels, | ||
}) => { | ||
const options = React.useMemo(() => { | ||
return Object.entries(enumLabels).map(([key, label]) => ({ | ||
label, | ||
value: key, | ||
})); | ||
}, [enumLabels]); | ||
|
||
const selectValueRef = React.useRef<string[]>(); | ||
|
||
return ( | ||
<Select | ||
mode="multiple" | ||
autoFocus | ||
style={{minWidth: 100}} | ||
placeholder="..." | ||
options={options} | ||
defaultOpen | ||
onBlur={() => { | ||
if (!selectValueRef.current?.length) { | ||
onCancel(); | ||
} | ||
}} | ||
onChange={(value) => { | ||
if (!value.length) { | ||
onCancel(); | ||
return; | ||
} | ||
selectValueRef.current = value; | ||
onChange(value); | ||
}} | ||
onClear={onCancel} | ||
onKeyDown={(event) => { | ||
if (event.key === 'Enter' || event.key === 'Escape') { | ||
event.currentTarget.blur(); | ||
} | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters