1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Cleaning up

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-08-04 13:17:58 +03:00
parent 989549a4f4
commit e80ef2def3
3 changed files with 9 additions and 18 deletions

View File

@ -22,7 +22,6 @@
import EventEmitter from "events";
import type TypedEmitter from "typed-emitter";
import { observable, makeObservable } from "mobx";
import type React from "react";
type ExtractEntityMetadataType<Entity> = Entity extends CatalogEntity<infer Metadata> ? Metadata : never;
type ExtractEntityStatusType<Entity> = Entity extends CatalogEntity<any, infer Status> ? Status : never;
@ -109,7 +108,7 @@ export interface CatalogEntityContextMenu {
/**
* Menu icon
*/
icon?: string | React.ComponentType;
icon?: string;
/**
* OnClick handler
*/
@ -123,7 +122,7 @@ export interface CatalogEntityContextMenu {
}
export interface CatalogEntityAddMenu extends CatalogEntityContextMenu {
icon: string | React.ComponentType;
icon: string;
defaultAction?: boolean;
}

View File

@ -98,7 +98,7 @@ export class CatalogAddButton extends React.Component<CatalogAddButtonProps> {
{ this.menuItems.map((menuItem, index) => {
return <SpeedDialAction
key={index}
icon={typeof menuItem.icon === "string" ? <Icon material={menuItem.icon} /> : <menuItem.icon />}
icon={<Icon material={menuItem.icon}/>}
tooltipTitle={menuItem.title}
onClick={() => menuItem.onClick()}
TooltipClasses={{

View File

@ -31,24 +31,11 @@ import { ConfirmDialog } from "../confirm-dialog";
import { HotbarStore } from "../../../common/hotbar-store";
import { Icon } from "../icon";
import type { CatalogEntityItem } from "./catalog-entity.store";
import { Tooltip } from "@material-ui/core";
export interface CatalogEntityDrawerMenuProps<T extends CatalogEntity> extends MenuActionsProps {
item: CatalogEntityItem<T> | null | undefined;
}
function resolveIcon(item: CatalogEntityContextMenu) {
if (typeof item.icon === "string") {
if (item.icon.includes("<svg")) {
return <Icon title={item.title} svg={item.icon} />;
}
return <Icon title={item.title} material={item.icon} />;
}
return <Tooltip title={item.title}><item.icon /></Tooltip>;
}
@observer
export class CatalogEntityDrawerMenu<T extends CatalogEntity> extends React.Component<CatalogEntityDrawerMenuProps<T>> {
@observable private contextMenu: CatalogEntityContextMenuContext;
@ -99,9 +86,14 @@ export class CatalogEntityDrawerMenu<T extends CatalogEntity> extends React.Comp
continue;
}
const key = menuItem.icon.includes("<svg") ? "svg" : "material";
items.push(
<MenuItem key={menuItem.title} onClick={() => this.onMenuItemClick(menuItem)}>
{resolveIcon(menuItem)}
<Icon
tooltip={menuItem.title}
{...{ [key]: menuItem.icon }}
/>
</MenuItem>
);
}