Skip to content

Commit

Permalink
fix action order
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Mar 16, 2020
1 parent 94894c1 commit 65f5414
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ReplacePanelActionContext {
export class ReplacePanelAction implements ActionByType<typeof ACTION_REPLACE_PANEL> {
public readonly type = ACTION_REPLACE_PANEL;
public readonly id = ACTION_REPLACE_PANEL;
public order = 11;
public order = 3;

constructor(
private core: CoreStart,
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/embeddable/public/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import { UiActionsSetup } from '../../ui_actions/public';
import {
contextMenuTrigger,
contextMenuDrilldownsTrigger,
createFilterAction,
panelBadgeTrigger,
EmbeddableContext,
CONTEXT_MENU_TRIGGER,
CONTEXT_MENU_DRILLDOWNS_TRIGGER,
PANEL_BADGE_TRIGGER,
ACTION_ADD_PANEL,
ACTION_CUSTOMIZE_PANEL,
Expand All @@ -38,7 +36,6 @@ import {
declare module '../../ui_actions/public' {
export interface TriggerContextMapping {
[CONTEXT_MENU_TRIGGER]: EmbeddableContext;
[CONTEXT_MENU_DRILLDOWNS_TRIGGER]: EmbeddableContext;
[PANEL_BADGE_TRIGGER]: EmbeddableContext;
}

Expand All @@ -58,7 +55,6 @@ declare module '../../ui_actions/public' {
*/
export const bootstrap = (uiActions: UiActionsSetup) => {
uiActions.registerTrigger(contextMenuTrigger);
uiActions.registerTrigger(contextMenuDrilldownsTrigger);
uiActions.registerTrigger(panelBadgeTrigger);

const actionApplyFilter = createFilterAction();
Expand Down
1 change: 0 additions & 1 deletion src/plugins/embeddable/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export {
ContainerInput,
ContainerOutput,
CONTEXT_MENU_TRIGGER,
CONTEXT_MENU_DRILLDOWNS_TRIGGER,
contextMenuTrigger,
ACTION_EDIT_PANEL,
EditPanelAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface ActionContext {
export class EditPanelAction implements Action<ActionContext> {
public readonly type = ACTION_EDIT_PANEL;
public readonly id = ACTION_EDIT_PANEL;
public order = 15;
public order = 50;

constructor(private readonly getEmbeddableFactory: GetEmbeddableFactory) {}

Expand Down
9 changes: 4 additions & 5 deletions src/plugins/embeddable/public/lib/embeddables/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
import { isEqual, cloneDeep } from 'lodash';
import { cloneDeep, isEqual } from 'lodash';
import * as Rx from 'rxjs';
import { Adapters } from '../types';
import { Adapters, ViewMode } from '../types';
import { IContainer } from '../containers';
import { IEmbeddable, EmbeddableInput, EmbeddableOutput } from './i_embeddable';
import { ViewMode } from '../types';
import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable';
import { EmbeddableActionStorage } from './embeddable_action_storage';
import {
UiActionsStart,
UiActionsDynamicActionManager,
UiActionsStart,
} from '../../../../../plugins/ui_actions/public';

function getPanelTitle(input: EmbeddableInput, output: EmbeddableOutput) {
Expand Down
28 changes: 4 additions & 24 deletions src/plugins/embeddable/public/lib/panel/embeddable_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,12 @@ import { EuiContextMenuPanelDescriptor, EuiPanel, htmlIdGenerator } from '@elast
import classNames from 'classnames';
import React from 'react';
import { Subscription } from 'rxjs';
import {
buildContextMenuForActions,
UiActionsService,
Action,
contextMenuSeparatorAction,
} from '../ui_actions';
import { buildContextMenuForActions, UiActionsService, Action } from '../ui_actions';
import { CoreStart, OverlayStart } from '../../../../../core/public';
import { toMountPoint } from '../../../../kibana_react/public';

import { Start as InspectorStartContract } from '../inspector';
import {
CONTEXT_MENU_TRIGGER,
CONTEXT_MENU_DRILLDOWNS_TRIGGER,
PANEL_BADGE_TRIGGER,
EmbeddableContext,
} from '../triggers';
import { CONTEXT_MENU_TRIGGER, PANEL_BADGE_TRIGGER, EmbeddableContext } from '../triggers';
import { IEmbeddable } from '../embeddables/i_embeddable';
import { ViewMode, GetEmbeddableFactory, GetEmbeddableFactories } from '../types';

Expand Down Expand Up @@ -236,15 +226,11 @@ export class EmbeddablePanel extends React.Component<Props, State> {
let regularActions = await this.props.getActions(CONTEXT_MENU_TRIGGER, {
embeddable: this.props.embeddable,
});
let drilldownActions = await this.props.getActions(CONTEXT_MENU_DRILLDOWNS_TRIGGER, {
embeddable: this.props.embeddable,
});

const { disabledActions } = this.props.embeddable.getInput();
if (disabledActions) {
const removeDisabledActions = removeById(disabledActions);
regularActions = regularActions.filter(removeDisabledActions);
drilldownActions = drilldownActions.filter(removeDisabledActions);
}

const createGetUserData = (overlays: OverlayStart) =>
Expand Down Expand Up @@ -283,16 +269,10 @@ export class EmbeddablePanel extends React.Component<Props, State> {
new EditPanelAction(this.props.getEmbeddableFactory),
];

const sortedRegularActions = [...regularActions, ...extraActions].sort(sortByOrderField);
const sortedDrilldownActions = [...drilldownActions].sort(sortByOrderField);
const actions = [
...sortedDrilldownActions,
...(sortedDrilldownActions.length ? [contextMenuSeparatorAction] : []),
...sortedRegularActions,
];
const sortedActions = [...regularActions, ...extraActions].sort(sortByOrderField);

return await buildContextMenuForActions({
actions,
actions: sortedActions,
actionContext: { embeddable: this.props.embeddable },
closeMenu: this.closeMyContextMenuPanel,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ interface ActionContext {
export class CustomizePanelTitleAction implements Action<ActionContext> {
public readonly type = ACTION_CUSTOMIZE_PANEL;
public id = ACTION_CUSTOMIZE_PANEL;
public order = 10;
public order = 40;

constructor(private readonly getDataFromUser: GetUserData) {
this.order = 10;
}
constructor(private readonly getDataFromUser: GetUserData) {}

public getDisplayName() {
return i18n.translate('embeddableApi.customizePanel.action.displayName', {
defaultMessage: 'Customize panel',
defaultMessage: 'Edit panel title',
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface ActionContext {
export class InspectPanelAction implements Action<ActionContext> {
public readonly type = ACTION_INSPECT_PANEL;
public readonly id = ACTION_INSPECT_PANEL;
public order = 10;
public order = 20;

constructor(private readonly inspector: InspectorStartContract) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function hasExpandedPanelInput(
export class RemovePanelAction implements Action<ActionContext> {
public readonly type = REMOVE_PANEL_ACTION;
public readonly id = REMOVE_PANEL_ACTION;
public order = 5;
public order = 1;

constructor() {}

Expand Down
7 changes: 0 additions & 7 deletions src/plugins/embeddable/public/lib/triggers/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ export const contextMenuTrigger: Trigger<'CONTEXT_MENU_TRIGGER'> = {
description: 'Triggered on top-right corner context-menu select.',
};

export const CONTEXT_MENU_DRILLDOWNS_TRIGGER = 'CONTEXT_MENU_DRILLDOWNS_TRIGGER';
export const contextMenuDrilldownsTrigger: Trigger<'CONTEXT_MENU_DRILLDOWNS_TRIGGER'> = {
id: CONTEXT_MENU_DRILLDOWNS_TRIGGER,
title: 'Drilldown context menu',
description: 'Triggered on top-right corner context-menu select.',
};

export const PANEL_BADGE_TRIGGER = 'PANEL_BADGE_TRIGGER';
export const panelBadgeTrigger: Trigger<'PANEL_BADGE_TRIGGER'> = {
id: PANEL_BADGE_TRIGGER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,11 @@
*/

import * as React from 'react';
import {
EuiContextMenuPanelDescriptor,
EuiContextMenuPanelItemDescriptor,
EuiHorizontalRule,
} from '@elastic/eui';
import { EuiContextMenuPanelDescriptor, EuiContextMenuPanelItemDescriptor } from '@elastic/eui';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { uiToReactComponent, reactToUiComponent } from '../../../kibana_react/public';
import { Action, ActionInternal } from '../actions';

export const contextMenuSeparatorAction = new ActionInternal({
id: 'CONTEXT_MENU_SEPARATOR',
getDisplayName: () => 'separator',
MenuItem: reactToUiComponent(() => <EuiHorizontalRule margin={'none'} />),
execute: () => Promise.resolve(),
});
import { uiToReactComponent } from '../../../kibana_react/public';
import { Action } from '../actions';

/**
* Transforms an array of Actions to the shape EuiContextMenuPanel expects.
Expand Down Expand Up @@ -113,12 +102,10 @@ function convertPanelActionToContextMenuItem<Context extends object>({
'data-test-subj': `embeddablePanelAction-${action.id}`,
};

if (action.id !== 'CONTEXT_MENU_SEPARATOR') {
menuPanelItem.onClick = () => {
action.execute(actionContext);
closeMenu();
};
}
menuPanelItem.onClick = () => {
action.execute(actionContext);
closeMenu();
};

if (action.getHref) {
const href = action.getHref(actionContext);
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/ui_actions/public/context_menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@
* under the License.
*/

export {
buildContextMenuForActions,
contextMenuSeparatorAction,
} from './build_eui_context_menu_panels';
export { buildContextMenuForActions } from './build_eui_context_menu_panels';
export { openContextMenu } from './open_context_menu';
2 changes: 1 addition & 1 deletion src/plugins/ui_actions/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export {
SerializedAction as UiActionsSerializedAction,
SerializedEvent as UiActionsSerializedEvent,
} from './actions';
export { buildContextMenuForActions, contextMenuSeparatorAction } from './context_menu';
export { buildContextMenuForActions } from './context_menu';
export {
Presentable as UiActionsPresentable,
Configurable as UiActionsConfigurable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class CustomTimeRangeAction implements ActionByType<typeof CUSTOM_TIME_RA
private dateFormat?: string;
private commonlyUsedRanges: CommonlyUsedRange[];
public readonly id = CUSTOM_TIME_RANGE;
public order = 7;
public order = 30;

constructor({
openModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface OpenFlyoutAddDrilldownParams {
export class FlyoutCreateDrilldownAction implements ActionByType<typeof OPEN_FLYOUT_ADD_DRILLDOWN> {
public readonly type = OPEN_FLYOUT_ADD_DRILLDOWN;
public readonly id = OPEN_FLYOUT_ADD_DRILLDOWN;
public order = 2;
public order = 12;

constructor(protected readonly params: OpenFlyoutAddDrilldownParams) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface FlyoutEditDrilldownParams {
export class FlyoutEditDrilldownAction implements ActionByType<typeof OPEN_FLYOUT_EDIT_DRILLDOWN> {
public readonly type = OPEN_FLYOUT_EDIT_DRILLDOWN;
public readonly id = OPEN_FLYOUT_EDIT_DRILLDOWN;
public order = 1;
public order = 10;

constructor(protected readonly params: FlyoutEditDrilldownParams) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { CoreSetup } from 'src/core/public';
import { SetupDependencies } from '../../plugin';
import {
CONTEXT_MENU_DRILLDOWNS_TRIGGER,
CONTEXT_MENU_TRIGGER,
EmbeddableContext,
} from '../../../../../../src/plugins/embeddable/public';
import {
Expand Down Expand Up @@ -37,11 +37,11 @@ export class DashboardDrilldownsService {

const actionFlyoutCreateDrilldown = new FlyoutCreateDrilldownAction({ overlays, drilldowns });
plugins.uiActions.registerAction(actionFlyoutCreateDrilldown);
plugins.uiActions.attachAction(CONTEXT_MENU_DRILLDOWNS_TRIGGER, actionFlyoutCreateDrilldown);
plugins.uiActions.attachAction(CONTEXT_MENU_TRIGGER, actionFlyoutCreateDrilldown);

const actionFlyoutEditDrilldown = new FlyoutEditDrilldownAction({ overlays, drilldowns });
plugins.uiActions.registerAction(actionFlyoutEditDrilldown);
plugins.uiActions.attachAction(CONTEXT_MENU_DRILLDOWNS_TRIGGER, actionFlyoutEditDrilldown);
plugins.uiActions.attachAction(CONTEXT_MENU_TRIGGER, actionFlyoutEditDrilldown);

const dashboardToDashboardDrilldown = new DashboardToDashboardDrilldown({
savedObjects,
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@
"embeddableApi.addPanel.noMatchingObjectsMessage": "一致するオブジェクトが見つかりませんでした。",
"embeddableApi.addPanel.savedObjectAddedToContainerSuccessMessageTitle": "{savedObjectName} が追加されました",
"embeddableApi.addPanel.Title": "パネルの追加",
"embeddableApi.customizePanel.action.displayName": "パネルをカスタマイズ",
"embeddableApi.customizePanel.modal.cancel": "キャンセル",
"embeddableApi.customizePanel.modal.optionsMenuForm.panelTitleFormRowLabel": "パネルタイトル",
"embeddableApi.customizePanel.modal.optionsMenuForm.panelTitleInputAriaLabel": "パネルのカスタムタイトルを入力してください",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@
"embeddableApi.addPanel.noMatchingObjectsMessage": "未找到任何匹配对象。",
"embeddableApi.addPanel.savedObjectAddedToContainerSuccessMessageTitle": "{savedObjectName} 已添加",
"embeddableApi.addPanel.Title": "添加面板",
"embeddableApi.customizePanel.action.displayName": "定制面板",
"embeddableApi.customizePanel.modal.cancel": "取消",
"embeddableApi.customizePanel.modal.optionsMenuForm.panelTitleFormRowLabel": "面板标题",
"embeddableApi.customizePanel.modal.optionsMenuForm.panelTitleInputAriaLabel": "为面板输入定制标题",
Expand Down

0 comments on commit 65f5414

Please sign in to comment.