mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Show active item in hotbar & allow to pin/unpin (#2790)
* show active item in hotbar & allow to pin it Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix styles Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
d08d5a24d7
commit
752f49821a
7 files changed
+109
-111
No files matched your search
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
|
||||
import mockFs from "mock-fs";
|
||||
import { CatalogEntityItem } from "../../renderer/components/+catalog/catalog-entity.store";
|
||||
import { ClusterStore } from "../cluster-store";
|
||||
import { HotbarStore } from "../hotbar-store";
|
||||
|
||||
@@ -159,10 +158,9 @@ describe("HotbarStore", () => {
|
||||
|
||||
it("adds items", () => {
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
const entity = new CatalogEntityItem(testCluster);
|
||||
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(entity);
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
const items = hotbarStore.getActive().items.filter(Boolean);
|
||||
|
||||
expect(items.length).toEqual(1);
|
||||
@@ -170,10 +168,9 @@ describe("HotbarStore", () => {
|
||||
|
||||
it("removes items", () => {
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
const entity = new CatalogEntityItem(testCluster);
|
||||
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(entity);
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
hotbarStore.removeFromHotbar("test");
|
||||
const items = hotbarStore.getActive().items.filter(Boolean);
|
||||
|
||||
@@ -182,10 +179,9 @@ describe("HotbarStore", () => {
|
||||
|
||||
it("does nothing if removing with invalid uid", () => {
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
const entity = new CatalogEntityItem(testCluster);
|
||||
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(entity);
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
hotbarStore.removeFromHotbar("invalid uid");
|
||||
const items = hotbarStore.getActive().items.filter(Boolean);
|
||||
|
||||
@@ -194,14 +190,11 @@ describe("HotbarStore", () => {
|
||||
|
||||
it("moves item to empty cell", () => {
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
const test = new CatalogEntityItem(testCluster);
|
||||
const minikube = new CatalogEntityItem(minikubeCluster);
|
||||
const aws = new CatalogEntityItem(awsCluster);
|
||||
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(test);
|
||||
hotbarStore.addToHotbar(minikube);
|
||||
hotbarStore.addToHotbar(aws);
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
hotbarStore.addToHotbar(minikubeCluster);
|
||||
hotbarStore.addToHotbar(awsCluster);
|
||||
|
||||
expect(hotbarStore.getActive().items[5]).toBeNull();
|
||||
|
||||
@@ -213,14 +206,11 @@ describe("HotbarStore", () => {
|
||||
|
||||
it("moves items down", () => {
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
const test = new CatalogEntityItem(testCluster);
|
||||
const minikube = new CatalogEntityItem(minikubeCluster);
|
||||
const aws = new CatalogEntityItem(awsCluster);
|
||||
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(test);
|
||||
hotbarStore.addToHotbar(minikube);
|
||||
hotbarStore.addToHotbar(aws);
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
hotbarStore.addToHotbar(minikubeCluster);
|
||||
hotbarStore.addToHotbar(awsCluster);
|
||||
|
||||
// aws -> test
|
||||
hotbarStore.restackItems(2, 0);
|
||||
@@ -232,14 +222,11 @@ describe("HotbarStore", () => {
|
||||
|
||||
it("moves items up", () => {
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
const test = new CatalogEntityItem(testCluster);
|
||||
const minikube = new CatalogEntityItem(minikubeCluster);
|
||||
const aws = new CatalogEntityItem(awsCluster);
|
||||
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(test);
|
||||
hotbarStore.addToHotbar(minikube);
|
||||
hotbarStore.addToHotbar(aws);
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
hotbarStore.addToHotbar(minikubeCluster);
|
||||
hotbarStore.addToHotbar(awsCluster);
|
||||
|
||||
// test -> aws
|
||||
hotbarStore.restackItems(0, 2);
|
||||
@@ -251,10 +238,9 @@ describe("HotbarStore", () => {
|
||||
|
||||
it("does nothing when item moved to same cell", () => {
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
const test = new CatalogEntityItem(testCluster);
|
||||
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(test);
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
hotbarStore.restackItems(0, 0);
|
||||
|
||||
expect(hotbarStore.getActive().items[0].entity.uid).toEqual("test");
|
||||
@@ -262,15 +248,12 @@ describe("HotbarStore", () => {
|
||||
|
||||
it("new items takes first empty cell", () => {
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
const test = new CatalogEntityItem(testCluster);
|
||||
const minikube = new CatalogEntityItem(minikubeCluster);
|
||||
const aws = new CatalogEntityItem(awsCluster);
|
||||
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(test);
|
||||
hotbarStore.addToHotbar(aws);
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
hotbarStore.addToHotbar(awsCluster);
|
||||
hotbarStore.restackItems(0, 3);
|
||||
hotbarStore.addToHotbar(minikube);
|
||||
hotbarStore.addToHotbar(minikubeCluster);
|
||||
|
||||
expect(hotbarStore.getActive().items[0].entity.uid).toEqual("minikube");
|
||||
});
|
||||
@@ -282,10 +265,9 @@ describe("HotbarStore", () => {
|
||||
console.error = jest.fn();
|
||||
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
const test = new CatalogEntityItem(testCluster);
|
||||
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(test);
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
|
||||
expect(() => hotbarStore.restackItems(-5, 0)).toThrow();
|
||||
expect(() => hotbarStore.restackItems(2, -1)).toThrow();
|
||||
|
||||
@@ -23,8 +23,8 @@ import { action, comparer, observable, toJS } from "mobx";
|
||||
import { BaseStore } from "./base-store";
|
||||
import migrations from "../migrations/hotbar-store";
|
||||
import * as uuid from "uuid";
|
||||
import { CatalogEntityItem } from "../renderer/components/+catalog/catalog-entity.store";
|
||||
import isNull from "lodash/isNull";
|
||||
import { CatalogEntity } from "./catalog";
|
||||
|
||||
export interface HotbarItem {
|
||||
entity: {
|
||||
@@ -151,15 +151,15 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
}
|
||||
|
||||
@action
|
||||
addToHotbar(item: CatalogEntityItem, cellIndex = -1) {
|
||||
addToHotbar(item: CatalogEntity, cellIndex = -1) {
|
||||
const hotbar = this.getActive();
|
||||
const newItem = { entity: {
|
||||
uid: item.id,
|
||||
name: item.name,
|
||||
source: item.source
|
||||
uid: item.metadata.uid,
|
||||
name: item.metadata.name,
|
||||
source: item.metadata.source
|
||||
}};
|
||||
|
||||
if (hotbar.items.find(i => i?.entity.uid === item.id)) {
|
||||
if (hotbar.items.find(i => i?.entity.uid === item.metadata.uid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user