flipper-plugin
Version:
Flipper Desktop plugin SDK and components
122 lines • 5.96 kB
JavaScript
/**
* 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
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PowerSearchTerm = void 0;
const icons_1 = require("@ant-design/icons");
const antd_1 = require("antd");
const React = __importStar(require("react"));
const theme_1 = require("../theme");
const PowerSearchAbsoluteDateTerm_1 = require("./PowerSearchAbsoluteDateTerm");
const PowerSearchEnumSetTerm_1 = require("./PowerSearchEnumSetTerm");
const PowerSearchFloatTerm_1 = require("./PowerSearchFloatTerm");
const PowerSearchIntegerTerm_1 = require("./PowerSearchIntegerTerm");
const PowerSearchStringSetTerm_1 = require("./PowerSearchStringSetTerm");
const PowerSearchStringTerm_1 = require("./PowerSearchStringTerm");
const PowerSearchTerm = ({ searchTerm, onCancel, onFinalize, }) => {
let searchValueComponent = null;
switch (searchTerm.operator.valueType) {
case 'STRING': {
searchValueComponent = (React.createElement(PowerSearchStringTerm_1.PowerSearchStringTerm, { onCancel: onCancel, onChange: (newValue) => {
onFinalize({
...searchTerm,
searchValue: newValue,
});
}, defaultValue: searchTerm.searchValue }));
break;
}
case 'STRING_SET': {
searchValueComponent = (React.createElement(PowerSearchStringSetTerm_1.PowerSearchStringSetTerm, { onCancel: onCancel, onChange: (newValue) => {
onFinalize({
...searchTerm,
searchValue: newValue,
});
}, defaultValue: searchTerm.searchValue }));
break;
}
case 'INTEGER': {
searchValueComponent = (React.createElement(PowerSearchIntegerTerm_1.PowerSearchIntegerTerm, { onCancel: onCancel, onChange: (newValue) => {
onFinalize({
...searchTerm,
searchValue: newValue,
});
}, defaultValue: searchTerm.searchValue }));
break;
}
case 'FLOAT': {
searchValueComponent = (React.createElement(PowerSearchFloatTerm_1.PowerSearchFloatTerm, { onCancel: onCancel, onChange: (newValue) => {
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_SET': {
searchValueComponent = (React.createElement(PowerSearchEnumSetTerm_1.PowerSearchEnumSetTerm, { onCancel: onCancel, onChange: (newValue) => {
onFinalize({
...searchTerm,
searchValue: newValue,
});
}, enumLabels: searchTerm.operator.enumLabels, allowFreeform: searchTerm.operator.allowFreeform, defaultValue: searchTerm.searchValue }));
break;
}
case 'ABSOLUTE_DATE': {
searchValueComponent = (React.createElement(PowerSearchAbsoluteDateTerm_1.PowerSearchAbsoluteDateTerm, { onCancel: onCancel, onChange: (newValue) => {
onFinalize({
...searchTerm,
searchValue: newValue,
});
}, minValue: searchTerm.operator.minValue, maxValue: searchTerm.operator.maxValue, dateOnly: searchTerm.operator.dateOnly, defaultValue: searchTerm.searchValue }));
break;
}
default: {
// Compilation is going to fail if switch-case is not exhaustive (i.e. we did not cover all possible cases)
const exhaustiveCheck = searchTerm.operator;
console.error('PowerSearchTerm -> unknown operator.valueType', searchTerm, exhaustiveCheck);
}
}
return (React.createElement(antd_1.Space.Compact, { size: "small", style: { margin: theme_1.theme.space.tiny / 2 } },
React.createElement(antd_1.Button, { tabIndex: -1, style: { pointerEvents: 'none' } }, searchTerm.field.label),
searchTerm.operator.label ? (React.createElement(antd_1.Button, { tabIndex: -1, style: { pointerEvents: 'none' } }, searchTerm.operator.label)) : null,
searchValueComponent,
React.createElement(antd_1.Button, { icon: React.createElement(icons_1.CloseOutlined, null), onClick: () => {
onCancel();
} })));
};
exports.PowerSearchTerm = PowerSearchTerm;
//# sourceMappingURL=PowerSearchTerm.js.map
;