flipper-plugin
Version:
Flipper Desktop plugin SDK and components
64 lines • 2.9 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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PowerSearchAbsoluteDateTerm = exports.DATE_TIME_FORMAT = exports.DATE_ONLY_FORMAT = void 0;
const antd_1 = require("antd");
const dayjs_1 = __importDefault(require("dayjs"));
const react_1 = __importDefault(require("react"));
// Use this exact version of moment to match what antd has
// eslint-disable-next-line no-restricted-imports
const moment_1 = __importDefault(require("antd/node_modules/moment"));
exports.DATE_ONLY_FORMAT = 'YYYY-MM-DD';
exports.DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
const PowerSearchAbsoluteDateTerm = ({ onCancel, onChange, dateOnly, minValue, maxValue, defaultValue }) => {
const [editing, setEditing] = react_1.default.useState(!defaultValue);
const disabledDate = react_1.default.useCallback((date) => {
if (minValue !== undefined && date < minValue) {
return true;
}
if (maxValue !== undefined && date > maxValue) {
return true;
}
return false;
}, [minValue, maxValue]);
const format = dateOnly ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss';
const valueRef = react_1.default.useRef();
if (defaultValue && !valueRef.current) {
valueRef.current = defaultValue;
}
if (editing) {
return (react_1.default.createElement(antd_1.DatePicker, { autoFocus: true, style: { width: 100 }, placeholder: "...", format: format, onChange: (newValue) => {
if (!newValue) {
onCancel();
return;
}
const newDate = newValue.toDate();
valueRef.current = newDate;
onChange(newDate);
}, onKeyDown: (event) => {
if (event.key === 'Escape') {
onCancel();
}
}, onBlur: () => {
if (!valueRef.current) {
onCancel();
}
setEditing(false);
}, disabledDate: disabledDate, showTime: !dateOnly, defaultOpen: true, defaultValue: defaultValue ? (0, moment_1.default)(defaultValue) : undefined }));
}
return (react_1.default.createElement(antd_1.Button, { onClick: () => setEditing(true) }, dateOnly
? (0, dayjs_1.default)(defaultValue).format(exports.DATE_ONLY_FORMAT)
: (0, dayjs_1.default)(defaultValue).format(exports.DATE_TIME_FORMAT)));
};
exports.PowerSearchAbsoluteDateTerm = PowerSearchAbsoluteDateTerm;
//# sourceMappingURL=PowerSearchAbsoluteDateTerm.js.map
;