"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.CasesUiPlugin = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _public = require("@kbn/kibana-utils-plugin/public"); var _history = require("history"); var _kibana = require("./common/lib/kibana"); var _constants = require("../common/constants"); var _translations = require("./common/translations"); var _use_cases_add_to_existing_case_modal = require("./components/all_cases/selector_modal/use_cases_add_to_existing_case_modal"); var _use_cases_add_to_new_case_flyout = require("./components/create/flyout/use_cases_add_to_new_case_flyout"); var _api = require("./client/api"); var _can_use_cases = require("./client/helpers/can_use_cases"); var _get_rule_id_from_event = require("./client/helpers/get_rule_id_from_event"); var _get_all_cases_selector_modal = require("./client/ui/get_all_cases_selector_modal"); var _get_cases = require("./client/ui/get_cases"); var _get_cases_context = require("./client/ui/get_cases_context"); var _get_recent_cases = require("./client/ui/get_recent_cases"); var _group_alerts_by_rule = require("./client/helpers/group_alerts_by_rule"); var _capabilities = require("./client/helpers/capabilities"); var _external_reference_registry = require("./client/attachment_framework/external_reference_registry"); var _persistable_state_registry = require("./client/attachment_framework/persistable_state_registry"); var _files = require("./files"); var _internal_attachments = require("./internal_attachments"); var _actions = require("./components/visualizations/actions"); 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; } /** * @public * A plugin for retrieving Cases UI components */ class CasesUiPlugin { constructor(initializerContext) { (0, _defineProperty2.default)(this, "kibanaVersion", void 0); (0, _defineProperty2.default)(this, "storage", new _public.Storage(localStorage)); (0, _defineProperty2.default)(this, "externalReferenceAttachmentTypeRegistry", void 0); (0, _defineProperty2.default)(this, "persistableStateAttachmentTypeRegistry", void 0); this.initializerContext = initializerContext; this.kibanaVersion = initializerContext.env.packageInfo.version; this.externalReferenceAttachmentTypeRegistry = new _external_reference_registry.ExternalReferenceAttachmentTypeRegistry(); this.persistableStateAttachmentTypeRegistry = new _persistable_state_registry.PersistableStateAttachmentTypeRegistry(); } setup(core, plugins) { const kibanaVersion = this.kibanaVersion; const storage = this.storage; const externalReferenceAttachmentTypeRegistry = this.externalReferenceAttachmentTypeRegistry; const persistableStateAttachmentTypeRegistry = this.persistableStateAttachmentTypeRegistry; (0, _internal_attachments.registerInternalAttachments)(externalReferenceAttachmentTypeRegistry, persistableStateAttachmentTypeRegistry); const config = this.initializerContext.config.get(); (0, _files.registerCaseFileKinds)(config.files, plugins.files); if (plugins.home) { plugins.home.featureCatalogue.register({ id: _constants.APP_ID, title: _translations.APP_TITLE, description: _translations.APP_DESC, icon: 'casesApp', path: _constants.APP_PATH, showOnHomePage: false, category: 'admin' }); } if (config.stack.enabled) { plugins.management.sections.section.insightsAndAlerting.registerApp({ id: _constants.APP_ID, title: _translations.APP_TITLE, order: 1, async mount(params) { const [coreStart, pluginsStart] = await core.getStartServices(); const { renderApp } = await Promise.resolve().then(() => _interopRequireWildcard(require('./application'))); return renderApp({ mountParams: params, coreStart, pluginsStart, storage, kibanaVersion, externalReferenceAttachmentTypeRegistry, persistableStateAttachmentTypeRegistry }); } }); } return { attachmentFramework: { registerExternalReference: externalReferenceAttachmentType => { this.externalReferenceAttachmentTypeRegistry.register(externalReferenceAttachmentType); }, registerPersistableState: persistableStateAttachmentType => { this.persistableStateAttachmentTypeRegistry.register(persistableStateAttachmentType); } } }; } start(core, plugins) { const config = this.initializerContext.config.get(); _kibana.KibanaServices.init({ ...core, ...plugins, kibanaVersion: this.kibanaVersion, config }); /** * getCasesContextLazy returns a new component each time is being called. To avoid re-renders * we get the component on start and provide the same component to all consumers. */ const getCasesContext = (0, _get_cases_context.getCasesContextLazy)({ externalReferenceAttachmentTypeRegistry: this.externalReferenceAttachmentTypeRegistry, persistableStateAttachmentTypeRegistry: this.persistableStateAttachmentTypeRegistry, getFilesClient: plugins.files.filesClientFactory.asScoped }); (0, _actions.registerActions)({ core, plugins, caseContextProps: { externalReferenceAttachmentTypeRegistry: this.externalReferenceAttachmentTypeRegistry, persistableStateAttachmentTypeRegistry: this.persistableStateAttachmentTypeRegistry, getFilesClient: plugins.files.filesClientFactory.asScoped }, history: (0, _history.createBrowserHistory)(), storage: this.storage }); return { api: (0, _api.createClientAPI)({ http: core.http }), ui: { getCases: props => (0, _get_cases.getCasesLazy)({ ...props, externalReferenceAttachmentTypeRegistry: this.externalReferenceAttachmentTypeRegistry, persistableStateAttachmentTypeRegistry: this.persistableStateAttachmentTypeRegistry, getFilesClient: plugins.files.filesClientFactory.asScoped }), getCasesContext, getRecentCases: props => (0, _get_recent_cases.getRecentCasesLazy)({ ...props, externalReferenceAttachmentTypeRegistry: this.externalReferenceAttachmentTypeRegistry, persistableStateAttachmentTypeRegistry: this.persistableStateAttachmentTypeRegistry, getFilesClient: plugins.files.filesClientFactory.asScoped }), // @deprecated Please use the hook useCasesAddToExistingCaseModal getAllCasesSelectorModal: props => (0, _get_all_cases_selector_modal.getAllCasesSelectorModalLazy)({ ...props, externalReferenceAttachmentTypeRegistry: this.externalReferenceAttachmentTypeRegistry, persistableStateAttachmentTypeRegistry: this.persistableStateAttachmentTypeRegistry, getFilesClient: plugins.files.filesClientFactory.asScoped }) }, hooks: { useCasesAddToNewCaseFlyout: _use_cases_add_to_new_case_flyout.useCasesAddToNewCaseFlyout, useCasesAddToExistingCaseModal: _use_cases_add_to_existing_case_modal.useCasesAddToExistingCaseModal }, helpers: { canUseCases: (0, _can_use_cases.canUseCases)(core.application.capabilities), getUICapabilities: _capabilities.getUICapabilities, getRuleIdFromEvent: _get_rule_id_from_event.getRuleIdFromEvent, groupAlertsByRule: _group_alerts_by_rule.groupAlertsByRule } }; } stop() {} } exports.CasesUiPlugin = CasesUiPlugin;