Allow embeddable to specify edit label (#36296) (#36399)

* Allow embeddable to specify edit label

* update test plugins

* pass getDisplayName in options parameter to ContextMenuAction constructor in plugin example

* more typescript clean-up magic

* some more typescript error fun

* change maps embeddable edit label i18n prefix

* clean-up localization
This commit is contained in:
Nathan Reese 2019-05-09 15:53:54 -06:00 committed by GitHub
parent 48ddc41d8b
commit 95be609ba4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 88 additions and 45 deletions

View file

@ -37,9 +37,6 @@ export function getCustomizePanelAction({
}): ContextMenuAction {
return new ContextMenuAction(
{
displayName: i18n.translate('kbn.dashboard.panel.customizePanel.displayName', {
defaultMessage: 'Customize panel',
}),
id: 'customizePanel',
parentPanelId: 'mainMenu',
},
@ -64,6 +61,11 @@ export function getCustomizePanelAction({
),
icon: <EuiIcon type="pencil" />,
isVisible: ({ containerState }) => containerState.viewMode === DashboardViewMode.EDIT,
getDisplayName: () => {
return i18n.translate('kbn.dashboard.panel.customizePanel.displayName', {
defaultMessage: 'Customize panel',
});
},
}
);
}

View file

@ -32,9 +32,6 @@ import { DashboardViewMode } from '../../../dashboard_view_mode';
export function getEditPanelAction() {
return new ContextMenuAction(
{
displayName: i18n.translate('kbn.dashboard.panel.editPanel.displayName', {
defaultMessage: 'Edit visualization',
}),
id: 'editPanel',
parentPanelId: 'mainMenu',
},
@ -54,6 +51,15 @@ export function getEditPanelAction() {
return embeddable.metadata.editUrl;
}
},
getDisplayName: ({ embeddable }) => {
if (embeddable && embeddable.metadata.editLabel) {
return embeddable.metadata.editLabel;
}
return i18n.translate('kbn.dashboard.panel.editPanel.defaultDisplayName', {
defaultMessage: 'Edit',
});
},
}
);
}

View file

@ -40,12 +40,14 @@ export function getInspectorPanelAction({
return new ContextMenuAction(
{
id: 'openInspector',
displayName: i18n.translate('kbn.dashboard.panel.inspectorPanel.displayName', {
defaultMessage: 'Inspect',
}),
parentPanelId: 'mainMenu',
},
{
getDisplayName: () => {
return i18n.translate('kbn.dashboard.panel.inspectorPanel.displayName', {
defaultMessage: 'Inspect',
});
},
icon: <EuiIcon type="inspect" />,
isVisible: ({ embeddable }) => {
if (!embeddable) {

View file

@ -32,13 +32,15 @@ import { DashboardViewMode } from '../../../dashboard_view_mode';
export function getRemovePanelAction(onDeletePanel: () => void) {
return new ContextMenuAction(
{
displayName: i18n.translate('kbn.dashboard.panel.removePanel.displayName', {
defaultMessage: 'Delete from dashboard',
}),
id: 'deletePanel',
parentPanelId: 'mainMenu',
},
{
getDisplayName: () => {
return i18n.translate('kbn.dashboard.panel.removePanel.displayName', {
defaultMessage: 'Delete from dashboard',
});
},
icon: <EuiIcon type="trash" />,
isVisible: ({ containerState }) =>
containerState.viewMode === DashboardViewMode.EDIT && !containerState.isPanelExpanded,

View file

@ -38,17 +38,19 @@ export function getToggleExpandPanelAction({
}) {
return new ContextMenuAction(
{
displayName: isExpanded
? i18n.translate('kbn.dashboard.panel.toggleExpandPanel.expandedDisplayName', {
defaultMessage: 'Minimize',
})
: i18n.translate('kbn.dashboard.panel.toggleExpandPanel.notExpandedDisplayName', {
defaultMessage: 'Full screen',
}),
id: 'togglePanel',
parentPanelId: 'mainMenu',
},
{
getDisplayName: () => {
return isExpanded
? i18n.translate('kbn.dashboard.panel.toggleExpandPanel.expandedDisplayName', {
defaultMessage: 'Minimize',
})
: i18n.translate('kbn.dashboard.panel.toggleExpandPanel.notExpandedDisplayName', {
defaultMessage: 'Full screen',
});
},
// TODO: Update to minimize icon when https://github.com/elastic/eui/issues/837 is complete.
icon: <EuiIcon type={isExpanded ? 'expand' : 'expand'} />,
onClick: toggleExpandedPanel,

View file

@ -19,6 +19,7 @@
import angular from 'angular';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { SearchSource } from 'ui/courier';
import {
ContainerState,
@ -89,6 +90,9 @@ export class SearchEmbeddable extends Embeddable {
super({
title: savedSearch.title,
editUrl,
editLabel: i18n.translate('kbn.embeddable.search.editLabel', {
defaultMessage: 'Edit saved search',
}),
editable,
indexPatterns: _.compact([savedSearch.searchSource.getField('index')]),
});

View file

@ -30,6 +30,7 @@ import {
VisualizeLoaderParams,
VisualizeUpdateParams,
} from 'ui/visualize/loader/types';
import { i18n } from '@kbn/i18n';
export interface VisualizeEmbeddableConfiguration {
onEmbeddableStateChanged: OnEmbeddableStateChanged;
@ -63,6 +64,9 @@ export class VisualizeEmbeddable extends Embeddable {
super({
title: savedVisualization.title,
editUrl,
editLabel: i18n.translate('kbn.embeddable.visualize.editLabel', {
defaultMessage: 'Edit visualization',
}),
editable,
indexPatterns,
});

View file

@ -141,7 +141,7 @@ function convertPanelActionToContextMenuItem({
embeddable?: Embeddable;
}): EuiContextMenuPanelItemDescriptor {
const menuPanelItem: EuiContextMenuPanelItemDescriptor = {
name: action.displayName,
name: action.getDisplayName({ embeddable, containerState }),
icon: action.icon,
panel: _.get(action, 'childContextMenuPanel.id'),
disabled: action.isDisabled({ embeddable, containerState }),

View file

@ -49,6 +49,11 @@ interface ContextMenuActionOptions {
* Optional icon to display to the left of the action.
*/
icon?: EuiContextMenuItemIcon;
/**
* Return display name of the action in the menu
*/
getDisplayName: (actionAPI: PanelActionAPI) => string;
}
interface ContextMenuButtonOptions extends ContextMenuActionOptions {
@ -69,11 +74,6 @@ interface ContextMenuLinkOptions extends ContextMenuActionOptions {
interface ContextMenuActionsConfig {
id: string;
/**
* Display name of the action in the menu
*/
displayName: string;
/**
* Determines which ContextMenuPanel this action is displayed on.
*/
@ -88,11 +88,6 @@ export class ContextMenuAction {
*/
public readonly icon?: EuiContextMenuItemIcon;
/**
* Display name of the action in the menu
*/
public readonly displayName: string;
/**
* Optional child context menu to open when the action is clicked.
*/
@ -113,28 +108,33 @@ export class ContextMenuAction {
*/
public readonly getHref?: (panelActionAPI: PanelActionAPI) => string;
/**
* @param {PanelActionAPI} panelActionAPI
*/
public readonly getDisplayName: (panelActionAPI: PanelActionAPI) => string;
/**
*
* @param {string} config.id
* @param {string} config.displayName
* @param {string} config.parentPanelId - set if this action belongs on a nested child panel
* @param {function} options.onClick
* @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 {function} options.getHref
* @param {function} options.getDisplayName
* @param {Element} options.icon
*/
public constructor(
config: ContextMenuActionsConfig,
options: ContextMenuButtonOptions | ContextMenuLinkOptions = {}
options: ContextMenuButtonOptions | ContextMenuLinkOptions
) {
this.id = config.id;
this.displayName = config.displayName;
this.parentPanelId = config.parentPanelId;
this.icon = options.icon;
this.childContextMenuPanel = options.childContextMenuPanel;
this.getDisplayName = options.getDisplayName;
if ('onClick' in options) {
this.onClick = options.onClick;

View file

@ -40,6 +40,8 @@ export interface EmbeddableMetadata {
*/
editUrl?: string;
editLabel?: string;
/**
* A flag indicating if this embeddable can be edited.
*/

View file

@ -28,11 +28,17 @@ import {
class SamplePanelAction extends ContextMenuAction {
constructor() {
super({
displayName: 'Sample Panel Action',
id: 'samplePanelAction',
parentPanelId: 'mainMenu',
});
super(
{
id: 'samplePanelAction',
parentPanelId: 'mainMenu',
},
{
getDisplayName: () => {
return 'Sample Panel Action';
},
}
);
}
public onClick = ({ embeddable }: PanelActionAPI) => {
if (!embeddable) {

View file

@ -20,11 +20,17 @@ import { ContextMenuAction, ContextMenuActionsRegistryProvider } from 'ui/embedd
class SamplePanelLink extends ContextMenuAction {
constructor() {
super({
displayName: 'Sample Panel Link',
id: 'samplePanelLink',
parentPanelId: 'mainMenu',
});
super(
{
id: 'samplePanelLink',
parentPanelId: 'mainMenu',
},
{
getDisplayName: () => {
return 'Sample Panel Link';
},
}
);
}
public getHref = () => {

View file

@ -34,6 +34,7 @@ import {
} from '../store/ui';
import { getInspectorAdapters } from '../store/non_serializable_instances';
import { getMapCenter, getMapZoom } from '../selectors/map_selectors';
import { i18n } from '@kbn/i18n';
export class MapEmbeddable extends Embeddable {
@ -45,7 +46,14 @@ export class MapEmbeddable extends Embeddable {
editable,
indexPatterns = []
}) {
super({ title: savedMap.title, editUrl, editable, indexPatterns });
super({
title: savedMap.title,
editUrl,
editLabel: i18n.translate('xpack.maps.embeddable.editLabel', {
defaultMessage: 'Edit map',
}),
editable,
indexPatterns });
this._onEmbeddableStateChanged = onEmbeddableStateChanged;
this._embeddableConfig = _.cloneDeep(embeddableConfig);

View file

@ -1113,7 +1113,6 @@
"kbn.dashboard.panel.customizePanel.displayName": "定制面板",
"kbn.dashboard.panel.customizePanelTitle": "定制面板",
"kbn.dashboard.panel.dashboardPanelAriaLabel": "仪表板面板:{title}",
"kbn.dashboard.panel.editPanel.displayName": "编辑可视化",
"kbn.dashboard.panel.inspectorPanel.displayName": "检查",
"kbn.dashboard.panel.invalidVersionErrorMessage": "版本 {version} 无效,应为 {semver}",
"kbn.dashboard.panel.noFoundEmbeddableFactoryErrorMessage": "未找到面板类型 {panelType} 的 Embeddable 工厂",