Skip to content

Commit

Permalink
switch to icon type string instead of node (#43111)
Browse files Browse the repository at this point in the history
* switch to icon type string instead of node. Some EUI components only take the string.

* Fix lint errors

* another type fix
  • Loading branch information
stacey-gammon authored Aug 12, 2019
1 parent 3503aa1 commit 4cfcad4
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ test('Returns title', async () => {

test('Returns an icon', async () => {
const action = new ExpandPanelAction();
expect(action.getIcon({ embeddable })).toBeDefined();
expect(action.getIconType({ embeddable })).toBeDefined();
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
* under the License.
*/

import { EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import {
Action,
IEmbeddable,
Expand Down Expand Up @@ -70,12 +68,12 @@ export class ExpandPanelAction extends Action {
);
}

public getIcon({ embeddable }: ActionContext) {
public getIconType({ embeddable }: ActionContext) {
if (!embeddable.parent || !isDashboard(embeddable.parent)) {
throw new IncompatibleActionError();
}
// TODO: use 'minimize' when an eui-icon of such is available.
return <EuiIcon type={isExpanded(embeddable) ? 'expand' : 'expand'} />;
return isExpanded(embeddable) ? 'expand' : 'expand';
}

public async isCompatible({ embeddable }: ActionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

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

import { IEmbeddable } from '../embeddables';

export interface ActionContext<
Expand All @@ -43,11 +41,9 @@ export abstract class Action<
constructor(public readonly id: string) {}

/**
* Optional icon that can be displayed along with the title.
* Optional EUI icon type that can be displayed along with the title.
*/
public getIcon(
context: ActionContext<TEmbeddable, TTriggerContext>
): EuiContextMenuItemIcon | undefined {
public getIconType(context: ActionContext<TEmbeddable, TTriggerContext>): string | undefined {
return undefined;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
* under the License.
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiIcon } from '@elastic/eui';
import { Action, ActionContext } from './action';
import { GetEmbeddableFactory, ViewMode } from '../types';
import { EmbeddableFactoryNotFoundError } from '../errors';
Expand All @@ -46,8 +44,8 @@ export class EditPanelAction extends Action {
});
}

getIcon() {
return <EuiIcon type="pencil" />;
getIconType() {
return 'pencil';
}

public async isCompatible({ embeddable }: ActionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function convertPanelActionToContextMenuItem({
}): EuiContextMenuPanelItemDescriptor {
const menuPanelItem: EuiContextMenuPanelItemDescriptor = {
name: action.getDisplayName(actionContext),
icon: action.getIcon(actionContext),
icon: action.getIconType(actionContext),
panel: _.get(action, 'childContextMenuPanel.id'),
'data-test-subj': `embeddablePanelAction-${action.id}`,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ test('Returns title', async () => {
});

test('Returns an icon', async () => {
expect(action.getIcon()).toBeDefined();
expect(action.getIconType()).toBeDefined();
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/

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

import { i18n } from '@kbn/i18n';
import { ViewMode, GetEmbeddableFactory, GetEmbeddableFactories } from '../../../../types';
import { Action, ActionContext } from '../../../../actions';
Expand Down Expand Up @@ -47,8 +43,8 @@ export class AddPanelAction extends Action {
});
}

public getIcon() {
return <EuiIcon type="plusInCircleFilled" />;
public getIconType() {
return 'plusInCircleFilled';
}

public async isCompatible({ embeddable }: ActionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import { EuiIcon } from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { Action, ActionContext } from '../../../../actions';
import { ViewMode } from '../../../../types';
Expand All @@ -41,8 +39,8 @@ export class CustomizePanelTitleAction extends Action {
});
}

public getIcon() {
return <EuiIcon type="pencil" />;
public getIconType() {
return 'pencil';
}

public async isCompatible({ embeddable }: ActionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,5 @@ test('Returns title', async () => {
test('Returns an icon', async () => {
const inspector = inspectorPluginMock.createStartContract();
const inspectAction = new InspectPanelAction(inspector);
expect(inspectAction.getIcon()).toMatchInlineSnapshot(`
<EuiIcon
type="inspect"
/>
`);
expect(inspectAction.getIconType()).toBe('inspect');
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import { EuiIcon } from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { Action, ActionContext } from '../../../actions';
import { Start as InspectorStartContract } from '../../../../../../../../../../plugins/inspector/public';
Expand All @@ -39,8 +37,8 @@ export class InspectPanelAction extends Action {
});
}

public getIcon() {
return <EuiIcon type="inspect" />;
public getIconType() {
return 'inspect';
}

public async isCompatible({ embeddable }: ActionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test('Returns title', async () => {
expect(action.getDisplayName()).toBeDefined();
});

test('Returns an icon', async () => {
test('Returns an icon type', async () => {
const action = new RemovePanelAction();
expect(action.getIcon()).toBeDefined();
expect(action.getIconType()).toBeDefined();
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiIcon } from '@elastic/eui';
import { ContainerInput, IContainer } from '../../../containers';
import { ViewMode } from '../../../types';
import { Action, ActionContext } from '../../../actions';
Expand Down Expand Up @@ -50,8 +48,8 @@ export class RemovePanelAction extends Action {
});
}

public getIcon() {
return <EuiIcon type="trash" />;
public getIconType() {
return 'trash';
}

public async isCompatible({ embeddable }: ActionContext) {
Expand Down

0 comments on commit 4cfcad4

Please sign in to comment.