Skip to content

Commit

Permalink
Generalize dashboard panel actions to not be dashboard specific (#22775
Browse files Browse the repository at this point in the history
…) (#22829)
  • Loading branch information
stacey-gammon committed Sep 7, 2018
1 parent e3865d5 commit 64db863
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 75 deletions.
4 changes: 2 additions & 2 deletions src/core_plugins/kibana/public/dashboard/dashboard_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { migrateLegacyQuery } from 'ui/utils/migrateLegacyQuery';
import * as filterActions from 'ui/doc_table/actions/filter';
import { FilterManagerProvider } from 'ui/filter_manager';
import { EmbeddableFactoriesRegistryProvider } from 'ui/embeddable/embeddable_factories_registry';
import { DashboardPanelActionsRegistryProvider } from 'ui/dashboard_panel_actions/dashboard_panel_actions_registry';
import { ContextMenuActionsRegistryProvider } from 'ui/embeddable';
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
import { timefilter } from 'ui/timefilter';
import { getUnhashableStatesProvider } from 'ui/state_management/state_hashing';
Expand Down Expand Up @@ -84,7 +84,7 @@ app.directive('dashboardApp', function ($injector) {
const filterBar = Private(FilterBarQueryFilterProvider);
const docTitle = Private(DocTitleProvider);
const embeddableFactories = Private(EmbeddableFactoriesRegistryProvider);
const panelActionsRegistry = Private(DashboardPanelActionsRegistryProvider);
const panelActionsRegistry = Private(ContextMenuActionsRegistryProvider);
const getUnhashableStates = Private(getUnhashableStatesProvider);

panelActionsStore.initializeFromRegistry(panelActionsRegistry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { EuiIcon } from '@elastic/eui';
import React from 'react';
import { DashboardContextMenuPanel, DashboardPanelAction } from 'ui/dashboard_panel_actions';
import { ContextMenuAction, ContextMenuPanel } from 'ui/embeddable';
import { DashboardViewMode } from '../../../dashboard_view_mode';
import { PanelOptionsMenuForm } from '../panel_options_menu_form';

Expand All @@ -33,15 +33,15 @@ export function getCustomizePanelAction({
onUpdatePanelTitle: (title: string) => void;
closeContextMenu: () => void;
title?: string;
}): DashboardPanelAction {
return new DashboardPanelAction(
}): ContextMenuAction {
return new ContextMenuAction(
{
displayName: 'Customize panel',
id: 'customizePanel',
parentPanelId: 'mainMenu',
},
{
childContextMenuPanel: new DashboardContextMenuPanel(
childContextMenuPanel: new ContextMenuPanel(
{
id: 'panelSubOptionsMenu',
title: 'Customize panel',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import React from 'react';

import { EuiIcon } from '@elastic/eui';

import { DashboardPanelAction } from 'ui/dashboard_panel_actions';
import { ContextMenuAction } from 'ui/embeddable';
import { DashboardViewMode } from '../../../dashboard_view_mode';

/**
*
* @return {DashboardPanelAction}
* @return {ContextMenuAction}
*/
export function getEditPanelAction() {
return new DashboardPanelAction(
return new ContextMenuAction(
{
displayName: 'Edit visualization',
id: 'editPanel',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import React from 'react';

import { EuiIcon } from '@elastic/eui';

import { DashboardPanelAction } from 'ui/dashboard_panel_actions';
import { ContextMenuAction } from 'ui/embeddable';
import { Inspector } from 'ui/inspector';

/**
* Returns the dashboard panel action for opening an inspector for a specific panel.
* This will check if the embeddable inside the panel actually exposes inspector adapters
* via its embeddable.getInspectorAdapters() method. If so - and if an inspector
* could be shown for those adapters - the inspector icon will be visible.
* @return {DashboardPanelAction}
* @return {ContextMenuAction}
*/
export function getInspectorPanelAction({
closeContextMenu,
Expand All @@ -38,7 +38,7 @@ export function getInspectorPanelAction({
closeContextMenu: () => void;
panelTitle?: string;
}) {
return new DashboardPanelAction(
return new ContextMenuAction(
{
id: 'openInspector',
displayName: 'Inspect',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
import { EuiIcon } from '@elastic/eui';
import React from 'react';

import { DashboardPanelAction } from 'ui/dashboard_panel_actions';
import { ContextMenuAction } from 'ui/embeddable';
import { DashboardViewMode } from '../../../dashboard_view_mode';

/**
*
* @param {function} onDeletePanel
* @return {DashboardPanelAction}
* @return {ContextMenuAction}
*/
export function getRemovePanelAction(onDeletePanel: () => void) {
return new DashboardPanelAction(
return new ContextMenuAction(
{
displayName: 'Delete from dashboard',
id: 'deletePanel',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import { EuiIcon } from '@elastic/eui';
import React from 'react';

import { DashboardPanelAction } from 'ui/dashboard_panel_actions';
import { ContextMenuAction } from 'ui/embeddable';

/**
* Returns an action that toggles the panel into maximized or minimized state.
* @param {boolean} isExpanded
* @param {function} toggleExpandedPanel
* @return {DashboardPanelAction}
* @return {ContextMenuAction}
*/
export function getToggleExpandPanelAction({
isExpanded,
Expand All @@ -35,7 +35,7 @@ export function getToggleExpandPanelAction({
isExpanded: boolean;
toggleExpandedPanel: () => void;
}) {
return new DashboardPanelAction(
return new ContextMenuAction(
{
displayName: isExpanded ? 'Minimize' : 'Full screen',
id: 'togglePanel',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

export { getEditPanelAction } from './get_edit_panel_action';
export { getRemovePanelAction } from './get_remove_panel_action';
export { buildEuiContextMenuPanels } from './build_context_menu';
export { getCustomizePanelAction } from './get_customize_panel_action';
export { getToggleExpandPanelAction } from './get_toggle_expand_panel_action';
export { getInspectorPanelAction } from './get_inspector_panel_action';
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@

import { EuiContextMenuPanelDescriptor } from '@elastic/eui';
import { connect } from 'react-redux';
import { ContainerState, Embeddable } from 'ui/embeddable';
import { panelActionsStore } from '../../store/panel_actions_store';
import {
buildEuiContextMenuPanels,
ContainerState,
ContextMenuPanel,
Embeddable,
} from 'ui/embeddable';
import { panelActionsStore } from '../../store/panel_actions_store';
import {
getCustomizePanelAction,
getEditPanelAction,
getInspectorPanelAction,
Expand All @@ -42,7 +46,6 @@ import {
} from '../../actions';

import { Dispatch } from 'redux';
import { DashboardContextMenuPanel } from 'ui/dashboard_panel_actions';
import { CoreKibanaState } from '../../../selectors';
import { DashboardViewMode } from '../../dashboard_view_mode';
import {
Expand Down Expand Up @@ -163,7 +166,7 @@ const mergeProps = (
// Don't build the panels if the pop over is not open, or this gets expensive - this function is called once for
// every panel, every time any state changes.
if (isPopoverOpen) {
const contextMenuPanel = new DashboardContextMenuPanel({
const contextMenuPanel = new ContextMenuPanel({
title: 'Options',
id: 'mainMenu',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
* under the License.
*/

import { DashboardPanelAction } from 'ui/dashboard_panel_actions';
import { ContextMenuAction } from 'ui/embeddable';

class PanelActionsStore {
public actions: DashboardPanelAction[] = [];
public actions: ContextMenuAction[] = [];

/**
*
* @type {IndexedArray} panelActionsRegistry
*/
public initializeFromRegistry(panelActionsRegistry: DashboardPanelAction[]) {
public initializeFromRegistry(panelActionsRegistry: ContextMenuAction[]) {
panelActionsRegistry.forEach(panelAction => {
this.actions.push(panelAction);
});
Expand Down
2 changes: 1 addition & 1 deletion src/core_plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import 'uiExports/savedObjectTypes';
import 'uiExports/fieldFormats';
import 'uiExports/fieldFormatEditors';
import 'uiExports/navbarExtensions';
import 'uiExports/dashboardPanelActions';
import 'uiExports/contextMenuActions';
import 'uiExports/managementSections';
import 'uiExports/devTools';
import 'uiExports/docViews';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@

import { EuiContextMenuPanelDescriptor, EuiContextMenuPanelItemDescriptor } from '@elastic/eui';
import _ from 'lodash';
import { DashboardContextMenuPanel, DashboardPanelAction } from 'ui/dashboard_panel_actions';
import { ContainerState, Embeddable } from 'ui/embeddable';
import { PanelId } from '../../../selectors';
import { ContainerState, ContextMenuAction, ContextMenuPanel, Embeddable } from 'ui/embeddable';

/**
* Loops through allActions and extracts those that belong on the given contextMenuPanelId
* @param {string} contextMenuPanelId
* @param {Array.<DashboardPanelAction>} allActions
* @param {Array.<ContextMenuAction>} allActions
*/
function getActionsForPanel(contextMenuPanelId: PanelId, allActions: DashboardPanelAction[]) {
function getActionsForPanel(contextMenuPanelId: string, allActions: ContextMenuAction[]) {
return allActions.filter(action => action.parentPanelId === contextMenuPanelId);
}

/**
* @param {String} contextMenuPanelId
* @param {Array.<DashboardPanelAction>} actions
* @param {Array.<ContextMenuAction>} actions
* @param {Embeddable} embeddable
* @param {ContainerState} containerState
* @return {{
Expand All @@ -50,8 +48,8 @@ function buildEuiContextMenuPanelItemsAndChildPanels({
embeddable,
containerState,
}: {
contextMenuPanelId: PanelId;
actions: DashboardPanelAction[];
contextMenuPanelId: string;
actions: ContextMenuAction[];
embeddable?: Embeddable;
containerState: ContainerState;
}) {
Expand Down Expand Up @@ -90,8 +88,8 @@ function buildEuiContextMenuPanelItemsAndChildPanels({
/**
* Transforms a DashboardContextMenuPanel to the shape EuiContextMenuPanel expects, inserting any registered pluggable
* panel actions.
* @param {DashboardContextMenuPanel} contextMenuPanel
* @param {Array.<DashboardPanelAction>} actions to build the context menu with
* @param {ContextMenuPanel} contextMenuPanel
* @param {Array.<ContextMenuAction>} actions to build the context menu with
* @param {Embeddable} embeddable
* @param {ContainerState} containerState
* @return {EuiContextMenuPanelDescriptor[]} An array of context menu panels to be used in the eui react component.
Expand All @@ -102,8 +100,8 @@ export function buildEuiContextMenuPanels({
embeddable,
containerState,
}: {
contextMenuPanel: DashboardContextMenuPanel;
actions: DashboardPanelAction[];
contextMenuPanel: ContextMenuPanel;
actions: ContextMenuAction[];
embeddable?: Embeddable;
containerState: ContainerState;
}): EuiContextMenuPanelDescriptor[] {
Expand All @@ -128,7 +126,7 @@ export function buildEuiContextMenuPanels({

/**
*
* @param {DashboardPanelAction} action
* @param {ContextMenuAction} action
* @param {ContainerState} containerState
* @param {Embeddable} embeddable
* @return {EuiContextMenuPanelItemDescriptor}
Expand All @@ -138,7 +136,7 @@ function convertPanelActionToContextMenuItem({
containerState,
embeddable,
}: {
action: DashboardPanelAction;
action: ContextMenuAction;
containerState: ContainerState;
embeddable?: Embeddable;
}): EuiContextMenuPanelItemDescriptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* under the License.
*/
import { EuiContextMenuItemIcon } from '@elastic/eui';
import { DashboardContextMenuPanel } from './dashboard_context_menu_panel';
import { ContextMenuPanel } from './context_menu_panel';
import { PanelActionAPI } from './types';

interface DashboardPanelActionOptions {
interface ContextMenuActionOptions {
/**
* An optional action to take when the action is clicked on. Either this or childContextMenuPanel should be
* given.
Expand All @@ -30,7 +30,7 @@ interface DashboardPanelActionOptions {
/**
* An optional child context menu to display when the action is clicked.
*/
childContextMenuPanel?: DashboardContextMenuPanel;
childContextMenuPanel?: ContextMenuPanel;

/**
* Whether this action should be disabled based on the parameters given.
Expand All @@ -47,7 +47,7 @@ interface DashboardPanelActionOptions {
isVisible?: (panelActionAPI: PanelActionAPI) => boolean;

/**
* Determines which DashboardContextMenuPanel this action is displayed on.
* Determines which ContextMenuPanel this action is displayed on.
*/
parentPanelId?: string;

Expand All @@ -57,7 +57,7 @@ interface DashboardPanelActionOptions {
icon?: EuiContextMenuItemIcon;
}

interface DashboardPanelActionsConfig {
interface ContextMenuActionsConfig {
id: string;

/**
Expand All @@ -66,12 +66,12 @@ interface DashboardPanelActionsConfig {
displayName: string;

/**
* Determines which DashboardContextMenuPanel this action is displayed on.
* Determines which ContextMenuPanel this action is displayed on.
*/
parentPanelId: string;
}

export class DashboardPanelAction {
export class ContextMenuAction {
public readonly id: string;

/**
Expand All @@ -87,10 +87,10 @@ export class DashboardPanelAction {
/**
* Optional child context menu to open when the action is clicked.
*/
public readonly childContextMenuPanel?: DashboardContextMenuPanel;
public readonly childContextMenuPanel?: ContextMenuPanel;

/**
* Determines which DashboardContextMenuPanel this action is displayed on.
* Determines which ContextMenuPanel this action is displayed on.
*/
public readonly parentPanelId: string;

Expand All @@ -100,15 +100,12 @@ export class DashboardPanelAction {
* @param {string} config.displayName
* @param {string} config.parentPanelId - set if this action belongs on a nested child panel
* @param {function} options.onClick
* @param {DashboardContextMenuPanel} options.childContextMenuPanel - optional child panel to open when clicked.
* @param {ContextMenuPanel} options.childContextMenuPanel - optional child panel to open when clicked.
* @param {function} options.isDisabled - optionally set a custom disabled function
* @param {function} options.isVisible - optionally set a custom isVisible function
* @param {Element} options.icon
*/
public constructor(
config: DashboardPanelActionsConfig,
options: DashboardPanelActionOptions = {}
) {
public constructor(config: ContextMenuActionsConfig, options: ContextMenuActionOptions = {}) {
this.id = config.id;
this.displayName = config.displayName;
this.parentPanelId = config.parentPanelId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// @ts-ignore: implicit any for JS file
import { uiRegistry } from 'ui/registry/_registry';

export const DashboardPanelActionsRegistryProvider = uiRegistry({
export const ContextMenuActionsRegistryProvider = uiRegistry({
index: ['name'],
name: 'dashboardPanelActions',
name: 'ContextMenuActions',
});
Loading

0 comments on commit 64db863

Please sign in to comment.