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

Setting background for hotbar icon explicitly

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-06-18 11:47:55 +03:00
parent 2f92e80e08
commit 724bd14218
12 changed files with 45 additions and 22 deletions

View File

@ -25,7 +25,6 @@ import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
type GeneralEntitySpec = { type GeneralEntitySpec = {
path: string; path: string;
materialIcon?: string;
} & CatalogEntitySpec; } & CatalogEntitySpec;
export class GeneralEntity extends CatalogEntity<CatalogEntityMetadata, CatalogEntityStatus, GeneralEntitySpec> { export class GeneralEntity extends CatalogEntity<CatalogEntityMetadata, CatalogEntityStatus, GeneralEntitySpec> {

View File

@ -28,6 +28,7 @@ import { productName } from "../vars";
import { CatalogCategory, CatalogCategorySpec } from "../catalog"; import { CatalogCategory, CatalogCategorySpec } from "../catalog";
import { addClusterURL } from "../routes"; import { addClusterURL } from "../routes";
import { app } from "electron"; import { app } from "electron";
import type { CatalogEntitySpec } from "../catalog/catalog-entity";
export type KubernetesClusterPrometheusMetrics = { export type KubernetesClusterPrometheusMetrics = {
address?: { address?: {
@ -42,12 +43,11 @@ export type KubernetesClusterPrometheusMetrics = {
export type KubernetesClusterSpec = { export type KubernetesClusterSpec = {
kubeconfigPath: string; kubeconfigPath: string;
kubeconfigContext: string; kubeconfigContext: string;
iconData?: string;
metrics?: { metrics?: {
source: string; source: string;
prometheus?: KubernetesClusterPrometheusMetrics; prometheus?: KubernetesClusterPrometheusMetrics;
} }
}; } & CatalogEntitySpec;
export interface KubernetesClusterStatus extends CatalogEntityStatus { export interface KubernetesClusterStatus extends CatalogEntityStatus {
phase: "connected" | "disconnected"; phase: "connected" | "disconnected";

View File

@ -142,7 +142,13 @@ export interface CatalogEntityAddMenuContext {
menuItems: CatalogEntityAddMenu[]; menuItems: CatalogEntityAddMenu[];
} }
export type CatalogEntitySpec = Record<string, any>; export type CatalogEntitySpec = {
icon?: {
src?: string;
material?: string;
background?: string;
}
} & Record<string, any>;
export interface CatalogEntityData< export interface CatalogEntityData<
Metadata extends CatalogEntityMetadata = CatalogEntityMetadata, Metadata extends CatalogEntityMetadata = CatalogEntityMetadata,

View File

@ -34,7 +34,10 @@ const generalEntities = observable([
}, },
spec: { spec: {
path: catalogURL(), path: catalogURL(),
materialIcon: "view_list", icon: {
material: "view_list",
background: "#3d90ce"
}
}, },
status: { status: {
phase: "active", phase: "active",
@ -49,7 +52,10 @@ const generalEntities = observable([
}, },
spec: { spec: {
path: preferencesURL(), path: preferencesURL(),
materialIcon: "settings" icon: {
material: "settings",
background: "#3d90ce"
}
}, },
status: { status: {
phase: "active", phase: "active",

View File

@ -110,7 +110,7 @@ export class ClusterManager extends Singleton {
entity.spec.metrics.prometheus = prometheus; entity.spec.metrics.prometheus = prometheus;
} }
entity.spec.iconData = cluster.preferences.icon; entity.spec.icon.src = cluster.preferences.icon;
catalogEntityRegistry.items.splice(index, 1, entity); catalogEntityRegistry.items.splice(index, 1, entity);
} }
@ -204,7 +204,8 @@ export function catalogEntityFromCluster(cluster: Cluster) {
}, },
spec: { spec: {
kubeconfigPath: cluster.kubeConfigPath, kubeconfigPath: cluster.kubeConfigPath,
kubeconfigContext: cluster.contextName kubeconfigContext: cluster.contextName,
icon: {}
}, },
status: { status: {
phase: cluster.disconnected ? "disconnected" : "connected", phase: cluster.disconnected ? "disconnected" : "connected",

View File

@ -79,8 +79,9 @@ export class CatalogEntityDetails extends Component<Props> {
uid={entity.metadata.uid} uid={entity.metadata.uid}
title={entity.metadata.name} title={entity.metadata.name}
source={entity.metadata.source} source={entity.metadata.source}
src={entity.spec.iconData} src={entity.spec.icon?.src}
materialIcon={entity.spec.materialIcon} material={entity.spec.icon?.material}
background={entity.spec.icon?.background}
onClick={() => this.openEntity()} onClick={() => this.openEntity()}
size={128} /> size={128} />
<div className="IconHint"> <div className="IconHint">

View File

@ -173,10 +173,12 @@ export class Catalog extends React.Component<Props> {
uid={item.getId()} uid={item.getId()}
title={item.getName()} title={item.getName()}
source={item.source} source={item.source}
src={item.entity.spec.iconData} src={item.entity.spec.icon?.src}
materialIcon={item.entity.spec.materialIcon} material={item.entity.spec.icon?.material}
background={item.entity.spec.icon?.background}
onClick={() => this.onDetails(item)} onClick={() => this.onDetails(item)}
size={24} /> size={24}
/>
); );
} }

View File

@ -32,6 +32,7 @@ interface Props extends DOMAttributes<HTMLElement>, Partial<AvatarTypeMap> {
height?: number; height?: number;
src?: string; src?: string;
className?: string; className?: string;
background?: string;
} }
function getNameParts(name: string): string[] { function getNameParts(name: string): string[] {
@ -69,11 +70,11 @@ function getIconString(title: string) {
} }
export function Avatar(props: Props) { export function Avatar(props: Props) {
const { title, width = 32, height = 32, colorHash, children, ...settings } = props; const { title, width = 32, height = 32, colorHash, children, background, ...settings } = props;
const generateAvatarStyle = (): React.CSSProperties => { const generateAvatarStyle = (): React.CSSProperties => {
return { return {
backgroundColor: settings.src ? "transparent" : randomColor({ seed: colorHash, luminosity: "dark" }), backgroundColor: background || randomColor({ seed: colorHash, luminosity: "dark" }),
width, width,
height, height,
textTransform: "uppercase" textTransform: "uppercase"

View File

@ -86,7 +86,7 @@ export class ClusterIconSetting extends React.Component<Props> {
uid={entity.metadata.uid} uid={entity.metadata.uid}
title={entity.metadata.name} title={entity.metadata.name}
source={entity.metadata.source} source={entity.metadata.source}
src={entity.spec.iconData} src={entity.spec.icon?.src}
/> />
<span style={{marginRight: "var(--unit)"}}>Browse for new icon...</span> <span style={{marginRight: "var(--unit)"}}>Browse for new icon...</span>
</> </>

View File

@ -129,8 +129,9 @@ export class HotbarEntityIcon extends React.Component<Props> {
uid={entity.metadata.uid} uid={entity.metadata.uid}
title={entity.metadata.name} title={entity.metadata.name}
source={entity.metadata.source} source={entity.metadata.source}
src={entity.spec.iconData} src={entity.spec.icon?.src}
materialIcon={entity.spec.materialIcon} material={entity.spec.icon?.material}
background={entity.spec.icon?.background}
className={className} className={className}
active={isActive} active={isActive}
onMenuOpen={onOpen} onMenuOpen={onOpen}

View File

@ -20,7 +20,6 @@
*/ */
.HotbarMenu { .HotbarMenu {
.HotbarIconMenu { .HotbarIconMenu {
left: 30px; left: 30px;
min-width: 250px; min-width: 250px;
@ -126,4 +125,10 @@
} }
} }
} }
.materialIcon {
margin-left: 1px;
margin-top: 1px;
text-shadow: none;
}
} }

View File

@ -37,13 +37,14 @@ export interface HotbarIconProps extends DOMAttributes<HTMLElement> {
title: string; title: string;
source: string; source: string;
src?: string; src?: string;
materialIcon?: string; material?: string;
onMenuOpen?: () => void; onMenuOpen?: () => void;
className?: IClassName; className?: IClassName;
active?: boolean; active?: boolean;
menuItems?: CatalogEntityContextMenu[]; menuItems?: CatalogEntityContextMenu[];
disabled?: boolean; disabled?: boolean;
size?: number; size?: number;
background?: string;
} }
function onMenuItemClick(menuItem: CatalogEntityContextMenu) { function onMenuItemClick(menuItem: CatalogEntityContextMenu) {
@ -64,7 +65,7 @@ function onMenuItemClick(menuItem: CatalogEntityContextMenu) {
} }
export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: HotbarIconProps) => { export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: HotbarIconProps) => {
const { uid, title, src, materialIcon, active, className, source, disabled, onMenuOpen, children, ...rest } = props; const { uid, title, src, material, active, className, source, disabled, onMenuOpen, children, ...rest } = props;
const id = `hotbarIcon-${uid}`; const id = `hotbarIcon-${uid}`;
const [menuOpen, setMenuOpen] = useState(false); const [menuOpen, setMenuOpen] = useState(false);
@ -83,7 +84,7 @@ export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: Hotba
height={size} height={size}
src={src} src={src}
> >
{materialIcon && <Icon material={materialIcon}/>} {material && <Icon className="materialIcon" material={material}/>}
</Avatar> </Avatar>
); );
}; };