"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.tooltipContentIsExplicitlyNull = exports.getDefaultWhenTooltipIsUnspecified = exports.DraggableBadge = exports.DefaultDraggable = exports.Content = exports.Badge = void 0; var _eui = require("@elastic/eui"); var _react = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _draggable_wrapper = require("../drag_and_drop/draggable_wrapper"); var _helpers = require("../drag_and_drop/helpers"); var _empty_value = require("../empty_value"); var _data_provider = require("../../../timelines/components/timeline/data_providers/data_provider"); var _provider = require("../../../timelines/components/timeline/data_providers/provider"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ /** * Only returns true if the specified tooltipContent is exactly `null`. * Example input / output: * `bob -> false` * `undefined -> false` * `thing -> false` * `null -> true` */ const tooltipContentIsExplicitlyNull = tooltipContent => tooltipContent === null; // an explicit / exact null check /** * Derives the tooltip content from the field name if no tooltip was specified */ exports.tooltipContentIsExplicitlyNull = tooltipContentIsExplicitlyNull; const getDefaultWhenTooltipIsUnspecified = ({ field, tooltipContent }) => tooltipContent != null ? tooltipContent : field; /** * Renders the content of the draggable, wrapped in a tooltip */ exports.getDefaultWhenTooltipIsUnspecified = getDefaultWhenTooltipIsUnspecified; const Content = /*#__PURE__*/_react.default.memo(({ children, field, tooltipContent, tooltipPosition, value }) => !tooltipContentIsExplicitlyNull(tooltipContent) ? /*#__PURE__*/_react.default.createElement(_eui.EuiToolTip, { "data-test-subj": `${field}-tooltip`, position: tooltipPosition, content: getDefaultWhenTooltipIsUnspecified({ tooltipContent, field }) }, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children ? children : value)) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children ? children : value)); exports.Content = Content; Content.displayName = 'Content'; /** * Draggable text (or an arbitrary visualization specified by `children`) * that's only displayed when the specified value is non-`null`. * * @param id - a unique draggable id, which typically follows the format `${contextId}-${eventId}-${field}-${value}` * @param isDraggable - optional prop to disable drag & drop and it will defaulted to true * @param field - the name of the field, e.g. `network.transport` * @param value - value of the field e.g. `tcp` * @param name - defaulting to `field`, this optional human readable name is used by the `DataProvider` that represents the data * @param children - defaults to displaying `value`, this allows an arbitrary visualization to be displayed in lieu of the default behavior * @param tooltipContent - defaults to displaying `field`, pass `null` to * prevent a tooltip from being displayed, or pass arbitrary content * @param tooltipPosition - defaults to eui's default tooltip position * @param queryValue - defaults to `value`, this query overrides the `queryMatch.value` used by the `DataProvider` that represents the data * @param hideTopN - defaults to `false`, when true, the option to aggregate this field will be hidden */ const DefaultDraggable = /*#__PURE__*/_react.default.memo(({ hideTopN = false, id, isDraggable = true, field, fieldType = '', isAggregatable = false, value, name, children, scopeId, tooltipContent, tooltipPosition, queryValue, truncate }) => { const dataProviderProp = (0, _react.useMemo)(() => { var _value$toString; return { and: [], enabled: true, id: (0, _helpers.escapeDataProviderId)(id), name: name ? name : (_value$toString = value === null || value === void 0 ? void 0 : value.toString()) !== null && _value$toString !== void 0 ? _value$toString : '', excluded: false, kqlQuery: '', queryMatch: { field, value: queryValue ? queryValue : value !== null && value !== void 0 ? value : '', operator: _data_provider.IS_OPERATOR } }; }, [field, id, name, queryValue, value]); const renderCallback = (0, _react.useCallback)((dataProvider, _, snapshot) => snapshot.isDragging ? /*#__PURE__*/_react.default.createElement(_draggable_wrapper.DragEffects, null, /*#__PURE__*/_react.default.createElement(_provider.Provider, { dataProvider: dataProvider })) : /*#__PURE__*/_react.default.createElement(Content, { field: field, tooltipContent: tooltipContent, tooltipPosition: tooltipPosition, value: value }, children), [children, field, tooltipContent, tooltipPosition, value]); if (value == null) return null; return /*#__PURE__*/_react.default.createElement(_draggable_wrapper.DraggableWrapper, { dataProvider: dataProviderProp, fieldType: fieldType, isAggregatable: isAggregatable, hideTopN: hideTopN, isDraggable: isDraggable, render: renderCallback, scopeId: scopeId, truncate: truncate }); }); exports.DefaultDraggable = DefaultDraggable; DefaultDraggable.displayName = 'DefaultDraggable'; const Badge = (0, _styledComponents.default)(_eui.EuiBadge)` vertical-align: top; `; exports.Badge = Badge; Badge.displayName = 'Badge'; /** * A draggable badge that's only displayed when the specified value is non-`null`. * * @param contextId - used as part of the formula to derive a unique draggable id, this describes the context e.g. `event-fields-browser` in which the badge is displayed * @param eventId - uniquely identifies an event, as specified in the `_id` field of the document * @param field - the name of the field, e.g. `network.transport` * @param value - value of the field e.g. `tcp` * @param iconType -the (optional) type of icon e.g. `snowflake` to display on the badge * @param isDraggable * @param name - defaulting to `field`, this optional human readable name is used by the `DataProvider` that represents the data * @param color - defaults to `hollow`, optionally overwrite the color of the badge icon * @param children - defaults to displaying `value`, this allows an arbitrary visualization to be displayed in lieu of the default behavior * @param tooltipContent - defaults to displaying `field`, pass `null` to * prevent a tooltip from being displayed, or pass arbitrary content * @param queryValue - defaults to `value`, this query overrides the `queryMatch.value` used by the `DataProvider` that represents the data */ const DraggableBadgeComponent = ({ contextId, eventId, field, value, iconType, isDraggable, isAggregatable, fieldType, name, color = 'hollow', children, scopeId, tooltipContent, queryValue }) => value != null ? /*#__PURE__*/_react.default.createElement(DefaultDraggable, { id: `draggable-badge-default-draggable-${contextId}-${eventId}-${field}-${value}`, isDraggable: isDraggable, isAggregatable: isAggregatable, fieldType: fieldType, field: field, name: name, value: value, scopeId: scopeId, tooltipContent: tooltipContent, queryValue: queryValue }, /*#__PURE__*/_react.default.createElement(Badge, { iconType: iconType, color: color, title: "" }, children ? children : value !== '' ? value : (0, _empty_value.getEmptyStringTag)())) : null; DraggableBadgeComponent.displayName = 'DraggableBadgeComponent'; const DraggableBadge = /*#__PURE__*/_react.default.memo(DraggableBadgeComponent); exports.DraggableBadge = DraggableBadge; DraggableBadge.displayName = 'DraggableBadge';