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

Set custom backround for hotbar entities

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-03-16 13:12:24 +03:00
parent 6021c66540
commit 6102b130cb

View File

@ -23,6 +23,8 @@ import visitEntityContextMenuInjectable from "../../../common/catalog/visit-enti
import activeEntityInjectable from "../../api/catalog/entity/active.injectable";
import type { Navigate } from "../../navigation/navigate.injectable";
import navigateInjectable from "../../navigation/navigate.injectable";
import getClusterByIdInjectable from "../../../common/cluster-store/get-by-id.injectable";
import type { Cluster } from "../../../common/cluster/cluster";
export interface HotbarEntityIconProps {
entity: CatalogEntity;
@ -40,6 +42,7 @@ interface Dependencies {
catalogCategoryRegistry: CatalogCategoryRegistry;
activeEntity: IComputedValue<CatalogEntity | undefined>;
navigate: Navigate;
getClusterById: (id: string) => Cluster | undefined;
}
@observer
@ -92,6 +95,17 @@ class NonInjectedHotbarEntityIcon extends React.Component<HotbarEntityIconProps
});
}
get entityBackground() {
const { entity, getClusterById } = this.props;
const cluster = getClusterById(entity.metadata.uid);
if (cluster) {
return cluster.preferences?.iconBackgroundColor;
}
return entity.spec.icon?.background;
}
render() {
const { entity, className, onClick } = this.props;
@ -102,7 +116,7 @@ class NonInjectedHotbarEntityIcon extends React.Component<HotbarEntityIconProps
source={entity.metadata.source}
src={entity.spec.icon?.src}
material={entity.spec.icon?.material}
background={entity.spec.icon?.background}
background={this.entityBackground}
className={className}
active={this.isActive(entity)}
onMenuOpen={() => this.onMenuOpen()}
@ -129,5 +143,6 @@ export const HotbarEntityIcon = withInjectables<Dependencies, HotbarEntityIconPr
visitEntityContextMenu: di.inject(visitEntityContextMenuInjectable),
activeEntity: di.inject(activeEntityInjectable),
navigate: di.inject(navigateInjectable),
getClusterById: di.inject(getClusterByIdInjectable),
}),
});