mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
General catalog category (#3106)
* Adding General Entities and General Category Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Usign material icons for general entities Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Setting background for hotbar icon explicitly Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding Catalog initially to first hotbar Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Tuning hotbar store tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Changing type from GeneralEntity to General Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Search for catalog hotbar item in tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Removing Catalog link from bottom bar Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Waiting for hotbar catalog entity Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Opening cluster list by data-testId Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Replacing types on interfaces Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fixing integration tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding general entities throught initializers Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Removing icon refs from CatalogEntitySpec Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
1 parent
48e278c71b
commit
d9ceb8fa08
27 files changed
+261
-73
No files matched your search
@@ -156,6 +156,13 @@ describe("HotbarStore", () => {
|
||||
expect(hotbarStore.getActive().items.length).toEqual(12);
|
||||
});
|
||||
|
||||
it("initially adds catalog entity as first item", () => {
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
|
||||
hotbarStore.load();
|
||||
expect(hotbarStore.getActive().items[0].entity.name).toEqual("Catalog");
|
||||
});
|
||||
|
||||
it("adds items", () => {
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
|
||||
@@ -163,7 +170,7 @@ describe("HotbarStore", () => {
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
const items = hotbarStore.getActive().items.filter(Boolean);
|
||||
|
||||
expect(items.length).toEqual(1);
|
||||
expect(items.length).toEqual(2);
|
||||
});
|
||||
|
||||
it("removes items", () => {
|
||||
@@ -172,6 +179,7 @@ describe("HotbarStore", () => {
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
hotbarStore.removeFromHotbar("test");
|
||||
hotbarStore.removeFromHotbar("catalog-entity");
|
||||
const items = hotbarStore.getActive().items.filter(Boolean);
|
||||
|
||||
expect(items.length).toEqual(0);
|
||||
@@ -185,7 +193,7 @@ describe("HotbarStore", () => {
|
||||
hotbarStore.removeFromHotbar("invalid uid");
|
||||
const items = hotbarStore.getActive().items.filter(Boolean);
|
||||
|
||||
expect(items.length).toEqual(1);
|
||||
expect(items.length).toEqual(2);
|
||||
});
|
||||
|
||||
it("moves item to empty cell", () => {
|
||||
@@ -196,12 +204,12 @@ describe("HotbarStore", () => {
|
||||
hotbarStore.addToHotbar(minikubeCluster);
|
||||
hotbarStore.addToHotbar(awsCluster);
|
||||
|
||||
expect(hotbarStore.getActive().items[5]).toBeNull();
|
||||
expect(hotbarStore.getActive().items[6]).toBeNull();
|
||||
|
||||
hotbarStore.restackItems(1, 5);
|
||||
|
||||
expect(hotbarStore.getActive().items[5]).toBeTruthy();
|
||||
expect(hotbarStore.getActive().items[5].entity.uid).toEqual("minikube");
|
||||
expect(hotbarStore.getActive().items[5].entity.uid).toEqual("test");
|
||||
});
|
||||
|
||||
it("moves items down", () => {
|
||||
@@ -212,12 +220,12 @@ describe("HotbarStore", () => {
|
||||
hotbarStore.addToHotbar(minikubeCluster);
|
||||
hotbarStore.addToHotbar(awsCluster);
|
||||
|
||||
// aws -> test
|
||||
hotbarStore.restackItems(2, 0);
|
||||
// aws -> catalog
|
||||
hotbarStore.restackItems(3, 0);
|
||||
|
||||
const items = hotbarStore.getActive().items.map(item => item?.entity.uid || null);
|
||||
|
||||
expect(items.slice(0, 4)).toEqual(["aws", "test", "minikube", null]);
|
||||
expect(items.slice(0, 4)).toEqual(["aws", "catalog-entity", "test", "minikube"]);
|
||||
});
|
||||
|
||||
it("moves items up", () => {
|
||||
@@ -229,11 +237,11 @@ describe("HotbarStore", () => {
|
||||
hotbarStore.addToHotbar(awsCluster);
|
||||
|
||||
// test -> aws
|
||||
hotbarStore.restackItems(0, 2);
|
||||
hotbarStore.restackItems(1, 3);
|
||||
|
||||
const items = hotbarStore.getActive().items.map(item => item?.entity.uid || null);
|
||||
|
||||
expect(items.slice(0, 4)).toEqual(["minikube", "aws", "test", null]);
|
||||
expect(items.slice(0, 4)).toEqual(["catalog-entity", "minikube", "aws", "test"]);
|
||||
});
|
||||
|
||||
it("does nothing when item moved to same cell", () => {
|
||||
@@ -241,9 +249,9 @@ describe("HotbarStore", () => {
|
||||
|
||||
hotbarStore.load();
|
||||
hotbarStore.addToHotbar(testCluster);
|
||||
hotbarStore.restackItems(0, 0);
|
||||
hotbarStore.restackItems(1, 1);
|
||||
|
||||
expect(hotbarStore.getActive().items[0].entity.uid).toEqual("test");
|
||||
expect(hotbarStore.getActive().items[1].entity.uid).toEqual("test");
|
||||
});
|
||||
|
||||
it("new items takes first empty cell", () => {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { navigate } from "../../renderer/navigation";
|
||||
import { CatalogCategory, CatalogEntity, CatalogEntityMetadata, CatalogEntitySpec, CatalogEntityStatus } from "../catalog";
|
||||
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
||||
|
||||
interface GeneralEntitySpec extends CatalogEntitySpec {
|
||||
path: string;
|
||||
icon?: {
|
||||
material?: string;
|
||||
background?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export class GeneralEntity extends CatalogEntity<CatalogEntityMetadata, CatalogEntityStatus, GeneralEntitySpec> {
|
||||
public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
|
||||
public readonly kind = "General";
|
||||
|
||||
async onRun() {
|
||||
navigate(this.spec.path);
|
||||
}
|
||||
|
||||
public onSettingsOpen(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
public onDetailsOpen(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
public onContextMenuOpen(): void {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export class GeneralCategory extends CatalogCategory {
|
||||
public readonly apiVersion = "catalog.k8slens.dev/v1alpha1";
|
||||
public readonly kind = "CatalogCategory";
|
||||
public metadata = {
|
||||
name: "General",
|
||||
icon: "settings"
|
||||
};
|
||||
public spec = {
|
||||
group: "entity.k8slens.dev",
|
||||
versions: [
|
||||
{
|
||||
name: "v1alpha1",
|
||||
entityClass: GeneralEntity
|
||||
}
|
||||
],
|
||||
names: {
|
||||
kind: "General"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
catalogCategoryRegistry.add(new GeneralCategory());
|
||||
@@ -19,5 +19,6 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export * from "./general";
|
||||
export * from "./kubernetes-cluster";
|
||||
export * from "./web-link";
|
||||
@@ -27,9 +27,10 @@ import { requestMain } from "../ipc";
|
||||
import { CatalogCategory, CatalogCategorySpec } from "../catalog";
|
||||
import { addClusterURL } from "../routes";
|
||||
import { app } from "electron";
|
||||
import type { CatalogEntitySpec } from "../catalog/catalog-entity";
|
||||
import { HotbarStore } from "../hotbar-store";
|
||||
|
||||
export type KubernetesClusterPrometheusMetrics = {
|
||||
export interface KubernetesClusterPrometheusMetrics {
|
||||
address?: {
|
||||
namespace: string;
|
||||
service: string;
|
||||
@@ -37,17 +38,19 @@ export type KubernetesClusterPrometheusMetrics = {
|
||||
prefix: string;
|
||||
};
|
||||
type?: string;
|
||||
};
|
||||
icon?: {
|
||||
src?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type KubernetesClusterSpec = {
|
||||
export interface KubernetesClusterSpec extends CatalogEntitySpec {
|
||||
kubeconfigPath: string;
|
||||
kubeconfigContext: string;
|
||||
iconData?: string;
|
||||
metrics?: {
|
||||
source: string;
|
||||
prometheus?: KubernetesClusterPrometheusMetrics;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export interface KubernetesClusterStatus extends CatalogEntityStatus {
|
||||
phase: "connected" | "disconnected" | "deleting";
|
||||
|
||||
@@ -149,6 +149,7 @@ export interface CatalogEntityAddMenuContext {
|
||||
|
||||
export type CatalogEntitySpec = Record<string, any>;
|
||||
|
||||
|
||||
export interface CatalogEntityData<
|
||||
Metadata extends CatalogEntityMetadata = CatalogEntityMetadata,
|
||||
Status extends CatalogEntityStatus = CatalogEntityStatus,
|
||||
|
||||
@@ -26,6 +26,7 @@ import * as uuid from "uuid";
|
||||
import isNull from "lodash/isNull";
|
||||
import { toJS } from "./utils";
|
||||
import { CatalogEntity } from "./catalog";
|
||||
import { catalogEntity } from "../main/catalog-sources/general";
|
||||
|
||||
export interface HotbarItem {
|
||||
entity: {
|
||||
@@ -91,6 +92,16 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
return this.hotbarIndex(this.activeHotbarId);
|
||||
}
|
||||
|
||||
get defaultHotbarInitialItems() {
|
||||
const { metadata: { uid, name, source } } = catalogEntity;
|
||||
const initialItem = { entity: { uid, name, source }};
|
||||
|
||||
return [
|
||||
initialItem,
|
||||
...Array.from(Array(defaultHotbarCells - 1).fill(null))
|
||||
];
|
||||
}
|
||||
|
||||
get initialItems() {
|
||||
return [...Array.from(Array(defaultHotbarCells).fill(null))];
|
||||
}
|
||||
@@ -100,7 +111,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
this.hotbars = [{
|
||||
id: uuid.v4(),
|
||||
name: "Default",
|
||||
items: this.initialItems,
|
||||
items: this.defaultHotbarInitialItems,
|
||||
}];
|
||||
} else {
|
||||
this.hotbars = data.hotbars;
|
||||
|
||||
Reference in new issue
Block a user