Files
flipper/desktop/flipper-plugin/src/ui/data-table/DataTableDefaultPowerSearchOperators.tsx
Andrey Goncharov a27f4580a3 Add string_set_contains_any_of operator
Summary: Doc: https://docs.google.com/document/d/1miofxds9DJgWScj0zFyBbdpRH5Rj0T9FqiCapof5-vU/edit#heading=h.pg8svtdjlx7

Reviewed By: lblasa

Differential Revision: D49230134

fbshipit-source-id: aa8c4494e707dfbf70568517a50c1f5803fce32a
2023-09-14 04:48:12 -07:00

69 lines
2.0 KiB
TypeScript

/**
* 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 {OperatorConfig} from '../PowerSearch';
export type PowerSearchOperatorProcessor = (
powerSearchOperatorConfig: OperatorConfig,
searchValue: any,
value: any,
) => boolean;
export const dataTablePowerSearchOperators = {
string_contains: () => ({
label: 'contains',
key: 'string_contains',
valueType: 'STRING',
}),
string_not_contains: () => ({
label: 'does not contain',
key: 'string_not_contains',
valueType: 'STRING',
}),
string_matches_exactly: () => ({
label: 'is',
key: 'string_matches_exactly',
valueType: 'STRING',
}),
string_not_matches_exactly: () => ({
label: 'is not',
key: 'string_not_matches_exactly',
valueType: 'STRING',
}),
string_set_contains_any_of: () => ({
label: 'contains any of',
key: 'string_set_contains_any_of',
valueType: 'STRING_SET',
}),
} satisfies {
[key: string]: (...args: any[]) => OperatorConfig;
};
export type PowerSearchOperatorProcessorConfig = {
[K in keyof typeof dataTablePowerSearchOperators]: PowerSearchOperatorProcessor;
};
export const dataTablePowerSearchOperatorProcessorConfig = {
string_contains: (operator, searchValue, value) =>
(value as string)
.toLowerCase()
.includes((searchValue as string).toLowerCase()),
string_not_contains: (operator, searchValue, value) =>
!(value as string)
.toLowerCase()
.includes((searchValue as string).toLowerCase()),
string_matches_exactly: (operator, searchValue, value) =>
value === searchValue,
string_not_matches_exactly: (operator, searchValue, value) =>
value !== searchValue,
// See PowerSearchStringSetTerm
string_set_contains_any_of: (operator, searchValue: string[], value) =>
searchValue.some((item) => (value as string).toLowerCase().includes(item)),
} satisfies PowerSearchOperatorProcessorConfig;