From c68a846cfaaef36eb5a4a25030dabc2b4c868454 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 16 Apr 2020 10:02:30 +0200 Subject: [PATCH 01/11] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20example=20o?= =?UTF-8?q?f=20Discover=20drilldown=20to=20sample=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .i18nrc.json | 1 + examples/ui_action_examples/kibana.json | 2 +- .../public/components/README.md | 5 ++ .../discover_drilldown_config.tsx | 81 +++++++++++++++++++ .../discover_drilldown_config/i18n.ts | 27 +++++++ .../discover_drilldown_config/index.ts | 20 +++++ .../public/components/index.ts | 20 +++++ .../collect_config.tsx | 68 ++++++++++++++++ .../constants.ts | 20 +++++ .../drilldown.tsx | 67 +++++++++++++++ .../dashboard_to_discover_drilldown/i18n.ts | 24 ++++++ .../dashboard_to_discover_drilldown/index.ts | 29 +++++++ .../dashboard_to_discover_drilldown/types.ts | 35 ++++++++ examples/ui_action_examples/public/plugin.ts | 40 +++++++-- 14 files changed, 433 insertions(+), 6 deletions(-) create mode 100644 examples/ui_action_examples/public/components/README.md create mode 100644 examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx create mode 100644 examples/ui_action_examples/public/components/discover_drilldown_config/i18n.ts create mode 100644 examples/ui_action_examples/public/components/discover_drilldown_config/index.ts create mode 100644 examples/ui_action_examples/public/components/index.ts create mode 100644 examples/ui_action_examples/public/dashboard_to_discover_drilldown/collect_config.tsx create mode 100644 examples/ui_action_examples/public/dashboard_to_discover_drilldown/constants.ts create mode 100644 examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx create mode 100644 examples/ui_action_examples/public/dashboard_to_discover_drilldown/i18n.ts create mode 100644 examples/ui_action_examples/public/dashboard_to_discover_drilldown/index.ts create mode 100644 examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts diff --git a/.i18nrc.json b/.i18nrc.json index e18f529b92ac3..43d5867924f1a 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -8,6 +8,7 @@ "data": "src/plugins/data", "embeddableApi": "src/plugins/embeddable", "embeddableExamples": "examples/embeddable_examples", + "uiActionsExamples": "examples/ui_action_examples", "share": "src/plugins/share", "home": "src/plugins/home", "charts": "src/plugins/charts", diff --git a/examples/ui_action_examples/kibana.json b/examples/ui_action_examples/kibana.json index d5c3f0f2ec33a..1c9323c394a3d 100644 --- a/examples/ui_action_examples/kibana.json +++ b/examples/ui_action_examples/kibana.json @@ -5,6 +5,6 @@ "configPath": ["ui_actions_examples"], "server": false, "ui": true, - "requiredPlugins": ["uiActions"], + "requiredPlugins": ["uiActions", "drilldowns"], "optionalPlugins": [] } diff --git a/examples/ui_action_examples/public/components/README.md b/examples/ui_action_examples/public/components/README.md new file mode 100644 index 0000000000000..8081f8a2451cf --- /dev/null +++ b/examples/ui_action_examples/public/components/README.md @@ -0,0 +1,5 @@ +# Presentation React components + +Here we keep reusable *presentation* (aka *dumb*) React components—these +components should not be connected to state and ideally should not know anything +about Kibana. diff --git a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx new file mode 100644 index 0000000000000..c20dca0b5310d --- /dev/null +++ b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx @@ -0,0 +1,81 @@ +/* + * 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 React from 'react'; +import { EuiFormRow, EuiSelect, EuiSwitch } from '@elastic/eui'; +import { txtChooseDestinationIndexPattern } from './i18n'; + +export interface IndexPatternItem { + id: string; + title: string; +} + +export interface DiscoverDrilldownConfigProps { + activeDashboardId?: string; + dashboards: IndexPatternItem[]; + currentFilters?: boolean; + keepRange?: boolean; + onDashboardSelect: (dashboardId: string) => void; + onCurrentFiltersToggle?: () => void; + onKeepRangeToggle?: () => void; +} + +export const DiscoverDrilldownConfig: React.FC = ({ + activeDashboardId, + dashboards, + currentFilters, + keepRange, + onDashboardSelect, + onCurrentFiltersToggle, + onKeepRangeToggle, +}) => { + return ( + <> + + ({ value: id, text: title }))} + value={activeDashboardId} + onChange={e => onDashboardSelect(e.target.value)} + /> + + {!!onCurrentFiltersToggle && ( + + + + )} + {!!onKeepRangeToggle && ( + + + + )} + + ); +}; diff --git a/examples/ui_action_examples/public/components/discover_drilldown_config/i18n.ts b/examples/ui_action_examples/public/components/discover_drilldown_config/i18n.ts new file mode 100644 index 0000000000000..676b70c0a6082 --- /dev/null +++ b/examples/ui_action_examples/public/components/discover_drilldown_config/i18n.ts @@ -0,0 +1,27 @@ +/* + * 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 { i18n } from '@kbn/i18n'; + +export const txtChooseDestinationIndexPattern = i18n.translate( + 'uiActionsExamples.components.DashboardDrilldownConfig.chooseIndexPattern', + { + defaultMessage: 'Choose destination index pattern', + } +); diff --git a/examples/ui_action_examples/public/components/discover_drilldown_config/index.ts b/examples/ui_action_examples/public/components/discover_drilldown_config/index.ts new file mode 100644 index 0000000000000..53df6c8e5401f --- /dev/null +++ b/examples/ui_action_examples/public/components/discover_drilldown_config/index.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +export * from './discover_drilldown_config'; diff --git a/examples/ui_action_examples/public/components/index.ts b/examples/ui_action_examples/public/components/index.ts new file mode 100644 index 0000000000000..53df6c8e5401f --- /dev/null +++ b/examples/ui_action_examples/public/components/index.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +export * from './discover_drilldown_config'; diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/collect_config.tsx b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/collect_config.tsx new file mode 100644 index 0000000000000..7d1bf1fe64bf5 --- /dev/null +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/collect_config.tsx @@ -0,0 +1,68 @@ +/* + * 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 React, { useState, useEffect } from 'react'; +import { CollectConfigProps } from './types'; +import { DiscoverDrilldownConfig } from '../components/discover_drilldown_config'; +import { Params } from './drilldown'; + +export interface CollectConfigContainerProps extends CollectConfigProps { + params: Params; +} + +export const CollectConfigContainer: React.FC = ({ + config, + onConfig, + params: { start }, +}) => { + const [dashboards] = useState([ + { id: 'dashboard1', title: 'Dashboard 1' }, + { id: 'dashboard2', title: 'Dashboard 2' }, + { id: 'dashboard3', title: 'Dashboard 3' }, + { id: 'dashboard4', title: 'Dashboard 4' }, + ]); + + useEffect(() => { + // TODO: Load dashboards... + }, [start]); + + return ( + { + onConfig({ ...config, indexPatternId }); + }} + onCurrentFiltersToggle={() => + onConfig({ + ...config, + useCurrentFilters: !config.useCurrentFilters, + }) + } + onKeepRangeToggle={() => + onConfig({ + ...config, + useCurrentDateRange: !config.useCurrentDateRange, + }) + } + /> + ); +}; diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/constants.ts b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/constants.ts new file mode 100644 index 0000000000000..9fa3e87ac1aeb --- /dev/null +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/constants.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +export const DASHBOARD_TO_DISCOVER_DRILLDOWN = 'DASHBOARD_TO_DISCOVER_DRILLDOWN'; diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx new file mode 100644 index 0000000000000..dc0483a6421f3 --- /dev/null +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx @@ -0,0 +1,67 @@ +/* + * 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 React from 'react'; +import { StartDeps } from '../plugin'; +import { reactToUiComponent } from '../../../../src/plugins/kibana_react/public'; +import { PlaceContext, ActionContext, Config, CollectConfigProps } from './types'; +import { CollectConfigContainer } from './collect_config'; +import { DASHBOARD_TO_DISCOVER_DRILLDOWN } from './constants'; +import { DrilldownDefinition as Drilldown } from '../../../../x-pack/plugins/drilldowns/public'; +import { txtGoToDiscover } from './i18n'; + +export interface Params { + start: () => { + core: Pick; + }; +} + +export class DashboardToDiscoverDrilldown + implements Drilldown { + constructor(protected readonly params: Params) {} + + public readonly id = DASHBOARD_TO_DISCOVER_DRILLDOWN; + + public readonly order = 100; + + public readonly getDisplayName = () => txtGoToDiscover; + + public readonly euiIcon = 'discoverApp'; + + private readonly ReactCollectConfig: React.FC = props => ( + + ); + + public readonly CollectConfig = reactToUiComponent(this.ReactCollectConfig); + + public readonly createConfig = () => ({ + indexPatternId: '123', + useCurrentFilters: true, + useCurrentDateRange: true, + }); + + public readonly isConfigValid = (config: Config): config is Config => { + if (!config.indexPatternId) return false; + return true; + }; + + public readonly execute = () => { + alert('Go to discover!'); + }; +} diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/i18n.ts b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/i18n.ts new file mode 100644 index 0000000000000..ae2aaf229277f --- /dev/null +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/i18n.ts @@ -0,0 +1,24 @@ +/* + * 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 { i18n } from '@kbn/i18n'; + +export const txtGoToDiscover = i18n.translate('uiActionsExamples.drilldown.goToDashboard', { + defaultMessage: 'Go to Discover', +}); diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/index.ts b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/index.ts new file mode 100644 index 0000000000000..4eb0650b3cdc6 --- /dev/null +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/index.ts @@ -0,0 +1,29 @@ +/* + * 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. + */ + +export { DASHBOARD_TO_DISCOVER_DRILLDOWN } from './constants'; +export { + DashboardToDiscoverDrilldown, + Params as DashboardToDiscoverDrilldownParams, +} from './drilldown'; +export { + PlaceContext as DashboardToDiscoverPlaceContext, + ActionContext as DashboardToDiscoverActionContext, + Config as DashboardToDiscoverConfig, +} from './types'; diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts new file mode 100644 index 0000000000000..7b8dade3ef45d --- /dev/null +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts @@ -0,0 +1,35 @@ +/* + * 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 { + EmbeddableVisTriggerContext, + EmbeddableContext, +} from '../../../../src/plugins/embeddable/public'; +import { UiActionsCollectConfigProps } from '../../../../src/plugins/ui_actions/public'; + +export type PlaceContext = EmbeddableContext; +export type ActionContext = EmbeddableVisTriggerContext; + +export interface Config { + indexPatternId?: string; + useCurrentFilters: boolean; + useCurrentDateRange: boolean; +} + +export type CollectConfigProps = UiActionsCollectConfigProps; diff --git a/examples/ui_action_examples/public/plugin.ts b/examples/ui_action_examples/public/plugin.ts index d053f7e82862c..fd43d07a6819c 100644 --- a/examples/ui_action_examples/public/plugin.ts +++ b/examples/ui_action_examples/public/plugin.ts @@ -17,13 +17,26 @@ * under the License. */ -import { Plugin, CoreSetup } from '../../../src/core/public'; -import { UiActionsSetup } from '../../../src/plugins/ui_actions/public'; +import { Plugin, CoreSetup, CoreStart } from '../../../src/core/public'; +import { UiActionsSetup, UiActionsStart } from '../../../src/plugins/ui_actions/public'; +import { DrilldownsSetup, DrilldownsStart } from '../../../x-pack/plugins/drilldowns/public'; import { createHelloWorldAction, ACTION_HELLO_WORLD } from './hello_world_action'; import { helloWorldTrigger, HELLO_WORLD_TRIGGER_ID } from './hello_world_trigger'; +import { DashboardToDiscoverDrilldown } from './dashboard_to_discover_drilldown'; interface UiActionExamplesSetupDependencies { uiActions: UiActionsSetup; + drilldowns: DrilldownsSetup; +} + +interface UiActionExamplesStartDependencies { + uiActions: UiActionsStart; + drilldowns: DrilldownsStart; +} + +export interface StartDeps { + core: CoreStart; + plugins: UiActionExamplesStartDependencies; } declare module '../../../src/plugins/ui_actions/public' { @@ -37,8 +50,16 @@ declare module '../../../src/plugins/ui_actions/public' { } export class UiActionExamplesPlugin - implements Plugin { - public setup(core: CoreSetup, { uiActions }: UiActionExamplesSetupDependencies) { + implements + Plugin { + private startDeps?: StartDeps; + + private readonly getStartServicesOrDie = (): StartDeps => { + if (!this.startDeps) throw new Error('Start dependencies not ready.'); + return this.startDeps; + }; + + public setup(core: CoreSetup, { uiActions, drilldowns }: UiActionExamplesSetupDependencies) { uiActions.registerTrigger(helloWorldTrigger); const helloWorldAction = createHelloWorldAction(async () => ({ @@ -47,8 +68,17 @@ export class UiActionExamplesPlugin uiActions.registerAction(helloWorldAction); uiActions.addTriggerAction(helloWorldTrigger.id, helloWorldAction); + + drilldowns.registerDrilldown( + new DashboardToDiscoverDrilldown({ + start: this.getStartServicesOrDie, + }) + ); + } + + public start(core: CoreStart, plugins: UiActionExamplesStartDependencies) { + this.startDeps = { core, plugins }; } - public start() {} public stop() {} } From 9659d344ca24579366dbb219cec2c6812461ad8a Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 16 Apr 2020 10:19:00 +0200 Subject: [PATCH 02/11] =?UTF-8?q?fix:=20=F0=9F=90=9B=20show=20drilldowns?= =?UTF-8?q?=20with=20higher=20"order"=20first?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/dashboard_to_discover_drilldown/drilldown.tsx | 2 +- .../public/components/action_wizard/action_wizard.tsx | 2 +- .../plugins/drilldowns/public/services/drilldown_service.ts | 2 ++ x-pack/plugins/drilldowns/public/types.ts | 6 ++++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx index dc0483a6421f3..668941b24eec6 100644 --- a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx @@ -38,7 +38,7 @@ export class DashboardToDiscoverDrilldown public readonly id = DASHBOARD_TO_DISCOVER_DRILLDOWN; - public readonly order = 100; + public readonly order = 50; public readonly getDisplayName = () => txtGoToDiscover; diff --git a/x-pack/plugins/advanced_ui_actions/public/components/action_wizard/action_wizard.tsx b/x-pack/plugins/advanced_ui_actions/public/components/action_wizard/action_wizard.tsx index ac6aead489edd..554ff58d5b555 100644 --- a/x-pack/plugins/advanced_ui_actions/public/components/action_wizard/action_wizard.tsx +++ b/x-pack/plugins/advanced_ui_actions/public/components/action_wizard/action_wizard.tsx @@ -175,7 +175,7 @@ const ActionFactorySelector: React.FC = ({ return ( {[...actionFactories] - .sort((f1, f2) => f1.order - f2.order) + .sort((f1, f2) => f2.order - f1.order) .map(actionFactory => ( ({ id: factoryId, + order, CollectConfig, createConfig, isConfigValid, @@ -52,6 +53,7 @@ export class DrilldownService { ExecutionContext > = { id: factoryId, + order, CollectConfig, createConfig, isConfigValid, diff --git a/x-pack/plugins/drilldowns/public/types.ts b/x-pack/plugins/drilldowns/public/types.ts index a8232887f9ca6..40bbc95c345de 100644 --- a/x-pack/plugins/drilldowns/public/types.ts +++ b/x-pack/plugins/drilldowns/public/types.ts @@ -34,6 +34,12 @@ export interface DrilldownDefinition< */ id: string; + /** + * Determines the display order of the drilldowns in the flyout picker. + * Higher numbers are displayed first. + */ + order?: number; + /** * Function that returns default config for this drilldown. */ From 5ada60f4b0adffeace0606566568ebb2ef4473fa Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 16 Apr 2020 10:39:43 +0200 Subject: [PATCH 03/11] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20createStartS?= =?UTF-8?q?ervicesGetter()=20to=20/public=20=20kibana=5Futil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/create_start_service_getter.ts | 56 +++++++++++++++++++ src/plugins/kibana_utils/public/core/index.ts | 1 + 2 files changed, 57 insertions(+) create mode 100644 src/plugins/kibana_utils/public/core/create_start_service_getter.ts diff --git a/src/plugins/kibana_utils/public/core/create_start_service_getter.ts b/src/plugins/kibana_utils/public/core/create_start_service_getter.ts new file mode 100644 index 0000000000000..e507d1ae778e5 --- /dev/null +++ b/src/plugins/kibana_utils/public/core/create_start_service_getter.ts @@ -0,0 +1,56 @@ +/* + * 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 { CoreStart, StartServicesAccessor } from '../../../../core/public'; + +export interface StartServices { + plugins: Plugins; + self: OwnContract; + core: CoreStart; +} + +export type StartServicesGetter = () => StartServices< + Plugins, + OwnContract +>; + +export const createStartServicesGetter = ( + accessor: StartServicesAccessor +): StartServicesGetter => { + let services: StartServices | undefined; + + accessor().then( + ([core, plugins, self]) => { + services = { + core, + plugins, + self, + }; + }, + error => { + // eslint-disable-next-line no-console + console.error('Could not access start services.', error); + } + ); + + return () => { + if (!services) throw new Error('Trying to access start services before start.'); + return services; + }; +}; diff --git a/src/plugins/kibana_utils/public/core/index.ts b/src/plugins/kibana_utils/public/core/index.ts index 3f08d591300a2..8bbb2129071f5 100644 --- a/src/plugins/kibana_utils/public/core/index.ts +++ b/src/plugins/kibana_utils/public/core/index.ts @@ -18,3 +18,4 @@ */ export * from './create_kibana_utils_core'; +export * from './create_start_service_getter'; From aa103a1f48ff0467067eb33da674c9a7aa9c71b4 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 16 Apr 2020 11:25:20 +0200 Subject: [PATCH 04/11] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20load=20index=20pat?= =?UTF-8?q?terns=20in=20Discover=20drilldown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ui_action_examples/kibana.json | 2 +- .../discover_drilldown_config.tsx | 38 +++++++++--------- .../collect_config.tsx | 40 +++++++++++-------- .../drilldown.tsx | 13 +++--- .../dashboard_to_discover_drilldown/types.ts | 21 +++++++++- examples/ui_action_examples/public/plugin.ts | 36 ++++++----------- .../index_patterns/index_patterns.ts | 8 +++- 7 files changed, 87 insertions(+), 71 deletions(-) diff --git a/examples/ui_action_examples/kibana.json b/examples/ui_action_examples/kibana.json index 1c9323c394a3d..881ac5aadf58b 100644 --- a/examples/ui_action_examples/kibana.json +++ b/examples/ui_action_examples/kibana.json @@ -5,6 +5,6 @@ "configPath": ["ui_actions_examples"], "server": false, "ui": true, - "requiredPlugins": ["uiActions", "drilldowns"], + "requiredPlugins": ["uiActions", "drilldowns", "data"], "optionalPlugins": [] } diff --git a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx index c20dca0b5310d..a57dd461bad37 100644 --- a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx +++ b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx @@ -28,22 +28,22 @@ export interface IndexPatternItem { export interface DiscoverDrilldownConfigProps { activeDashboardId?: string; - dashboards: IndexPatternItem[]; - currentFilters?: boolean; - keepRange?: boolean; + indexPatterns: IndexPatternItem[]; onDashboardSelect: (dashboardId: string) => void; - onCurrentFiltersToggle?: () => void; - onKeepRangeToggle?: () => void; + carryFiltersAndQuery?: boolean; + onCarryFiltersAndQueryToggle?: () => void; + carryTimeRange?: boolean; + onCarryTimeRangeToggle?: () => void; } export const DiscoverDrilldownConfig: React.FC = ({ activeDashboardId, - dashboards, - currentFilters, - keepRange, + indexPatterns, onDashboardSelect, - onCurrentFiltersToggle, - onKeepRangeToggle, + carryFiltersAndQuery, + onCarryFiltersAndQueryToggle, + carryTimeRange, + onCarryTimeRangeToggle, }) => { return ( <> @@ -51,28 +51,28 @@ export const DiscoverDrilldownConfig: React.FC = ( ({ value: id, text: title }))} + options={indexPatterns.map(({ id, title }) => ({ value: id, text: title }))} value={activeDashboardId} onChange={e => onDashboardSelect(e.target.value)} /> - {!!onCurrentFiltersToggle && ( + {!!onCarryFiltersAndQueryToggle && ( )} - {!!onKeepRangeToggle && ( + {!!onCarryTimeRangeToggle && ( )} diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/collect_config.tsx b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/collect_config.tsx index 7d1bf1fe64bf5..55d331c14cdf1 100644 --- a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/collect_config.tsx +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/collect_config.tsx @@ -18,8 +18,9 @@ */ import React, { useState, useEffect } from 'react'; +import useMountedState from 'react-use/lib/useMountedState'; import { CollectConfigProps } from './types'; -import { DiscoverDrilldownConfig } from '../components/discover_drilldown_config'; +import { DiscoverDrilldownConfig, IndexPatternItem } from '../components/discover_drilldown_config'; import { Params } from './drilldown'; export interface CollectConfigContainerProps extends CollectConfigProps { @@ -31,36 +32,43 @@ export const CollectConfigContainer: React.FC = ({ onConfig, params: { start }, }) => { - const [dashboards] = useState([ - { id: 'dashboard1', title: 'Dashboard 1' }, - { id: 'dashboard2', title: 'Dashboard 2' }, - { id: 'dashboard3', title: 'Dashboard 3' }, - { id: 'dashboard4', title: 'Dashboard 4' }, - ]); + const isMounted = useMountedState(); + const [indexPatterns, setIndexPatterns] = useState([]); useEffect(() => { - // TODO: Load dashboards... - }, [start]); + (async () => { + const indexPatternSavedObjects = await start().plugins.data.indexPatterns.getCache(); + if (!isMounted()) return; + setIndexPatterns( + indexPatternSavedObjects + ? indexPatternSavedObjects.map(indexPattern => ({ + id: indexPattern.id, + title: indexPattern.attributes.title, + })) + : [] + ); + })(); + }, [isMounted, start]); return ( { onConfig({ ...config, indexPatternId }); }} - onCurrentFiltersToggle={() => + carryFiltersAndQuery={config.carryFiltersAndQuery} + onCarryFiltersAndQueryToggle={() => onConfig({ ...config, - useCurrentFilters: !config.useCurrentFilters, + carryFiltersAndQuery: !config.carryFiltersAndQuery, }) } - onKeepRangeToggle={() => + carryTimeRange={config.carryTimeRange} + onCarryTimeRangeToggle={() => onConfig({ ...config, - useCurrentDateRange: !config.useCurrentDateRange, + carryTimeRange: !config.carryTimeRange, }) } /> diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx index 668941b24eec6..a8dd209804392 100644 --- a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx @@ -18,8 +18,9 @@ */ import React from 'react'; -import { StartDeps } from '../plugin'; +import { UiActionExamplesStartDependencies as Start } from '../plugin'; import { reactToUiComponent } from '../../../../src/plugins/kibana_react/public'; +import { StartServicesGetter } from '../../../../src/plugins/kibana_utils/public'; import { PlaceContext, ActionContext, Config, CollectConfigProps } from './types'; import { CollectConfigContainer } from './collect_config'; import { DASHBOARD_TO_DISCOVER_DRILLDOWN } from './constants'; @@ -27,9 +28,7 @@ import { DrilldownDefinition as Drilldown } from '../../../../x-pack/plugins/dri import { txtGoToDiscover } from './i18n'; export interface Params { - start: () => { - core: Pick; - }; + start: StartServicesGetter>; } export class DashboardToDiscoverDrilldown @@ -51,9 +50,9 @@ export class DashboardToDiscoverDrilldown public readonly CollectConfig = reactToUiComponent(this.ReactCollectConfig); public readonly createConfig = () => ({ - indexPatternId: '123', - useCurrentFilters: true, - useCurrentDateRange: true, + pickIndexPattern: false, + carryFiltersAndQuery: true, + carryTimeRange: true, }); public readonly isConfigValid = (config: Config): config is Config => { diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts index 7b8dade3ef45d..5e9f38821ed74 100644 --- a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts @@ -27,9 +27,26 @@ export type PlaceContext = EmbeddableContext; export type ActionContext = EmbeddableVisTriggerContext; export interface Config { + /** + * Whether to use a user selected index pattern, stored in `indexPatternId` field. + */ + pickIndexPattern: boolean; + + /** + * ID of index pattern picked by user in UI. If not set, drilldown will use + * the index pattern of the visualization. + */ indexPatternId?: string; - useCurrentFilters: boolean; - useCurrentDateRange: boolean; + + /** + * Whether to carry over source dashboard filters and query. + */ + carryFiltersAndQuery: boolean; + + /** + * Whether to carry over source dashboard time range. + */ + carryTimeRange: boolean; } export type CollectConfigProps = UiActionsCollectConfigProps; diff --git a/examples/ui_action_examples/public/plugin.ts b/examples/ui_action_examples/public/plugin.ts index fd43d07a6819c..91d7ddeaf0a02 100644 --- a/examples/ui_action_examples/public/plugin.ts +++ b/examples/ui_action_examples/public/plugin.ts @@ -19,24 +19,23 @@ import { Plugin, CoreSetup, CoreStart } from '../../../src/core/public'; import { UiActionsSetup, UiActionsStart } from '../../../src/plugins/ui_actions/public'; +import { DataPublicPluginSetup, DataPublicPluginStart } from '../../../src/plugins/data/public'; import { DrilldownsSetup, DrilldownsStart } from '../../../x-pack/plugins/drilldowns/public'; import { createHelloWorldAction, ACTION_HELLO_WORLD } from './hello_world_action'; import { helloWorldTrigger, HELLO_WORLD_TRIGGER_ID } from './hello_world_trigger'; import { DashboardToDiscoverDrilldown } from './dashboard_to_discover_drilldown'; +import { createStartServicesGetter } from '../../../src/plugins/kibana_utils/public'; -interface UiActionExamplesSetupDependencies { - uiActions: UiActionsSetup; +export interface UiActionExamplesSetupDependencies { + data: DataPublicPluginSetup; drilldowns: DrilldownsSetup; + uiActions: UiActionsSetup; } -interface UiActionExamplesStartDependencies { - uiActions: UiActionsStart; +export interface UiActionExamplesStartDependencies { + data: DataPublicPluginStart; drilldowns: DrilldownsStart; -} - -export interface StartDeps { - core: CoreStart; - plugins: UiActionExamplesStartDependencies; + uiActions: UiActionsStart; } declare module '../../../src/plugins/ui_actions/public' { @@ -52,14 +51,9 @@ declare module '../../../src/plugins/ui_actions/public' { export class UiActionExamplesPlugin implements Plugin { - private startDeps?: StartDeps; - - private readonly getStartServicesOrDie = (): StartDeps => { - if (!this.startDeps) throw new Error('Start dependencies not ready.'); - return this.startDeps; - }; - public setup(core: CoreSetup, { uiActions, drilldowns }: UiActionExamplesSetupDependencies) { + const start = createStartServicesGetter(core.getStartServices); + uiActions.registerTrigger(helloWorldTrigger); const helloWorldAction = createHelloWorldAction(async () => ({ @@ -69,16 +63,10 @@ export class UiActionExamplesPlugin uiActions.registerAction(helloWorldAction); uiActions.addTriggerAction(helloWorldTrigger.id, helloWorldAction); - drilldowns.registerDrilldown( - new DashboardToDiscoverDrilldown({ - start: this.getStartServicesOrDie, - }) - ); + drilldowns.registerDrilldown(new DashboardToDiscoverDrilldown({ start })); } - public start(core: CoreStart, plugins: UiActionExamplesStartDependencies) { - this.startDeps = { core, plugins }; - } + public start(core: CoreStart, plugins: UiActionExamplesStartDependencies) {} public stop() {} } diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts index acce5ed57683c..002936b786773 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts @@ -32,10 +32,14 @@ const indexPatternCache = createIndexPatternCache(); type IndexPatternCachedFieldType = 'id' | 'title'; +export interface IndexPatternSavedObjectAttrs { + title: string; +} + export class IndexPatternsService { private config: IUiSettingsClient; private savedObjectsClient: SavedObjectsClientContract; - private savedObjectsCache?: Array>> | null; + private savedObjectsCache?: Array> | null; private apiClient: IndexPatternsApiClient; constructor( @@ -50,7 +54,7 @@ export class IndexPatternsService { private async refreshSavedObjectsCache() { this.savedObjectsCache = ( - await this.savedObjectsClient.find>({ + await this.savedObjectsClient.find({ type: 'index-pattern', fields: ['title'], perPage: 10000, From 4adecf0e80e1a3a1c35d2965c649276b73a05e2e Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 16 Apr 2020 11:42:34 +0200 Subject: [PATCH 05/11] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20toggle=20for?= =?UTF-8?q?=20index=20pattern=20selection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discover_drilldown_config.tsx | 46 +++++++++++++------ .../collect_config.tsx | 12 ++++- .../drilldown.tsx | 4 +- .../dashboard_to_discover_drilldown/types.ts | 2 +- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx index a57dd461bad37..6d729c27f8d95 100644 --- a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx +++ b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx @@ -27,9 +27,11 @@ export interface IndexPatternItem { } export interface DiscoverDrilldownConfigProps { - activeDashboardId?: string; + activeIndexPatternId?: string; indexPatterns: IndexPatternItem[]; - onDashboardSelect: (dashboardId: string) => void; + onIndexPatternSelect: (indexPatternId: string) => void; + customIndexPattern?: boolean; + onCustomIndexPatternToggle?: () => void; carryFiltersAndQuery?: boolean; onCarryFiltersAndQueryToggle?: () => void; carryTimeRange?: boolean; @@ -37,9 +39,11 @@ export interface DiscoverDrilldownConfigProps { } export const DiscoverDrilldownConfig: React.FC = ({ - activeDashboardId, + activeIndexPatternId, indexPatterns, - onDashboardSelect, + onIndexPatternSelect, + customIndexPattern, + onCustomIndexPatternToggle, carryFiltersAndQuery, onCarryFiltersAndQueryToggle, carryTimeRange, @@ -47,19 +51,31 @@ export const DiscoverDrilldownConfig: React.FC = ( }) => { return ( <> - - ({ value: id, text: title }))} - value={activeDashboardId} - onChange={e => onDashboardSelect(e.target.value)} - /> - + {!!onCustomIndexPatternToggle && ( + + + + )} + {!!customIndexPattern && ( + + ({ value: id, text: title }))} + value={activeIndexPatternId} + onChange={e => onIndexPatternSelect(e.target.value)} + /> + + )} {!!onCarryFiltersAndQueryToggle && ( = ( {!!onCarryTimeRangeToggle && ( = ({ return ( { + onIndexPatternSelect={indexPatternId => { onConfig({ ...config, indexPatternId }); }} + customIndexPattern={config.customIndexPattern} + onCustomIndexPatternToggle={() => + onConfig({ + ...config, + customIndexPattern: !config.customIndexPattern, + indexPatternId: undefined, + }) + } carryFiltersAndQuery={config.carryFiltersAndQuery} onCarryFiltersAndQueryToggle={() => onConfig({ diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx index a8dd209804392..a53bad9e30522 100644 --- a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx @@ -50,13 +50,13 @@ export class DashboardToDiscoverDrilldown public readonly CollectConfig = reactToUiComponent(this.ReactCollectConfig); public readonly createConfig = () => ({ - pickIndexPattern: false, + customIndexPattern: false, carryFiltersAndQuery: true, carryTimeRange: true, }); public readonly isConfigValid = (config: Config): config is Config => { - if (!config.indexPatternId) return false; + if (config.customIndexPattern && !config.indexPatternId) return false; return true; }; diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts index 5e9f38821ed74..3ffc010fbf2a4 100644 --- a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/types.ts @@ -30,7 +30,7 @@ export interface Config { /** * Whether to use a user selected index pattern, stored in `indexPatternId` field. */ - pickIndexPattern: boolean; + customIndexPattern: boolean; /** * ID of index pattern picked by user in UI. If not set, drilldown will use From f8006ae44f453bb65ed42112d3cfce51986976b5 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 16 Apr 2020 11:46:44 +0200 Subject: [PATCH 06/11] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20spacer=20to?= =?UTF-8?q?=20separate=20unrelated=20config=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discover_drilldown_config.tsx | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx index 6d729c27f8d95..2bb977932d691 100644 --- a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx +++ b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx @@ -18,7 +18,7 @@ */ import React from 'react'; -import { EuiFormRow, EuiSelect, EuiSwitch } from '@elastic/eui'; +import { EuiFormRow, EuiSelect, EuiSwitch, EuiSpacer } from '@elastic/eui'; import { txtChooseDestinationIndexPattern } from './i18n'; export interface IndexPatternItem { @@ -52,26 +52,30 @@ export const DiscoverDrilldownConfig: React.FC = ( return ( <> {!!onCustomIndexPatternToggle && ( - - - - )} - {!!customIndexPattern && ( - - ({ value: id, text: title }))} - value={activeIndexPatternId} - onChange={e => onIndexPatternSelect(e.target.value)} - /> - + <> + + + + {!!customIndexPattern && ( + + ({ value: id, text: title }))} + value={activeIndexPatternId} + onChange={e => onIndexPatternSelect(e.target.value)} + /> + + )} + + )} + {!!onCarryFiltersAndQueryToggle && ( Date: Thu, 16 Apr 2020 11:57:41 +0200 Subject: [PATCH 07/11] =?UTF-8?q?fix:=20=F0=9F=90=9B=20correctly=20configr?= =?UTF-8?q?e=20setup=20core?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ui_action_examples/public/plugin.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/ui_action_examples/public/plugin.ts b/examples/ui_action_examples/public/plugin.ts index 91d7ddeaf0a02..04ceb79af8346 100644 --- a/examples/ui_action_examples/public/plugin.ts +++ b/examples/ui_action_examples/public/plugin.ts @@ -51,7 +51,10 @@ declare module '../../../src/plugins/ui_actions/public' { export class UiActionExamplesPlugin implements Plugin { - public setup(core: CoreSetup, { uiActions, drilldowns }: UiActionExamplesSetupDependencies) { + public setup( + core: CoreSetup, + { uiActions, drilldowns }: UiActionExamplesSetupDependencies + ) { const start = createStartServicesGetter(core.getStartServices); uiActions.registerTrigger(helloWorldTrigger); From ab3deb73ea5169e116287c20ac71f728b0896ed2 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 16 Apr 2020 12:58:13 +0200 Subject: [PATCH 08/11] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20navigate=20to=20co?= =?UTF-8?q?rrect=20index=20pattern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discover_drilldown_config.tsx | 7 +++-- .../drilldown.tsx | 26 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx index 2bb977932d691..737f9e3ae1f89 100644 --- a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx +++ b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx @@ -66,8 +66,11 @@ export const DiscoverDrilldownConfig: React.FC = ( ({ value: id, text: title }))} - value={activeIndexPatternId} + options={[ + { id: '', text: 'Pick one...' }, + ...indexPatterns.map(({ id, title }) => ({ value: id, text: title })), + ]} + value={activeIndexPatternId || ''} onChange={e => onIndexPatternSelect(e.target.value)} /> diff --git a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx index a53bad9e30522..75ddaf390df3e 100644 --- a/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx +++ b/examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx @@ -27,6 +27,13 @@ import { DASHBOARD_TO_DISCOVER_DRILLDOWN } from './constants'; import { DrilldownDefinition as Drilldown } from '../../../../x-pack/plugins/drilldowns/public'; import { txtGoToDiscover } from './i18n'; +const isOutputWithIndexPatterns = ( + output: unknown +): output is { indexPatterns: Array<{ id: string }> } => { + if (!output || typeof output !== 'object') return false; + return Array.isArray((output as any).indexPatterns); +}; + export interface Params { start: StartServicesGetter>; } @@ -60,7 +67,22 @@ export class DashboardToDiscoverDrilldown return true; }; - public readonly execute = () => { - alert('Go to discover!'); + public readonly execute = async (config: Config, context: ActionContext) => { + let indexPatternId = + !!config.customIndexPattern && !!config.indexPatternId ? config.indexPatternId : ''; + + if (!indexPatternId && !!context.embeddable) { + const output = context.embeddable!.getOutput(); + if (isOutputWithIndexPatterns(output) && output.indexPatterns.length > 0) { + indexPatternId = output.indexPatterns[0].id; + } + } + + const index = indexPatternId ? `,index:'${indexPatternId}'` : ''; + const path = `#/discover?_g=(filters:!(),refreshInterval:(pause:!f,value:900000),time:(from:now-7d,to:now))&_a=(columns:!(_source),filters:!()${index},interval:auto,query:(language:kuery,query:''),sort:!())`; + + await this.params.start().core.application.navigateToApp('kibana', { + path, + }); }; } From 8f72315e740d37f43151a853ce0147d7a0f22845 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 16 Apr 2020 13:48:47 +0200 Subject: [PATCH 09/11] =?UTF-8?q?chore:=20=F0=9F=A4=96=20fix=20type=20chec?= =?UTF-8?q?k=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ui_action_examples/public/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/ui_action_examples/public/index.ts b/examples/ui_action_examples/public/index.ts index 88a36d278e256..5b08192a1196e 100644 --- a/examples/ui_action_examples/public/index.ts +++ b/examples/ui_action_examples/public/index.ts @@ -18,9 +18,8 @@ */ import { UiActionExamplesPlugin } from './plugin'; -import { PluginInitializer } from '../../../src/core/public'; -export const plugin: PluginInitializer = () => new UiActionExamplesPlugin(); +export const plugin = () => new UiActionExamplesPlugin(); export { HELLO_WORLD_TRIGGER_ID } from './hello_world_trigger'; export { ACTION_HELLO_WORLD } from './hello_world_action'; From fd96937edcd2d4d621ba55399edaa6da4b4f7fa5 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 16 Apr 2020 13:54:26 +0200 Subject: [PATCH 10/11] =?UTF-8?q?fix:=20=F0=9F=90=9B=20make=20index=20patt?= =?UTF-8?q?ern=20select=20full=20width?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discover_drilldown_config/discover_drilldown_config.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx index 737f9e3ae1f89..b414db9479a60 100644 --- a/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx +++ b/examples/ui_action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx @@ -62,10 +62,11 @@ export const DiscoverDrilldownConfig: React.FC = ( /> {!!customIndexPattern && ( - + ({ value: id, text: title })), From b20fd1e58568f0c3314a72f4f10f40fb48af7abb Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 16 Apr 2020 14:01:24 +0200 Subject: [PATCH 11/11] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20getHref=20sup?= =?UTF-8?q?port?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/drilldowns/public/services/drilldown_service.ts | 2 ++ x-pack/plugins/drilldowns/public/types.ts | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/x-pack/plugins/drilldowns/public/services/drilldown_service.ts b/x-pack/plugins/drilldowns/public/services/drilldown_service.ts index ee139443e8076..12ad507c86ff8 100644 --- a/x-pack/plugins/drilldowns/public/services/drilldown_service.ts +++ b/x-pack/plugins/drilldowns/public/services/drilldown_service.ts @@ -46,6 +46,7 @@ export class DrilldownService { getDisplayName, euiIcon, execute, + getHref, }: DrilldownDefinition) => { const actionFactory: ActionFactoryDefinition< Config, @@ -66,6 +67,7 @@ export class DrilldownService { getIconType: () => euiIcon, getDisplayName: () => serializedAction.name, execute: async context => await execute(serializedAction.config, context), + getHref: getHref ? context => getHref(serializedAction.config, context) : undefined, }), } as ActionFactoryDefinition< Config, diff --git a/x-pack/plugins/drilldowns/public/types.ts b/x-pack/plugins/drilldowns/public/types.ts index 40bbc95c345de..fc7fb53091c93 100644 --- a/x-pack/plugins/drilldowns/public/types.ts +++ b/x-pack/plugins/drilldowns/public/types.ts @@ -105,6 +105,11 @@ export interface DrilldownDefinition< * `UIAction` of this drilldown is being executed in. */ execute(config: Config, context: ExecutionContext): void; + + /** + * A link where drilldown should navigate on middle click or Ctrl + click. + */ + getHref?(config: Config, context: ExecutionContext): string | undefined; } /**