Skip to content

Commit

Permalink
feat: 🎸 add getHref support
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Apr 23, 2020
1 parent b6e8e51 commit ddd9eb4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions x-pack/examples/ui_actions_enhanced_examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ how a drilldown can be built, all in one file.
`dashboard_to_url_drilldown` is a good starting point for build a drilldown
that navigates somewhere externally.

One can see how middle-click or Ctrl + click behavior could be supported using
`getHref` field.

### `dashboard_to_discover_drilldown`

`dashboard_to_discover_drilldown` shows how a real-world drilldown could look like.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class DashboardToDiscoverDrilldown
return true;
};

public readonly execute = async (config: Config, context: ActionContext) => {
private readonly getPath = async (config: Config, context: ActionContext): Promise<string> => {
let indexPatternId =
!!config.customIndexPattern && !!config.indexPatternId ? config.indexPatternId : '';

Expand All @@ -66,7 +66,15 @@ export class DashboardToDiscoverDrilldown
}

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:!())`;
return `#/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:!())`;
};

public readonly getHref = async (config: Config, context: ActionContext): Promise<string> => {
return `kibana${await this.getPath(config, context)}`;
};

public readonly execute = async (config: Config, context: ActionContext) => {
const path = await this.getPath(config, context);

await this.params.start().core.application.navigateToApp('kibana', {
path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,21 @@ export class DashboardToUrlDrilldown implements Drilldown<Config, PlaceContext,
return !!config.url && typeof config.url === 'string';
};

/**
* `getHref` is need to support mouse middle-click and Cmd + Click behavior
* to open a link in new tab.
*/
public readonly getHref = async (config: Config, context: ActionContext) => {
return config.url;
};

public readonly execute = async (config: Config, context: ActionContext) => {
const url = await this.getHref(config, context);

if (config.openInNewTab) {
window.open(config.url, '_blank');
window.open(url, '_blank');
} else {
window.location.href = config.url;
window.location.href = url;
}
};
}

0 comments on commit ddd9eb4

Please sign in to comment.