From 16ce3fb7ee2f44d3ce81d02ebcf25a15c1d6ac7f Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 5 Aug 2020 03:38:16 -0700 Subject: [PATCH 01/23] adding telemetry, extraction, injection to embeddables --- .../default_embeddable_factory_provider.ts | 4 + .../lib/embeddables/embeddable_factory.ts | 3 +- .../embeddable_factory_definition.ts | 3 + .../public/lib/embeddables/i_embeddable.ts | 3 +- .../lib/embeddables/migrate_base_input.ts | 36 ++++++ src/plugins/embeddable/public/mocks.tsx | 4 + src/plugins/embeddable/public/plugin.tsx | 112 +++++++++++++++++- src/plugins/embeddable/public/types.ts | 11 ++ src/plugins/kibana_utils/common/index.ts | 1 + .../common/persistable_state/index.ts | 48 ++++++++ 10 files changed, 221 insertions(+), 4 deletions(-) create mode 100644 src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts create mode 100644 src/plugins/kibana_utils/common/persistable_state/index.ts diff --git a/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts b/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts index 570a78fc41ea9..c8a0efc361fda 100644 --- a/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts +++ b/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +import { identity } from 'lodash'; import { SavedObjectAttributes } from 'kibana/public'; import { EmbeddableFactoryDefinition } from './embeddable_factory_definition'; import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable'; @@ -47,6 +48,9 @@ export const defaultEmbeddableFactoryProvider = < isEditable: def.isEditable.bind(def), getDisplayName: def.getDisplayName.bind(def), savedObjectMetaData: def.savedObjectMetaData, + telemetry: def.telemetry || (() => ({})), + inject: def.inject || identity, + extract: def.extract || ((state: EmbeddableInput) => ({ state, references: [] })), }; return factory; }; diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts index 7949b6fb8ba27..a6fa46fbc4e3e 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts @@ -23,6 +23,7 @@ import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable'; import { ErrorEmbeddable } from './error_embeddable'; import { IContainer } from '../containers/i_container'; import { PropertySpec } from '../types'; +import { PersistableState } from '../../../../kibana_utils/common'; export interface EmbeddableInstanceConfiguration { id: string; @@ -44,7 +45,7 @@ export interface EmbeddableFactory< TEmbeddableOutput >, TSavedObjectAttributes extends SavedObjectAttributes = SavedObjectAttributes -> { +> extends PersistableState { // A unique identified for this factory, which will be used to map an embeddable spec to // a factory that can generate an instance of it. readonly type: string; diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory_definition.ts b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory_definition.ts index b8985f7311ea9..224a11a201b88 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory_definition.ts +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory_definition.ts @@ -40,5 +40,8 @@ export type EmbeddableFactoryDefinition< | 'savedObjectMetaData' | 'canCreateNew' | 'getDefaultInput' + | 'telemetry' + | 'extract' + | 'inject' > >; diff --git a/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts b/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts index e8aecdba0abc4..a1cb7e45b3a0b 100644 --- a/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts +++ b/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts @@ -23,6 +23,7 @@ import { IContainer } from '../containers/i_container'; import { ViewMode } from '../types'; import { TriggerContextMapping } from '../../../../ui_actions/public'; import type { TimeRange, Query, Filter } from '../../../../data/common'; +import { SerializableState } from '../../../../kibana_utils/common/persistable_state'; export interface EmbeddableError { name: string; @@ -44,7 +45,7 @@ export interface EmbeddableInput { /** * Reserved key for enhancements added by other plugins. */ - enhancements?: unknown; + enhancements?: Record; /** * List of action IDs that this embeddable should not render. diff --git a/src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts b/src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts new file mode 100644 index 0000000000000..aad7bdc3c336a --- /dev/null +++ b/src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts @@ -0,0 +1,36 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SavedObjectReference } from '../../../../../core/types'; +import { EmbeddableInput } from './i_embeddable'; + +export const telemetryBaseEmbeddableInput = (state: EmbeddableInput) => { + return {}; +}; + +export const extractBaseEmbeddableInput = (state: EmbeddableInput) => { + return { state, references: [] as SavedObjectReference[] }; +}; + +export const injectBaseEmbeddableInput = ( + state: EmbeddableInput, + references: SavedObjectReference[] +) => { + return state; +}; diff --git a/src/plugins/embeddable/public/mocks.tsx b/src/plugins/embeddable/public/mocks.tsx index 2064236e9ae7f..26c10121adb3d 100644 --- a/src/plugins/embeddable/public/mocks.tsx +++ b/src/plugins/embeddable/public/mocks.tsx @@ -109,6 +109,7 @@ export const mockRefOrValEmbeddable = < const createSetupContract = (): Setup => { const setupContract: Setup = { registerEmbeddableFactory: jest.fn(), + registerEnhancement: jest.fn(), setCustomEmbeddableFactoryProvider: jest.fn(), }; return setupContract; @@ -118,6 +119,9 @@ const createStartContract = (): Start => { const startContract: Start = { getEmbeddableFactories: jest.fn(), getEmbeddableFactory: jest.fn(), + telemetry: jest.fn(), + extract: jest.fn(), + inject: jest.fn(), EmbeddablePanel: jest.fn(), getEmbeddablePanel: jest.fn(), getStateTransfer: jest.fn(() => createEmbeddableStateTransferMock() as EmbeddableStateTransfer), diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index 2ca31994b722d..5560baed2dfb4 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -18,6 +18,7 @@ */ import React from 'react'; import { Subscription } from 'rxjs'; +import { identity } from 'lodash'; import { DataPublicPluginSetup, DataPublicPluginStart } from '../../data/public'; import { getSavedObjectFinder } from '../../saved_objects/public'; import { UiActionsSetup, UiActionsStart } from '../../ui_actions/public'; @@ -29,8 +30,14 @@ import { Plugin, ScopedHistory, PublicAppInfo, + SavedObjectReference, } from '../../../core/public'; -import { EmbeddableFactoryRegistry, EmbeddableFactoryProvider } from './types'; +import { + EmbeddableFactoryRegistry, + EmbeddableFactoryProvider, + EnhancementsRegistry, + EnhancementRegistryDefinition, +} from './types'; import { bootstrap } from './bootstrap'; import { EmbeddableFactory, @@ -42,6 +49,12 @@ import { } from './lib'; import { EmbeddableFactoryDefinition } from './lib/embeddables/embeddable_factory_definition'; import { EmbeddableStateTransfer } from './lib/state_transfer'; +import { + extractBaseEmbeddableInput, + injectBaseEmbeddableInput, + telemetryBaseEmbeddableInput, +} from './lib/embeddables/migrate_base_input'; +import { PersistableState, SerializableState } from '../../kibana_utils/common'; export interface EmbeddableSetupDependencies { data: DataPublicPluginSetup; @@ -63,10 +76,11 @@ export interface EmbeddableSetup { id: string, factory: EmbeddableFactoryDefinition ) => () => EmbeddableFactory; + registerEnhancement: (enhancement: EnhancementRegistryDefinition) => void; setCustomEmbeddableFactoryProvider: (customProvider: EmbeddableFactoryProvider) => void; } -export interface EmbeddableStart { +export interface EmbeddableStart extends PersistableState { getEmbeddableFactory: < I extends EmbeddableInput = EmbeddableInput, O extends EmbeddableOutput = EmbeddableOutput, @@ -88,6 +102,7 @@ export class EmbeddablePublicPlugin implements Plugin = new Map(); private readonly embeddableFactories: EmbeddableFactoryRegistry = new Map(); + private readonly enhancements: EnhancementsRegistry = new Map(); private customEmbeddableFactoryProvider?: EmbeddableFactoryProvider; private outgoingOnlyStateTransfer: EmbeddableStateTransfer = {} as EmbeddableStateTransfer; private isRegistryReady = false; @@ -101,6 +116,7 @@ export class EmbeddablePublicPlugin implements Plugin { if (this.customEmbeddableFactoryProvider) { throw new Error( @@ -168,6 +184,9 @@ export class EmbeddablePublicPlugin implements Plugin { + const enhancements: Record = (state as any).enhanecemnts || {}; + const factory = this.getEmbeddableFactory(state.id); + + const telemetryData = telemetryBaseEmbeddableInput(state); + factory.telemetry(state); + Object.keys(enhancements).map((key) => { + this.getEnhancement(key).telemetry(enhancements[key]); + }); + + return telemetryData; + }; + + private extract = (state: EmbeddableInput) => { + const enhancements = state.enhancements || {}; + const factory = this.getEmbeddableFactory(state.id); + + const baseResponse = extractBaseEmbeddableInput(state); + let updatedInput = baseResponse.state; + let refs = baseResponse.references; + + if (factory) { + const factoryResponse = factory.extract(state); + updatedInput = factoryResponse.state; + refs = refs.concat(factoryResponse.references); + } + + updatedInput.enhancements = {}; + Object.keys(enhancements).map((key) => { + const enhancementResult = this.getEnhancement(key).extract(enhancements[key]); + refs = refs.concat(enhancementResult.references); + updatedInput.enhancements![key] = enhancementResult.state; + }); + + return { + state: updatedInput, + references: refs, + }; + }; + + private inject = (state: EmbeddableInput, references: SavedObjectReference[]) => { + const enhancements = state.enhanecemnts || {}; + const factory = this.getEmbeddableFactory(state.id); + + let updatedInput = injectBaseEmbeddableInput(state, references); + + if (factory) { + updatedInput = factory.inject(updatedInput, references); + } + + updatedInput.enhancements = {}; + Object.keys(enhancements).map((key) => { + updatedInput.enhancements![key] = this.getEnhancement(key).inject( + enhancements[key], + references + ); + }); + + return updatedInput; + }; + + private registerEnhancement = (enhancement: EnhancementRegistryDefinition) => { + if (this.enhancements.has(enhancement.id)) { + throw new Error(`enhancement with id ${enhancement.id} already exists in the registry`); + } + this.enhancements.set(enhancement.id, { + id: enhancement.id, + telemetry: enhancement.telemetry || (() => ({})), + inject: enhancement.inject || identity, + extract: + enhancement.extract || + ((state: SerializableState) => { + return { state, references: [] }; + }), + }); + }; + + private getEnhancement = (id: string) => { + return ( + this.enhancements.get(id) || { + telemetry: () => ({}), + inject: identity, + extract: (state: SerializableState) => { + return { state, references: [] }; + }, + } + ); + }; + private getEmbeddableFactories = () => { this.ensureFactoriesExist(); return this.embeddableFactories.values(); diff --git a/src/plugins/embeddable/public/types.ts b/src/plugins/embeddable/public/types.ts index 2d112b2359818..98202b710e83a 100644 --- a/src/plugins/embeddable/public/types.ts +++ b/src/plugins/embeddable/public/types.ts @@ -25,8 +25,19 @@ import { IEmbeddable, EmbeddableFactoryDefinition, } from './lib/embeddables'; +import { PersistableStateDefinition, SerializableState } from '../../kibana_utils/common'; export type EmbeddableFactoryRegistry = Map; +export type EnhancementsRegistry = Map; + +export interface EnhancementRegistryDefinition + extends PersistableStateDefinition { + id: string; +} + +export interface EnhancementRegistryItem extends PersistableStateDefinition { + id: string; +} export type EmbeddableFactoryProvider = < I extends EmbeddableInput = EmbeddableInput, diff --git a/src/plugins/kibana_utils/common/index.ts b/src/plugins/kibana_utils/common/index.ts index 1ec5737c5a38b..e09290c811c7b 100644 --- a/src/plugins/kibana_utils/common/index.ts +++ b/src/plugins/kibana_utils/common/index.ts @@ -29,3 +29,4 @@ export { distinctUntilChangedWithInitialValue } from './distinct_until_changed_w export { url } from './url'; export { now } from './now'; export { calculateObjectHash } from './calculate_object_hash'; +export * from './persistable_state'; diff --git a/src/plugins/kibana_utils/common/persistable_state/index.ts b/src/plugins/kibana_utils/common/persistable_state/index.ts new file mode 100644 index 0000000000000..3bd54fda6b490 --- /dev/null +++ b/src/plugins/kibana_utils/common/persistable_state/index.ts @@ -0,0 +1,48 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SavedObjectReference } from '../../../../core/types'; + +type State = string | number | boolean | null | undefined | SerializableState; + +export interface SerializableState { + [key: string]: State | State[] | Record; +} + +export interface PersistableState

{ + // function to extract telemetry information + telemetry: (state: P) => Record; + // inject function receives state and a list of references and should return state with references injected + // default is identity function + inject: (state: P, references: SavedObjectReference[]) => P; + // extract function receives state and should return state with references extracted and array of references + // default returns same state with empty reference array + extract: (state: P) => { state: P; references: SavedObjectReference[] }; +} + +export interface PersistableStateDefinition

{ + // function to extract telemetry information + telemetry?: (state: P) => Record; + // inject function receives state and a list of references and should return state with references injected + // default is identity function + inject?: (state: P, references: SavedObjectReference[]) => P; + // extract function receives state and should return state with references extracted and array of references + // default returns same state with empty reference array + extract?: (state: P) => { state: P; references: SavedObjectReference[] }; +} From c363dd6135fa8df7cff9d98f37de1c53984994ca Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 5 Aug 2020 04:24:13 -0700 Subject: [PATCH 02/23] dynamic actions --- .../embeddables/dynamic_action_enhancement.ts | 30 +++++++++++++++++ .../embeddable_enhanced/public/plugin.ts | 3 +- .../public/dynamic_actions/action_factory.ts | 21 ++++++++++-- .../action_factory_definition.ts | 7 ++-- .../ui_actions_enhanced/public/mocks.ts | 3 ++ .../ui_actions_enhanced/public/plugin.ts | 5 ++- .../ui_actions_service_enhancements.ts | 32 ++++++++++++++++++- 7 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts diff --git a/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts b/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts new file mode 100644 index 0000000000000..828f452f5e7b5 --- /dev/null +++ b/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { EnhancementRegistryDefinition } from '../../../../../src/plugins/embeddable/public'; +import { SavedObjectReference } from '../../../../../src/core/types'; +import { StartServicesGetter } from '../../../../../src/plugins/kibana_utils/public'; +import { StartDependencies } from '../plugin'; +import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; + +export interface DynamicActionEnhancementDeps { + start: StartServicesGetter>; +} + +export const dynamicActionEnhancement = (start) => { + return { + id: 'dynamicActions', + telemetry: (state: SerializableState) => { + return start.uiActionsEnhanced.telemetry(state); + }, + extract: (state: SerializableState) => { + return start.uiActionsEnhanced.extract(state); + }, + inject: (state: SerializableState, refereces: SavedObjectReference[]) => { + return start.uiActionsEnhanced.inject(state, references); + }, + }; +}; diff --git a/x-pack/plugins/embeddable_enhanced/public/plugin.ts b/x-pack/plugins/embeddable_enhanced/public/plugin.ts index 37e102b40131d..769946461f824 100644 --- a/x-pack/plugins/embeddable_enhanced/public/plugin.ts +++ b/x-pack/plugins/embeddable_enhanced/public/plugin.ts @@ -68,6 +68,7 @@ export class EmbeddableEnhancedPlugin const panelNotificationAction = new PanelNotificationsAction(); plugins.uiActionsEnhanced.registerAction(panelNotificationAction); plugins.uiActionsEnhanced.attachAction(PANEL_NOTIFICATION_TRIGGER, panelNotificationAction.id); + plugins.embeddable.registerEmbeddableEnhancement(dynamicActionEnhancement(startServices)); plugins.uiActionsEnhanced.registerDrilldown( new UrlDrilldown({ @@ -82,7 +83,7 @@ export class EmbeddableEnhancedPlugin return {}; } - public start(core: CoreStart, plugins: StartDependencies): StartContract { + public start(core: CoreStart, plugins: StartDependenciesStartDependencies): StartContract { this.uiActions = plugins.uiActionsEnhanced; return {}; diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts index 35a82adf9896d..9c6de063a5ce9 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts @@ -12,9 +12,11 @@ import { } from '../../../../../src/plugins/ui_actions/public'; import { ActionFactoryDefinition } from './action_factory_definition'; import { Configurable } from '../../../../../src/plugins/kibana_utils/public'; -import { BaseActionFactoryContext, SerializedAction } from './types'; +import { BaseActionFactoryContext, SerializedAction, SerializedEvent } from './types'; import { ILicense, LicensingPluginStart } from '../../../licensing/public'; import { UiActionsActionDefinition as ActionDefinition } from '../../../../../src/plugins/ui_actions/public'; +import { SavedObjectReference } from '../../../../../src/core/types'; +import { Serializable } from '../../../../../src/plugins/kibana_utils/common/persistable_state'; export interface ActionFactoryDeps { readonly getLicense: () => ILicense; @@ -28,7 +30,10 @@ export class ActionFactory< triggers: SupportedTriggers[]; }, ActionContext extends TriggerContextMapping[SupportedTriggers] = TriggerContextMapping[SupportedTriggers] -> implements Omit, 'getHref'>, Configurable { +> implements + Omit, 'getHref'>, + Configurable, + PersistableState { constructor( protected readonly def: ActionFactoryDefinition< Config, @@ -120,4 +125,16 @@ export class ActionFactory< ); }); } + + public telemetry(state: SerializedEvent) { + return this.def.telemetry ? this.def.telemetry(state) : {}; + } + + public extract(state: SerializedEvent) { + return this.def.extract ? this.def.extract(state) : { state, references: [] }; + } + + public inject(state: SerializedEvent, references: SavedObjectReference[]) { + return this.def.inject ? this.def.inject(state, references) : state; + } } diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts index 91b8c8ec1e5ef..aa43b1f6f4178 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts @@ -5,7 +5,7 @@ */ import { Configurable } from '../../../../../src/plugins/kibana_utils/public'; -import { BaseActionFactoryContext, SerializedAction } from './types'; +import { BaseActionFactoryContext, SerializedAction, SerializedEvent } from './types'; import { LicenseType } from '../../../licensing/public'; import { TriggerContextMapping, @@ -13,6 +13,8 @@ import { UiActionsActionDefinition as ActionDefinition, UiActionsPresentable as Presentable, } from '../../../../../src/plugins/ui_actions/public'; +import { SavedObjectReference } from '../../../../../src/core/types'; +import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common'; /** * This is a convenience interface for registering new action factories. @@ -25,7 +27,8 @@ export interface ActionFactoryDefinition< }, ActionContext extends TriggerContextMapping[SupportedTriggers] = TriggerContextMapping[SupportedTriggers] > extends Partial, 'getHref'>>, - Configurable { + Configurable, + PersistableStateDefinition { /** * Unique ID of the action factory. This ID is used to identify this action * factory in the registry as well as to construct actions of this type and diff --git a/x-pack/plugins/ui_actions_enhanced/public/mocks.ts b/x-pack/plugins/ui_actions_enhanced/public/mocks.ts index 17a6fc1b955df..9eb0a06b6dbaf 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/mocks.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/mocks.ts @@ -30,6 +30,9 @@ const createStartContract = (): Start => { getActionFactories: jest.fn(), getActionFactory: jest.fn(), FlyoutManageDrilldowns: jest.fn(), + telemetry: jest.fn(), + extract: jest.fn(), + inject: jest.fn(), }; return startContract; diff --git a/x-pack/plugins/ui_actions_enhanced/public/plugin.ts b/x-pack/plugins/ui_actions_enhanced/public/plugin.ts index 015531aab9743..fb9077701a748 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/plugin.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/plugin.ts @@ -58,7 +58,10 @@ export interface SetupContract export interface StartContract extends UiActionsStart, - Pick { + Pick< + UiActionsServiceEnhancements, + 'getActionFactory' | 'getActionFactories' | 'telemetry' | 'extract' | 'inject' + > { FlyoutManageDrilldowns: ReturnType; } diff --git a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts index b8086c16f5e71..eaee39ddc4f50 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts @@ -9,11 +9,14 @@ import { ActionFactory, ActionFactoryDefinition, BaseActionFactoryContext, + SerializedEvent, } from '../dynamic_actions'; import { DrilldownDefinition } from '../drilldowns'; import { ILicense } from '../../../licensing/common/types'; import { TriggerContextMapping, TriggerId } from '../../../../../src/plugins/ui_actions/public'; import { LicensingPluginSetup, LicensingPluginStart } from '../../../licensing/public'; +import { SavedObjectReference } from '../../../../../src/core/types'; +import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common/persistable_state'; export interface UiActionsServiceEnhancementsParams { readonly actionFactories?: ActionFactoryRegistry; @@ -22,7 +25,7 @@ export interface UiActionsServiceEnhancementsParams { readonly getFeatureUsageStart: () => LicensingPluginStart['featureUsage']; } -export class UiActionsServiceEnhancements { +export class UiActionsServiceEnhancements implements PersistableStateDefinition { protected readonly actionFactories: ActionFactoryRegistry; protected readonly deps: Omit; @@ -101,6 +104,9 @@ export class UiActionsServiceEnhancements { licenseFeatureName, supportedTriggers, isCompatible, + migrate, + extract, + inject, }: DrilldownDefinition): void => { const actionFactory: ActionFactoryDefinition< Config, @@ -117,6 +123,9 @@ export class UiActionsServiceEnhancements { isConfigValid, getDisplayName, supportedTriggers, + telemetry, + extract, + inject, getIconType: () => euiIcon, isCompatible: async () => true, create: (serializedAction) => ({ @@ -149,4 +158,25 @@ export class UiActionsServiceEnhancements { ); }); }; + + public telemetry(state: SerializedEvent) { + return this.actionFactories.has(state.eventId) + ? this.actionFactories.get(state.eventId)!.telemetry(state) + : {}; + } + + public extract(state: SerializedEvent) { + return this.actionFactories.has(state.eventId) + ? this.actionFactories.get(state.eventId)!.extract(state) + : { + state, + references: [], + }; + } + + public inject(state: SerializedEvent, references: SavedObjectReference[]) { + return this.actionFactories.has(state.eventId) + ? this.actionFactories.get(state.eventId)!.inject(state, references) + : state; + } } From 76091313f668c35a100cf54de029811889242fc6 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 5 Aug 2020 06:31:09 -0700 Subject: [PATCH 03/23] drilldowns --- .../drilldown.tsx | 31 ++++++++++++++++++- .../public/drilldowns/drilldown_definition.ts | 5 +-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx index 056feeb2b2167..6016a9c28828e 100644 --- a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx +++ b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx @@ -13,7 +13,10 @@ import { } from '../../../../../../../src/plugins/dashboard/public'; import { CollectConfigContainer } from './components'; import { DASHBOARD_TO_DASHBOARD_DRILLDOWN } from './constants'; -import { UiActionsEnhancedDrilldownDefinition as Drilldown } from '../../../../../ui_actions_enhanced/public'; +import { + UiActionsEnhancedDrilldownDefinition as Drilldown, + SerializedEvent, +} from '../../../../../ui_actions_enhanced/public'; import { txtGoToDashboard } from './i18n'; import { ApplyGlobalFilterActionContext, @@ -26,6 +29,7 @@ import { StartServicesGetter } from '../../../../../../../src/plugins/kibana_uti import { StartDependencies } from '../../../plugin'; import { Config, FactoryContext } from './types'; import { SearchInput } from '../../../../../../../src/plugins/discover/public'; +import { SavedObjectReference } from '../../../../../../../src/core/types'; export interface Params { start: StartServicesGetter>; @@ -122,4 +126,29 @@ export class DashboardToDashboardDrilldown return this.params.getDashboardUrlGenerator().createUrl(state); }; + + public telemetry = () => ({}); + + public extract = (state: SerializedEvent) => { + return { + references: [ + { + id: `${state.id}-dashboardId`, + type: 'dashboard', + value: state.dashboardId, + }, + ], + state: { + ...state, + dashboardId: `${state.id}-dashboardId`, + }, + }; + }; + + public inject = (state: SerializedEvent, references: SavedObjectReference[]) => { + return { + ...state, + dashboardId: references.find((r) => r.id === `${state.id}-dashboardId`).value, + }; + }; } diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts index 8faccc088a327..3451af9bf0eda 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts @@ -4,10 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ActionFactoryDefinition, BaseActionFactoryContext } from '../dynamic_actions'; +import { ActionFactoryDefinition, BaseActionFactoryContext, SerializedEvent } from '../dynamic_actions'; import { LicenseType } from '../../../licensing/public'; import { TriggerContextMapping, TriggerId } from '../../../../../src/plugins/ui_actions/public'; import { ActionExecutionContext } from '../../../../../src/plugins/ui_actions/public'; +import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common/persistable_state'; /** * This is a convenience interface to register a drilldown. Drilldown has @@ -30,7 +31,7 @@ export interface DrilldownDefinition< triggers: SupportedTriggers[]; }, ExecutionContext extends TriggerContextMapping[SupportedTriggers] = TriggerContextMapping[SupportedTriggers] -> { +> extends PersistableStateDefinition { /** * Globally unique identifier for this drilldown. */ From b4afe357e91eca739a1c0aa2cb3fd246e64a29fa Mon Sep 17 00:00:00 2001 From: ppisljar Date: Tue, 25 Aug 2020 10:25:44 +0200 Subject: [PATCH 04/23] fixing after rebase --- src/plugins/embeddable/public/index.ts | 2 ++ .../public/lib/embeddables/embeddable_factory.ts | 1 + src/plugins/embeddable/public/plugin.tsx | 7 +++++-- src/plugins/embeddable/public/types.ts | 8 ++++++-- x-pack/plugins/embeddable_enhanced/kibana.json | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plugins/embeddable/public/index.ts b/src/plugins/embeddable/public/index.ts index 57253c1f741ab..c5d8853ada5e8 100644 --- a/src/plugins/embeddable/public/index.ts +++ b/src/plugins/embeddable/public/index.ts @@ -78,6 +78,8 @@ export { EmbeddableRendererProps, } from './lib'; +export { EnhancementRegistryDefinition } from './types'; + export function plugin(initializerContext: PluginInitializerContext) { return new EmbeddablePublicPlugin(initializerContext); } diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts index a6fa46fbc4e3e..fce37fb2d9f20 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts @@ -45,6 +45,7 @@ export interface EmbeddableFactory< TEmbeddableOutput >, TSavedObjectAttributes extends SavedObjectAttributes = SavedObjectAttributes + // @ts-ignore > extends PersistableState { // A unique identified for this factory, which will be used to map an embeddable spec to // a factory that can generate an instance of it. diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index 5560baed2dfb4..b492c7e11e6c2 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -37,6 +37,7 @@ import { EmbeddableFactoryProvider, EnhancementsRegistry, EnhancementRegistryDefinition, + EnhancementRegistryItem, } from './types'; import { bootstrap } from './bootstrap'; import { @@ -80,6 +81,7 @@ export interface EmbeddableSetup { setCustomEmbeddableFactoryProvider: (customProvider: EmbeddableFactoryProvider) => void; } +// @ts-ignore export interface EmbeddableStart extends PersistableState { getEmbeddableFactory: < I extends EmbeddableInput = EmbeddableInput, @@ -237,7 +239,7 @@ export class EmbeddablePublicPlugin implements Plugin { - const enhancements = state.enhanecemnts || {}; + const enhancements = state.enhancements || {}; const factory = this.getEmbeddableFactory(state.id); let updatedInput = injectBaseEmbeddableInput(state, references); @@ -273,9 +275,10 @@ export class EmbeddablePublicPlugin implements Plugin { + private getEnhancement = (id: string): EnhancementRegistryItem => { return ( this.enhancements.get(id) || { + id: 'unknown', telemetry: () => ({}), inject: identity, extract: (state: SerializableState) => { diff --git a/src/plugins/embeddable/public/types.ts b/src/plugins/embeddable/public/types.ts index 98202b710e83a..6669a56dcc821 100644 --- a/src/plugins/embeddable/public/types.ts +++ b/src/plugins/embeddable/public/types.ts @@ -25,7 +25,11 @@ import { IEmbeddable, EmbeddableFactoryDefinition, } from './lib/embeddables'; -import { PersistableStateDefinition, SerializableState } from '../../kibana_utils/common'; +import { + PersistableState, + PersistableStateDefinition, + SerializableState, +} from '../../kibana_utils/common'; export type EmbeddableFactoryRegistry = Map; export type EnhancementsRegistry = Map; @@ -35,7 +39,7 @@ export interface EnhancementRegistryDefinition id: string; } -export interface EnhancementRegistryItem extends PersistableStateDefinition { +export interface EnhancementRegistryItem extends PersistableState { id: string; } diff --git a/x-pack/plugins/embeddable_enhanced/kibana.json b/x-pack/plugins/embeddable_enhanced/kibana.json index acada946fe0d1..69d928bb5f45c 100644 --- a/x-pack/plugins/embeddable_enhanced/kibana.json +++ b/x-pack/plugins/embeddable_enhanced/kibana.json @@ -3,6 +3,6 @@ "version": "kibana", "server": false, "ui": true, - "requiredPlugins": ["embeddable", "kibanaReact", "uiActions", "uiActionsEnhanced"], + "requiredPlugins": ["embeddable", "kibanaReact", "uiActions", "uiActionsEnhanced", "kibanaUtils"], "requiredBundles": ["kibanaUtils"] } From 0fec27d5e7fa787c7d148f943ccdb7a82b0252d2 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Mon, 31 Aug 2020 06:44:19 -0700 Subject: [PATCH 05/23] reverting drilldown fn implementations --- .../drilldown.tsx | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx index 6016a9c28828e..056feeb2b2167 100644 --- a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx +++ b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx @@ -13,10 +13,7 @@ import { } from '../../../../../../../src/plugins/dashboard/public'; import { CollectConfigContainer } from './components'; import { DASHBOARD_TO_DASHBOARD_DRILLDOWN } from './constants'; -import { - UiActionsEnhancedDrilldownDefinition as Drilldown, - SerializedEvent, -} from '../../../../../ui_actions_enhanced/public'; +import { UiActionsEnhancedDrilldownDefinition as Drilldown } from '../../../../../ui_actions_enhanced/public'; import { txtGoToDashboard } from './i18n'; import { ApplyGlobalFilterActionContext, @@ -29,7 +26,6 @@ import { StartServicesGetter } from '../../../../../../../src/plugins/kibana_uti import { StartDependencies } from '../../../plugin'; import { Config, FactoryContext } from './types'; import { SearchInput } from '../../../../../../../src/plugins/discover/public'; -import { SavedObjectReference } from '../../../../../../../src/core/types'; export interface Params { start: StartServicesGetter>; @@ -126,29 +122,4 @@ export class DashboardToDashboardDrilldown return this.params.getDashboardUrlGenerator().createUrl(state); }; - - public telemetry = () => ({}); - - public extract = (state: SerializedEvent) => { - return { - references: [ - { - id: `${state.id}-dashboardId`, - type: 'dashboard', - value: state.dashboardId, - }, - ], - state: { - ...state, - dashboardId: `${state.id}-dashboardId`, - }, - }; - }; - - public inject = (state: SerializedEvent, references: SavedObjectReference[]) => { - return { - ...state, - dashboardId: references.find((r) => r.id === `${state.id}-dashboardId`).value, - }; - }; } From 17db743bb2fc08144cce120e13d8ea84545138b2 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Mon, 31 Aug 2020 06:48:20 -0700 Subject: [PATCH 06/23] ui actions enhanced --- .../embeddables/dynamic_action_enhancement.ts | 24 ++++----- .../embeddables/embeddable_action_storage.ts | 7 +-- .../embeddable_enhanced/public/plugin.ts | 5 +- .../flyout_drilldown_wizard.tsx | 5 +- .../public/drilldowns/drilldown_definition.ts | 6 ++- .../public/dynamic_actions/action_factory.ts | 2 +- .../action_factory_definition.ts | 1 - .../dynamic_action_manager.test.ts | 33 ++++++------ .../dynamic_actions/dynamic_action_manager.ts | 9 ++-- .../public/dynamic_actions/types.ts | 3 +- .../ui_actions_enhanced/public/index.ts | 2 + .../ui_actions_service_enhancements.ts | 51 ++++++++++++++----- 12 files changed, 92 insertions(+), 56 deletions(-) diff --git a/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts b/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts index 828f452f5e7b5..421712fa10d38 100644 --- a/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts +++ b/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts @@ -8,23 +8,21 @@ import { EnhancementRegistryDefinition } from '../../../../../src/plugins/embedd import { SavedObjectReference } from '../../../../../src/core/types'; import { StartServicesGetter } from '../../../../../src/plugins/kibana_utils/public'; import { StartDependencies } from '../plugin'; -import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; +import { DynamicActionsState } from '../../../ui_actions_enhanced/public'; -export interface DynamicActionEnhancementDeps { - start: StartServicesGetter>; -} - -export const dynamicActionEnhancement = (start) => { +export const dynamicActionEnhancement = ( + start: StartServicesGetter> +) => { return { id: 'dynamicActions', - telemetry: (state: SerializableState) => { - return start.uiActionsEnhanced.telemetry(state); + telemetry: (state: DynamicActionsState) => { + return start().plugins.uiActionsEnhanced.telemetry(state); }, - extract: (state: SerializableState) => { - return start.uiActionsEnhanced.extract(state); + extract: (state: DynamicActionsState) => { + return start().plugins.uiActionsEnhanced.extract(state); }, - inject: (state: SerializableState, refereces: SavedObjectReference[]) => { - return start.uiActionsEnhanced.inject(state, references); + inject: (state: DynamicActionsState, references: SavedObjectReference[]) => { + return start().plugins.uiActionsEnhanced.inject(state, references); }, - }; + } as EnhancementRegistryDefinition; }; diff --git a/x-pack/plugins/embeddable_enhanced/public/embeddables/embeddable_action_storage.ts b/x-pack/plugins/embeddable_enhanced/public/embeddables/embeddable_action_storage.ts index 8881b2063c8db..e0403a74047fd 100644 --- a/x-pack/plugins/embeddable_enhanced/public/embeddables/embeddable_action_storage.ts +++ b/x-pack/plugins/embeddable_enhanced/public/embeddables/embeddable_action_storage.ts @@ -5,6 +5,7 @@ */ import { + DynamicActionsState, UiActionsEnhancedAbstractActionStorage as AbstractActionStorage, UiActionsEnhancedSerializedEvent as SerializedEvent, } from '../../../ui_actions_enhanced/public'; @@ -13,12 +14,12 @@ import { EmbeddableOutput, IEmbeddable, } from '../../../../../src/plugins/embeddable/public'; +import { SerializableState } from '../../../../../src/plugins/kibana_utils/common/persistable_state'; export interface EmbeddableWithDynamicActionsInput extends EmbeddableInput { enhancements?: { - dynamicActions?: { - events: SerializedEvent[]; - }; + dynamicActions: DynamicActionsState; + [key: string]: SerializableState; }; } diff --git a/x-pack/plugins/embeddable_enhanced/public/plugin.ts b/x-pack/plugins/embeddable_enhanced/public/plugin.ts index 769946461f824..a6f99be2ef02c 100644 --- a/x-pack/plugins/embeddable_enhanced/public/plugin.ts +++ b/x-pack/plugins/embeddable_enhanced/public/plugin.ts @@ -32,6 +32,7 @@ import { } from '../../ui_actions_enhanced/public'; import { PanelNotificationsAction, ACTION_PANEL_NOTIFICATIONS } from './actions'; import { UrlDrilldown } from './drilldowns'; +import { dynamicActionEnhancement } from './embeddables/dynamic_action_enhancement'; import { createStartServicesGetter } from '../../../../src/plugins/kibana_utils/public'; declare module '../../../../src/plugins/ui_actions/public' { @@ -68,7 +69,7 @@ export class EmbeddableEnhancedPlugin const panelNotificationAction = new PanelNotificationsAction(); plugins.uiActionsEnhanced.registerAction(panelNotificationAction); plugins.uiActionsEnhanced.attachAction(PANEL_NOTIFICATION_TRIGGER, panelNotificationAction.id); - plugins.embeddable.registerEmbeddableEnhancement(dynamicActionEnhancement(startServices)); + plugins.embeddable.registerEnhancement(dynamicActionEnhancement(startServices)); plugins.uiActionsEnhanced.registerDrilldown( new UrlDrilldown({ @@ -83,7 +84,7 @@ export class EmbeddableEnhancedPlugin return {}; } - public start(core: CoreStart, plugins: StartDependenciesStartDependencies): StartContract { + public start(core: CoreStart, plugins: StartDependencies): StartContract { this.uiActions = plugins.uiActionsEnhanced; return {}; diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.tsx index c8e3f454bd53d..6ab72749fdd77 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.tsx @@ -19,6 +19,7 @@ import { DrilldownHelloBar } from '../drilldown_hello_bar'; import { ActionFactory, BaseActionFactoryContext } from '../../../dynamic_actions'; import { Trigger, TriggerId } from '../../../../../../../src/plugins/ui_actions/public'; import { ActionFactoryPlaceContext } from '../types'; +import { SerializableState } from '../../../../../../../src/plugins/kibana_utils/common'; export interface DrilldownWizardConfig { name: string; @@ -133,7 +134,9 @@ function useWizardConfigState( ]; } -export function FlyoutDrilldownWizard({ +export function FlyoutDrilldownWizard< + CurrentActionConfig extends SerializableState = SerializableState +>({ onClose, onBack, onSubmit = () => {}, diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts index 3451af9bf0eda..aebd328705912 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts @@ -4,7 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ActionFactoryDefinition, BaseActionFactoryContext, SerializedEvent } from '../dynamic_actions'; +import { + ActionFactoryDefinition, + BaseActionFactoryContext, + SerializedEvent, +} from '../dynamic_actions'; import { LicenseType } from '../../../licensing/public'; import { TriggerContextMapping, TriggerId } from '../../../../../src/plugins/ui_actions/public'; import { ActionExecutionContext } from '../../../../../src/plugins/ui_actions/public'; diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts index 9c6de063a5ce9..d623216dd88d8 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts @@ -16,7 +16,7 @@ import { BaseActionFactoryContext, SerializedAction, SerializedEvent } from './t import { ILicense, LicensingPluginStart } from '../../../licensing/public'; import { UiActionsActionDefinition as ActionDefinition } from '../../../../../src/plugins/ui_actions/public'; import { SavedObjectReference } from '../../../../../src/core/types'; -import { Serializable } from '../../../../../src/plugins/kibana_utils/common/persistable_state'; +import { PersistableState } from '../../../../../src/plugins/kibana_utils/common'; export interface ActionFactoryDeps { readonly getLicense: () => ILicense; diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts index aa43b1f6f4178..aea1db0d18dc0 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts @@ -13,7 +13,6 @@ import { UiActionsActionDefinition as ActionDefinition, UiActionsPresentable as Presentable, } from '../../../../../src/plugins/ui_actions/public'; -import { SavedObjectReference } from '../../../../../src/core/types'; import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common'; /** diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.test.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.test.ts index 39d9dfeca2fd6..d14c1153cbcb7 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.test.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.test.ts @@ -13,6 +13,7 @@ import { UiActionsServiceEnhancements } from '../services'; import { ActionFactoryDefinition } from './action_factory_definition'; import { SerializedAction, SerializedEvent } from './types'; import { licensingMock } from '../../../licensing/public/mocks'; +import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; const actionFactoryDefinition1: ActionFactoryDefinition = { id: 'ACTION_FACTORY_1', @@ -250,7 +251,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition1); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -277,7 +278,7 @@ describe('DynamicActionManager', () => { test('adds event to UI state', async () => { const { manager, uiActions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -296,7 +297,7 @@ describe('DynamicActionManager', () => { test('optimistically adds event to UI state', async () => { const { manager, uiActions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -319,7 +320,7 @@ describe('DynamicActionManager', () => { test('instantiates event in actions service', async () => { const { manager, uiActions, actions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -348,7 +349,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition1); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -361,7 +362,7 @@ describe('DynamicActionManager', () => { test('does not add even to UI state', async () => { const { manager, storage, uiActions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -380,7 +381,7 @@ describe('DynamicActionManager', () => { test('optimistically adds event to UI state and then removes it', async () => { const { manager, storage, uiActions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -406,7 +407,7 @@ describe('DynamicActionManager', () => { test('does not instantiate event in actions service', async () => { const { manager, storage, uiActions, actions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -432,7 +433,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition1); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -457,7 +458,7 @@ describe('DynamicActionManager', () => { expect(registeredAction1.getDisplayName()).toBe('Action 3'); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -479,7 +480,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition2); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -505,7 +506,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition2); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -524,7 +525,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition2); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -552,7 +553,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition2); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -580,7 +581,7 @@ describe('DynamicActionManager', () => { expect(registeredAction1.getDisplayName()).toBe('Action 3'); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -604,7 +605,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition2); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.ts index 6ca388281ad76..d256da56b7d10 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.ts @@ -15,6 +15,7 @@ import { defaultState, transitions, selectors, State } from './dynamic_action_ma import { StateContainer, createStateContainer, + SerializableState, } from '../../../../../src/plugins/kibana_utils/common'; import { StartContract } from '../plugin'; import { SerializedAction, SerializedEvent } from './types'; @@ -74,7 +75,9 @@ export class DynamicActionManager { const actionId = this.generateActionId(eventId); const factory = uiActions.getActionFactory(event.action.factoryId); - const actionDefinition: ActionDefinition = factory.create(action as SerializedAction); + const actionDefinition: ActionDefinition = factory.create( + action as SerializedAction + ); uiActions.registerAction({ ...actionDefinition, id: actionId, @@ -196,7 +199,7 @@ export class DynamicActionManager { * @param triggers List of triggers to which action should react. */ public async createEvent( - action: SerializedAction, + action: SerializedAction, triggers: Array ) { const event: SerializedEvent = { @@ -231,7 +234,7 @@ export class DynamicActionManager { */ public async updateEvent( eventId: string, - action: SerializedAction, + action: SerializedAction, triggers: Array ) { const event: SerializedEvent = { diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts index d00db0d9acb7a..8a8c7b1310c87 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts @@ -5,8 +5,9 @@ */ import { TriggerId } from '../../../../../src/plugins/ui_actions/public'; +import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; -export interface SerializedAction { +export interface SerializedAction { readonly factoryId: string; readonly name: string; readonly config: Config; diff --git a/x-pack/plugins/ui_actions_enhanced/public/index.ts b/x-pack/plugins/ui_actions_enhanced/public/index.ts index 4a899b24852a9..1832f1b4661d3 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/index.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/index.ts @@ -31,5 +31,7 @@ export { BaseActionFactoryContext as UiActionsEnhancedBaseActionFactoryContext, } from './dynamic_actions'; +export { DynamicActionsState } from './services/ui_actions_service_enhancements'; + export { DrilldownDefinition as UiActionsEnhancedDrilldownDefinition } from './drilldowns'; export * from './drilldowns/url_drilldown'; diff --git a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts index eaee39ddc4f50..858e80f35f2d9 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts @@ -16,7 +16,11 @@ import { ILicense } from '../../../licensing/common/types'; import { TriggerContextMapping, TriggerId } from '../../../../../src/plugins/ui_actions/public'; import { LicensingPluginSetup, LicensingPluginStart } from '../../../licensing/public'; import { SavedObjectReference } from '../../../../../src/core/types'; -import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common/persistable_state'; +import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common'; + +export interface DynamicActionsState { + events: SerializedEvent[]; +} export interface UiActionsServiceEnhancementsParams { readonly actionFactories?: ActionFactoryRegistry; @@ -25,7 +29,8 @@ export interface UiActionsServiceEnhancementsParams { readonly getFeatureUsageStart: () => LicensingPluginStart['featureUsage']; } -export class UiActionsServiceEnhancements implements PersistableStateDefinition { +export class UiActionsServiceEnhancements + implements PersistableStateDefinition { protected readonly actionFactories: ActionFactoryRegistry; protected readonly deps: Omit; @@ -104,7 +109,7 @@ export class UiActionsServiceEnhancements implements PersistableStateDefinition< licenseFeatureName, supportedTriggers, isCompatible, - migrate, + telemetry, extract, inject, }: DrilldownDefinition): void => { @@ -144,6 +149,12 @@ export class UiActionsServiceEnhancements implements PersistableStateDefinition< this.registerActionFactory(actionFactory); }; + public telemetry(state: DynamicActionsState) { + return state.events.map((event: SerializedEvent) => { + return this.actionFactories.has(event.action.factoryId) + ? this.actionFactories.get(event.action.factoryId)!.telemetry(event) + : {}; + }); private registerFeatureUsage = (definition: ActionFactoryDefinition): void => { if (!definition.minimalLicense || !definition.licenseFeatureName) return; @@ -165,18 +176,30 @@ export class UiActionsServiceEnhancements implements PersistableStateDefinition< : {}; } - public extract(state: SerializedEvent) { - return this.actionFactories.has(state.eventId) - ? this.actionFactories.get(state.eventId)!.extract(state) - : { - state, - references: [], - }; + public extract(state: DynamicActionsState) { + const references: SavedObjectReference[] = []; + const newState = { + events: state.events.map((event: SerializedEvent) => { + const result = this.actionFactories.has(event.action.factoryId) + ? this.actionFactories.get(event.action.factoryId)!.extract(event) + : { + state: event, + references: [], + }; + result.references.forEach((r) => references.push(r)); + return result.state; + }), + }; + return { state: newState, references }; } - public inject(state: SerializedEvent, references: SavedObjectReference[]) { - return this.actionFactories.has(state.eventId) - ? this.actionFactories.get(state.eventId)!.inject(state, references) - : state; + public inject(state: DynamicActionsState, references: SavedObjectReference[]) { + return { + events: state.events.map((event: SerializedEvent) => { + return this.actionFactories.has(event.action.factoryId) + ? this.actionFactories.get(event.action.factoryId)!.inject(event, references) + : event; + }), + }; } } From 5a808db2e2c3b9861eec4f83a6934c25d00d46e7 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 2 Sep 2020 03:37:53 -0700 Subject: [PATCH 07/23] first --- src/plugins/embeddable/public/types.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/embeddable/public/types.ts b/src/plugins/embeddable/public/types.ts index 6669a56dcc821..c5148bbaefb6b 100644 --- a/src/plugins/embeddable/public/types.ts +++ b/src/plugins/embeddable/public/types.ts @@ -34,12 +34,13 @@ import { export type EmbeddableFactoryRegistry = Map; export type EnhancementsRegistry = Map; -export interface EnhancementRegistryDefinition - extends PersistableStateDefinition { +export interface EnhancementRegistryDefinition

+ extends PersistableStateDefinition

{ id: string; } -export interface EnhancementRegistryItem extends PersistableState { +export interface EnhancementRegistryItem

+ extends PersistableState

{ id: string; } From 0585d92d941339b09abfec2cfe11ca41c497c323 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 2 Sep 2020 03:47:54 -0700 Subject: [PATCH 08/23] dyamic actions --- .../public/dynamic_actions/dynamic_action_manager.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.ts index d256da56b7d10..471b929fdbc06 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.ts @@ -15,7 +15,6 @@ import { defaultState, transitions, selectors, State } from './dynamic_action_ma import { StateContainer, createStateContainer, - SerializableState, } from '../../../../../src/plugins/kibana_utils/common'; import { StartContract } from '../plugin'; import { SerializedAction, SerializedEvent } from './types'; @@ -75,9 +74,7 @@ export class DynamicActionManager { const actionId = this.generateActionId(eventId); const factory = uiActions.getActionFactory(event.action.factoryId); - const actionDefinition: ActionDefinition = factory.create( - action as SerializedAction - ); + const actionDefinition: ActionDefinition = factory.create(action as SerializedAction); uiActions.registerAction({ ...actionDefinition, id: actionId, @@ -198,10 +195,7 @@ export class DynamicActionManager { * @param action Dynamic action for which to create an event. * @param triggers List of triggers to which action should react. */ - public async createEvent( - action: SerializedAction, - triggers: Array - ) { + public async createEvent(action: SerializedAction, triggers: Array) { const event: SerializedEvent = { eventId: uuidv4(), triggers, @@ -234,7 +228,7 @@ export class DynamicActionManager { */ public async updateEvent( eventId: string, - action: SerializedAction, + action: SerializedAction, triggers: Array ) { const event: SerializedEvent = { From 331d71d644f0033d2082b0feea37433d5e8a2534 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Mon, 7 Sep 2020 03:16:49 -0700 Subject: [PATCH 09/23] from interface to type --- .../public/lib/embeddables/i_embeddable.ts | 4 +- src/plugins/embeddable/public/plugin.tsx | 12 +++-- .../common/persistable_state/index.ts | 10 +++-- .../kibana_utils/public/ui/configurable.ts | 11 ++++- .../dashboard_to_dashboard_drilldown/types.ts | 5 ++- .../action_wizard/action_wizard.tsx | 9 ++-- .../components/action_wizard/test_data.tsx | 14 +++--- .../connected_flyout_manage_drilldowns.tsx | 3 +- .../test_data.ts | 7 ++- .../flyout_drilldown_wizard.tsx | 14 +++--- .../form_drilldown_wizard.tsx | 5 ++- .../public/drilldowns/drilldown_definition.ts | 7 ++- .../public/drilldowns/url_drilldown/types.ts | 5 ++- .../public/dynamic_actions/action_factory.ts | 7 ++- .../action_factory_definition.ts | 7 ++- .../public/dynamic_actions/types.ts | 10 +++-- .../ui_actions_service_enhancements.ts | 45 ++++++++++--------- 17 files changed, 108 insertions(+), 67 deletions(-) diff --git a/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts b/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts index a1cb7e45b3a0b..091e28c7b26e3 100644 --- a/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts +++ b/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts @@ -23,7 +23,7 @@ import { IContainer } from '../containers/i_container'; import { ViewMode } from '../types'; import { TriggerContextMapping } from '../../../../ui_actions/public'; import type { TimeRange, Query, Filter } from '../../../../data/common'; -import { SerializableState } from '../../../../kibana_utils/common/persistable_state'; +import { SerializableState } from '../../../../kibana_utils/common'; export interface EmbeddableError { name: string; @@ -45,7 +45,7 @@ export interface EmbeddableInput { /** * Reserved key for enhancements added by other plugins. */ - enhancements?: Record; + enhancements?: SerializableState; /** * List of action IDs that this embeddable should not render. diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index b492c7e11e6c2..082fdd17c953a 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -226,8 +226,11 @@ export class EmbeddablePublicPlugin implements Plugin { - const enhancementResult = this.getEnhancement(key).extract(enhancements[key]); + Object.keys(enhancements).forEach((key) => { + if (!enhancements[key]) return; + const enhancementResult = this.getEnhancement(key).extract( + enhancements[key] as SerializableState + ); refs = refs.concat(enhancementResult.references); updatedInput.enhancements![key] = enhancementResult.state; }); @@ -249,9 +252,10 @@ export class EmbeddablePublicPlugin implements Plugin { + Object.keys(enhancements).forEach((key) => { + if (!enhancements[key]) return; updatedInput.enhancements![key] = this.getEnhancement(key).inject( - enhancements[key], + enhancements[key] as SerializableState, references ); }); diff --git a/src/plugins/kibana_utils/common/persistable_state/index.ts b/src/plugins/kibana_utils/common/persistable_state/index.ts index 3bd54fda6b490..8d0987cc4e1ce 100644 --- a/src/plugins/kibana_utils/common/persistable_state/index.ts +++ b/src/plugins/kibana_utils/common/persistable_state/index.ts @@ -19,11 +19,13 @@ import { SavedObjectReference } from '../../../../core/types'; -type State = string | number | boolean | null | undefined | SerializableState; +export type SerializableValue = string | number | boolean | null | undefined | SerializableState; +export type Serializable = SerializableValue | SerializableValue[]; -export interface SerializableState { - [key: string]: State | State[] | Record; -} +// eslint-disable-next-line +export type SerializableState = { + [key: string]: Serializable; +}; export interface PersistableState

{ // function to extract telemetry information diff --git a/src/plugins/kibana_utils/public/ui/configurable.ts b/src/plugins/kibana_utils/public/ui/configurable.ts index 3fa5cdc8b5e47..1b8998ba3593c 100644 --- a/src/plugins/kibana_utils/public/ui/configurable.ts +++ b/src/plugins/kibana_utils/public/ui/configurable.ts @@ -18,11 +18,15 @@ */ import { UiComponent } from '../../common/ui/ui_component'; +import { SerializableState } from '../../common/persistable_state'; /** * Represents something that can be configured by user using UI. */ -export interface Configurable { +export interface Configurable< + Config extends SerializableState = SerializableState, + Context = object +> { /** * Create default config for this item, used when item is created for the first time. */ @@ -42,7 +46,10 @@ export interface Configurable /** * Props provided to `CollectConfig` component on every re-render. */ -export interface CollectConfigProps { +export interface CollectConfigProps< + Config extends SerializableState = SerializableState, + Context = object +> { /** * Current (latest) config of the item. */ diff --git a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/types.ts b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/types.ts index c21109f8a596a..330a501a78d39 100644 --- a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/types.ts +++ b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/types.ts @@ -7,10 +7,11 @@ import { UiActionsEnhancedBaseActionFactoryContext } from '../../../../../ui_actions_enhanced/public'; import { APPLY_FILTER_TRIGGER } from '../../../../../../../src/plugins/ui_actions/public'; -export interface Config { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type Config = { dashboardId?: string; useCurrentFilters: boolean; useCurrentDateRange: boolean; -} +}; export type FactoryContext = UiActionsEnhancedBaseActionFactoryContext; diff --git a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx index 16d0250c5721e..1bd58e20e5e6f 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx @@ -30,6 +30,7 @@ import { import './action_wizard.scss'; import { ActionFactory, BaseActionFactoryContext } from '../../dynamic_actions'; import { Trigger, TriggerId } from '../../../../../../src/plugins/ui_actions/public'; +import { SerializableState } from '../../../../../../src/plugins/kibana_utils/common/persistable_state'; export interface ActionWizardProps< ActionFactoryContext extends BaseActionFactoryContext = BaseActionFactoryContext @@ -54,12 +55,12 @@ export interface ActionWizardProps< /** * current config for currently selected action factory */ - config?: object; + config?: SerializableState; /** * config changed */ - onConfigChange: (config: object) => void; + onConfigChange: (config: SerializableState) => void; /** * Context will be passed into ActionFactory's methods @@ -216,9 +217,9 @@ interface SelectedActionFactoryProps< ActionFactoryContext extends BaseActionFactoryContext = BaseActionFactoryContext > { actionFactory: ActionFactory; - config: object; + config: SerializableState; context: ActionFactoryContext; - onConfigChange: (config: object) => void; + onConfigChange: (config: SerializableState) => void; showDeselect: boolean; onDeselect: () => void; allTriggers: TriggerId[]; diff --git a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx index 71286e9a59c06..a860a723708b2 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx @@ -18,19 +18,21 @@ import { TriggerId, VALUE_CLICK_TRIGGER, } from '../../../../../../src/plugins/ui_actions/public'; +import { SerializableState } from '../../../../../../src/plugins/kibana_utils/common'; -type ActionBaseConfig = object; +type ActionBaseConfig = SerializableState; export const dashboards = [ { id: 'dashboard1', title: 'Dashboard 1' }, { id: 'dashboard2', title: 'Dashboard 2' }, ]; -interface DashboardDrilldownConfig { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +type DashboardDrilldownConfig = { dashboardId?: string; useCurrentFilters: boolean; useCurrentDateRange: boolean; -} +}; function DashboardDrilldownCollectConfig(props: CollectConfigProps) { const config = props.config ?? { @@ -121,10 +123,12 @@ export const dashboardFactory = new ActionFactory(dashboardDrilldownActionFactor getFeatureUsageStart: () => licensingMock.createStart().featureUsage, }); -interface UrlDrilldownConfig { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +type UrlDrilldownConfig = { url: string; openInNewTab: boolean; -} +}; + function UrlDrilldownCollectConfig(props: CollectConfigProps) { const config = props.config ?? { url: '', diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx index 8154ec45b8ae1..9b6804f809ff6 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx @@ -31,6 +31,7 @@ import { SerializedEvent, } from '../../../dynamic_actions'; import { ActionFactoryPlaceContext } from '../types'; +import { SerializableState } from '../../../../../../../src/plugins/kibana_utils/common/persistable_state'; interface ConnectedFlyoutManageDrilldownsProps< ActionFactoryContext extends BaseActionFactoryContext = BaseActionFactoryContext @@ -125,7 +126,7 @@ export function createFlyoutManageDrilldowns({ return { actionFactory: allActionFactoriesById[drilldownToEdit.action.factoryId], - actionConfig: drilldownToEdit.action.config as object, + actionConfig: drilldownToEdit.action.config as SerializableState, name: drilldownToEdit.action.name, selectedTriggers: (drilldownToEdit.triggers ?? []) as TriggerId[], }; diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/test_data.ts b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/test_data.ts index 58c36e36481b8..e623edb2d1a5c 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/test_data.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/test_data.ts @@ -11,7 +11,10 @@ import { UiActionsEnhancedSerializedAction, } from '../../../index'; import { TriggerContextMapping } from '../../../../../../../src/plugins/ui_actions/public'; -import { createStateContainer } from '../../../../../../../src/plugins/kibana_utils/common'; +import { + createStateContainer, + SerializableState, +} from '../../../../../../../src/plugins/kibana_utils/common'; class MockDynamicActionManager implements PublicMethodsOf { public readonly state = createStateContainer({ @@ -60,7 +63,7 @@ class MockDynamicActionManager implements PublicMethodsOf async updateEvent( eventId: string, - action: UiActionsEnhancedSerializedAction, + action: UiActionsEnhancedSerializedAction, triggers: Array ) { const state = this.state.get(); diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.tsx index 6ab72749fdd77..f4657fb98f61c 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.tsx @@ -21,7 +21,7 @@ import { Trigger, TriggerId } from '../../../../../../../src/plugins/ui_actions/ import { ActionFactoryPlaceContext } from '../types'; import { SerializableState } from '../../../../../../../src/plugins/kibana_utils/common'; -export interface DrilldownWizardConfig { +export interface DrilldownWizardConfig { name: string; actionFactory?: ActionFactory; actionConfig?: ActionConfig; @@ -29,7 +29,7 @@ export interface DrilldownWizardConfig { } export interface FlyoutDrilldownWizardProps< - CurrentActionConfig extends object = object, + CurrentActionConfig extends SerializableState = SerializableState, ActionFactoryContext extends BaseActionFactoryContext = BaseActionFactoryContext > { drilldownActionFactories: ActionFactory[]; @@ -64,7 +64,7 @@ function useWizardConfigState( DrilldownWizardConfig, { setName: (name: string) => void; - setActionConfig: (actionConfig: object) => void; + setActionConfig: (actionConfig: SerializableState) => void; setActionFactory: (actionFactory?: ActionFactory) => void; setSelectedTriggers: (triggers?: TriggerId[]) => void; } @@ -93,7 +93,7 @@ function useWizardConfigState( name, }); }, - setActionConfig: (actionConfig: object) => { + setActionConfig: (actionConfig: SerializableState) => { setWizardConfig({ ...wizardConfig, actionConfig, @@ -101,12 +101,12 @@ function useWizardConfigState( }, setActionFactory: (actionFactory?: ActionFactory) => { if (actionFactory) { + const actionConfig = (actionConfigCache[actionFactory.id] ?? + actionFactory.createConfig(actionFactoryContext)) as SerializableState; setWizardConfig({ ...wizardConfig, actionFactory, - actionConfig: - actionConfigCache[actionFactory.id] ?? - actionFactory.createConfig(actionFactoryContext), + actionConfig, selectedTriggers: [], }); } else { diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx index d7f94a52088b7..8d0d48f16daaf 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx @@ -11,6 +11,7 @@ import { txtDrilldownAction, txtNameOfDrilldown, txtUntitledDrilldown } from './ import { ActionFactory, BaseActionFactoryContext } from '../../../dynamic_actions'; import { ActionWizard } from '../../../components/action_wizard'; import { Trigger, TriggerId } from '../../../../../../../src/plugins/ui_actions/public'; +import { SerializableState } from '../../../../../../../src/plugins/kibana_utils/common/persistable_state'; const GET_MORE_ACTIONS_LINK = 'https://www.elastic.co/subscriptions'; @@ -26,8 +27,8 @@ export interface FormDrilldownWizardProps< onActionFactoryChange?: (actionFactory?: ActionFactory) => void; actionFactoryContext: ActionFactoryContext; - actionConfig?: object; - onActionConfigChange?: (config: object) => void; + actionConfig?: SerializableState; + onActionConfigChange?: (config: SerializableState) => void; actionFactories?: ActionFactory[]; diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts index aebd328705912..f1348b865c218 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts @@ -12,7 +12,10 @@ import { import { LicenseType } from '../../../licensing/public'; import { TriggerContextMapping, TriggerId } from '../../../../../src/plugins/ui_actions/public'; import { ActionExecutionContext } from '../../../../../src/plugins/ui_actions/public'; -import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common/persistable_state'; +import { + PersistableStateDefinition, + SerializableState, +} from '../../../../../src/plugins/kibana_utils/common/persistable_state'; /** * This is a convenience interface to register a drilldown. Drilldown has @@ -29,7 +32,7 @@ import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_ut */ export interface DrilldownDefinition< - Config extends object = object, + Config extends SerializableState = SerializableState, SupportedTriggers extends TriggerId = TriggerId, FactoryContext extends BaseActionFactoryContext = { triggers: SupportedTriggers[]; diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/types.ts b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/types.ts index 31c7481c9d63e..893adb754e79c 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/types.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/types.ts @@ -4,10 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -export interface UrlDrilldownConfig { +// eslint-disable-next-line +export type UrlDrilldownConfig = { url: { format?: 'handlebars_v1'; template: string }; openInNewTab: boolean; -} +}; /** * URL drilldown has 3 sources for variables: global, context and event variables diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts index d623216dd88d8..6086ea771a550 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts @@ -16,7 +16,10 @@ import { BaseActionFactoryContext, SerializedAction, SerializedEvent } from './t import { ILicense, LicensingPluginStart } from '../../../licensing/public'; import { UiActionsActionDefinition as ActionDefinition } from '../../../../../src/plugins/ui_actions/public'; import { SavedObjectReference } from '../../../../../src/core/types'; -import { PersistableState } from '../../../../../src/plugins/kibana_utils/common'; +import { + PersistableState, + SerializableState, +} from '../../../../../src/plugins/kibana_utils/common'; export interface ActionFactoryDeps { readonly getLicense: () => ILicense; @@ -24,7 +27,7 @@ export interface ActionFactoryDeps { } export class ActionFactory< - Config extends object = object, + Config extends SerializableState = SerializableState, SupportedTriggers extends TriggerId = TriggerId, FactoryContext extends BaseActionFactoryContext = { triggers: SupportedTriggers[]; diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts index aea1db0d18dc0..1c501300f6716 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts @@ -13,13 +13,16 @@ import { UiActionsActionDefinition as ActionDefinition, UiActionsPresentable as Presentable, } from '../../../../../src/plugins/ui_actions/public'; -import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common'; +import { + PersistableStateDefinition, + SerializableState, +} from '../../../../../src/plugins/kibana_utils/common'; /** * This is a convenience interface for registering new action factories. */ export interface ActionFactoryDefinition< - Config extends object = object, + Config extends SerializableState = SerializableState, SupportedTriggers extends TriggerId = TriggerId, FactoryContext extends BaseActionFactoryContext = { triggers: SupportedTriggers[]; diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts index 8a8c7b1310c87..509ae7dc44b0c 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts @@ -7,20 +7,22 @@ import { TriggerId } from '../../../../../src/plugins/ui_actions/public'; import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; -export interface SerializedAction { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type SerializedAction = { readonly factoryId: string; readonly name: string; readonly config: Config; -} +}; /** * Serialized representation of a triggers-action pair, used to persist in storage. */ -export interface SerializedEvent { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type SerializedEvent = { eventId: string; triggers: string[]; action: SerializedAction; -} +}; /** * Action factory context passed into ActionFactories' CollectConfig, getDisplayName, getIconType diff --git a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts index 858e80f35f2d9..d300150d15cd6 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts @@ -16,11 +16,15 @@ import { ILicense } from '../../../licensing/common/types'; import { TriggerContextMapping, TriggerId } from '../../../../../src/plugins/ui_actions/public'; import { LicensingPluginSetup, LicensingPluginStart } from '../../../licensing/public'; import { SavedObjectReference } from '../../../../../src/core/types'; -import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common'; +import { + PersistableStateDefinition, + SerializableState, +} from '../../../../../src/plugins/kibana_utils/common'; -export interface DynamicActionsState { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type DynamicActionsState = { events: SerializedEvent[]; -} +}; export interface UiActionsServiceEnhancementsParams { readonly actionFactories?: ActionFactoryRegistry; @@ -44,7 +48,7 @@ export class UiActionsServiceEnhancements * serialize/deserialize dynamic actions. */ public readonly registerActionFactory = < - Config extends object = object, + Config extends SerializableState = SerializableState, SupportedTriggers extends TriggerId = TriggerId, FactoryContext extends BaseActionFactoryContext = { triggers: SupportedTriggers[]; @@ -89,7 +93,7 @@ export class UiActionsServiceEnhancements * Convenience method to register a {@link DrilldownDefinition | drilldown}. */ public readonly registerDrilldown = < - Config extends object = object, + Config extends SerializableState = SerializableState, SupportedTriggers extends TriggerId = TriggerId, FactoryContext extends BaseActionFactoryContext = { triggers: SupportedTriggers[]; @@ -149,12 +153,6 @@ export class UiActionsServiceEnhancements this.registerActionFactory(actionFactory); }; - public telemetry(state: DynamicActionsState) { - return state.events.map((event: SerializedEvent) => { - return this.actionFactories.has(event.action.factoryId) - ? this.actionFactories.get(event.action.factoryId)!.telemetry(event) - : {}; - }); private registerFeatureUsage = (definition: ActionFactoryDefinition): void => { if (!definition.minimalLicense || !definition.licenseFeatureName) return; @@ -170,13 +168,20 @@ export class UiActionsServiceEnhancements }); }; - public telemetry(state: SerializedEvent) { - return this.actionFactories.has(state.eventId) - ? this.actionFactories.get(state.eventId)!.telemetry(state) - : {}; - } + public readonly telemetry = (state: DynamicActionsState) => { + const telemetry: Record = {}; + state.events.forEach((event: SerializedEvent) => { + const eventTelemetry = this.actionFactories.has(event.action.factoryId) + ? this.actionFactories.get(event.action.factoryId)!.telemetry(event) + : {}; + Object.keys(eventTelemetry).forEach((key) => { + telemetry[key] = eventTelemetry[key]; + }); + }); + return telemetry; + }; - public extract(state: DynamicActionsState) { + public readonly extract = (state: DynamicActionsState) => { const references: SavedObjectReference[] = []; const newState = { events: state.events.map((event: SerializedEvent) => { @@ -191,9 +196,9 @@ export class UiActionsServiceEnhancements }), }; return { state: newState, references }; - } + }; - public inject(state: DynamicActionsState, references: SavedObjectReference[]) { + public readonly inject = (state: DynamicActionsState, references: SavedObjectReference[]) => { return { events: state.events.map((event: SerializedEvent) => { return this.actionFactories.has(event.action.factoryId) @@ -201,5 +206,5 @@ export class UiActionsServiceEnhancements : event; }), }; - } + }; } From de6ba329ed67946c8b9aea7aa179c9a6605cf34d Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 7 Sep 2020 12:35:41 +0000 Subject: [PATCH 10/23] =?UTF-8?q?chore:=20=F0=9F=A4=96=20fix=20TypeScript?= =?UTF-8?q?=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../embeddables/dynamic_action_enhancement.ts | 17 +++++++++-------- ...connected_flyout_manage_drilldowns.story.tsx | 5 ++++- .../connected_flyout_manage_drilldowns.test.tsx | 5 ++++- .../flyout_drilldown_wizard.story.tsx | 15 +++++++++------ 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts b/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts index 421712fa10d38..d650867a420b0 100644 --- a/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts +++ b/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts @@ -7,22 +7,23 @@ import { EnhancementRegistryDefinition } from '../../../../../src/plugins/embeddable/public'; import { SavedObjectReference } from '../../../../../src/core/types'; import { StartServicesGetter } from '../../../../../src/plugins/kibana_utils/public'; +import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; import { StartDependencies } from '../plugin'; import { DynamicActionsState } from '../../../ui_actions_enhanced/public'; export const dynamicActionEnhancement = ( start: StartServicesGetter> -) => { +): EnhancementRegistryDefinition => { return { id: 'dynamicActions', - telemetry: (state: DynamicActionsState) => { - return start().plugins.uiActionsEnhanced.telemetry(state); + telemetry: (state: SerializableState) => { + return start().plugins.uiActionsEnhanced.telemetry(state as DynamicActionsState); }, - extract: (state: DynamicActionsState) => { - return start().plugins.uiActionsEnhanced.extract(state); + extract: (state: SerializableState) => { + return start().plugins.uiActionsEnhanced.extract(state as DynamicActionsState); }, - inject: (state: DynamicActionsState, references: SavedObjectReference[]) => { - return start().plugins.uiActionsEnhanced.inject(state, references); + inject: (state: SerializableState, references: SavedObjectReference[]) => { + return start().plugins.uiActionsEnhanced.inject(state as DynamicActionsState, references); }, - } as EnhancementRegistryDefinition; + } as EnhancementRegistryDefinition; }; diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.story.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.story.tsx index f7284539ab2fe..70aeebb592206 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.story.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.story.tsx @@ -15,7 +15,10 @@ import { mockDynamicActionManager } from './test_data'; import { ActionFactory } from '../../../dynamic_actions'; const FlyoutManageDrilldowns = createFlyoutManageDrilldowns({ - actionFactories: [dashboardFactory as ActionFactory, urlFactory as ActionFactory], + actionFactories: [ + (dashboardFactory as unknown) as ActionFactory, + (urlFactory as unknown) as ActionFactory, + ], storage: new Storage(new StubBrowserStorage()), toastService: { addError: (...args: any[]) => { diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.test.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.test.tsx index 2412cdd51748c..f3a4b9832b7a9 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.test.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.test.tsx @@ -26,7 +26,10 @@ import { ActionFactory } from '../../../dynamic_actions'; const storage = new Storage(new StubBrowserStorage()); const toasts = coreMock.createStart().notifications.toasts; const FlyoutManageDrilldowns = createFlyoutManageDrilldowns({ - actionFactories: [dashboardFactory as ActionFactory, urlFactory as ActionFactory], + actionFactories: [ + (dashboardFactory as unknown) as ActionFactory, + (urlFactory as unknown) as ActionFactory, + ], storage: new Storage(new StubBrowserStorage()), toastService: toasts, getTrigger: mockGetTriggerInfo, diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.story.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.story.tsx index 8f73c2b3b3cc9..28d5c51a42d02 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.story.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.story.tsx @@ -26,7 +26,10 @@ storiesOf('components/FlyoutDrilldownWizard', module) .add('default', () => { return ( ); @@ -36,8 +39,8 @@ storiesOf('components/FlyoutDrilldownWizard', module) {}}> @@ -49,8 +52,8 @@ storiesOf('components/FlyoutDrilldownWizard', module) {}}> {}}> Date: Tue, 8 Sep 2020 02:22:01 -0700 Subject: [PATCH 11/23] adding tests --- .../lib/embeddables/migrate_base_input.ts | 2 +- src/plugins/embeddable/public/plugin.test.ts | 102 +++++++++++++++--- src/plugins/embeddable/public/plugin.tsx | 21 ++-- .../dashboard_hello_world_drilldown/index.tsx | 5 +- .../index.tsx | 5 +- .../dashboard_to_discover_drilldown/types.ts | 5 +- .../embeddable_enhanced/public/plugin.ts | 2 - .../dynamic_action_enhancement.ts | 11 +- .../ui_actions_enhanced/public/plugin.ts | 4 +- .../ui_actions_service_enhancements.test.ts | 60 +++++++++++ 10 files changed, 177 insertions(+), 40 deletions(-) rename x-pack/plugins/{embeddable_enhanced/public/embeddables => ui_actions_enhanced/public/dynamic_actions}/dynamic_action_enhancement.ts (66%) diff --git a/src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts b/src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts index aad7bdc3c336a..63e9caede19bc 100644 --- a/src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts +++ b/src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts @@ -21,7 +21,7 @@ import { SavedObjectReference } from '../../../../../core/types'; import { EmbeddableInput } from './i_embeddable'; export const telemetryBaseEmbeddableInput = (state: EmbeddableInput) => { - return {}; + return {} as Record; }; export const extractBaseEmbeddableInput = (state: EmbeddableInput) => { diff --git a/src/plugins/embeddable/public/plugin.test.ts b/src/plugins/embeddable/public/plugin.test.ts index e37d602ad8cac..7da6f4d8997bc 100644 --- a/src/plugins/embeddable/public/plugin.test.ts +++ b/src/plugins/embeddable/public/plugin.test.ts @@ -22,21 +22,6 @@ import { EmbeddableFactoryProvider } from './types'; import { defaultEmbeddableFactoryProvider } from './lib'; import { HelloWorldEmbeddable } from '../../../../examples/embeddable_examples/public'; -test('cannot register embeddable factory with the same ID', async () => { - const coreSetup = coreMock.createSetup(); - const coreStart = coreMock.createStart(); - const { setup } = testPlugin(coreSetup, coreStart); - const embeddableFactoryId = 'ID'; - const embeddableFactory = {} as any; - - setup.registerEmbeddableFactory(embeddableFactoryId, embeddableFactory); - expect(() => - setup.registerEmbeddableFactory(embeddableFactoryId, embeddableFactory) - ).toThrowError( - 'Embeddable factory [embeddableFactoryId = ID] already registered in Embeddables API.' - ); -}); - test('can set custom embeddable factory provider', async () => { const coreSetup = coreMock.createSetup(); const coreStart = coreMock.createStart(); @@ -108,3 +93,90 @@ test('custom embeddable factory provider test for intercepting embeddable creati await new Promise((resolve) => process.nextTick(resolve)); expect(updateCount).toEqual(0); }); + +describe('embeddable factory', () => { + const coreSetup = coreMock.createSetup(); + const coreStart = coreMock.createStart(); + const { setup, doStart } = testPlugin(coreSetup, coreStart); + const start = doStart(); + const embeddableFactoryId = 'ID'; + const embeddableFactory = { + type: embeddableFactoryId, + create: jest.fn(), + getDisplayName: () => 'Test', + isEditable: () => Promise.resolve(true), + extract: jest.fn().mockImplementation((state) => ({ state, references: [] })), + inject: jest.fn().mockImplementation((state) => state), + telemetry: jest.fn().mockResolvedValue({}), + } as any; + const embeddableState = { + id: embeddableFactoryId, + my: 'state', + } as any; + + test('cannot register embeddable factory with the same ID', async () => { + setup.registerEmbeddableFactory(embeddableFactoryId, embeddableFactory); + expect(() => + setup.registerEmbeddableFactory(embeddableFactoryId, embeddableFactory) + ).toThrowError( + 'Embeddable factory [embeddableFactoryId = ID] already registered in Embeddables API.' + ); + }); + + test('embeddableFactory extract function gets called when calling embeddable extract', () => { + start.extract(embeddableState); + expect(embeddableFactory.extract).toBeCalledWith(embeddableState); + }); + + test('embeddableFactory inject function gets called when calling embeddable inject', () => { + start.inject(embeddableState, []); + expect(embeddableFactory.extract).toBeCalledWith(embeddableState); + }); + + test('embeddableFactory telemetry function gets called when calling embeddable telemetry', () => { + start.telemetry(embeddableState); + expect(embeddableFactory.telemetry).toBeCalledWith(embeddableState); + }); +}); + +describe('embeddable enhancements', () => { + const coreSetup = coreMock.createSetup(); + const coreStart = coreMock.createStart(); + const { setup, doStart } = testPlugin(coreSetup, coreStart); + const start = doStart(); + const embeddableEnhancement = { + id: 'test', + extract: jest.fn().mockImplementation((state) => ({ state, references: [] })), + inject: jest.fn().mockImplementation((state) => state), + telemetry: jest.fn().mockResolvedValue({}), + } as any; + const embeddableState = { + enhancements: { + test: { + my: 'state', + }, + }, + } as any; + + test('cannot register embeddable enhancement with the same ID', async () => { + setup.registerEnhancement(embeddableEnhancement); + expect(() => setup.registerEnhancement(embeddableEnhancement)).toThrowError( + 'enhancement with id test already exists in the registry' + ); + }); + + test('enhancement extract function gets called when calling embeddable extract', () => { + start.extract(embeddableState); + expect(embeddableEnhancement.extract).toBeCalledWith(embeddableState.enhancements.test); + }); + + test('enhancement inject function gets called when calling embeddable inject', () => { + start.inject(embeddableState, []); + expect(embeddableEnhancement.extract).toBeCalledWith(embeddableState.enhancements.test); + }); + + test('enhancement telemetry function gets called when calling embeddable telemetry', () => { + start.telemetry(embeddableState); + expect(embeddableEnhancement.telemetry).toBeCalledWith(embeddableState.enhancements.test); + }); +}); diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index 082fdd17c953a..abbc23938a74d 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -199,13 +199,22 @@ export class EmbeddablePublicPlugin implements Plugin { - const enhancements: Record = (state as any).enhanecemnts || {}; + const enhancements: Record = state.enhancements || {}; const factory = this.getEmbeddableFactory(state.id); const telemetryData = telemetryBaseEmbeddableInput(state); - factory.telemetry(state); + if (factory) { + const factoryTelemetry = factory.telemetry(state); + Object.keys(factoryTelemetry).forEach((key) => { + telemetryData[key] = factoryTelemetry[key]; + }); + } Object.keys(enhancements).map((key) => { - this.getEnhancement(key).telemetry(enhancements[key]); + if (!enhancements[key]) return; + const enhancementTelemetry = this.getEnhancement(key).telemetry(enhancements[key]); + Object.keys(enhancementTelemetry).forEach((k) => { + telemetryData[k] = enhancementTelemetry[k]; + }); }); return telemetryData; @@ -330,12 +339,6 @@ export class EmbeddablePublicPlugin implements Plugin; }; diff --git a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_drilldown/index.tsx b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_drilldown/index.tsx index fd782f5468c85..986a1ebe3557c 100644 --- a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_drilldown/index.tsx +++ b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_drilldown/index.tsx @@ -17,9 +17,10 @@ import { export type ActionContext = ChartActionContext; -export interface Config { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type Config = { name: string; -} +}; const SAMPLE_DASHBOARD_HELLO_WORLD_DRILLDOWN = 'SAMPLE_DASHBOARD_HELLO_WORLD_DRILLDOWN'; diff --git a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_only_range_select_drilldown/index.tsx b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_only_range_select_drilldown/index.tsx index 7394690a61eae..2a07edb3e5c83 100644 --- a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_only_range_select_drilldown/index.tsx +++ b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_only_range_select_drilldown/index.tsx @@ -13,9 +13,10 @@ import { CollectConfigProps } from '../../../../../src/plugins/kibana_utils/publ import { SELECT_RANGE_TRIGGER } from '../../../../../src/plugins/ui_actions/public'; import { BaseActionFactoryContext } from '../../../../plugins/ui_actions_enhanced/public/dynamic_actions'; -export interface Config { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type Config = { name: string; -} +}; const SAMPLE_DASHBOARD_HELLO_WORLD_DRILLDOWN_ONLY_RANGE_SELECT = 'SAMPLE_DASHBOARD_HELLO_WORLD_DRILLDOWN_ONLY_RANGE_SELECT'; diff --git a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_to_discover_drilldown/types.ts b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_to_discover_drilldown/types.ts index a10e8ad707e97..7eef10fa61c17 100644 --- a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_to_discover_drilldown/types.ts +++ b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_to_discover_drilldown/types.ts @@ -9,7 +9,8 @@ import { ApplyGlobalFilterActionContext } from '../../../../../src/plugins/data/ export type ActionContext = ApplyGlobalFilterActionContext; -export interface Config { +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type Config = { /** * Whether to use a user selected index pattern, stored in `indexPatternId` field. */ @@ -30,6 +31,6 @@ export interface Config { * Whether to carry over source dashboard time range. */ carryTimeRange: boolean; -} +}; export type CollectConfigProps = CollectConfigPropsBase; diff --git a/x-pack/plugins/embeddable_enhanced/public/plugin.ts b/x-pack/plugins/embeddable_enhanced/public/plugin.ts index a6f99be2ef02c..37e102b40131d 100644 --- a/x-pack/plugins/embeddable_enhanced/public/plugin.ts +++ b/x-pack/plugins/embeddable_enhanced/public/plugin.ts @@ -32,7 +32,6 @@ import { } from '../../ui_actions_enhanced/public'; import { PanelNotificationsAction, ACTION_PANEL_NOTIFICATIONS } from './actions'; import { UrlDrilldown } from './drilldowns'; -import { dynamicActionEnhancement } from './embeddables/dynamic_action_enhancement'; import { createStartServicesGetter } from '../../../../src/plugins/kibana_utils/public'; declare module '../../../../src/plugins/ui_actions/public' { @@ -69,7 +68,6 @@ export class EmbeddableEnhancedPlugin const panelNotificationAction = new PanelNotificationsAction(); plugins.uiActionsEnhanced.registerAction(panelNotificationAction); plugins.uiActionsEnhanced.attachAction(PANEL_NOTIFICATION_TRIGGER, panelNotificationAction.id); - plugins.embeddable.registerEnhancement(dynamicActionEnhancement(startServices)); plugins.uiActionsEnhanced.registerDrilldown( new UrlDrilldown({ diff --git a/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_enhancement.ts similarity index 66% rename from x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts rename to x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_enhancement.ts index d650867a420b0..8c08bbceb74a1 100644 --- a/x-pack/plugins/embeddable_enhanced/public/embeddables/dynamic_action_enhancement.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_enhancement.ts @@ -6,24 +6,23 @@ import { EnhancementRegistryDefinition } from '../../../../../src/plugins/embeddable/public'; import { SavedObjectReference } from '../../../../../src/core/types'; -import { StartServicesGetter } from '../../../../../src/plugins/kibana_utils/public'; import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; -import { StartDependencies } from '../plugin'; import { DynamicActionsState } from '../../../ui_actions_enhanced/public'; +import { UiActionsServiceEnhancements } from '../services'; export const dynamicActionEnhancement = ( - start: StartServicesGetter> + uiActionsEnhanced: UiActionsServiceEnhancements ): EnhancementRegistryDefinition => { return { id: 'dynamicActions', telemetry: (state: SerializableState) => { - return start().plugins.uiActionsEnhanced.telemetry(state as DynamicActionsState); + return uiActionsEnhanced.telemetry(state as DynamicActionsState); }, extract: (state: SerializableState) => { - return start().plugins.uiActionsEnhanced.extract(state as DynamicActionsState); + return uiActionsEnhanced.extract(state as DynamicActionsState); }, inject: (state: SerializableState, references: SavedObjectReference[]) => { - return start().plugins.uiActionsEnhanced.inject(state as DynamicActionsState, references); + return uiActionsEnhanced.inject(state as DynamicActionsState, references); }, } as EnhancementRegistryDefinition; }; diff --git a/x-pack/plugins/ui_actions_enhanced/public/plugin.ts b/x-pack/plugins/ui_actions_enhanced/public/plugin.ts index fb9077701a748..9071b9e4b4d84 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/plugin.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/plugin.ts @@ -39,6 +39,7 @@ import { UiActionsServiceEnhancements } from './services'; import { ILicense, LicensingPluginSetup, LicensingPluginStart } from '../../licensing/public'; import { createFlyoutManageDrilldowns } from './drilldowns'; import { createStartServicesGetter, Storage } from '../../../../src/plugins/kibana_utils/public'; +import { dynamicActionEnhancement } from './dynamic_actions/dynamic_action_enhancement'; interface SetupDependencies { embeddable: EmbeddableSetup; // Embeddable are needed because they register basic triggers/actions. @@ -90,7 +91,7 @@ export class AdvancedUiActionsPublicPlugin public setup( core: CoreSetup, - { uiActions, licensing }: SetupDependencies + { embeddable, uiActions, licensing }: SetupDependencies ): SetupContract { const startServices = createStartServicesGetter(core.getStartServices); this.enhancements = new UiActionsServiceEnhancements({ @@ -98,6 +99,7 @@ export class AdvancedUiActionsPublicPlugin featureUsageSetup: licensing.featureUsage, getFeatureUsageStart: () => startServices().plugins.licensing.featureUsage, }); + embeddable.registerEnhancement(dynamicActionEnhancement(this.enhancements)); return { ...uiActions, ...this.enhancements, diff --git a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.test.ts b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.test.ts index 3a0b65d2ed844..fd47411542a5d 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.test.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.test.ts @@ -96,6 +96,66 @@ describe('UiActionsService', () => { ).resolves.toBe(false); }); + test('action factory extract function gets called when calling uiactions extract', () => { + const service = new UiActionsServiceEnhancements(deps); + const actionState = { + events: [ + { + eventId: 'test', + triggers: [], + action: { factoryId: factoryDefinition1.id, name: 'test', config: {} }, + }, + ], + }; + const extract = jest.fn().mockImplementation((state) => ({ state, references: [] })); + service.registerActionFactory({ + ...factoryDefinition1, + extract, + }); + service.extract(actionState); + expect(extract).toBeCalledWith(actionState.events[0]); + }); + + test('action factory inject function gets called when calling uiactions inject', () => { + const service = new UiActionsServiceEnhancements(deps); + const actionState = { + events: [ + { + eventId: 'test', + triggers: [], + action: { factoryId: factoryDefinition1.id, name: 'test', config: {} }, + }, + ], + }; + const inject = jest.fn().mockImplementation((state) => state); + service.registerActionFactory({ + ...factoryDefinition1, + inject, + }); + service.inject(actionState, []); + expect(inject).toBeCalledWith(actionState.events[0], []); + }); + + test('action factory telemetry function gets called when calling uiactions telemetry', () => { + const service = new UiActionsServiceEnhancements(deps); + const actionState = { + events: [ + { + eventId: 'test', + triggers: [], + action: { factoryId: factoryDefinition1.id, name: 'test', config: {} }, + }, + ], + }; + const telemetry = jest.fn().mockImplementation((state) => ({})); + service.registerActionFactory({ + ...factoryDefinition1, + telemetry, + }); + service.telemetry(actionState); + expect(telemetry).toBeCalledWith(actionState.events[0]); + }); + describe('registerFeature for licensing', () => { const spy = jest.spyOn(deps.featureUsageSetup, 'register'); beforeEach(() => { From af659bc52056edec20af55c1e56b731495d32dad Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 9 Sep 2020 08:41:15 -0700 Subject: [PATCH 12/23] server side --- .../es_query/filters/get_display_value.ts | 2 +- .../common/es_query/filters/meta_filter.ts | 17 +- .../data/common/query/timefilter/types.ts | 5 +- src/plugins/data/common/query/types.ts | 5 +- .../lib/map_and_flatten_filters.test.ts | 4 +- .../filter_manager/lib/map_filter.test.ts | 4 +- .../lib}/migrate_base_input.ts | 4 +- src/plugins/embeddable/common/types.ts | 71 +++++++ src/plugins/embeddable/kibana.json | 2 +- .../public/lib/embeddables/embeddable.tsx | 5 +- .../public/lib/embeddables/i_embeddable.ts | 47 +---- src/plugins/embeddable/public/lib/types.ts | 7 +- src/plugins/embeddable/public/plugin.tsx | 2 +- src/plugins/embeddable/server/index.ts | 26 +++ src/plugins/embeddable/server/plugin.ts | 192 ++++++++++++++++++ src/plugins/embeddable/server/types.ts | 48 +++++ .../plugins/ui_actions_enhanced/kibana.json | 2 +- .../server/dynamic_action_enhancement.ts | 28 +++ .../ui_actions_enhanced/server/index.ts | 24 +++ .../ui_actions_enhanced/server/plugin.ts | 123 +++++++++++ .../ui_actions_enhanced/server/types.ts | 45 ++++ 21 files changed, 591 insertions(+), 72 deletions(-) rename src/plugins/embeddable/{public/lib/embeddables => common/lib}/migrate_base_input.ts (91%) create mode 100644 src/plugins/embeddable/common/types.ts create mode 100644 src/plugins/embeddable/server/index.ts create mode 100644 src/plugins/embeddable/server/plugin.ts create mode 100644 src/plugins/embeddable/server/types.ts create mode 100644 x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts create mode 100644 x-pack/plugins/ui_actions_enhanced/server/index.ts create mode 100644 x-pack/plugins/ui_actions_enhanced/server/plugin.ts create mode 100644 x-pack/plugins/ui_actions_enhanced/server/types.ts diff --git a/src/plugins/data/common/es_query/filters/get_display_value.ts b/src/plugins/data/common/es_query/filters/get_display_value.ts index 28ba0ab629e8f..317d0f0140293 100644 --- a/src/plugins/data/common/es_query/filters/get_display_value.ts +++ b/src/plugins/data/common/es_query/filters/get_display_value.ts @@ -43,7 +43,7 @@ export function getDisplayValueFromFilter(filter: Filter, indexPatterns: IIndexP if (typeof filter.meta.value === 'function') { const indexPattern = getIndexPatternFromFilter(filter, indexPatterns); const valueFormatter: any = getValueFormatter(indexPattern, filter.meta.key); - return filter.meta.value(valueFormatter); + return (filter.meta.value as any)(valueFormatter); } else { return filter.meta.value || ''; } diff --git a/src/plugins/data/common/es_query/filters/meta_filter.ts b/src/plugins/data/common/es_query/filters/meta_filter.ts index e3099ae6a4026..1e892d452f401 100644 --- a/src/plugins/data/common/es_query/filters/meta_filter.ts +++ b/src/plugins/data/common/es_query/filters/meta_filter.ts @@ -22,9 +22,10 @@ export enum FilterStateStore { GLOBAL_STATE = 'globalState', } -export interface FilterState { +// eslint-disable-next-line +export type FilterState = { store: FilterStateStore; -} +}; type FilterFormatterFunction = (value: any) => string; export interface FilterValueFormatter { @@ -32,7 +33,8 @@ export interface FilterValueFormatter { getConverterFor: (type: string) => FilterFormatterFunction; } -export interface FilterMeta { +// eslint-disable-next-line +export type FilterMeta = { alias: string | null; disabled: boolean; negate: boolean; @@ -43,14 +45,15 @@ export interface FilterMeta { type?: string; key?: string; params?: any; - value?: string | ((formatter?: FilterValueFormatter) => string); -} + value?: string; +}; -export interface Filter { +// eslint-disable-next-line +export type Filter = { $state?: FilterState; meta: FilterMeta; query?: any; -} +}; export interface LatLon { lat: number; diff --git a/src/plugins/data/common/query/timefilter/types.ts b/src/plugins/data/common/query/timefilter/types.ts index 60008ce6054e1..82b1ae69cc73b 100644 --- a/src/plugins/data/common/query/timefilter/types.ts +++ b/src/plugins/data/common/query/timefilter/types.ts @@ -24,11 +24,12 @@ export interface RefreshInterval { value: number; } -export interface TimeRange { +// eslint-disable-next-line +export type TimeRange = { from: string; to: string; mode?: 'absolute' | 'relative'; -} +}; export interface TimeRangeBounds { min: Moment | undefined; diff --git a/src/plugins/data/common/query/types.ts b/src/plugins/data/common/query/types.ts index 6b34a1baf293b..c1a98eac5350e 100644 --- a/src/plugins/data/common/query/types.ts +++ b/src/plugins/data/common/query/types.ts @@ -19,7 +19,8 @@ export * from './timefilter/types'; -export interface Query { +// eslint-disable-next-line +export type Query = { query: string | { [key: string]: any }; language: string; -} +}; diff --git a/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.test.ts b/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.test.ts index 1b2d476570902..996a7aaa27c31 100644 --- a/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/map_and_flatten_filters.test.ts @@ -25,7 +25,9 @@ describe('filter manager utilities', () => { let filters: unknown; function getDisplayName(filter: Filter) { - return typeof filter.meta.value === 'function' ? filter.meta.value() : filter.meta.value; + return typeof filter.meta.value === 'function' + ? (filter.meta.value as any)() + : filter.meta.value; } beforeEach(() => { diff --git a/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts b/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts index 35d2f2b7b294e..7b303ca4d5314 100644 --- a/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts @@ -22,7 +22,9 @@ import { Filter } from '../../../../common'; describe('filter manager utilities', () => { function getDisplayName(filter: Filter) { - return typeof filter.meta.value === 'function' ? filter.meta.value() : filter.meta.value; + return typeof filter.meta.value === 'function' + ? (filter.meta.value as any)() + : filter.meta.value; } describe('mapFilter()', () => { diff --git a/src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts b/src/plugins/embeddable/common/lib/migrate_base_input.ts similarity index 91% rename from src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts rename to src/plugins/embeddable/common/lib/migrate_base_input.ts index 63e9caede19bc..0ee655d750584 100644 --- a/src/plugins/embeddable/public/lib/embeddables/migrate_base_input.ts +++ b/src/plugins/embeddable/common/lib/migrate_base_input.ts @@ -17,8 +17,8 @@ * under the License. */ -import { SavedObjectReference } from '../../../../../core/types'; -import { EmbeddableInput } from './i_embeddable'; +import { SavedObjectReference } from '../../../../core/types'; +import { EmbeddableInput } from '../types'; export const telemetryBaseEmbeddableInput = (state: EmbeddableInput) => { return {} as Record; diff --git a/src/plugins/embeddable/common/types.ts b/src/plugins/embeddable/common/types.ts new file mode 100644 index 0000000000000..404a203e5c701 --- /dev/null +++ b/src/plugins/embeddable/common/types.ts @@ -0,0 +1,71 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SerializableState } from '../../kibana_utils/common/persistable_state'; +import { Query, TimeRange } from '../../data/common/query'; +import { Filter } from '../../data/common/es_query/filters'; + +export enum ViewMode { + EDIT = 'edit', + VIEW = 'view', +} + +// eslint-disable-next-line +export type EmbeddableInput = { + viewMode?: ViewMode; + title?: string; + /** + * Note this is not a saved object id. It is used to uniquely identify this + * Embeddable instance from others (e.g. inside a container). It's possible to + * have two Embeddables where everything else is the same but the id. + */ + id: string; + lastReloadRequestTime?: number; + hidePanelTitles?: boolean; + + /** + * Reserved key for enhancements added by other plugins. + */ + enhancements?: SerializableState; + + /** + * List of action IDs that this embeddable should not render. + */ + disabledActions?: string[]; + + /** + * Whether this embeddable should not execute triggers. + */ + disableTriggers?: boolean; + + /** + * Time range of the chart. + */ + timeRange?: TimeRange; + + /** + * Visualization query string used to narrow down results. + */ + query?: Query; + + /** + * Visualization filters used to narrow down results. + */ + filters?: Filter[]; +}; diff --git a/src/plugins/embeddable/kibana.json b/src/plugins/embeddable/kibana.json index 6a8e6079232aa..1ecf76dbbd5c2 100644 --- a/src/plugins/embeddable/kibana.json +++ b/src/plugins/embeddable/kibana.json @@ -1,7 +1,7 @@ { "id": "embeddable", "version": "kibana", - "server": false, + "server": true, "ui": true, "requiredPlugins": [ "inspector", diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx b/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx index ffe8a5bf6e7dc..9267d600360cf 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx @@ -21,10 +21,11 @@ import { cloneDeep, isEqual } from 'lodash'; import * as Rx from 'rxjs'; import { distinctUntilChanged, map } from 'rxjs/operators'; import { RenderCompleteDispatcher } from '../../../../kibana_utils/public'; -import { Adapters, ViewMode } from '../types'; +import { Adapters } from '../types'; import { IContainer } from '../containers'; -import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable'; +import { EmbeddableOutput, IEmbeddable } from './i_embeddable'; import { TriggerContextMapping } from '../ui_actions'; +import { EmbeddableInput, ViewMode } from '../../../common/types'; function getPanelTitle(input: EmbeddableInput, output: EmbeddableOutput) { return input.hidePanelTitles ? '' : input.title === undefined ? output.defaultTitle : input.title; diff --git a/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts b/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts index 091e28c7b26e3..3843950c164c9 100644 --- a/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts +++ b/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts @@ -20,58 +20,15 @@ import { Observable } from 'rxjs'; import { Adapters } from '../types'; import { IContainer } from '../containers/i_container'; -import { ViewMode } from '../types'; import { TriggerContextMapping } from '../../../../ui_actions/public'; -import type { TimeRange, Query, Filter } from '../../../../data/common'; -import { SerializableState } from '../../../../kibana_utils/common'; +import { EmbeddableInput } from '../../../common/types'; export interface EmbeddableError { name: string; message: string; } -export interface EmbeddableInput { - viewMode?: ViewMode; - title?: string; - /** - * Note this is not a saved object id. It is used to uniquely identify this - * Embeddable instance from others (e.g. inside a container). It's possible to - * have two Embeddables where everything else is the same but the id. - */ - id: string; - lastReloadRequestTime?: number; - hidePanelTitles?: boolean; - - /** - * Reserved key for enhancements added by other plugins. - */ - enhancements?: SerializableState; - - /** - * List of action IDs that this embeddable should not render. - */ - disabledActions?: string[]; - - /** - * Whether this embeddable should not execute triggers. - */ - disableTriggers?: boolean; - - /** - * Time range of the chart. - */ - timeRange?: TimeRange; - - /** - * Visualization query string used to narrow down results. - */ - query?: Query; - - /** - * Visualization filters used to narrow down results. - */ - filters?: Filter[]; -} +export { EmbeddableInput }; export interface EmbeddableOutput { // Whether the embeddable is actively loading. diff --git a/src/plugins/embeddable/public/lib/types.ts b/src/plugins/embeddable/public/lib/types.ts index 1cfff7baca186..7fe189dea2381 100644 --- a/src/plugins/embeddable/public/lib/types.ts +++ b/src/plugins/embeddable/public/lib/types.ts @@ -32,10 +32,5 @@ export interface PropertySpec { description: string; value?: string; } - -export enum ViewMode { - EDIT = 'edit', - VIEW = 'view', -} - +export { ViewMode } from '../../common/types'; export { Adapters }; diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index abbc23938a74d..b1d65d9749a9f 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -54,7 +54,7 @@ import { extractBaseEmbeddableInput, injectBaseEmbeddableInput, telemetryBaseEmbeddableInput, -} from './lib/embeddables/migrate_base_input'; +} from '../common/lib/migrate_base_input'; import { PersistableState, SerializableState } from '../../kibana_utils/common'; export interface EmbeddableSetupDependencies { diff --git a/src/plugins/embeddable/server/index.ts b/src/plugins/embeddable/server/index.ts new file mode 100644 index 0000000000000..1138478bff4b7 --- /dev/null +++ b/src/plugins/embeddable/server/index.ts @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { EmbeddableServerPlugin, EmbeddableSetup } from './plugin'; + +export { EmbeddableSetup }; + +export { EnhancementRegistryDefinition, EmbeddableRegistryDefinition } from './types'; + +export const plugin = () => new EmbeddableServerPlugin(); diff --git a/src/plugins/embeddable/server/plugin.ts b/src/plugins/embeddable/server/plugin.ts new file mode 100644 index 0000000000000..60335ea5c16d5 --- /dev/null +++ b/src/plugins/embeddable/server/plugin.ts @@ -0,0 +1,192 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { CoreSetup, CoreStart, Plugin, SavedObjectReference } from 'kibana/server'; +import { identity } from 'lodash'; +import { + EmbeddableFactoryRegistry, + EnhancementsRegistry, + EnhancementRegistryDefinition, + EnhancementRegistryItem, + EmbeddableRegistryDefinition, +} from './types'; +import { + extractBaseEmbeddableInput, + injectBaseEmbeddableInput, + telemetryBaseEmbeddableInput, +} from '../common/lib/migrate_base_input'; +import { SerializableState } from '../../kibana_utils/common/persistable_state'; +import { EmbeddableInput } from '../common/types'; + +export interface EmbeddableSetup { + registerEmbeddableFactory: (factory: EmbeddableRegistryDefinition) => void; + registerEnhancement: (enhancement: EnhancementRegistryDefinition) => void; +} + +export class EmbeddableServerPlugin implements Plugin { + private readonly embeddableFactories: EmbeddableFactoryRegistry = new Map(); + private readonly enhancements: EnhancementsRegistry = new Map(); + + public setup(core: CoreSetup) { + return { + registerEmbeddableFactory: this.registerEmbeddableFactory, + registerEnhancement: this.registerEnhancement, + }; + } + + public start(core: CoreStart) { + return { + telemetry: this.telemetry, + extract: this.extract, + inject: this.inject, + }; + } + + public stop() {} + + private telemetry = (state: EmbeddableInput) => { + const enhancements: Record = state.enhancements || {}; + const factory = this.getEmbeddableFactory(state.id); + + const telemetryData = telemetryBaseEmbeddableInput(state); + if (factory) { + const factoryTelemetry = factory.telemetry(state); + Object.keys(factoryTelemetry).forEach((key) => { + telemetryData[key] = factoryTelemetry[key]; + }); + } + Object.keys(enhancements).map((key) => { + if (!enhancements[key]) return; + const enhancementTelemetry = this.getEnhancement(key).telemetry(enhancements[key]); + Object.keys(enhancementTelemetry).forEach((k) => { + telemetryData[k] = enhancementTelemetry[k]; + }); + }); + + return telemetryData; + }; + + private extract = (state: EmbeddableInput) => { + const enhancements = state.enhancements || {}; + const factory = this.getEmbeddableFactory(state.id); + + const baseResponse = extractBaseEmbeddableInput(state); + let updatedInput = baseResponse.state; + let refs = baseResponse.references; + + if (factory) { + const factoryResponse = factory.extract(state); + updatedInput = factoryResponse.state; + refs = refs.concat(factoryResponse.references); + } + + updatedInput.enhancements = {}; + Object.keys(enhancements).forEach((key) => { + if (!enhancements[key]) return; + const enhancementResult = this.getEnhancement(key).extract( + enhancements[key] as SerializableState + ); + refs = refs.concat(enhancementResult.references); + updatedInput.enhancements![key] = enhancementResult.state; + }); + + return { + state: updatedInput, + references: refs, + }; + }; + + private inject = (state: EmbeddableInput, references: SavedObjectReference[]) => { + const enhancements = state.enhancements || {}; + const factory = this.getEmbeddableFactory(state.id); + + let updatedInput = injectBaseEmbeddableInput(state, references); + + if (factory) { + updatedInput = factory.inject(updatedInput, references); + } + + updatedInput.enhancements = {}; + Object.keys(enhancements).forEach((key) => { + if (!enhancements[key]) return; + updatedInput.enhancements![key] = this.getEnhancement(key).inject( + enhancements[key] as SerializableState, + references + ); + }); + + return updatedInput; + }; + + private registerEnhancement = (enhancement: EnhancementRegistryDefinition) => { + if (this.enhancements.has(enhancement.id)) { + throw new Error(`enhancement with id ${enhancement.id} already exists in the registry`); + } + this.enhancements.set(enhancement.id, { + id: enhancement.id, + telemetry: enhancement.telemetry || (() => ({})), + inject: enhancement.inject || identity, + extract: + enhancement.extract || + ((state: SerializableState) => { + return { state, references: [] }; + }), + }); + }; + + private getEnhancement = (id: string): EnhancementRegistryItem => { + return ( + this.enhancements.get(id) || { + id: 'unknown', + telemetry: () => ({}), + inject: identity, + extract: (state: SerializableState) => { + return { state, references: [] }; + }, + } + ); + }; + + private registerEmbeddableFactory = (factory: EmbeddableRegistryDefinition) => { + if (this.embeddableFactories.has(factory.id)) { + throw new Error( + `Embeddable factory [embeddableFactoryId = ${factory.id}] already registered in Embeddables API.` + ); + } + this.embeddableFactories.set(factory.id, { + id: factory.id, + telemetry: factory.telemetry || (() => ({})), + inject: factory.inject || identity, + extract: factory.extract || ((state: EmbeddableInput) => ({ state, references: [] })), + }); + }; + + private getEmbeddableFactory = (embeddableFactoryId: string) => { + return ( + this.embeddableFactories.get(embeddableFactoryId) || { + id: 'unknown', + telemetry: () => ({}), + inject: (state: EmbeddableInput) => state, + extract: (state: EmbeddableInput) => { + return { state, references: [] }; + }, + } + ); + }; +} diff --git a/src/plugins/embeddable/server/types.ts b/src/plugins/embeddable/server/types.ts new file mode 100644 index 0000000000000..9d940d0945440 --- /dev/null +++ b/src/plugins/embeddable/server/types.ts @@ -0,0 +1,48 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { + PersistableState, + PersistableStateDefinition, + SerializableState, +} from '../../kibana_utils/common/persistable_state'; +import { EmbeddableInput } from '../common/types'; + +export type EmbeddableFactoryRegistry = Map; +export type EnhancementsRegistry = Map; + +export interface EnhancementRegistryDefinition

+ extends PersistableStateDefinition

{ + id: string; +} + +export interface EnhancementRegistryItem

+ extends PersistableState

{ + id: string; +} + +export interface EmbeddableRegistryDefinition

+ extends PersistableStateDefinition

{ + id: string; +} + +export interface EmbeddableRegistryItem

+ extends PersistableState

{ + id: string; +} diff --git a/x-pack/plugins/ui_actions_enhanced/kibana.json b/x-pack/plugins/ui_actions_enhanced/kibana.json index 108c66505f25c..5435019f216f2 100644 --- a/x-pack/plugins/ui_actions_enhanced/kibana.json +++ b/x-pack/plugins/ui_actions_enhanced/kibana.json @@ -7,7 +7,7 @@ "uiActions", "licensing" ], - "server": false, + "server": true, "ui": true, "requiredBundles": [ "kibanaUtils", diff --git a/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts b/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts new file mode 100644 index 0000000000000..b0203dbb720f5 --- /dev/null +++ b/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { EnhancementRegistryDefinition } from '../../../../src/plugins/embeddable/server'; +import { SavedObjectReference } from '../../../../src/core/types'; +import { SerializableState } from '../../../../src/plugins/kibana_utils/common'; +import { DynamicActionsState } from './types'; +import { AdvancedUiActionsPublicPlugin } from './plugin'; + +export const dynamicActionEnhancement = ( + uiActionsEnhanced: AdvancedUiActionsPublicPlugin +): EnhancementRegistryDefinition => { + return { + id: 'dynamicActions', + telemetry: (state: SerializableState) => { + return uiActionsEnhanced.telemetry(state as DynamicActionsState); + }, + extract: (state: SerializableState) => { + return uiActionsEnhanced.extract(state as DynamicActionsState); + }, + inject: (state: SerializableState, references: SavedObjectReference[]) => { + return uiActionsEnhanced.inject(state as DynamicActionsState, references); + }, + } as EnhancementRegistryDefinition; +}; diff --git a/x-pack/plugins/ui_actions_enhanced/server/index.ts b/x-pack/plugins/ui_actions_enhanced/server/index.ts new file mode 100644 index 0000000000000..97552a6eda60b --- /dev/null +++ b/x-pack/plugins/ui_actions_enhanced/server/index.ts @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { AdvancedUiActionsPublicPlugin } from './plugin'; + +export function plugin() { + return new AdvancedUiActionsPublicPlugin(); +} + +export { AdvancedUiActionsPublicPlugin as Plugin }; +export { + SetupContract as AdvancedUiActionsSetup, + StartContract as AdvancedUiActionsStart, +} from './plugin'; + +export { + ActionFactoryDefinition as UiActionsEnhancedActionFactoryDefinition, + ActionFactory as UiActionsEnhancedActionFactory, + SerializedAction as UiActionsEnhancedSerializedAction, + SerializedEvent as UiActionsEnhancedSerializedEvent, +} from './types'; diff --git a/x-pack/plugins/ui_actions_enhanced/server/plugin.ts b/x-pack/plugins/ui_actions_enhanced/server/plugin.ts new file mode 100644 index 0000000000000..f9126c473d11d --- /dev/null +++ b/x-pack/plugins/ui_actions_enhanced/server/plugin.ts @@ -0,0 +1,123 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { identity } from 'lodash'; +import { CoreSetup, Plugin, SavedObjectReference } from '../../../../src/core/server'; +import { EmbeddableSetup } from '../../../../src/plugins/embeddable/server'; +import { dynamicActionEnhancement } from './dynamic_action_enhancement'; +import { + ActionFactoryRegistry, + SerializedEvent, + ActionFactoryDefinition, + DynamicActionsState, +} from './types'; +import { PersistableState } from '../../../../src/plugins/kibana_utils/common/persistable_state'; + +export interface SetupContract { + registerActionFactory: any; +} + +export type StartContract = PersistableState; + +interface SetupDependencies { + embeddable: EmbeddableSetup; // Embeddable are needed because they register basic triggers/actions. +} + +export class AdvancedUiActionsPublicPlugin + implements Plugin { + protected readonly actionFactories: ActionFactoryRegistry = new Map(); + + constructor() {} + + public setup(core: CoreSetup, { embeddable }: SetupDependencies) { + // this.enhancements = new UiActionsServiceEnhancements({ + // getLicense: () => this.getLicenseInfo(), + // featureUsageSetup: licensing.featureUsage, + // getFeatureUsageStart: () => startServices().plugins.licensing.featureUsage, + // }); + embeddable.registerEnhancement(dynamicActionEnhancement(this)); + + return { + registerActionFactory: this.registerActionFactory, + }; + } + + public start() { + return { + telemetry: this.telemetry, + inject: this.inject, + extract: this.extract, + }; + } + + public stop() {} + + /** + * Register an action factory. Action factories are used to configure and + * serialize/deserialize dynamic actions. + */ + public readonly registerActionFactory = (definition: ActionFactoryDefinition) => { + if (this.actionFactories.has(definition.id)) { + throw new Error(`ActionFactory [actionFactory.id = ${definition.id}] already registered.`); + } + + this.actionFactories.set(definition.id, { + id: definition.id, + telemetry: definition.telemetry || (() => ({})), + inject: definition.inject || identity, + extract: + definition.extract || + ((state: SerializedEvent) => { + return { state, references: [] }; + }), + }); + }; + + public readonly getActionFactory = (actionFactoryId: string) => { + const actionFactory = this.actionFactories.get(actionFactoryId); + return actionFactory; + }; + + public readonly telemetry = (state: DynamicActionsState) => { + const telemetry: Record = {}; + state.events.forEach((event: SerializedEvent) => { + const eventTelemetry = this.actionFactories.has(event.action.factoryId) + ? this.actionFactories.get(event.action.factoryId)!.telemetry(event) + : {}; + Object.keys(eventTelemetry).forEach((key) => { + telemetry[key] = eventTelemetry[key]; + }); + }); + return telemetry; + }; + + public readonly extract = (state: DynamicActionsState) => { + const references: SavedObjectReference[] = []; + const newState = { + events: state.events.map((event: SerializedEvent) => { + const result = this.actionFactories.has(event.action.factoryId) + ? this.actionFactories.get(event.action.factoryId)!.extract(event) + : { + state: event, + references: [], + }; + result.references.forEach((r) => references.push(r)); + return result.state; + }), + }; + return { state: newState, references }; + }; + + public readonly inject = (state: DynamicActionsState, references: SavedObjectReference[]) => { + return { + events: state.events.map((event: SerializedEvent) => { + return this.actionFactories.has(event.action.factoryId) + ? this.actionFactories.get(event.action.factoryId)!.inject(event, references) + : event; + }), + }; + }; +} diff --git a/x-pack/plugins/ui_actions_enhanced/server/types.ts b/x-pack/plugins/ui_actions_enhanced/server/types.ts new file mode 100644 index 0000000000000..b462218334d9b --- /dev/null +++ b/x-pack/plugins/ui_actions_enhanced/server/types.ts @@ -0,0 +1,45 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { + PersistableState, + PersistableStateDefinition, + SerializableState, +} from '../../../../src/plugins/kibana_utils/common/persistable_state'; + +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type SerializedAction = { + readonly factoryId: string; + readonly name: string; + readonly config: Config; +}; + +/** + * Serialized representation of a triggers-action pair, used to persist in storage. + */ +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type SerializedEvent = { + eventId: string; + triggers: string[]; + action: SerializedAction; +}; + +// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +export type DynamicActionsState = { + events: SerializedEvent[]; +}; + +export type ActionFactoryRegistry = Map; + +export interface ActionFactoryDefinition

+ extends PersistableStateDefinition

{ + id: string; +} + +export interface ActionFactory

+ extends PersistableState

{ + id: string; +} From b3e128162516aa07b9f0ccd99d1ed69b8268183c Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 9 Sep 2020 08:59:00 -0700 Subject: [PATCH 13/23] updating telemetry function --- src/plugins/embeddable/public/plugin.tsx | 10 ++-------- src/plugins/embeddable/server/plugin.ts | 10 ++-------- .../kibana_utils/common/persistable_state/index.ts | 7 ++++--- .../public/dynamic_actions/action_factory.ts | 4 ++-- .../dynamic_actions/dynamic_action_enhancement.ts | 4 ++-- .../services/ui_actions_service_enhancements.ts | 12 ++++-------- .../server/dynamic_action_enhancement.ts | 4 ++-- x-pack/plugins/ui_actions_enhanced/server/plugin.ts | 12 ++++-------- 8 files changed, 22 insertions(+), 41 deletions(-) diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index b1d65d9749a9f..d7a4fa1eb0679 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -204,17 +204,11 @@ export class EmbeddablePublicPlugin implements Plugin { - telemetryData[key] = factoryTelemetry[key]; - }); + factory.telemetry(state, telemetryData); } Object.keys(enhancements).map((key) => { if (!enhancements[key]) return; - const enhancementTelemetry = this.getEnhancement(key).telemetry(enhancements[key]); - Object.keys(enhancementTelemetry).forEach((k) => { - telemetryData[k] = enhancementTelemetry[k]; - }); + this.getEnhancement(key).telemetry(enhancements[key], telemetryData); }); return telemetryData; diff --git a/src/plugins/embeddable/server/plugin.ts b/src/plugins/embeddable/server/plugin.ts index 60335ea5c16d5..050dff750dc8d 100644 --- a/src/plugins/embeddable/server/plugin.ts +++ b/src/plugins/embeddable/server/plugin.ts @@ -66,17 +66,11 @@ export class EmbeddableServerPlugin implements Plugin { const telemetryData = telemetryBaseEmbeddableInput(state); if (factory) { - const factoryTelemetry = factory.telemetry(state); - Object.keys(factoryTelemetry).forEach((key) => { - telemetryData[key] = factoryTelemetry[key]; - }); + factory.telemetry(state, telemetryData); } Object.keys(enhancements).map((key) => { if (!enhancements[key]) return; - const enhancementTelemetry = this.getEnhancement(key).telemetry(enhancements[key]); - Object.keys(enhancementTelemetry).forEach((k) => { - telemetryData[k] = enhancementTelemetry[k]; - }); + this.getEnhancement(key).telemetry(enhancements[key], telemetryData); }); return telemetryData; diff --git a/src/plugins/kibana_utils/common/persistable_state/index.ts b/src/plugins/kibana_utils/common/persistable_state/index.ts index 8d0987cc4e1ce..e0d4c371757a0 100644 --- a/src/plugins/kibana_utils/common/persistable_state/index.ts +++ b/src/plugins/kibana_utils/common/persistable_state/index.ts @@ -28,8 +28,9 @@ export type SerializableState = { }; export interface PersistableState

{ - // function to extract telemetry information - telemetry: (state: P) => Record; + // function to extract telemetry information, receives a state and an object with telemetry collected so far + // function needs to check if the key it wants to add already exist and if so handle it correctly + telemetry: (state: P, collector: Record) => Record; // inject function receives state and a list of references and should return state with references injected // default is identity function inject: (state: P, references: SavedObjectReference[]) => P; @@ -40,7 +41,7 @@ export interface PersistableState

{ // function to extract telemetry information - telemetry?: (state: P) => Record; + telemetry?: (state: P, collector: Record) => Record; // inject function receives state and a list of references and should return state with references injected // default is identity function inject?: (state: P, references: SavedObjectReference[]) => P; diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts index 6086ea771a550..d11e692a03303 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts @@ -129,8 +129,8 @@ export class ActionFactory< }); } - public telemetry(state: SerializedEvent) { - return this.def.telemetry ? this.def.telemetry(state) : {}; + public telemetry(state: SerializedEvent, telemetryData: Record) { + return this.def.telemetry ? this.def.telemetry(state, telemetryData) : {}; } public extract(state: SerializedEvent) { diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_enhancement.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_enhancement.ts index 8c08bbceb74a1..7cac49624bfdd 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_enhancement.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_enhancement.ts @@ -15,8 +15,8 @@ export const dynamicActionEnhancement = ( ): EnhancementRegistryDefinition => { return { id: 'dynamicActions', - telemetry: (state: SerializableState) => { - return uiActionsEnhanced.telemetry(state as DynamicActionsState); + telemetry: (state: SerializableState, telemetryData: Record) => { + return uiActionsEnhanced.telemetry(state as DynamicActionsState, telemetryData); }, extract: (state: SerializableState) => { return uiActionsEnhanced.extract(state as DynamicActionsState); diff --git a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts index d300150d15cd6..9b67eeddd3025 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts @@ -168,15 +168,11 @@ export class UiActionsServiceEnhancements }); }; - public readonly telemetry = (state: DynamicActionsState) => { - const telemetry: Record = {}; + public readonly telemetry = (state: DynamicActionsState, telemetry: Record = {}) => { state.events.forEach((event: SerializedEvent) => { - const eventTelemetry = this.actionFactories.has(event.action.factoryId) - ? this.actionFactories.get(event.action.factoryId)!.telemetry(event) - : {}; - Object.keys(eventTelemetry).forEach((key) => { - telemetry[key] = eventTelemetry[key]; - }); + if (this.actionFactories.has(event.action.factoryId)) { + this.actionFactories.get(event.action.factoryId)!.telemetry(event, telemetry); + } }); return telemetry; }; diff --git a/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts b/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts index b0203dbb720f5..7d4b27a3e5f71 100644 --- a/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts +++ b/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts @@ -15,8 +15,8 @@ export const dynamicActionEnhancement = ( ): EnhancementRegistryDefinition => { return { id: 'dynamicActions', - telemetry: (state: SerializableState) => { - return uiActionsEnhanced.telemetry(state as DynamicActionsState); + telemetry: (state: SerializableState, telemetryData: Record) => { + return uiActionsEnhanced.telemetry(state as DynamicActionsState, telemetryData); }, extract: (state: SerializableState) => { return uiActionsEnhanced.extract(state as DynamicActionsState); diff --git a/x-pack/plugins/ui_actions_enhanced/server/plugin.ts b/x-pack/plugins/ui_actions_enhanced/server/plugin.ts index f9126c473d11d..85023020e380d 100644 --- a/x-pack/plugins/ui_actions_enhanced/server/plugin.ts +++ b/x-pack/plugins/ui_actions_enhanced/server/plugin.ts @@ -81,15 +81,11 @@ export class AdvancedUiActionsPublicPlugin return actionFactory; }; - public readonly telemetry = (state: DynamicActionsState) => { - const telemetry: Record = {}; + public readonly telemetry = (state: DynamicActionsState, telemetry: Record = {}) => { state.events.forEach((event: SerializedEvent) => { - const eventTelemetry = this.actionFactories.has(event.action.factoryId) - ? this.actionFactories.get(event.action.factoryId)!.telemetry(event) - : {}; - Object.keys(eventTelemetry).forEach((key) => { - telemetry[key] = eventTelemetry[key]; - }); + if (this.actionFactories.has(event.action.factoryId)) { + this.actionFactories.get(event.action.factoryId)!.telemetry(event, telemetry); + } }); return telemetry; }; From 86f2e327464d4cfc1951a09208890c705def3908 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 9 Sep 2020 09:15:53 -0700 Subject: [PATCH 14/23] review feedback --- src/plugins/embeddable/common/types.ts | 2 +- .../default_embeddable_factory_provider.ts | 4 +-- src/plugins/embeddable/public/plugin.tsx | 7 ++-- src/plugins/embeddable/server/plugin.ts | 8 ++--- src/plugins/embeddable/server/types.ts | 2 +- .../common/persistable_state/index.ts | 35 ++++++++++--------- .../kibana_utils/public/ui/configurable.ts | 2 +- .../embeddables/embeddable_action_storage.ts | 2 +- .../action_wizard/action_wizard.tsx | 2 +- .../connected_flyout_manage_drilldowns.tsx | 2 +- .../form_drilldown_wizard.tsx | 2 +- .../public/drilldowns/drilldown_definition.ts | 2 +- .../ui_actions_service_enhancements.ts | 2 +- .../ui_actions_enhanced/server/plugin.ts | 2 +- .../ui_actions_enhanced/server/types.ts | 2 +- 15 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/plugins/embeddable/common/types.ts b/src/plugins/embeddable/common/types.ts index 404a203e5c701..dd68f57ca5d38 100644 --- a/src/plugins/embeddable/common/types.ts +++ b/src/plugins/embeddable/common/types.ts @@ -17,7 +17,7 @@ * under the License. */ -import { SerializableState } from '../../kibana_utils/common/persistable_state'; +import { SerializableState } from '../../kibana_utils/common'; import { Query, TimeRange } from '../../data/common/query'; import { Filter } from '../../data/common/es_query/filters'; diff --git a/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts b/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts index c8a0efc361fda..50b52bbf9089f 100644 --- a/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts +++ b/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { identity } from 'lodash'; + import { SavedObjectAttributes } from 'kibana/public'; import { EmbeddableFactoryDefinition } from './embeddable_factory_definition'; import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable'; @@ -49,7 +49,7 @@ export const defaultEmbeddableFactoryProvider = < getDisplayName: def.getDisplayName.bind(def), savedObjectMetaData: def.savedObjectMetaData, telemetry: def.telemetry || (() => ({})), - inject: def.inject || identity, + inject: def.inject || ((state: EmbeddableInput) => state), extract: def.extract || ((state: EmbeddableInput) => ({ state, references: [] })), }; return factory; diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index d7a4fa1eb0679..d5134ecac1102 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -81,7 +81,6 @@ export interface EmbeddableSetup { setCustomEmbeddableFactoryProvider: (customProvider: EmbeddableFactoryProvider) => void; } -// @ts-ignore export interface EmbeddableStart extends PersistableState { getEmbeddableFactory: < I extends EmbeddableInput = EmbeddableInput, @@ -220,12 +219,12 @@ export class EmbeddablePublicPlugin implements Plugin { const baseResponse = extractBaseEmbeddableInput(state); let updatedInput = baseResponse.state; - let refs = baseResponse.references; + const refs = baseResponse.references; if (factory) { const factoryResponse = factory.extract(state); updatedInput = factoryResponse.state; - refs = refs.concat(factoryResponse.references); + refs.push(...factoryResponse.references); } updatedInput.enhancements = {}; @@ -96,7 +96,7 @@ export class EmbeddableServerPlugin implements Plugin { const enhancementResult = this.getEnhancement(key).extract( enhancements[key] as SerializableState ); - refs = refs.concat(enhancementResult.references); + refs.push(...enhancementResult.references); updatedInput.enhancements![key] = enhancementResult.state; }); diff --git a/src/plugins/embeddable/server/types.ts b/src/plugins/embeddable/server/types.ts index 9d940d0945440..64f9325dad3cb 100644 --- a/src/plugins/embeddable/server/types.ts +++ b/src/plugins/embeddable/server/types.ts @@ -21,7 +21,7 @@ import { PersistableState, PersistableStateDefinition, SerializableState, -} from '../../kibana_utils/common/persistable_state'; +} from '../../kibana_utils/common'; import { EmbeddableInput } from '../common/types'; export type EmbeddableFactoryRegistry = Map; diff --git a/src/plugins/kibana_utils/common/persistable_state/index.ts b/src/plugins/kibana_utils/common/persistable_state/index.ts index e0d4c371757a0..ae5e3d514554c 100644 --- a/src/plugins/kibana_utils/common/persistable_state/index.ts +++ b/src/plugins/kibana_utils/common/persistable_state/index.ts @@ -28,24 +28,27 @@ export type SerializableState = { }; export interface PersistableState

{ - // function to extract telemetry information, receives a state and an object with telemetry collected so far - // function needs to check if the key it wants to add already exist and if so handle it correctly + /** + * function to extract telemetry information + * @param state + * @param collector + */ telemetry: (state: P, collector: Record) => Record; - // inject function receives state and a list of references and should return state with references injected - // default is identity function + /** + * inject function receives state and a list of references and should return state with references injected + * default is identity function + * @param state + * @param references + */ inject: (state: P, references: SavedObjectReference[]) => P; - // extract function receives state and should return state with references extracted and array of references - // default returns same state with empty reference array + /** + * extract function receives state and should return state with references extracted and array of references + * default returns same state with empty reference array + * @param state + */ extract: (state: P) => { state: P; references: SavedObjectReference[] }; } -export interface PersistableStateDefinition

{ - // function to extract telemetry information - telemetry?: (state: P, collector: Record) => Record; - // inject function receives state and a list of references and should return state with references injected - // default is identity function - inject?: (state: P, references: SavedObjectReference[]) => P; - // extract function receives state and should return state with references extracted and array of references - // default returns same state with empty reference array - extract?: (state: P) => { state: P; references: SavedObjectReference[] }; -} +export type PersistableStateDefinition

= Partial< + PersistableState

+>; diff --git a/src/plugins/kibana_utils/public/ui/configurable.ts b/src/plugins/kibana_utils/public/ui/configurable.ts index 1b8998ba3593c..89bce5ae423ee 100644 --- a/src/plugins/kibana_utils/public/ui/configurable.ts +++ b/src/plugins/kibana_utils/public/ui/configurable.ts @@ -18,7 +18,7 @@ */ import { UiComponent } from '../../common/ui/ui_component'; -import { SerializableState } from '../../common/persistable_state'; +import { SerializableState } from '../../common'; /** * Represents something that can be configured by user using UI. diff --git a/x-pack/plugins/embeddable_enhanced/public/embeddables/embeddable_action_storage.ts b/x-pack/plugins/embeddable_enhanced/public/embeddables/embeddable_action_storage.ts index e0403a74047fd..e0960b83b23f9 100644 --- a/x-pack/plugins/embeddable_enhanced/public/embeddables/embeddable_action_storage.ts +++ b/x-pack/plugins/embeddable_enhanced/public/embeddables/embeddable_action_storage.ts @@ -14,7 +14,7 @@ import { EmbeddableOutput, IEmbeddable, } from '../../../../../src/plugins/embeddable/public'; -import { SerializableState } from '../../../../../src/plugins/kibana_utils/common/persistable_state'; +import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; export interface EmbeddableWithDynamicActionsInput extends EmbeddableInput { enhancements?: { diff --git a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx index 1bd58e20e5e6f..a83ac9324d35f 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx @@ -30,7 +30,7 @@ import { import './action_wizard.scss'; import { ActionFactory, BaseActionFactoryContext } from '../../dynamic_actions'; import { Trigger, TriggerId } from '../../../../../../src/plugins/ui_actions/public'; -import { SerializableState } from '../../../../../../src/plugins/kibana_utils/common/persistable_state'; +import { SerializableState } from '../../../../../../src/plugins/kibana_utils/common'; export interface ActionWizardProps< ActionFactoryContext extends BaseActionFactoryContext = BaseActionFactoryContext diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx index 9b6804f809ff6..a3345c5c23669 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx @@ -31,7 +31,7 @@ import { SerializedEvent, } from '../../../dynamic_actions'; import { ActionFactoryPlaceContext } from '../types'; -import { SerializableState } from '../../../../../../../src/plugins/kibana_utils/common/persistable_state'; +import { SerializableState } from '../../../../../../../src/plugins/kibana_utils/common'; interface ConnectedFlyoutManageDrilldownsProps< ActionFactoryContext extends BaseActionFactoryContext = BaseActionFactoryContext diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx index 8d0d48f16daaf..adf404e7a9110 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx @@ -11,7 +11,7 @@ import { txtDrilldownAction, txtNameOfDrilldown, txtUntitledDrilldown } from './ import { ActionFactory, BaseActionFactoryContext } from '../../../dynamic_actions'; import { ActionWizard } from '../../../components/action_wizard'; import { Trigger, TriggerId } from '../../../../../../../src/plugins/ui_actions/public'; -import { SerializableState } from '../../../../../../../src/plugins/kibana_utils/common/persistable_state'; +import { SerializableState } from '../../../../../../../src/plugins/kibana_utils/common'; const GET_MORE_ACTIONS_LINK = 'https://www.elastic.co/subscriptions'; diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts index f1348b865c218..690fece84170f 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts @@ -15,7 +15,7 @@ import { ActionExecutionContext } from '../../../../../src/plugins/ui_actions/pu import { PersistableStateDefinition, SerializableState, -} from '../../../../../src/plugins/kibana_utils/common/persistable_state'; +} from '../../../../../src/plugins/kibana_utils/common'; /** * This is a convenience interface to register a drilldown. Drilldown has diff --git a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts index 9b67eeddd3025..fae4681452adc 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts @@ -187,7 +187,7 @@ export class UiActionsServiceEnhancements state: event, references: [], }; - result.references.forEach((r) => references.push(r)); + references.push(...result.references); return result.state; }), }; diff --git a/x-pack/plugins/ui_actions_enhanced/server/plugin.ts b/x-pack/plugins/ui_actions_enhanced/server/plugin.ts index 85023020e380d..a3c4a45303cb2 100644 --- a/x-pack/plugins/ui_actions_enhanced/server/plugin.ts +++ b/x-pack/plugins/ui_actions_enhanced/server/plugin.ts @@ -14,7 +14,7 @@ import { ActionFactoryDefinition, DynamicActionsState, } from './types'; -import { PersistableState } from '../../../../src/plugins/kibana_utils/common/persistable_state'; +import { PersistableState } from '../../../../src/plugins/kibana_utils/common'; export interface SetupContract { registerActionFactory: any; diff --git a/x-pack/plugins/ui_actions_enhanced/server/types.ts b/x-pack/plugins/ui_actions_enhanced/server/types.ts index b462218334d9b..5942a03d6fe2b 100644 --- a/x-pack/plugins/ui_actions_enhanced/server/types.ts +++ b/x-pack/plugins/ui_actions_enhanced/server/types.ts @@ -8,7 +8,7 @@ import { PersistableState, PersistableStateDefinition, SerializableState, -} from '../../../../src/plugins/kibana_utils/common/persistable_state'; +} from '../../../../src/plugins/kibana_utils/common'; // eslint-disable-next-line @typescript-eslint/consistent-type-definitions export type SerializedAction = { From 663032e7a948310adc2ae909b830c227d09e71cc Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 9 Sep 2020 09:23:21 -0700 Subject: [PATCH 15/23] updating docs --- ...na-plugin-plugins-data-public.esfilters.md | 2 +- ...lugin-plugins-data-public.filter._state.md | 11 ------- ...ibana-plugin-plugins-data-public.filter.md | 17 ++++------ ...-plugin-plugins-data-public.filter.meta.md | 11 ------- ...plugin-plugins-data-public.filter.query.md | 11 ------- .../kibana-plugin-plugins-data-public.md | 6 ++-- ...ugin-plugins-data-public.query.language.md | 11 ------- ...kibana-plugin-plugins-data-public.query.md | 17 ++++------ ...-plugin-plugins-data-public.query.query.md | 13 -------- ...ugin-plugins-data-public.timerange.from.md | 11 ------- ...na-plugin-plugins-data-public.timerange.md | 17 ++++------ ...ugin-plugins-data-public.timerange.mode.md | 11 ------- ...plugin-plugins-data-public.timerange.to.md | 11 ------- src/plugins/data/public/public.api.md | 32 +++++++------------ src/plugins/embeddable/public/plugin.test.ts | 8 ++--- 15 files changed, 38 insertions(+), 151 deletions(-) delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter._state.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.meta.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.query.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.language.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.query.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.from.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.mode.md delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.to.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.esfilters.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.esfilters.md index bc34d4113f847..4422b755faa77 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.esfilters.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.esfilters.md @@ -35,7 +35,7 @@ esFilters: { type?: string | undefined; key?: string | undefined; params?: any; - value?: string | ((formatter?: import("../common").FilterValueFormatter | undefined) => string) | undefined; + value?: string | undefined; }; $state?: import("../common").FilterState | undefined; query?: any; diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter._state.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter._state.md deleted file mode 100644 index bfb5dff71e70d..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter._state.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [Filter](./kibana-plugin-plugins-data-public.filter.md) > [$state](./kibana-plugin-plugins-data-public.filter._state.md) - -## Filter.$state property - -Signature: - -```typescript -$state?: FilterState; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.md index f993721ee96ad..9212b757e07df 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.md @@ -2,19 +2,14 @@ [Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [Filter](./kibana-plugin-plugins-data-public.filter.md) -## Filter interface +## Filter type Signature: ```typescript -export interface Filter +export declare type Filter = { + $state?: FilterState; + meta: FilterMeta; + query?: any; +}; ``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [$state](./kibana-plugin-plugins-data-public.filter._state.md) | FilterState | | -| [meta](./kibana-plugin-plugins-data-public.filter.meta.md) | FilterMeta | | -| [query](./kibana-plugin-plugins-data-public.filter.query.md) | any | | - diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.meta.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.meta.md deleted file mode 100644 index 3385a3773a2aa..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.meta.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [Filter](./kibana-plugin-plugins-data-public.filter.md) > [meta](./kibana-plugin-plugins-data-public.filter.meta.md) - -## Filter.meta property - -Signature: - -```typescript -meta: FilterMeta; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.query.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.query.md deleted file mode 100644 index 083b544493e80..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.filter.query.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [Filter](./kibana-plugin-plugins-data-public.filter.md) > [query](./kibana-plugin-plugins-data-public.filter.query.md) - -## Filter.query property - -Signature: - -```typescript -query?: any; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md index 0c493ca492953..fe48761a18e8b 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md @@ -52,7 +52,6 @@ | [EsQueryConfig](./kibana-plugin-plugins-data-public.esqueryconfig.md) | | | [FieldFormatConfig](./kibana-plugin-plugins-data-public.fieldformatconfig.md) | | | [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) | | -| [Filter](./kibana-plugin-plugins-data-public.filter.md) | | | [IDataPluginServices](./kibana-plugin-plugins-data-public.idatapluginservices.md) | | | [IEsSearchRequest](./kibana-plugin-plugins-data-public.iessearchrequest.md) | | | [IEsSearchResponse](./kibana-plugin-plugins-data-public.iessearchresponse.md) | | @@ -67,7 +66,6 @@ | [ISearchOptions](./kibana-plugin-plugins-data-public.isearchoptions.md) | | | [KueryNode](./kibana-plugin-plugins-data-public.kuerynode.md) | | | [OptionedValueProp](./kibana-plugin-plugins-data-public.optionedvalueprop.md) | | -| [Query](./kibana-plugin-plugins-data-public.query.md) | | | [QueryState](./kibana-plugin-plugins-data-public.querystate.md) | All query state service state | | [QueryStateChange](./kibana-plugin-plugins-data-public.querystatechange.md) | | | [QuerySuggestionBasic](./kibana-plugin-plugins-data-public.querysuggestionbasic.md) | \* | @@ -82,7 +80,6 @@ | [SearchSourceFields](./kibana-plugin-plugins-data-public.searchsourcefields.md) | | | [TabbedAggColumn](./kibana-plugin-plugins-data-public.tabbedaggcolumn.md) | \* | | [TabbedTable](./kibana-plugin-plugins-data-public.tabbedtable.md) | \* | -| [TimeRange](./kibana-plugin-plugins-data-public.timerange.md) | | ## Variables @@ -134,6 +131,7 @@ | [FieldFormatId](./kibana-plugin-plugins-data-public.fieldformatid.md) | id type is needed for creating custom converters. | | [FieldFormatsContentType](./kibana-plugin-plugins-data-public.fieldformatscontenttype.md) | \* | | [FieldFormatsGetConfigFn](./kibana-plugin-plugins-data-public.fieldformatsgetconfigfn.md) | | +| [Filter](./kibana-plugin-plugins-data-public.filter.md) | | | [IAggConfig](./kibana-plugin-plugins-data-public.iaggconfig.md) | AggConfig This class represents an aggregation, which is displayed in the left-hand nav of the Visualize app. | | [IAggType](./kibana-plugin-plugins-data-public.iaggtype.md) | | | [IFieldFormat](./kibana-plugin-plugins-data-public.ifieldformat.md) | | @@ -151,6 +149,7 @@ | [ParsedInterval](./kibana-plugin-plugins-data-public.parsedinterval.md) | | | [PhraseFilter](./kibana-plugin-plugins-data-public.phrasefilter.md) | | | [PhrasesFilter](./kibana-plugin-plugins-data-public.phrasesfilter.md) | | +| [Query](./kibana-plugin-plugins-data-public.query.md) | | | [QuerySuggestion](./kibana-plugin-plugins-data-public.querysuggestion.md) | \* | | [QuerySuggestionGetFn](./kibana-plugin-plugins-data-public.querysuggestiongetfn.md) | | | [RangeFilter](./kibana-plugin-plugins-data-public.rangefilter.md) | | @@ -161,4 +160,5 @@ | [TabbedAggRow](./kibana-plugin-plugins-data-public.tabbedaggrow.md) | \* | | [TimefilterContract](./kibana-plugin-plugins-data-public.timefiltercontract.md) | | | [TimeHistoryContract](./kibana-plugin-plugins-data-public.timehistorycontract.md) | | +| [TimeRange](./kibana-plugin-plugins-data-public.timerange.md) | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.language.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.language.md deleted file mode 100644 index 127ee9210799e..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.language.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [Query](./kibana-plugin-plugins-data-public.query.md) > [language](./kibana-plugin-plugins-data-public.query.language.md) - -## Query.language property - -Signature: - -```typescript -language: string; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.md index a1dffe5ff5fa4..e15b04236a0b5 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.md @@ -2,18 +2,15 @@ [Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [Query](./kibana-plugin-plugins-data-public.query.md) -## Query interface +## Query type Signature: ```typescript -export interface Query +export declare type Query = { + query: string | { + [key: string]: any; + }; + language: string; +}; ``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [language](./kibana-plugin-plugins-data-public.query.language.md) | string | | -| [query](./kibana-plugin-plugins-data-public.query.query.md) | string | {
[key: string]: any;
} | | - diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.query.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.query.md deleted file mode 100644 index 9fcd0310af0fe..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.query.query.md +++ /dev/null @@ -1,13 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [Query](./kibana-plugin-plugins-data-public.query.md) > [query](./kibana-plugin-plugins-data-public.query.query.md) - -## Query.query property - -Signature: - -```typescript -query: string | { - [key: string]: any; - }; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.from.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.from.md deleted file mode 100644 index b428bd9cd90ca..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.from.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [TimeRange](./kibana-plugin-plugins-data-public.timerange.md) > [from](./kibana-plugin-plugins-data-public.timerange.from.md) - -## TimeRange.from property - -Signature: - -```typescript -from: string; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.md index 69078ca40d20d..482501e494c7a 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.md @@ -2,19 +2,14 @@ [Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [TimeRange](./kibana-plugin-plugins-data-public.timerange.md) -## TimeRange interface +## TimeRange type Signature: ```typescript -export interface TimeRange +export declare type TimeRange = { + from: string; + to: string; + mode?: 'absolute' | 'relative'; +}; ``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [from](./kibana-plugin-plugins-data-public.timerange.from.md) | string | | -| [mode](./kibana-plugin-plugins-data-public.timerange.mode.md) | 'absolute' | 'relative' | | -| [to](./kibana-plugin-plugins-data-public.timerange.to.md) | string | | - diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.mode.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.mode.md deleted file mode 100644 index fb9ebd3c9165f..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.mode.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [TimeRange](./kibana-plugin-plugins-data-public.timerange.md) > [mode](./kibana-plugin-plugins-data-public.timerange.mode.md) - -## TimeRange.mode property - -Signature: - -```typescript -mode?: 'absolute' | 'relative'; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.to.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.to.md deleted file mode 100644 index 342acd5e049f1..0000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.timerange.to.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [TimeRange](./kibana-plugin-plugins-data-public.timerange.md) > [to](./kibana-plugin-plugins-data-public.timerange.to.md) - -## TimeRange.to property - -Signature: - -```typescript -to: string; -``` diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 27d4ea49f9eb1..4930eca5a1d56 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -393,7 +393,7 @@ export const esFilters: { type?: string | undefined; key?: string | undefined; params?: any; - value?: string | ((formatter?: import("../common").FilterValueFormatter | undefined) => string) | undefined; + value?: string | undefined; }; $state?: import("../common").FilterState | undefined; query?: any; @@ -614,18 +614,11 @@ export interface FieldMappingSpec { // Warning: (ae-missing-release-tag) "Filter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export interface Filter { - // Warning: (ae-forgotten-export) The symbol "FilterState" needs to be exported by the entry point index.d.ts - // - // (undocumented) +export type Filter = { $state?: FilterState; - // Warning: (ae-forgotten-export) The symbol "FilterMeta" needs to be exported by the entry point index.d.ts - // - // (undocumented) meta: FilterMeta; - // (undocumented) query?: any; -} +}; // Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "FilterBar" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -1441,14 +1434,12 @@ export function plugin(initializerContext: PluginInitializerContext; // Warning: (ae-missing-release-tag) "TimeRange" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export interface TimeRange { - // (undocumented) +export type TimeRange = { from: string; - // (undocumented) - mode?: 'absolute' | 'relative'; - // (undocumented) to: string; -} + mode?: 'absolute' | 'relative'; +}; // Warning: (ae-missing-release-tag) "UI_SETTINGS" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -1942,6 +1930,8 @@ export const UI_SETTINGS: { // src/plugins/data/common/es_query/filters/exists_filter.ts:30:3 - (ae-forgotten-export) The symbol "ExistsFilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/common/es_query/filters/exists_filter.ts:31:3 - (ae-forgotten-export) The symbol "FilterExistsProperty" needs to be exported by the entry point index.d.ts // src/plugins/data/common/es_query/filters/match_all_filter.ts:28:3 - (ae-forgotten-export) The symbol "MatchAllFilterMeta" needs to be exported by the entry point index.d.ts +// src/plugins/data/common/es_query/filters/meta_filter.ts:53:3 - (ae-forgotten-export) The symbol "FilterState" needs to be exported by the entry point index.d.ts +// src/plugins/data/common/es_query/filters/meta_filter.ts:54:3 - (ae-forgotten-export) The symbol "FilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/common/es_query/filters/phrase_filter.ts:33:3 - (ae-forgotten-export) The symbol "PhraseFilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/common/es_query/filters/phrases_filter.ts:31:3 - (ae-forgotten-export) The symbol "PhrasesFilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:66:23 - (ae-forgotten-export) The symbol "FilterLabel" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/embeddable/public/plugin.test.ts b/src/plugins/embeddable/public/plugin.test.ts index 7da6f4d8997bc..5fd3bcdd61318 100644 --- a/src/plugins/embeddable/public/plugin.test.ts +++ b/src/plugins/embeddable/public/plugin.test.ts @@ -134,8 +134,8 @@ describe('embeddable factory', () => { }); test('embeddableFactory telemetry function gets called when calling embeddable telemetry', () => { - start.telemetry(embeddableState); - expect(embeddableFactory.telemetry).toBeCalledWith(embeddableState); + start.telemetry(embeddableState, {}); + expect(embeddableFactory.telemetry).toBeCalledWith(embeddableState, {}); }); }); @@ -176,7 +176,7 @@ describe('embeddable enhancements', () => { }); test('enhancement telemetry function gets called when calling embeddable telemetry', () => { - start.telemetry(embeddableState); - expect(embeddableEnhancement.telemetry).toBeCalledWith(embeddableState.enhancements.test); + start.telemetry(embeddableState, {}); + expect(embeddableEnhancement.telemetry).toBeCalledWith(embeddableState.enhancements.test, {}); }); }); From 578c987ef18d5f24978cd0646d3233641c25d33e Mon Sep 17 00:00:00 2001 From: ppisljar Date: Thu, 10 Sep 2020 05:29:53 -0700 Subject: [PATCH 16/23] fixing test --- .../public/services/ui_actions_service_enhancements.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.test.ts b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.test.ts index fd47411542a5d..6c71868222b24 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.test.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.test.ts @@ -153,7 +153,7 @@ describe('UiActionsService', () => { telemetry, }); service.telemetry(actionState); - expect(telemetry).toBeCalledWith(actionState.events[0]); + expect(telemetry).toBeCalledWith(actionState.events[0], {}); }); describe('registerFeature for licensing', () => { From ab3ac0c8fb5a88b0da88bcee8e63cf0804263a3b Mon Sep 17 00:00:00 2001 From: ppisljar Date: Thu, 10 Sep 2020 05:56:40 -0700 Subject: [PATCH 17/23] updating docs --- ...lugin-plugins-data-server.filter._state.md | 11 ------- ...ibana-plugin-plugins-data-server.filter.md | 17 ++++------- ...-plugin-plugins-data-server.filter.meta.md | 11 ------- ...plugin-plugins-data-server.filter.query.md | 11 ------- .../kibana-plugin-plugins-data-server.md | 6 ++-- ...ugin-plugins-data-server.query.language.md | 11 ------- ...kibana-plugin-plugins-data-server.query.md | 17 +++++------ ...-plugin-plugins-data-server.query.query.md | 13 -------- ...ugin-plugins-data-server.timerange.from.md | 11 ------- ...na-plugin-plugins-data-server.timerange.md | 17 ++++------- ...ugin-plugins-data-server.timerange.mode.md | 11 ------- ...plugin-plugins-data-server.timerange.to.md | 11 ------- src/plugins/data/server/server.api.md | 30 +++++++------------ 13 files changed, 32 insertions(+), 145 deletions(-) delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter._state.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.meta.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.query.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.language.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.query.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.from.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.mode.md delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.to.md diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter._state.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter._state.md deleted file mode 100644 index 079f352609a70..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter._state.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [Filter](./kibana-plugin-plugins-data-server.filter.md) > [$state](./kibana-plugin-plugins-data-server.filter._state.md) - -## Filter.$state property - -Signature: - -```typescript -$state?: FilterState; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.md index 4e4c49b222f01..519bbaf8f9416 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.md @@ -2,19 +2,14 @@ [Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [Filter](./kibana-plugin-plugins-data-server.filter.md) -## Filter interface +## Filter type Signature: ```typescript -export interface Filter +export declare type Filter = { + $state?: FilterState; + meta: FilterMeta; + query?: any; +}; ``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [$state](./kibana-plugin-plugins-data-server.filter._state.md) | FilterState | | -| [meta](./kibana-plugin-plugins-data-server.filter.meta.md) | FilterMeta | | -| [query](./kibana-plugin-plugins-data-server.filter.query.md) | any | | - diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.meta.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.meta.md deleted file mode 100644 index 6d11804704d82..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.meta.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [Filter](./kibana-plugin-plugins-data-server.filter.md) > [meta](./kibana-plugin-plugins-data-server.filter.meta.md) - -## Filter.meta property - -Signature: - -```typescript -meta: FilterMeta; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.query.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.query.md deleted file mode 100644 index 942c7930f449d..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.filter.query.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [Filter](./kibana-plugin-plugins-data-server.filter.md) > [query](./kibana-plugin-plugins-data-server.filter.query.md) - -## Filter.query property - -Signature: - -```typescript -query?: any; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md index f5b587d86b349..3c477e17503f4 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md @@ -42,7 +42,6 @@ | [AggParamOption](./kibana-plugin-plugins-data-server.aggparamoption.md) | | | [EsQueryConfig](./kibana-plugin-plugins-data-server.esqueryconfig.md) | | | [FieldFormatConfig](./kibana-plugin-plugins-data-server.fieldformatconfig.md) | | -| [Filter](./kibana-plugin-plugins-data-server.filter.md) | | | [IEsSearchRequest](./kibana-plugin-plugins-data-server.iessearchrequest.md) | | | [IEsSearchResponse](./kibana-plugin-plugins-data-server.iessearchresponse.md) | | | [IFieldSubType](./kibana-plugin-plugins-data-server.ifieldsubtype.md) | | @@ -58,12 +57,10 @@ | [OptionedValueProp](./kibana-plugin-plugins-data-server.optionedvalueprop.md) | | | [PluginSetup](./kibana-plugin-plugins-data-server.pluginsetup.md) | | | [PluginStart](./kibana-plugin-plugins-data-server.pluginstart.md) | | -| [Query](./kibana-plugin-plugins-data-server.query.md) | | | [RefreshInterval](./kibana-plugin-plugins-data-server.refreshinterval.md) | | | [SearchUsage](./kibana-plugin-plugins-data-server.searchusage.md) | | | [TabbedAggColumn](./kibana-plugin-plugins-data-server.tabbedaggcolumn.md) | \* | | [TabbedTable](./kibana-plugin-plugins-data-server.tabbedtable.md) | \* | -| [TimeRange](./kibana-plugin-plugins-data-server.timerange.md) | | ## Variables @@ -91,11 +88,14 @@ | [AggParam](./kibana-plugin-plugins-data-server.aggparam.md) | | | [EsaggsExpressionFunctionDefinition](./kibana-plugin-plugins-data-server.esaggsexpressionfunctiondefinition.md) | | | [FieldFormatsGetConfigFn](./kibana-plugin-plugins-data-server.fieldformatsgetconfigfn.md) | | +| [Filter](./kibana-plugin-plugins-data-server.filter.md) | | | [IAggConfig](./kibana-plugin-plugins-data-server.iaggconfig.md) | AggConfig This class represents an aggregation, which is displayed in the left-hand nav of the Visualize app. | | [IAggType](./kibana-plugin-plugins-data-server.iaggtype.md) | | | [IFieldFormatsRegistry](./kibana-plugin-plugins-data-server.ifieldformatsregistry.md) | | | [IFieldParamType](./kibana-plugin-plugins-data-server.ifieldparamtype.md) | | | [IMetricAggType](./kibana-plugin-plugins-data-server.imetricaggtype.md) | | | [ParsedInterval](./kibana-plugin-plugins-data-server.parsedinterval.md) | | +| [Query](./kibana-plugin-plugins-data-server.query.md) | | | [TabbedAggRow](./kibana-plugin-plugins-data-server.tabbedaggrow.md) | \* | +| [TimeRange](./kibana-plugin-plugins-data-server.timerange.md) | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.language.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.language.md deleted file mode 100644 index 384fc77d801c0..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.language.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [Query](./kibana-plugin-plugins-data-server.query.md) > [language](./kibana-plugin-plugins-data-server.query.language.md) - -## Query.language property - -Signature: - -```typescript -language: string; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.md index 5d61c75bc5e99..6a7bdfe51f1c0 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.md @@ -2,18 +2,15 @@ [Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [Query](./kibana-plugin-plugins-data-server.query.md) -## Query interface +## Query type Signature: ```typescript -export interface Query +export declare type Query = { + query: string | { + [key: string]: any; + }; + language: string; +}; ``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [language](./kibana-plugin-plugins-data-server.query.language.md) | string | | -| [query](./kibana-plugin-plugins-data-server.query.query.md) | string | {
[key: string]: any;
} | | - diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.query.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.query.md deleted file mode 100644 index 5c2aa700bc603..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.query.query.md +++ /dev/null @@ -1,13 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [Query](./kibana-plugin-plugins-data-server.query.md) > [query](./kibana-plugin-plugins-data-server.query.query.md) - -## Query.query property - -Signature: - -```typescript -query: string | { - [key: string]: any; - }; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.from.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.from.md deleted file mode 100644 index b6f40cc2e4203..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.from.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TimeRange](./kibana-plugin-plugins-data-server.timerange.md) > [from](./kibana-plugin-plugins-data-server.timerange.from.md) - -## TimeRange.from property - -Signature: - -```typescript -from: string; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.md index 8280d924eb609..1ac59343220fd 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.md @@ -2,19 +2,14 @@ [Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TimeRange](./kibana-plugin-plugins-data-server.timerange.md) -## TimeRange interface +## TimeRange type Signature: ```typescript -export interface TimeRange +export declare type TimeRange = { + from: string; + to: string; + mode?: 'absolute' | 'relative'; +}; ``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [from](./kibana-plugin-plugins-data-server.timerange.from.md) | string | | -| [mode](./kibana-plugin-plugins-data-server.timerange.mode.md) | 'absolute' | 'relative' | | -| [to](./kibana-plugin-plugins-data-server.timerange.to.md) | string | | - diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.mode.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.mode.md deleted file mode 100644 index 1408fb43cbf39..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.mode.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TimeRange](./kibana-plugin-plugins-data-server.timerange.md) > [mode](./kibana-plugin-plugins-data-server.timerange.mode.md) - -## TimeRange.mode property - -Signature: - -```typescript -mode?: 'absolute' | 'relative'; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.to.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.to.md deleted file mode 100644 index 98aca5474d350..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.timerange.to.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TimeRange](./kibana-plugin-plugins-data-server.timerange.md) > [to](./kibana-plugin-plugins-data-server.timerange.to.md) - -## TimeRange.to property - -Signature: - -```typescript -to: string; -``` diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index cd0369a5c4551..aed6bffafd5e7 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -433,18 +433,11 @@ export type FieldFormatsGetConfigFn = GetConfigFn; // Warning: (ae-missing-release-tag) "Filter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export interface Filter { - // Warning: (ae-forgotten-export) The symbol "FilterState" needs to be exported by the entry point index.d.ts - // - // (undocumented) +export type Filter = { $state?: FilterState; - // Warning: (ae-forgotten-export) The symbol "FilterMeta" needs to be exported by the entry point index.d.ts - // - // (undocumented) meta: FilterMeta; - // (undocumented) query?: any; -} +}; // Warning: (ae-forgotten-export) The symbol "IUiSettingsClient" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "getDefaultSearchParams" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -934,14 +927,12 @@ export interface PluginStart { // Warning: (ae-missing-release-tag) "Query" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export interface Query { - // (undocumented) - language: string; - // (undocumented) +export type Query = { query: string | { [key: string]: any; }; -} + language: string; +}; // Warning: (ae-missing-release-tag) "RefreshInterval" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -1056,14 +1047,11 @@ export interface TabbedTable { // Warning: (ae-missing-release-tag) "TimeRange" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export interface TimeRange { - // (undocumented) +export type TimeRange = { from: string; - // (undocumented) - mode?: 'absolute' | 'relative'; - // (undocumented) to: string; -} + mode?: 'absolute' | 'relative'; +}; // Warning: (ae-missing-release-tag) "toSnakeCase" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -1113,6 +1101,8 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // Warnings were encountered during analysis: // +// src/plugins/data/common/es_query/filters/meta_filter.ts:53:3 - (ae-forgotten-export) The symbol "FilterState" needs to be exported by the entry point index.d.ts +// src/plugins/data/common/es_query/filters/meta_filter.ts:54:3 - (ae-forgotten-export) The symbol "FilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/common/index_patterns/fields/types.ts:41:25 - (ae-forgotten-export) The symbol "IndexPattern" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildCustomFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildFilter" needs to be exported by the entry point index.d.ts From 00838799e723cefbdb346b8189e47b6589c24bbd Mon Sep 17 00:00:00 2001 From: ppisljar Date: Mon, 14 Sep 2020 02:54:08 -0700 Subject: [PATCH 18/23] updating based on review --- .../common/lib/migrate_base_input.ts | 7 ++-- src/plugins/embeddable/public/plugin.tsx | 4 +- src/plugins/embeddable/server/plugin.ts | 4 +- .../server/dynamic_action_enhancement.ts | 38 +++++++++++++++---- .../ui_actions_enhanced/server/plugin.ts | 16 +------- 5 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/plugins/embeddable/common/lib/migrate_base_input.ts b/src/plugins/embeddable/common/lib/migrate_base_input.ts index 0ee655d750584..16e1bb456356a 100644 --- a/src/plugins/embeddable/common/lib/migrate_base_input.ts +++ b/src/plugins/embeddable/common/lib/migrate_base_input.ts @@ -20,9 +20,10 @@ import { SavedObjectReference } from '../../../../core/types'; import { EmbeddableInput } from '../types'; -export const telemetryBaseEmbeddableInput = (state: EmbeddableInput) => { - return {} as Record; -}; +export const telemetryBaseEmbeddableInput = ( + state: EmbeddableInput, + telemetryData: Record +) => {}; export const extractBaseEmbeddableInput = (state: EmbeddableInput) => { return { state, references: [] as SavedObjectReference[] }; diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index d5134ecac1102..b289b18810407 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -197,11 +197,11 @@ export class EmbeddablePublicPlugin implements Plugin { + private telemetry = (state: EmbeddableInput, telemetryData: Record = {}) => { const enhancements: Record = state.enhancements || {}; const factory = this.getEmbeddableFactory(state.id); - const telemetryData = telemetryBaseEmbeddableInput(state); + telemetryBaseEmbeddableInput(state, telemetryData); if (factory) { factory.telemetry(state, telemetryData); } diff --git a/src/plugins/embeddable/server/plugin.ts b/src/plugins/embeddable/server/plugin.ts index 1a1f90a077eb0..2528952ba8535 100644 --- a/src/plugins/embeddable/server/plugin.ts +++ b/src/plugins/embeddable/server/plugin.ts @@ -60,11 +60,11 @@ export class EmbeddableServerPlugin implements Plugin { public stop() {} - private telemetry = (state: EmbeddableInput) => { + private telemetry = (state: EmbeddableInput, telemetryData: Record = {}) => { const enhancements: Record = state.enhancements || {}; const factory = this.getEmbeddableFactory(state.id); - const telemetryData = telemetryBaseEmbeddableInput(state); + telemetryBaseEmbeddableInput(state, telemetryData); if (factory) { factory.telemetry(state, telemetryData); } diff --git a/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts b/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts index 7d4b27a3e5f71..093e16593ef08 100644 --- a/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts +++ b/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts @@ -6,23 +6,47 @@ import { EnhancementRegistryDefinition } from '../../../../src/plugins/embeddable/server'; import { SavedObjectReference } from '../../../../src/core/types'; -import { SerializableState } from '../../../../src/plugins/kibana_utils/common'; -import { DynamicActionsState } from './types'; +import { DynamicActionsState, SerializedEvent } from './types'; import { AdvancedUiActionsPublicPlugin } from './plugin'; +import { SerializableState } from '../../../../src/plugins/kibana_utils/common/persistable_state'; export const dynamicActionEnhancement = ( uiActionsEnhanced: AdvancedUiActionsPublicPlugin -): EnhancementRegistryDefinition => { +): EnhancementRegistryDefinition => { return { id: 'dynamicActions', - telemetry: (state: SerializableState, telemetryData: Record) => { - return uiActionsEnhanced.telemetry(state as DynamicActionsState, telemetryData); + telemetry: (state: SerializableState, telemetry: Record) => { + (state as DynamicActionsState).events.forEach((event: SerializedEvent) => { + if (uiActionsEnhanced.getActionFactory(event.action.factoryId)) { + uiActionsEnhanced.getActionFactory(event.action.factoryId)!.telemetry(event, telemetry); + } + }); + return telemetry; }, extract: (state: SerializableState) => { - return uiActionsEnhanced.extract(state as DynamicActionsState); + const references: SavedObjectReference[] = []; + const newState: DynamicActionsState = { + events: (state as DynamicActionsState).events.map((event: SerializedEvent) => { + const result = uiActionsEnhanced.getActionFactory(event.action.factoryId) + ? uiActionsEnhanced.getActionFactory(event.action.factoryId)!.extract(event) + : { + state: event, + references: [], + }; + result.references.forEach((r) => references.push(r)); + return result.state; + }), + }; + return { state: newState, references }; }, inject: (state: SerializableState, references: SavedObjectReference[]) => { - return uiActionsEnhanced.inject(state as DynamicActionsState, references); + return { + events: (state as DynamicActionsState).events.map((event: SerializedEvent) => { + return uiActionsEnhanced.getActionFactory(event.action.factoryId) + ? uiActionsEnhanced.getActionFactory(event.action.factoryId)!.inject(event, references) + : event; + }), + } as DynamicActionsState; }, } as EnhancementRegistryDefinition; }; diff --git a/x-pack/plugins/ui_actions_enhanced/server/plugin.ts b/x-pack/plugins/ui_actions_enhanced/server/plugin.ts index a3c4a45303cb2..0a61c917a2c5c 100644 --- a/x-pack/plugins/ui_actions_enhanced/server/plugin.ts +++ b/x-pack/plugins/ui_actions_enhanced/server/plugin.ts @@ -14,13 +14,12 @@ import { ActionFactoryDefinition, DynamicActionsState, } from './types'; -import { PersistableState } from '../../../../src/plugins/kibana_utils/common'; export interface SetupContract { registerActionFactory: any; } -export type StartContract = PersistableState; +export type StartContract = void; interface SetupDependencies { embeddable: EmbeddableSetup; // Embeddable are needed because they register basic triggers/actions. @@ -33,11 +32,6 @@ export class AdvancedUiActionsPublicPlugin constructor() {} public setup(core: CoreSetup, { embeddable }: SetupDependencies) { - // this.enhancements = new UiActionsServiceEnhancements({ - // getLicense: () => this.getLicenseInfo(), - // featureUsageSetup: licensing.featureUsage, - // getFeatureUsageStart: () => startServices().plugins.licensing.featureUsage, - // }); embeddable.registerEnhancement(dynamicActionEnhancement(this)); return { @@ -45,13 +39,7 @@ export class AdvancedUiActionsPublicPlugin }; } - public start() { - return { - telemetry: this.telemetry, - inject: this.inject, - extract: this.extract, - }; - } + public start() {} public stop() {} From c8b7958c45e944af3651655563f061e140c33538 Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Tue, 15 Sep 2020 20:35:11 +0200 Subject: [PATCH 19/23] minor clean up --- .../plugins/embeddable_enhanced/kibana.json | 2 +- .../action_wizard/action_wizard.tsx | 11 +++---- .../components/action_wizard/test_data.tsx | 11 ++++--- ...nnected_flyout_manage_drilldowns.story.tsx | 8 ++--- ...onnected_flyout_manage_drilldowns.test.tsx | 9 ++--- .../connected_flyout_manage_drilldowns.tsx | 4 +-- .../test_data.ts | 7 ++-- .../flyout_drilldown_wizard.story.tsx | 32 ++++-------------- .../flyout_drilldown_wizard.tsx | 19 ++++++----- .../form_drilldown_wizard.tsx | 11 ++++--- .../public/drilldowns/drilldown_definition.ts | 8 ++--- .../public/dynamic_actions/action_factory.ts | 14 ++++---- .../action_factory_definition.ts | 14 ++++---- .../dynamic_action_manager.test.ts | 33 +++++++++---------- .../public/dynamic_actions/types.ts | 4 ++- .../ui_actions_enhanced/public/index.ts | 1 + .../ui_actions_service_enhancements.ts | 10 +++--- .../server/dynamic_action_enhancement.ts | 6 ++-- 18 files changed, 91 insertions(+), 113 deletions(-) diff --git a/x-pack/plugins/embeddable_enhanced/kibana.json b/x-pack/plugins/embeddable_enhanced/kibana.json index 69d928bb5f45c..acada946fe0d1 100644 --- a/x-pack/plugins/embeddable_enhanced/kibana.json +++ b/x-pack/plugins/embeddable_enhanced/kibana.json @@ -3,6 +3,6 @@ "version": "kibana", "server": false, "ui": true, - "requiredPlugins": ["embeddable", "kibanaReact", "uiActions", "uiActionsEnhanced", "kibanaUtils"], + "requiredPlugins": ["embeddable", "kibanaReact", "uiActions", "uiActionsEnhanced"], "requiredBundles": ["kibanaUtils"] } diff --git a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx index a83ac9324d35f..2aa80b46129a2 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/action_wizard.tsx @@ -28,9 +28,8 @@ import { txtTriggerPickerHelpTooltip, } from './i18n'; import './action_wizard.scss'; -import { ActionFactory, BaseActionFactoryContext } from '../../dynamic_actions'; +import { ActionFactory, BaseActionConfig, BaseActionFactoryContext } from '../../dynamic_actions'; import { Trigger, TriggerId } from '../../../../../../src/plugins/ui_actions/public'; -import { SerializableState } from '../../../../../../src/plugins/kibana_utils/common'; export interface ActionWizardProps< ActionFactoryContext extends BaseActionFactoryContext = BaseActionFactoryContext @@ -55,12 +54,12 @@ export interface ActionWizardProps< /** * current config for currently selected action factory */ - config?: SerializableState; + config?: BaseActionConfig; /** * config changed */ - onConfigChange: (config: SerializableState) => void; + onConfigChange: (config: BaseActionConfig) => void; /** * Context will be passed into ActionFactory's methods @@ -217,9 +216,9 @@ interface SelectedActionFactoryProps< ActionFactoryContext extends BaseActionFactoryContext = BaseActionFactoryContext > { actionFactory: ActionFactory; - config: SerializableState; + config: BaseActionConfig; context: ActionFactoryContext; - onConfigChange: (config: SerializableState) => void; + onConfigChange: (config: BaseActionConfig) => void; showDeselect: boolean; onDeselect: () => void; allTriggers: TriggerId[]; diff --git a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx index a860a723708b2..4b8f52b48e2c9 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx @@ -8,7 +8,7 @@ import React, { useState } from 'react'; import { EuiFieldText, EuiFormRow, EuiSelect, EuiSwitch } from '@elastic/eui'; import { reactToUiComponent } from '../../../../../../src/plugins/kibana_react/public'; import { ActionWizard } from './action_wizard'; -import { ActionFactory, ActionFactoryDefinition } from '../../dynamic_actions'; +import { ActionFactory, ActionFactoryDefinition, BaseActionConfig } from '../../dynamic_actions'; import { CollectConfigProps } from '../../../../../../src/plugins/kibana_utils/public'; import { licensingMock } from '../../../../licensing/public/mocks'; import { @@ -18,9 +18,6 @@ import { TriggerId, VALUE_CLICK_TRIGGER, } from '../../../../../../src/plugins/ui_actions/public'; -import { SerializableState } from '../../../../../../src/plugins/kibana_utils/common'; - -type ActionBaseConfig = SerializableState; export const dashboards = [ { id: 'dashboard1', title: 'Dashboard 1' }, @@ -186,6 +183,10 @@ export const urlFactory = new ActionFactory(urlDrilldownActionFactory, { getFeatureUsageStart: () => licensingMock.createStart().featureUsage, }); +export const mockActionFactories: ActionFactory[] = ([dashboardFactory, urlFactory] as Array< + ActionFactory +>) as ActionFactory[]; + export const mockSupportedTriggers: TriggerId[] = [ VALUE_CLICK_TRIGGER, SELECT_RANGE_TRIGGER, @@ -214,7 +215,7 @@ export const mockGetTriggerInfo = (triggerId: TriggerId): Trigger => { export function Demo({ actionFactories }: { actionFactories: Array> }) { const [state, setState] = useState<{ currentActionFactory?: ActionFactory; - config?: ActionBaseConfig; + config?: BaseActionConfig; selectedTriggers?: TriggerId[]; }>({}); diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.story.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.story.tsx index 70aeebb592206..daa56354289cf 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.story.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.story.tsx @@ -8,17 +8,13 @@ import * as React from 'react'; import { EuiFlyout } from '@elastic/eui'; import { storiesOf } from '@storybook/react'; import { createFlyoutManageDrilldowns } from './connected_flyout_manage_drilldowns'; -import { dashboardFactory, urlFactory } from '../../../components/action_wizard/test_data'; +import { mockActionFactories } from '../../../components/action_wizard/test_data'; import { Storage } from '../../../../../../../src/plugins/kibana_utils/public'; import { StubBrowserStorage } from '../../../../../../../src/test_utils/public/stub_browser_storage'; import { mockDynamicActionManager } from './test_data'; -import { ActionFactory } from '../../../dynamic_actions'; const FlyoutManageDrilldowns = createFlyoutManageDrilldowns({ - actionFactories: [ - (dashboardFactory as unknown) as ActionFactory, - (urlFactory as unknown) as ActionFactory, - ], + actionFactories: mockActionFactories, storage: new Storage(new StubBrowserStorage()), toastService: { addError: (...args: any[]) => { diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.test.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.test.tsx index f3a4b9832b7a9..c4b07fa05c3c1 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.test.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.test.tsx @@ -8,10 +8,9 @@ import React from 'react'; import { cleanup, fireEvent, render, wait } from '@testing-library/react/pure'; import { createFlyoutManageDrilldowns } from './connected_flyout_manage_drilldowns'; import { - dashboardFactory, mockGetTriggerInfo, mockSupportedTriggers, - urlFactory, + mockActionFactories, } from '../../../components/action_wizard/test_data'; import { StubBrowserStorage } from '../../../../../../../src/test_utils/public/stub_browser_storage'; import { Storage } from '../../../../../../../src/plugins/kibana_utils/public'; @@ -21,15 +20,11 @@ import { WELCOME_MESSAGE_TEST_SUBJ } from '../drilldown_hello_bar'; import { coreMock } from '../../../../../../../src/core/public/mocks'; import { NotificationsStart } from 'kibana/public'; import { toastDrilldownsCRUDError } from './i18n'; -import { ActionFactory } from '../../../dynamic_actions'; const storage = new Storage(new StubBrowserStorage()); const toasts = coreMock.createStart().notifications.toasts; const FlyoutManageDrilldowns = createFlyoutManageDrilldowns({ - actionFactories: [ - (dashboardFactory as unknown) as ActionFactory, - (urlFactory as unknown) as ActionFactory, - ], + actionFactories: mockActionFactories, storage: new Storage(new StubBrowserStorage()), toastService: toasts, getTrigger: mockGetTriggerInfo, diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx index a3345c5c23669..aa73bf6409d85 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/connected_flyout_manage_drilldowns.tsx @@ -25,13 +25,13 @@ import { } from './i18n'; import { ActionFactory, + BaseActionConfig, BaseActionFactoryContext, DynamicActionManager, SerializedAction, SerializedEvent, } from '../../../dynamic_actions'; import { ActionFactoryPlaceContext } from '../types'; -import { SerializableState } from '../../../../../../../src/plugins/kibana_utils/common'; interface ConnectedFlyoutManageDrilldownsProps< ActionFactoryContext extends BaseActionFactoryContext = BaseActionFactoryContext @@ -126,7 +126,7 @@ export function createFlyoutManageDrilldowns({ return { actionFactory: allActionFactoriesById[drilldownToEdit.action.factoryId], - actionConfig: drilldownToEdit.action.config as SerializableState, + actionConfig: drilldownToEdit.action.config as BaseActionConfig, name: drilldownToEdit.action.name, selectedTriggers: (drilldownToEdit.triggers ?? []) as TriggerId[], }; diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/test_data.ts b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/test_data.ts index e623edb2d1a5c..78eec05eb2d0b 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/test_data.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/connected_flyout_manage_drilldowns/test_data.ts @@ -11,10 +11,7 @@ import { UiActionsEnhancedSerializedAction, } from '../../../index'; import { TriggerContextMapping } from '../../../../../../../src/plugins/ui_actions/public'; -import { - createStateContainer, - SerializableState, -} from '../../../../../../../src/plugins/kibana_utils/common'; +import { createStateContainer } from '../../../../../../../src/plugins/kibana_utils/common'; class MockDynamicActionManager implements PublicMethodsOf { public readonly state = createStateContainer({ @@ -63,7 +60,7 @@ class MockDynamicActionManager implements PublicMethodsOf async updateEvent( eventId: string, - action: UiActionsEnhancedSerializedAction, + action: UiActionsEnhancedSerializedAction, triggers: Array ) { const state = this.state.get(); diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.story.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.story.tsx index 28d5c51a42d02..2f5f7760d40bd 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.story.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/flyout_drilldown_wizard/flyout_drilldown_wizard.story.tsx @@ -8,8 +8,7 @@ import * as React from 'react'; import { EuiFlyout } from '@elastic/eui'; import { storiesOf } from '@storybook/react'; import { FlyoutDrilldownWizard } from './index'; -import { dashboardFactory, urlFactory } from '../../../components/action_wizard/test_data'; -import { ActionFactory } from '../../../dynamic_actions'; +import { mockActionFactories } from '../../../components/action_wizard/test_data'; import { Trigger, TriggerId } from '../../../../../../../src/plugins/ui_actions/public'; const otherProps = { @@ -24,26 +23,12 @@ const otherProps = { storiesOf('components/FlyoutDrilldownWizard', module) .add('default', () => { - return ( - - ); + return ; }) .add('open in flyout - create', () => { return ( {}}> - + ); }) @@ -51,13 +36,10 @@ storiesOf('components/FlyoutDrilldownWizard', module) return ( {}}> {}}> { +export interface DrilldownWizardConfig { name: string; actionFactory?: ActionFactory; actionConfig?: ActionConfig; @@ -29,7 +32,7 @@ export interface DrilldownWizardConfig { drilldownActionFactories: ActionFactory[]; @@ -64,7 +67,7 @@ function useWizardConfigState( DrilldownWizardConfig, { setName: (name: string) => void; - setActionConfig: (actionConfig: SerializableState) => void; + setActionConfig: (actionConfig: BaseActionConfig) => void; setActionFactory: (actionFactory?: ActionFactory) => void; setSelectedTriggers: (triggers?: TriggerId[]) => void; } @@ -93,7 +96,7 @@ function useWizardConfigState( name, }); }, - setActionConfig: (actionConfig: SerializableState) => { + setActionConfig: (actionConfig: BaseActionConfig) => { setWizardConfig({ ...wizardConfig, actionConfig, @@ -102,7 +105,7 @@ function useWizardConfigState( setActionFactory: (actionFactory?: ActionFactory) => { if (actionFactory) { const actionConfig = (actionConfigCache[actionFactory.id] ?? - actionFactory.createConfig(actionFactoryContext)) as SerializableState; + actionFactory.createConfig(actionFactoryContext)) as BaseActionConfig; setWizardConfig({ ...wizardConfig, actionFactory, @@ -135,7 +138,7 @@ function useWizardConfigState( } export function FlyoutDrilldownWizard< - CurrentActionConfig extends SerializableState = SerializableState + CurrentActionConfig extends BaseActionConfig = BaseActionConfig >({ onClose, onBack, diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx index adf404e7a9110..45655c2634fe7 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/components/form_drilldown_wizard/form_drilldown_wizard.tsx @@ -8,10 +8,13 @@ import React from 'react'; import { EuiFieldText, EuiForm, EuiFormRow, EuiLink, EuiSpacer, EuiText } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { txtDrilldownAction, txtNameOfDrilldown, txtUntitledDrilldown } from './i18n'; -import { ActionFactory, BaseActionFactoryContext } from '../../../dynamic_actions'; +import { + ActionFactory, + BaseActionConfig, + BaseActionFactoryContext, +} from '../../../dynamic_actions'; import { ActionWizard } from '../../../components/action_wizard'; import { Trigger, TriggerId } from '../../../../../../../src/plugins/ui_actions/public'; -import { SerializableState } from '../../../../../../../src/plugins/kibana_utils/common'; const GET_MORE_ACTIONS_LINK = 'https://www.elastic.co/subscriptions'; @@ -27,8 +30,8 @@ export interface FormDrilldownWizardProps< onActionFactoryChange?: (actionFactory?: ActionFactory) => void; actionFactoryContext: ActionFactoryContext; - actionConfig?: SerializableState; - onActionConfigChange?: (config: SerializableState) => void; + actionConfig?: BaseActionConfig; + onActionConfigChange?: (config: BaseActionConfig) => void; actionFactories?: ActionFactory[]; diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts index 690fece84170f..85307cd463e63 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts @@ -6,16 +6,14 @@ import { ActionFactoryDefinition, + BaseActionConfig, BaseActionFactoryContext, SerializedEvent, } from '../dynamic_actions'; import { LicenseType } from '../../../licensing/public'; import { TriggerContextMapping, TriggerId } from '../../../../../src/plugins/ui_actions/public'; import { ActionExecutionContext } from '../../../../../src/plugins/ui_actions/public'; -import { - PersistableStateDefinition, - SerializableState, -} from '../../../../../src/plugins/kibana_utils/common'; +import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common'; /** * This is a convenience interface to register a drilldown. Drilldown has @@ -32,7 +30,7 @@ import { */ export interface DrilldownDefinition< - Config extends SerializableState = SerializableState, + Config extends BaseActionConfig = BaseActionConfig, SupportedTriggers extends TriggerId = TriggerId, FactoryContext extends BaseActionFactoryContext = { triggers: SupportedTriggers[]; diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts index d11e692a03303..5df07ca5a508b 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory.ts @@ -12,14 +12,16 @@ import { } from '../../../../../src/plugins/ui_actions/public'; import { ActionFactoryDefinition } from './action_factory_definition'; import { Configurable } from '../../../../../src/plugins/kibana_utils/public'; -import { BaseActionFactoryContext, SerializedAction, SerializedEvent } from './types'; +import { + BaseActionConfig, + BaseActionFactoryContext, + SerializedAction, + SerializedEvent, +} from './types'; import { ILicense, LicensingPluginStart } from '../../../licensing/public'; import { UiActionsActionDefinition as ActionDefinition } from '../../../../../src/plugins/ui_actions/public'; import { SavedObjectReference } from '../../../../../src/core/types'; -import { - PersistableState, - SerializableState, -} from '../../../../../src/plugins/kibana_utils/common'; +import { PersistableState } from '../../../../../src/plugins/kibana_utils/common'; export interface ActionFactoryDeps { readonly getLicense: () => ILicense; @@ -27,7 +29,7 @@ export interface ActionFactoryDeps { } export class ActionFactory< - Config extends SerializableState = SerializableState, + Config extends BaseActionConfig = BaseActionConfig, SupportedTriggers extends TriggerId = TriggerId, FactoryContext extends BaseActionFactoryContext = { triggers: SupportedTriggers[]; diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts index 1c501300f6716..b5041c99507e6 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/action_factory_definition.ts @@ -5,7 +5,12 @@ */ import { Configurable } from '../../../../../src/plugins/kibana_utils/public'; -import { BaseActionFactoryContext, SerializedAction, SerializedEvent } from './types'; +import { + BaseActionConfig, + BaseActionFactoryContext, + SerializedAction, + SerializedEvent, +} from './types'; import { LicenseType } from '../../../licensing/public'; import { TriggerContextMapping, @@ -13,16 +18,13 @@ import { UiActionsActionDefinition as ActionDefinition, UiActionsPresentable as Presentable, } from '../../../../../src/plugins/ui_actions/public'; -import { - PersistableStateDefinition, - SerializableState, -} from '../../../../../src/plugins/kibana_utils/common'; +import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common'; /** * This is a convenience interface for registering new action factories. */ export interface ActionFactoryDefinition< - Config extends SerializableState = SerializableState, + Config extends BaseActionConfig = BaseActionConfig, SupportedTriggers extends TriggerId = TriggerId, FactoryContext extends BaseActionFactoryContext = { triggers: SupportedTriggers[]; diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.test.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.test.ts index d14c1153cbcb7..83232bbce1ba7 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.test.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_manager.test.ts @@ -13,7 +13,6 @@ import { UiActionsServiceEnhancements } from '../services'; import { ActionFactoryDefinition } from './action_factory_definition'; import { SerializedAction, SerializedEvent } from './types'; import { licensingMock } from '../../../licensing/public/mocks'; -import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; const actionFactoryDefinition1: ActionFactoryDefinition = { id: 'ACTION_FACTORY_1', @@ -251,7 +250,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition1); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -278,7 +277,7 @@ describe('DynamicActionManager', () => { test('adds event to UI state', async () => { const { manager, uiActions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -297,7 +296,7 @@ describe('DynamicActionManager', () => { test('optimistically adds event to UI state', async () => { const { manager, uiActions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -320,7 +319,7 @@ describe('DynamicActionManager', () => { test('instantiates event in actions service', async () => { const { manager, uiActions, actions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -349,7 +348,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition1); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -362,7 +361,7 @@ describe('DynamicActionManager', () => { test('does not add even to UI state', async () => { const { manager, storage, uiActions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -381,7 +380,7 @@ describe('DynamicActionManager', () => { test('optimistically adds event to UI state and then removes it', async () => { const { manager, storage, uiActions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -407,7 +406,7 @@ describe('DynamicActionManager', () => { test('does not instantiate event in actions service', async () => { const { manager, storage, uiActions, actions } = setup([]); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -433,7 +432,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition1); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition1.id, name: 'foo', config: {}, @@ -458,7 +457,7 @@ describe('DynamicActionManager', () => { expect(registeredAction1.getDisplayName()).toBe('Action 3'); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -480,7 +479,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition2); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -506,7 +505,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition2); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -525,7 +524,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition2); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -553,7 +552,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition2); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -581,7 +580,7 @@ describe('DynamicActionManager', () => { expect(registeredAction1.getDisplayName()).toBe('Action 3'); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, @@ -605,7 +604,7 @@ describe('DynamicActionManager', () => { uiActions.registerActionFactory(actionFactoryDefinition2); await manager.start(); - const action: SerializedAction = { + const action: SerializedAction = { factoryId: actionFactoryDefinition2.id, name: 'foo', config: {}, diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts index 509ae7dc44b0c..e906540a268d5 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts @@ -7,8 +7,10 @@ import { TriggerId } from '../../../../../src/plugins/ui_actions/public'; import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; +export type BaseActionConfig = SerializableState; + // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export type SerializedAction = { +export type SerializedAction = { readonly factoryId: string; readonly name: string; readonly config: Config; diff --git a/x-pack/plugins/ui_actions_enhanced/public/index.ts b/x-pack/plugins/ui_actions_enhanced/public/index.ts index 1832f1b4661d3..ae720598ec759 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/index.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/index.ts @@ -29,6 +29,7 @@ export { DynamicActionManagerState as UiActionsEnhancedDynamicActionManagerState, MemoryActionStorage as UiActionsEnhancedMemoryActionStorage, BaseActionFactoryContext as UiActionsEnhancedBaseActionFactoryContext, + BaseActionConfig as UiActionsEnhancedBaseActionConfig, } from './dynamic_actions'; export { DynamicActionsState } from './services/ui_actions_service_enhancements'; diff --git a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts index fae4681452adc..360e30e11553d 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts @@ -8,6 +8,7 @@ import { ActionFactoryRegistry } from '../types'; import { ActionFactory, ActionFactoryDefinition, + BaseActionConfig, BaseActionFactoryContext, SerializedEvent, } from '../dynamic_actions'; @@ -16,10 +17,7 @@ import { ILicense } from '../../../licensing/common/types'; import { TriggerContextMapping, TriggerId } from '../../../../../src/plugins/ui_actions/public'; import { LicensingPluginSetup, LicensingPluginStart } from '../../../licensing/public'; import { SavedObjectReference } from '../../../../../src/core/types'; -import { - PersistableStateDefinition, - SerializableState, -} from '../../../../../src/plugins/kibana_utils/common'; +import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common'; // eslint-disable-next-line @typescript-eslint/consistent-type-definitions export type DynamicActionsState = { @@ -48,7 +46,7 @@ export class UiActionsServiceEnhancements * serialize/deserialize dynamic actions. */ public readonly registerActionFactory = < - Config extends SerializableState = SerializableState, + Config extends BaseActionConfig = BaseActionConfig, SupportedTriggers extends TriggerId = TriggerId, FactoryContext extends BaseActionFactoryContext = { triggers: SupportedTriggers[]; @@ -93,7 +91,7 @@ export class UiActionsServiceEnhancements * Convenience method to register a {@link DrilldownDefinition | drilldown}. */ public readonly registerDrilldown = < - Config extends SerializableState = SerializableState, + Config extends BaseActionConfig = BaseActionConfig, SupportedTriggers extends TriggerId = TriggerId, FactoryContext extends BaseActionFactoryContext = { triggers: SupportedTriggers[]; diff --git a/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts b/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts index 093e16593ef08..4436a8b966916 100644 --- a/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts +++ b/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts @@ -8,11 +8,11 @@ import { EnhancementRegistryDefinition } from '../../../../src/plugins/embeddabl import { SavedObjectReference } from '../../../../src/core/types'; import { DynamicActionsState, SerializedEvent } from './types'; import { AdvancedUiActionsPublicPlugin } from './plugin'; -import { SerializableState } from '../../../../src/plugins/kibana_utils/common/persistable_state'; +import { SerializableState } from '../../../../src/plugins/kibana_utils/common'; export const dynamicActionEnhancement = ( uiActionsEnhanced: AdvancedUiActionsPublicPlugin -): EnhancementRegistryDefinition => { +): EnhancementRegistryDefinition => { return { id: 'dynamicActions', telemetry: (state: SerializableState, telemetry: Record) => { @@ -48,5 +48,5 @@ export const dynamicActionEnhancement = ( }), } as DynamicActionsState; }, - } as EnhancementRegistryDefinition; + } as EnhancementRegistryDefinition; }; From 43438c37929bf3ee2010fe11ce1ca08477bbddb0 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 16 Sep 2020 03:04:00 -0700 Subject: [PATCH 20/23] review feedback --- .../ui_actions_enhanced/.eslintrc.json | 5 ++++ .../ui_actions_enhanced/common/types.ts | 28 +++++++++++++++++++ .../components/action_wizard/test_data.tsx | 2 -- .../public/dynamic_actions/types.ts | 21 ++------------ .../ui_actions_service_enhancements.ts | 7 ++--- .../test_helpers/time_range_container.ts | 1 - .../ui_actions_enhanced/server/index.ts | 7 ++++- .../ui_actions_enhanced/server/types.ts | 25 ++--------------- 8 files changed, 47 insertions(+), 49 deletions(-) create mode 100644 x-pack/plugins/ui_actions_enhanced/.eslintrc.json create mode 100644 x-pack/plugins/ui_actions_enhanced/common/types.ts diff --git a/x-pack/plugins/ui_actions_enhanced/.eslintrc.json b/x-pack/plugins/ui_actions_enhanced/.eslintrc.json new file mode 100644 index 0000000000000..2aab6c2d9093b --- /dev/null +++ b/x-pack/plugins/ui_actions_enhanced/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "@typescript-eslint/consistent-type-definitions": 0 + } +} diff --git a/x-pack/plugins/ui_actions_enhanced/common/types.ts b/x-pack/plugins/ui_actions_enhanced/common/types.ts new file mode 100644 index 0000000000000..1150f4f823e8e --- /dev/null +++ b/x-pack/plugins/ui_actions_enhanced/common/types.ts @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SerializableState } from '../../../../src/plugins/kibana_utils/common'; + +export type BaseActionConfig = SerializableState; + +export type SerializedAction = { + readonly factoryId: string; + readonly name: string; + readonly config: Config; +}; + +/** + * Serialized representation of a triggers-action pair, used to persist in storage. + */ +export type SerializedEvent = { + eventId: string; + triggers: string[]; + action: SerializedAction; +}; + +export type DynamicActionsState = { + events: SerializedEvent[]; +}; diff --git a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx index 4b8f52b48e2c9..af930bfba6b8b 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx +++ b/x-pack/plugins/ui_actions_enhanced/public/components/action_wizard/test_data.tsx @@ -24,7 +24,6 @@ export const dashboards = [ { id: 'dashboard2', title: 'Dashboard 2' }, ]; -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions type DashboardDrilldownConfig = { dashboardId?: string; useCurrentFilters: boolean; @@ -120,7 +119,6 @@ export const dashboardFactory = new ActionFactory(dashboardDrilldownActionFactor getFeatureUsageStart: () => licensingMock.createStart().featureUsage, }); -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions type UrlDrilldownConfig = { url: string; openInNewTab: boolean; diff --git a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts index e906540a268d5..28d104093f64f 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/dynamic_actions/types.ts @@ -5,26 +5,9 @@ */ import { TriggerId } from '../../../../../src/plugins/ui_actions/public'; -import { SerializableState } from '../../../../../src/plugins/kibana_utils/common'; +import { SerializedAction, SerializedEvent, BaseActionConfig } from '../../common/types'; -export type BaseActionConfig = SerializableState; - -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export type SerializedAction = { - readonly factoryId: string; - readonly name: string; - readonly config: Config; -}; - -/** - * Serialized representation of a triggers-action pair, used to persist in storage. - */ -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export type SerializedEvent = { - eventId: string; - triggers: string[]; - action: SerializedAction; -}; +export { SerializedAction, SerializedEvent, BaseActionConfig }; /** * Action factory context passed into ActionFactories' CollectConfig, getDisplayName, getIconType diff --git a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts index 360e30e11553d..a999f9ec0098b 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts @@ -19,10 +19,9 @@ import { LicensingPluginSetup, LicensingPluginStart } from '../../../licensing/p import { SavedObjectReference } from '../../../../../src/core/types'; import { PersistableStateDefinition } from '../../../../../src/plugins/kibana_utils/common'; -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export type DynamicActionsState = { - events: SerializedEvent[]; -}; +import { DynamicActionsState } from '../../common/types'; + +export { DynamicActionsState }; export interface UiActionsServiceEnhancementsParams { readonly actionFactories?: ActionFactoryRegistry; diff --git a/x-pack/plugins/ui_actions_enhanced/public/test_helpers/time_range_container.ts b/x-pack/plugins/ui_actions_enhanced/public/test_helpers/time_range_container.ts index 3d143b0cacd06..9a529f192158d 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/test_helpers/time_range_container.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/test_helpers/time_range_container.ts @@ -17,7 +17,6 @@ import { TimeRange } from '../../../../../src/plugins/data/public'; * https://github.com/microsoft/TypeScript/issues/15300 is fixed so we use a type * here instead */ -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions export type InheritedChildrenInput = { timeRange: TimeRange; id?: string; diff --git a/x-pack/plugins/ui_actions_enhanced/server/index.ts b/x-pack/plugins/ui_actions_enhanced/server/index.ts index 97552a6eda60b..5419c4135796d 100644 --- a/x-pack/plugins/ui_actions_enhanced/server/index.ts +++ b/x-pack/plugins/ui_actions_enhanced/server/index.ts @@ -19,6 +19,11 @@ export { export { ActionFactoryDefinition as UiActionsEnhancedActionFactoryDefinition, ActionFactory as UiActionsEnhancedActionFactory, +} from './types'; + +export { + DynamicActionsState, + BaseActionConfig as UiActionsEnhancedBaseActionConfig, SerializedAction as UiActionsEnhancedSerializedAction, SerializedEvent as UiActionsEnhancedSerializedEvent, -} from './types'; +} from '../common/types'; diff --git a/x-pack/plugins/ui_actions_enhanced/server/types.ts b/x-pack/plugins/ui_actions_enhanced/server/types.ts index 5942a03d6fe2b..4859be6728344 100644 --- a/x-pack/plugins/ui_actions_enhanced/server/types.ts +++ b/x-pack/plugins/ui_actions_enhanced/server/types.ts @@ -7,30 +7,9 @@ import { PersistableState, PersistableStateDefinition, - SerializableState, } from '../../../../src/plugins/kibana_utils/common'; -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export type SerializedAction = { - readonly factoryId: string; - readonly name: string; - readonly config: Config; -}; - -/** - * Serialized representation of a triggers-action pair, used to persist in storage. - */ -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export type SerializedEvent = { - eventId: string; - triggers: string[]; - action: SerializedAction; -}; - -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export type DynamicActionsState = { - events: SerializedEvent[]; -}; +import { SerializedAction, SerializedEvent, DynamicActionsState } from '../common/types'; export type ActionFactoryRegistry = Map; @@ -43,3 +22,5 @@ export interface ActionFactory

extends PersistableState

{ id: string; } + +export { SerializedEvent, SerializedAction, DynamicActionsState }; From a1317a55e61c14830b2b23b542c67097c470b916 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 16 Sep 2020 04:17:55 -0700 Subject: [PATCH 21/23] review feedback --- x-pack/examples/ui_actions_enhanced_examples/.eslintrc.json | 5 +++++ .../public/dashboard_hello_world_drilldown/index.tsx | 1 - .../index.tsx | 1 - .../public/dashboard_to_discover_drilldown/types.ts | 1 - .../public/drilldowns/url_drilldown/types.ts | 1 - 5 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 x-pack/examples/ui_actions_enhanced_examples/.eslintrc.json diff --git a/x-pack/examples/ui_actions_enhanced_examples/.eslintrc.json b/x-pack/examples/ui_actions_enhanced_examples/.eslintrc.json new file mode 100644 index 0000000000000..2aab6c2d9093b --- /dev/null +++ b/x-pack/examples/ui_actions_enhanced_examples/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "@typescript-eslint/consistent-type-definitions": 0 + } +} diff --git a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_drilldown/index.tsx b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_drilldown/index.tsx index 986a1ebe3557c..cac5f0b29dc6e 100644 --- a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_drilldown/index.tsx +++ b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_drilldown/index.tsx @@ -17,7 +17,6 @@ import { export type ActionContext = ChartActionContext; -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions export type Config = { name: string; }; diff --git a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_only_range_select_drilldown/index.tsx b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_only_range_select_drilldown/index.tsx index 2a07edb3e5c83..fa2f0825f9335 100644 --- a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_only_range_select_drilldown/index.tsx +++ b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_hello_world_only_range_select_drilldown/index.tsx @@ -13,7 +13,6 @@ import { CollectConfigProps } from '../../../../../src/plugins/kibana_utils/publ import { SELECT_RANGE_TRIGGER } from '../../../../../src/plugins/ui_actions/public'; import { BaseActionFactoryContext } from '../../../../plugins/ui_actions_enhanced/public/dynamic_actions'; -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions export type Config = { name: string; }; diff --git a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_to_discover_drilldown/types.ts b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_to_discover_drilldown/types.ts index 7eef10fa61c17..692de571e8a00 100644 --- a/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_to_discover_drilldown/types.ts +++ b/x-pack/examples/ui_actions_enhanced_examples/public/dashboard_to_discover_drilldown/types.ts @@ -9,7 +9,6 @@ import { ApplyGlobalFilterActionContext } from '../../../../../src/plugins/data/ export type ActionContext = ApplyGlobalFilterActionContext; -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions export type Config = { /** * Whether to use a user selected index pattern, stored in `indexPatternId` field. diff --git a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/types.ts b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/types.ts index 893adb754e79c..fb7d96aaf8325 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/types.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/types.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -// eslint-disable-next-line export type UrlDrilldownConfig = { url: { format?: 'handlebars_v1'; template: string }; openInNewTab: boolean; From 4817d123513399caf5bd50adda9c77e53b830d9c Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 16 Sep 2020 07:53:53 -0700 Subject: [PATCH 22/23] review feedback --- src/plugins/embeddable/.eslintrc.json | 5 +++++ src/plugins/embeddable/common/lib/migrate_base_input.ts | 4 +++- src/plugins/embeddable/common/types.ts | 1 - .../public/lib/embeddables/embeddable_factory.ts | 1 - src/plugins/embeddable/public/plugin.tsx | 8 ++++---- src/plugins/embeddable/server/plugin.ts | 8 ++++---- .../public/services/ui_actions_service_enhancements.ts | 7 +++++-- .../server/dynamic_action_enhancement.ts | 7 +++++-- 8 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 src/plugins/embeddable/.eslintrc.json diff --git a/src/plugins/embeddable/.eslintrc.json b/src/plugins/embeddable/.eslintrc.json new file mode 100644 index 0000000000000..2aab6c2d9093b --- /dev/null +++ b/src/plugins/embeddable/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "@typescript-eslint/consistent-type-definitions": 0 + } +} diff --git a/src/plugins/embeddable/common/lib/migrate_base_input.ts b/src/plugins/embeddable/common/lib/migrate_base_input.ts index 16e1bb456356a..0d5dc508e20ad 100644 --- a/src/plugins/embeddable/common/lib/migrate_base_input.ts +++ b/src/plugins/embeddable/common/lib/migrate_base_input.ts @@ -23,7 +23,9 @@ import { EmbeddableInput } from '../types'; export const telemetryBaseEmbeddableInput = ( state: EmbeddableInput, telemetryData: Record -) => {}; +) => { + return telemetryData; +}; export const extractBaseEmbeddableInput = (state: EmbeddableInput) => { return { state, references: [] as SavedObjectReference[] }; diff --git a/src/plugins/embeddable/common/types.ts b/src/plugins/embeddable/common/types.ts index dd68f57ca5d38..68b842c934de8 100644 --- a/src/plugins/embeddable/common/types.ts +++ b/src/plugins/embeddable/common/types.ts @@ -26,7 +26,6 @@ export enum ViewMode { VIEW = 'view', } -// eslint-disable-next-line export type EmbeddableInput = { viewMode?: ViewMode; title?: string; diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts index fce37fb2d9f20..a6fa46fbc4e3e 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts @@ -45,7 +45,6 @@ export interface EmbeddableFactory< TEmbeddableOutput >, TSavedObjectAttributes extends SavedObjectAttributes = SavedObjectAttributes - // @ts-ignore > extends PersistableState { // A unique identified for this factory, which will be used to map an embeddable spec to // a factory that can generate an instance of it. diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index b289b18810407..00eb923c26662 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -201,16 +201,16 @@ export class EmbeddablePublicPlugin implements Plugin = state.enhancements || {}; const factory = this.getEmbeddableFactory(state.id); - telemetryBaseEmbeddableInput(state, telemetryData); + let telemetry = telemetryBaseEmbeddableInput(state, telemetryData); if (factory) { - factory.telemetry(state, telemetryData); + telemetry = factory.telemetry(state, telemetry); } Object.keys(enhancements).map((key) => { if (!enhancements[key]) return; - this.getEnhancement(key).telemetry(enhancements[key], telemetryData); + telemetry = this.getEnhancement(key).telemetry(enhancements[key], telemetry); }); - return telemetryData; + return telemetry; }; private extract = (state: EmbeddableInput) => { diff --git a/src/plugins/embeddable/server/plugin.ts b/src/plugins/embeddable/server/plugin.ts index 2528952ba8535..f79c4b7620110 100644 --- a/src/plugins/embeddable/server/plugin.ts +++ b/src/plugins/embeddable/server/plugin.ts @@ -64,16 +64,16 @@ export class EmbeddableServerPlugin implements Plugin { const enhancements: Record = state.enhancements || {}; const factory = this.getEmbeddableFactory(state.id); - telemetryBaseEmbeddableInput(state, telemetryData); + let telemetry = telemetryBaseEmbeddableInput(state, telemetryData); if (factory) { - factory.telemetry(state, telemetryData); + telemetry = factory.telemetry(state, telemetry); } Object.keys(enhancements).map((key) => { if (!enhancements[key]) return; - this.getEnhancement(key).telemetry(enhancements[key], telemetryData); + telemetry = this.getEnhancement(key).telemetry(enhancements[key], telemetry); }); - return telemetryData; + return telemetry; }; private extract = (state: EmbeddableInput) => { diff --git a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts index a999f9ec0098b..28ce1b3524b06 100644 --- a/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts +++ b/x-pack/plugins/ui_actions_enhanced/public/services/ui_actions_service_enhancements.ts @@ -166,12 +166,15 @@ export class UiActionsServiceEnhancements }; public readonly telemetry = (state: DynamicActionsState, telemetry: Record = {}) => { + let telemetryData = telemetry; state.events.forEach((event: SerializedEvent) => { if (this.actionFactories.has(event.action.factoryId)) { - this.actionFactories.get(event.action.factoryId)!.telemetry(event, telemetry); + telemetryData = this.actionFactories + .get(event.action.factoryId)! + .telemetry(event, telemetryData); } }); - return telemetry; + return telemetryData; }; public readonly extract = (state: DynamicActionsState) => { diff --git a/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts b/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts index 4436a8b966916..b366436200914 100644 --- a/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts +++ b/x-pack/plugins/ui_actions_enhanced/server/dynamic_action_enhancement.ts @@ -16,12 +16,15 @@ export const dynamicActionEnhancement = ( return { id: 'dynamicActions', telemetry: (state: SerializableState, telemetry: Record) => { + let telemetryData = telemetry; (state as DynamicActionsState).events.forEach((event: SerializedEvent) => { if (uiActionsEnhanced.getActionFactory(event.action.factoryId)) { - uiActionsEnhanced.getActionFactory(event.action.factoryId)!.telemetry(event, telemetry); + telemetryData = uiActionsEnhanced + .getActionFactory(event.action.factoryId)! + .telemetry(event, telemetryData); } }); - return telemetry; + return telemetryData; }, extract: (state: SerializableState) => { const references: SavedObjectReference[] = []; From c1614919b689d8f80d991abe661627e3dc4e4819 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 16 Sep 2020 09:07:51 -0700 Subject: [PATCH 23/23] fixing eslint --- .../public/lib/test_samples/embeddables/filterable_container.tsx | 1 - .../lib/test_samples/embeddables/hello_world_container.tsx | 1 - 2 files changed, 2 deletions(-) diff --git a/src/plugins/embeddable/public/lib/test_samples/embeddables/filterable_container.tsx b/src/plugins/embeddable/public/lib/test_samples/embeddables/filterable_container.tsx index ceaa74218904d..db71b94ac855f 100644 --- a/src/plugins/embeddable/public/lib/test_samples/embeddables/filterable_container.tsx +++ b/src/plugins/embeddable/public/lib/test_samples/embeddables/filterable_container.tsx @@ -32,7 +32,6 @@ export interface FilterableContainerInput extends ContainerInput { * https://github.com/microsoft/TypeScript/issues/15300 is fixed so we use a type * here instead */ -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions export type InheritedChildrenInput = { filters: Filter[]; id?: string; diff --git a/src/plugins/embeddable/public/lib/test_samples/embeddables/hello_world_container.tsx b/src/plugins/embeddable/public/lib/test_samples/embeddables/hello_world_container.tsx index 913c3a0b30826..d47979b9419f3 100644 --- a/src/plugins/embeddable/public/lib/test_samples/embeddables/hello_world_container.tsx +++ b/src/plugins/embeddable/public/lib/test_samples/embeddables/hello_world_container.tsx @@ -30,7 +30,6 @@ export const HELLO_WORLD_CONTAINER = 'HELLO_WORLD_CONTAINER'; * https://github.com/microsoft/TypeScript/issues/15300 is fixed so we use a type * here instead */ -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions type InheritedInput = { id: string; viewMode: ViewMode;