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

Dim disabled pin icon

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-09-15 14:34:10 +03:00
parent ab38cd32b5
commit 329a1c93c4
4 changed files with 34 additions and 5 deletions

View File

@ -324,6 +324,15 @@ describe("HotbarStore", () => {
console.error = error; console.error = error;
console.warn = warn; console.warn = warn;
}); });
it("checks if entity already pinned to hotbar", () => {
const hotbarStore = HotbarStore.getInstance();
hotbarStore.addToHotbar(testCluster);
expect(hotbarStore.entityPinnedToHotbar(testCluster)).toBeTruthy();
expect(hotbarStore.entityPinnedToHotbar(awsCluster)).toBeFalsy();
});
}); });
describe("pre beta-5 migrations", () => { describe("pre beta-5 migrations", () => {

View File

@ -171,7 +171,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
}}; }};
if (hotbar.items.find(i => i?.entity.uid === uid)) { if (this.entityPinnedToHotbar(item)) {
return; return;
} }
@ -274,6 +274,14 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
hotbarStore.activeHotbarId = hotbarStore.hotbars[index].id; hotbarStore.activeHotbarId = hotbarStore.hotbars[index].id;
} }
/**
* Checks if entity already pinned to hotbar
* @returns boolean
*/
entityPinnedToHotbar(entity: CatalogEntity) {
return !!this.getActive().items.find(item => item?.entity.uid === entity.metadata.uid);
}
} }
/** /**

View File

@ -44,6 +44,10 @@
&:hover .pinIcon { &:hover .pinIcon {
opacity: 1; opacity: 1;
&:global(.disabled) {
opacity: 0.3;
}
} }
} }

View File

@ -188,13 +188,21 @@ export class Catalog extends React.Component<Props> {
}; };
renderName(item: CatalogEntityItem<CatalogEntity>) { renderName(item: CatalogEntityItem<CatalogEntity>) {
const disabledIcon = HotbarStore.getInstance().entityPinnedToHotbar(item.entity);
return ( return (
<div className={styles.entityName}> <div className={styles.entityName}>
{item.name} {item.name}
<Icon className={styles.pinIcon} material="push_pin" small tooltip="Pin to Hotbar" onClick={(event) => { <Icon
event.stopPropagation(); small
this.addToHotbar(item); disabled={disabledIcon}
}}/> className={styles.pinIcon}
material="push_pin"
tooltip={disabledIcon ? "" : "Pin to Hotbar"}
onClick={(event) => {
event.stopPropagation();
this.addToHotbar(item);
}}/>
</div> </div>
); );
} }