-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Drilldown demo #63684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Drilldown demo #63684
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c68a846
chore: 🤖 add example of Discover drilldown to sample plugin
streamich 9659d34
fix: 🐛 show drilldowns with higher "order" first
streamich 5ada60f
feat: 🎸 add createStartServicesGetter() to /public kibana_util
streamich aa103a1
feat: 🎸 load index patterns in Discover drilldown
streamich 4adecf0
feat: 🎸 add toggle for index pattern selection
streamich f8006ae
feat: 🎸 add spacer to separate unrelated config fields
streamich c894caa
fix: 🐛 correctly configre setup core
streamich ab3deb7
feat: 🎸 navigate to correct index pattern
streamich 8f72315
chore: 🤖 fix type check errors
streamich fd96937
fix: 🐛 make index pattern select full width
streamich b20fd1e
fix: 🐛 add getHref support
streamich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
105 changes: 105 additions & 0 deletions
105
...action_examples/public/components/discover_drilldown_config/discover_drilldown_config.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * 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, EuiSpacer } from '@elastic/eui'; | ||
| import { txtChooseDestinationIndexPattern } from './i18n'; | ||
|
|
||
| export interface IndexPatternItem { | ||
| id: string; | ||
| title: string; | ||
| } | ||
|
|
||
| export interface DiscoverDrilldownConfigProps { | ||
| activeIndexPatternId?: string; | ||
| indexPatterns: IndexPatternItem[]; | ||
| onIndexPatternSelect: (indexPatternId: string) => void; | ||
| customIndexPattern?: boolean; | ||
| onCustomIndexPatternToggle?: () => void; | ||
| carryFiltersAndQuery?: boolean; | ||
| onCarryFiltersAndQueryToggle?: () => void; | ||
| carryTimeRange?: boolean; | ||
| onCarryTimeRangeToggle?: () => void; | ||
| } | ||
|
|
||
| export const DiscoverDrilldownConfig: React.FC<DiscoverDrilldownConfigProps> = ({ | ||
| activeIndexPatternId, | ||
| indexPatterns, | ||
| onIndexPatternSelect, | ||
| customIndexPattern, | ||
| onCustomIndexPatternToggle, | ||
| carryFiltersAndQuery, | ||
| onCarryFiltersAndQueryToggle, | ||
| carryTimeRange, | ||
| onCarryTimeRangeToggle, | ||
| }) => { | ||
| return ( | ||
| <> | ||
| {!!onCustomIndexPatternToggle && ( | ||
| <> | ||
| <EuiFormRow hasChildLabel={false}> | ||
| <EuiSwitch | ||
| name="customIndexPattern" | ||
| label="Use custom index pattern" | ||
| checked={!!customIndexPattern} | ||
| onChange={onCustomIndexPatternToggle} | ||
| /> | ||
| </EuiFormRow> | ||
| {!!customIndexPattern && ( | ||
| <EuiFormRow fullWidth label={txtChooseDestinationIndexPattern}> | ||
| <EuiSelect | ||
| name="selectDashboard" | ||
| hasNoInitialSelection={true} | ||
| fullWidth | ||
| options={[ | ||
| { id: '', text: 'Pick one...' }, | ||
| ...indexPatterns.map(({ id, title }) => ({ value: id, text: title })), | ||
| ]} | ||
| value={activeIndexPatternId || ''} | ||
| onChange={e => onIndexPatternSelect(e.target.value)} | ||
| /> | ||
| </EuiFormRow> | ||
| )} | ||
| <EuiSpacer size="xl" /> | ||
| </> | ||
| )} | ||
|
|
||
| {!!onCarryFiltersAndQueryToggle && ( | ||
| <EuiFormRow hasChildLabel={false}> | ||
| <EuiSwitch | ||
| name="carryFiltersAndQuery" | ||
| label="Carry over filters and query" | ||
| checked={!!carryFiltersAndQuery} | ||
| onChange={onCarryFiltersAndQueryToggle} | ||
| /> | ||
| </EuiFormRow> | ||
| )} | ||
| {!!onCarryTimeRangeToggle && ( | ||
| <EuiFormRow hasChildLabel={false}> | ||
| <EuiSwitch | ||
| name="carryTimeRange" | ||
| label="Carry over time range" | ||
| checked={!!carryTimeRange} | ||
| onChange={onCarryTimeRangeToggle} | ||
| /> | ||
| </EuiFormRow> | ||
| )} | ||
| </> | ||
| ); | ||
| }; |
27 changes: 27 additions & 0 deletions
27
examples/ui_action_examples/public/components/discover_drilldown_config/i18n.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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', | ||
| } | ||
| ); |
20 changes: 20 additions & 0 deletions
20
examples/ui_action_examples/public/components/discover_drilldown_config/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'; |
84 changes: 84 additions & 0 deletions
84
examples/ui_action_examples/public/dashboard_to_discover_drilldown/collect_config.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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 useMountedState from 'react-use/lib/useMountedState'; | ||
| import { CollectConfigProps } from './types'; | ||
| import { DiscoverDrilldownConfig, IndexPatternItem } from '../components/discover_drilldown_config'; | ||
| import { Params } from './drilldown'; | ||
|
|
||
| export interface CollectConfigContainerProps extends CollectConfigProps { | ||
| params: Params; | ||
| } | ||
|
|
||
| export const CollectConfigContainer: React.FC<CollectConfigContainerProps> = ({ | ||
| config, | ||
| onConfig, | ||
| params: { start }, | ||
| }) => { | ||
| const isMounted = useMountedState(); | ||
| const [indexPatterns, setIndexPatterns] = useState<IndexPatternItem[]>([]); | ||
|
|
||
| useEffect(() => { | ||
| (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 ( | ||
| <DiscoverDrilldownConfig | ||
| activeIndexPatternId={config.indexPatternId} | ||
| indexPatterns={indexPatterns} | ||
| onIndexPatternSelect={indexPatternId => { | ||
| onConfig({ ...config, indexPatternId }); | ||
| }} | ||
| customIndexPattern={config.customIndexPattern} | ||
| onCustomIndexPatternToggle={() => | ||
| onConfig({ | ||
| ...config, | ||
| customIndexPattern: !config.customIndexPattern, | ||
| indexPatternId: undefined, | ||
| }) | ||
| } | ||
| carryFiltersAndQuery={config.carryFiltersAndQuery} | ||
| onCarryFiltersAndQueryToggle={() => | ||
| onConfig({ | ||
| ...config, | ||
| carryFiltersAndQuery: !config.carryFiltersAndQuery, | ||
| }) | ||
| } | ||
| carryTimeRange={config.carryTimeRange} | ||
| onCarryTimeRangeToggle={() => | ||
| onConfig({ | ||
| ...config, | ||
| carryTimeRange: !config.carryTimeRange, | ||
| }) | ||
| } | ||
| /> | ||
| ); | ||
| }; |
20 changes: 20 additions & 0 deletions
20
examples/ui_action_examples/public/dashboard_to_discover_drilldown/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'; |
88 changes: 88 additions & 0 deletions
88
examples/ui_action_examples/public/dashboard_to_discover_drilldown/drilldown.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * 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 { 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'; | ||
| 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<Pick<Start, 'data'>>; | ||
| } | ||
|
|
||
| export class DashboardToDiscoverDrilldown | ||
| implements Drilldown<Config, PlaceContext, ActionContext> { | ||
| constructor(protected readonly params: Params) {} | ||
|
|
||
| public readonly id = DASHBOARD_TO_DISCOVER_DRILLDOWN; | ||
|
|
||
| public readonly order = 50; | ||
|
|
||
| public readonly getDisplayName = () => txtGoToDiscover; | ||
|
|
||
| public readonly euiIcon = 'discoverApp'; | ||
|
|
||
| private readonly ReactCollectConfig: React.FC<CollectConfigProps> = props => ( | ||
| <CollectConfigContainer {...props} params={this.params} /> | ||
| ); | ||
|
|
||
| public readonly CollectConfig = reactToUiComponent(this.ReactCollectConfig); | ||
|
|
||
| public readonly createConfig = () => ({ | ||
| customIndexPattern: false, | ||
| carryFiltersAndQuery: true, | ||
| carryTimeRange: true, | ||
| }); | ||
|
|
||
| public readonly isConfigValid = (config: Config): config is Config => { | ||
| if (config.customIndexPattern && !config.indexPatternId) return false; | ||
| return true; | ||
| }; | ||
|
|
||
| public readonly execute = async (config: Config, context: ActionContext) => { | ||
streamich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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, | ||
| }); | ||
| }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.