diff --git a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx index e4c1a47201c..3ab0b175798 100644 --- a/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx +++ b/desktop/flipper-plugin/src/ui/PowerSearch/PowerSearchTerm.tsx @@ -9,14 +9,9 @@ import {CloseOutlined} from '@ant-design/icons'; import {Button, Space} from 'antd'; -import dayjs from 'dayjs'; import * as React from 'react'; -import { - DATE_ONLY_FORMAT, - DATE_TIME_FORMAT, - PowerSearchAbsoluteDateTerm, -} from './PowerSearchAbsoluteDateTerm'; -import {FieldConfig, OperatorConfig} from './PowerSearchConfig'; +import {PowerSearchAbsoluteDateTerm} from './PowerSearchAbsoluteDateTerm'; +import {OperatorConfig} from './PowerSearchConfig'; import {PowerSearchEnumSetTerm} from './PowerSearchEnumSetTerm'; import {PowerSearchEnumTerm} from './PowerSearchEnumTerm'; import {PowerSearchFloatTerm} from './PowerSearchFloatTerm'; @@ -42,250 +37,131 @@ export const PowerSearchTerm: React.FC = ({ onCancel, onFinalize, }) => { - const hasValue = searchTerm.searchValue != null; - let searchValueComponent: React.ReactNode = null; - if (!hasValue) { - switch (searchTerm.operator.valueType) { - case 'STRING': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'STRING_SET': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - /> - ); - break; - } - case 'INTEGER': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'FLOAT': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'NO_VALUE': { - // Nothing needs to be done. It should never be the case. - searchValueComponent = null; - break; - } - case 'ENUM': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - enumLabels={searchTerm.operator.enumLabels} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'ENUM_SET': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - enumLabels={searchTerm.operator.enumLabels} - /> - ); - break; - } - case 'ABSOLUTE_DATE': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - minValue={searchTerm.operator.minValue} - maxValue={searchTerm.operator.maxValue} - dateOnly={searchTerm.operator.dateOnly} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - default: { - console.error( - 'PowerSearchTerm -> unknown operator.valueType', - searchTerm, - ); - } + switch (searchTerm.operator.valueType) { + case 'STRING': { + searchValueComponent = ( + { + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + defaultValue={searchTerm.searchValue} + /> + ); + break; + } + case 'STRING_SET': { + searchValueComponent = ( + { + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + defaultValue={searchTerm.searchValue} + /> + ); + break; + } + case 'INTEGER': { + searchValueComponent = ( + { + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + defaultValue={searchTerm.searchValue} + /> + ); + break; + } + case 'FLOAT': { + searchValueComponent = ( + { + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + defaultValue={searchTerm.searchValue} + /> + ); + break; + } + case 'NO_VALUE': { + // Nothing needs to be done. It should never be the case. + searchValueComponent = null; + break; + } + case 'ENUM': { + searchValueComponent = ( + { + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + enumLabels={searchTerm.operator.enumLabels} + defaultValue={searchTerm.searchValue} + /> + ); + break; + } + case 'ENUM_SET': { + searchValueComponent = ( + { + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + enumLabels={searchTerm.operator.enumLabels} + defaultValue={searchTerm.searchValue} + /> + ); + break; + } + case 'ABSOLUTE_DATE': { + searchValueComponent = ( + { + onFinalize({ + ...searchTerm, + searchValue: newValue, + }); + }} + minValue={searchTerm.operator.minValue} + maxValue={searchTerm.operator.maxValue} + dateOnly={searchTerm.operator.dateOnly} + defaultValue={searchTerm.searchValue} + /> + ); + break; } - } else { - switch (searchTerm.operator.valueType) { - case 'STRING': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'INTEGER': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'FLOAT': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'ENUM': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - enumLabels={searchTerm.operator.enumLabels} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'ENUM_SET': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - enumLabels={searchTerm.operator.enumLabels} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'STRING_SET': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'ABSOLUTE_DATE': { - searchValueComponent = ( - { - onFinalize({ - ...searchTerm, - searchValue: newValue, - }); - }} - minValue={searchTerm.operator.minValue} - maxValue={searchTerm.operator.maxValue} - dateOnly={searchTerm.operator.dateOnly} - defaultValue={searchTerm.searchValue} - /> - ); - break; - } - case 'NO_VALUE': { - searchValueComponent = null; - break; - } - default: { - searchValueComponent = ; - } + default: { + // Compilation is going to fail if switch-case is not exhaustive (i.e. we did not cover all possible cases) + const exhaustiveCheck: never = searchTerm.operator; + console.error( + 'PowerSearchTerm -> unknown operator.valueType', + searchTerm, + exhaustiveCheck, + ); } }