Skip to content

Commit

Permalink
Support STRING_SET operator type
Browse files Browse the repository at this point in the history
Summary:
Project doc: https://docs.google.com/document/d/1miofxds9DJgWScj0zFyBbdpRH5Rj0T9FqiCapof5-vU

Data table integration comes later

Reviewed By: lblasa

Differential Revision: D48648822

fbshipit-source-id: 74f92c0e818c4507fd6575f6a122d107373cfe0c
  • Loading branch information
aigoncharov authored and facebook-github-bot committed Aug 30, 2023
1 parent 2affcbd commit caf55f5
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

// Mostly matches https://www.internalfb.com/code/www/html/intern/js/ui/PowerSearch/PowerSearchExampleConfig.js

export type SimpleFilterValueType = 'NO_VALUE' | 'INTEGER' | 'FLOAT' | 'STRING';
export type SimpleFilterValueType =
| 'NO_VALUE'
| 'INTEGER'
| 'FLOAT'
| 'STRING'
| 'STRING_SET';

export type EnumFilterValueType = 'ENUM' | 'ENUM_SET';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const operators = {
key: 'not_contain',
valueType: 'STRING',
},
contains_any_of: {
label: 'contains any of',
key: 'contains_any_of',
valueType: 'STRING_SET',
},
greater_than: {
label: '>',
key: 'greater_than',
Expand Down Expand Up @@ -115,6 +120,7 @@ export const powerSearchExampleConfig: PowerSearchConfig = {
operators: {
contain: operators.contain,
not_contain: operators.not_contain,
contains_any_of: operators.contains_any_of,
},
},
placeholder: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* 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 PowerSearchStringSetTermProps = {
onCancel: () => void;
onChange: (value: string[]) => void;
};

export const PowerSearchStringSetTerm: React.FC<
PowerSearchStringSetTermProps
> = ({onCancel, onChange}) => {
const selectValueRef = React.useRef<string[]>();

return (
<Select
mode="tags"
autoFocus
style={{minWidth: 100}}
placeholder="..."
onBlur={() => {
if (!selectValueRef.current?.length) {
onCancel();
}
}}
open={false}
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();
}
}}
/>
);
};
29 changes: 29 additions & 0 deletions desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {PowerSearchEnumSetTerm} from './PowerSearchEnumSetTerm';
import {PowerSearchEnumTerm} from './PowerSearchEnumTerm';
import {PowerSearchFloatTerm} from './PowerSearchFloatTerm';
import {PowerSearchIntegerTerm} from './PowerSearchIntegerTerm';
import {PowerSearchStringSetTerm} from './PowerSearchStringSetTerm';
import {PowerSearchStringTerm} from './PowerSearchStringTerm';

export type IncompleteSearchExpressionTerm = {
Expand Down Expand Up @@ -60,6 +61,20 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
);
break;
}
case 'STRING_SET': {
searchValueComponent = (
<PowerSearchStringSetTerm
onCancel={onCancel}
onChange={(newValue) => {
onFinalize({
...searchTerm,
searchValue: newValue,
});
}}
/>
);
break;
}
case 'INTEGER': {
searchValueComponent = (
<PowerSearchIntegerTerm
Expand Down Expand Up @@ -172,6 +187,20 @@ export const PowerSearchTerm: React.FC<PowerSearchTermProps> = ({
);
break;
}
case 'STRING_SET': {
searchValueComponent = (
<PowerSearchStringSetTerm
onCancel={onCancel}
onChange={(newValue) => {
onFinalize({
...searchTerm,
searchValue: newValue,
});
}}
/>
);
break;
}
case 'ABSOLUTE_DATE': {
searchValueComponent = (
<Button>
Expand Down

0 comments on commit caf55f5

Please sign in to comment.