"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.AddToCaseButton = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _react = _interopRequireWildcard(require("react")); var _common = require("@kbn/cases-plugin/common"); var _eui = require("@elastic/eui"); var _i18n = require("@kbn/i18n"); var _kibana = require("../common/lib/kibana"); var _contexts = require("../common/contexts"); 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. */ const ADD_TO_CASE = _i18n.i18n.translate('xpack.osquery.pack.queriesTable.addToCaseResultsActionAriaLabel', { defaultMessage: 'Add to Case' }); const AddToCaseButton = ({ actionId, agentIds = [], queryId = '', isIcon = false, isDisabled, iconProps }) => { const { cases } = (0, _kibana.useKibana)().services; const ecsData = (0, _react.useContext)(_contexts.AlertAttachmentContext); const alertAttachments = (0, _react.useMemo)(() => { var _ecsData$_id, _ecsData$_index; return ecsData !== null && ecsData !== void 0 && ecsData._id ? [{ alertId: (_ecsData$_id = ecsData === null || ecsData === void 0 ? void 0 : ecsData._id) !== null && _ecsData$_id !== void 0 ? _ecsData$_id : '', index: (_ecsData$_index = ecsData === null || ecsData === void 0 ? void 0 : ecsData._index) !== null && _ecsData$_index !== void 0 ? _ecsData$_index : '', rule: cases.helpers.getRuleIdFromEvent({ ecs: ecsData, data: [] }), type: _common.AttachmentType.alert }] : []; }, [cases.helpers, ecsData]); const casePermissions = cases.helpers.canUseCases(); const hasCasesPermissions = casePermissions.read && casePermissions.update && casePermissions.push; const selectCaseModal = cases.hooks.useCasesAddToExistingCaseModal(); const handleClick = (0, _react.useCallback)(() => { const attachments = [...alertAttachments, { type: _common.AttachmentType.externalReference, externalReferenceId: actionId, externalReferenceStorage: { type: _common.ExternalReferenceStorageType.elasticSearchDoc }, externalReferenceAttachmentTypeId: 'osquery', externalReferenceMetadata: { actionId, agentIds, queryId } }]; if (hasCasesPermissions) { selectCaseModal.open({ getAttachments: () => attachments }); } }, [actionId, agentIds, alertAttachments, hasCasesPermissions, queryId, selectCaseModal]); if (isIcon) { return /*#__PURE__*/_react.default.createElement(_eui.EuiToolTip, { content: /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, ADD_TO_CASE) }, /*#__PURE__*/_react.default.createElement(_eui.EuiButtonIcon, (0, _extends2.default)({ iconType: 'casesApp', onClick: handleClick, isDisabled: isDisabled || !hasCasesPermissions, "aria-label": ADD_TO_CASE }, iconProps))); } return /*#__PURE__*/_react.default.createElement(_eui.EuiButtonEmpty, { size: "xs", iconType: "casesApp", onClick: handleClick, isDisabled: isDisabled || !hasCasesPermissions, "aria-label": ADD_TO_CASE }, ADD_TO_CASE); }; exports.AddToCaseButton = AddToCaseButton;