Extend default list of operators for unconfigured columns
Summary: It does not make too much sense to keep the unknown value conversion behind a flag. It is relatively cheap. Let's do it for all strings. Also, let's extend the list of default string operators Reviewed By: lblasa Differential Revision: D51115573 fbshipit-source-id: a62c08a90d8ddf6f23f59412c3fd981e19225e47
This commit is contained in:
committed by
Facebook GitHub Bot
parent
51e149765e
commit
284dee0460
@@ -33,7 +33,6 @@ export type StringOperatorConfig = {
|
|||||||
valueType: StringFilterValueType;
|
valueType: StringFilterValueType;
|
||||||
key: string;
|
key: string;
|
||||||
label: string;
|
label: string;
|
||||||
handleUnknownValues?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type StringSetOperatorConfig = {
|
export type StringSetOperatorConfig = {
|
||||||
|
|||||||
@@ -8,12 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import {getFlipperLib} from 'flipper-plugin-core';
|
|
||||||
import {OperatorConfig} from '../PowerSearch';
|
import {OperatorConfig} from '../PowerSearch';
|
||||||
import {
|
import {FloatOperatorConfig} from '../PowerSearch/PowerSearchConfig';
|
||||||
FloatOperatorConfig,
|
|
||||||
StringOperatorConfig,
|
|
||||||
} from '../PowerSearch/PowerSearchConfig';
|
|
||||||
|
|
||||||
export type PowerSearchOperatorProcessor = (
|
export type PowerSearchOperatorProcessor = (
|
||||||
powerSearchOperatorConfig: OperatorConfig,
|
powerSearchOperatorConfig: OperatorConfig,
|
||||||
@@ -22,29 +18,25 @@ export type PowerSearchOperatorProcessor = (
|
|||||||
) => boolean;
|
) => boolean;
|
||||||
|
|
||||||
export const dataTablePowerSearchOperators = {
|
export const dataTablePowerSearchOperators = {
|
||||||
string_contains: (handleUnknownValues?: boolean) => ({
|
string_contains: () => ({
|
||||||
label: 'contains',
|
label: 'contains',
|
||||||
key: 'string_contains',
|
key: 'string_contains',
|
||||||
valueType: 'STRING',
|
valueType: 'STRING',
|
||||||
handleUnknownValues,
|
|
||||||
}),
|
}),
|
||||||
string_not_contains: (handleUnknownValues?: boolean) => ({
|
string_not_contains: () => ({
|
||||||
label: 'does not contain',
|
label: 'does not contain',
|
||||||
key: 'string_not_contains',
|
key: 'string_not_contains',
|
||||||
valueType: 'STRING',
|
valueType: 'STRING',
|
||||||
handleUnknownValues,
|
|
||||||
}),
|
}),
|
||||||
string_matches_exactly: (handleUnknownValues?: boolean) => ({
|
string_matches_exactly: () => ({
|
||||||
label: 'is',
|
label: 'is',
|
||||||
key: 'string_matches_exactly',
|
key: 'string_matches_exactly',
|
||||||
valueType: 'STRING',
|
valueType: 'STRING',
|
||||||
handleUnknownValues,
|
|
||||||
}),
|
}),
|
||||||
string_not_matches_exactly: (handleUnknownValues?: boolean) => ({
|
string_not_matches_exactly: () => ({
|
||||||
label: 'is not',
|
label: 'is not',
|
||||||
key: 'string_not_matches_exactly',
|
key: 'string_not_matches_exactly',
|
||||||
valueType: 'STRING',
|
valueType: 'STRING',
|
||||||
handleUnknownValues,
|
|
||||||
}),
|
}),
|
||||||
searializable_object_contains: () => ({
|
searializable_object_contains: () => ({
|
||||||
label: 'contains',
|
label: 'contains',
|
||||||
@@ -223,22 +215,12 @@ const tryConvertingUnknownToString = (value: unknown): string | null => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const dataTablePowerSearchOperatorProcessorConfig = {
|
export const dataTablePowerSearchOperatorProcessorConfig = {
|
||||||
string_contains: (operator, searchValue: string, value: string) =>
|
string_contains: (_operator, searchValue: string, value: string) =>
|
||||||
!!(
|
!!tryConvertingUnknownToString(value)
|
||||||
(operator as StringOperatorConfig).handleUnknownValues &&
|
|
||||||
getFlipperLib().GK('flipper_power_search_auto_json_stringify')
|
|
||||||
? tryConvertingUnknownToString(value)
|
|
||||||
: value
|
|
||||||
)
|
|
||||||
?.toLowerCase()
|
?.toLowerCase()
|
||||||
.includes(searchValue.toLowerCase()),
|
.includes(searchValue.toLowerCase()),
|
||||||
string_not_contains: (operator, searchValue: string, value: string) =>
|
string_not_contains: (_operator, searchValue: string, value: string) =>
|
||||||
!(
|
!tryConvertingUnknownToString(value)
|
||||||
(operator as StringOperatorConfig).handleUnknownValues &&
|
|
||||||
getFlipperLib().GK('flipper_power_search_auto_json_stringify')
|
|
||||||
? tryConvertingUnknownToString(value)
|
|
||||||
: value
|
|
||||||
)
|
|
||||||
?.toLowerCase()
|
?.toLowerCase()
|
||||||
.includes(searchValue.toLowerCase()),
|
.includes(searchValue.toLowerCase()),
|
||||||
searializable_object_contains: (
|
searializable_object_contains: (
|
||||||
@@ -251,16 +233,10 @@ export const dataTablePowerSearchOperatorProcessorConfig = {
|
|||||||
searchValue: string,
|
searchValue: string,
|
||||||
value: object,
|
value: object,
|
||||||
) => !JSON.stringify(value).toLowerCase().includes(searchValue.toLowerCase()),
|
) => !JSON.stringify(value).toLowerCase().includes(searchValue.toLowerCase()),
|
||||||
string_matches_exactly: (operator, searchValue: string, value: string) =>
|
string_matches_exactly: (_operator, searchValue: string, value: string) =>
|
||||||
((operator as StringOperatorConfig).handleUnknownValues &&
|
tryConvertingUnknownToString(value) === searchValue,
|
||||||
getFlipperLib().GK('flipper_power_search_auto_json_stringify')
|
string_not_matches_exactly: (_operator, searchValue: string, value: string) =>
|
||||||
? tryConvertingUnknownToString(value)
|
tryConvertingUnknownToString(value) !== searchValue,
|
||||||
: value) === searchValue,
|
|
||||||
string_not_matches_exactly: (operator, searchValue: string, value: string) =>
|
|
||||||
((operator as StringOperatorConfig).handleUnknownValues &&
|
|
||||||
getFlipperLib().GK('flipper_power_search_auto_json_stringify')
|
|
||||||
? tryConvertingUnknownToString(value)
|
|
||||||
: value) !== searchValue,
|
|
||||||
// See PowerSearchStringSetTerm
|
// See PowerSearchStringSetTerm
|
||||||
string_set_contains_any_of: (
|
string_set_contains_any_of: (
|
||||||
_operator,
|
_operator,
|
||||||
@@ -268,7 +244,9 @@ export const dataTablePowerSearchOperatorProcessorConfig = {
|
|||||||
value: string,
|
value: string,
|
||||||
) =>
|
) =>
|
||||||
searchValue.some((item) =>
|
searchValue.some((item) =>
|
||||||
value.toLowerCase().includes(item.toLowerCase()),
|
tryConvertingUnknownToString(value)
|
||||||
|
?.toLowerCase()
|
||||||
|
.includes(item.toLowerCase()),
|
||||||
),
|
),
|
||||||
string_set_contains_none_of: (
|
string_set_contains_none_of: (
|
||||||
_operator,
|
_operator,
|
||||||
@@ -276,7 +254,9 @@ export const dataTablePowerSearchOperatorProcessorConfig = {
|
|||||||
value: string,
|
value: string,
|
||||||
) =>
|
) =>
|
||||||
!searchValue.some((item) =>
|
!searchValue.some((item) =>
|
||||||
value.toLowerCase().includes(item.toLowerCase()),
|
tryConvertingUnknownToString(value)
|
||||||
|
?.toLowerCase()
|
||||||
|
.includes(item.toLowerCase()),
|
||||||
),
|
),
|
||||||
int_equals: (_operator, searchValue: number, value: number) =>
|
int_equals: (_operator, searchValue: number, value: number) =>
|
||||||
value === searchValue,
|
value === searchValue,
|
||||||
|
|||||||
@@ -361,10 +361,12 @@ export function DataTable<T extends object>(
|
|||||||
// If no power search config provided we treat every input as a string
|
// If no power search config provided we treat every input as a string
|
||||||
if (!column.powerSearchConfig) {
|
if (!column.powerSearchConfig) {
|
||||||
columnPowerSearchOperators = [
|
columnPowerSearchOperators = [
|
||||||
dataTablePowerSearchOperators.string_contains(true),
|
dataTablePowerSearchOperators.string_contains(),
|
||||||
dataTablePowerSearchOperators.string_not_contains(true),
|
dataTablePowerSearchOperators.string_not_contains(),
|
||||||
dataTablePowerSearchOperators.string_matches_exactly(true),
|
dataTablePowerSearchOperators.string_matches_exactly(),
|
||||||
dataTablePowerSearchOperators.string_not_matches_exactly(true),
|
dataTablePowerSearchOperators.string_not_matches_exactly(),
|
||||||
|
dataTablePowerSearchOperators.string_set_contains_any_of(),
|
||||||
|
dataTablePowerSearchOperators.string_set_contains_none_of(),
|
||||||
];
|
];
|
||||||
} else if (Array.isArray(column.powerSearchConfig)) {
|
} else if (Array.isArray(column.powerSearchConfig)) {
|
||||||
columnPowerSearchOperators = column.powerSearchConfig;
|
columnPowerSearchOperators = column.powerSearchConfig;
|
||||||
|
|||||||
Reference in New Issue
Block a user