From 65c7a183d34f8d2dffdafeeda21b7514d3fe6345 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Tue, 6 Apr 2021 09:19:22 +0300 Subject: [PATCH] refactor Signed-off-by: Jari Kolehmainen --- integration/__tests__/cluster-pages.tests.ts | 1 + integration/__tests__/workspace.tests.ts | 75 ------------------- integration/helpers/utils.ts | 2 +- src/common/hotbar-store.ts | 5 +- src/main/menu.ts | 4 +- .../catalog-entity.store.ts | 0 .../components/+catalog/catalog.route.ts | 8 ++ .../catalog.scss} | 0 .../landing-page.tsx => +catalog/catalog.tsx} | 12 ++- src/renderer/components/+catalog/index.tsx | 2 + .../components/+landing-page/index.tsx | 2 - .../+landing-page/landing-page.route.ts | 8 -- .../cluster-manager/cluster-actions.tsx | 6 +- .../cluster-manager/cluster-manager.tsx | 6 +- .../components/hotbar/hotbar-menu.tsx | 5 ++ src/renderer/protocol-handler/app-handlers.ts | 8 +- 16 files changed, 43 insertions(+), 101 deletions(-) delete mode 100644 integration/__tests__/workspace.tests.ts rename src/renderer/components/{+landing-page => +catalog}/catalog-entity.store.ts (100%) create mode 100644 src/renderer/components/+catalog/catalog.route.ts rename src/renderer/components/{+landing-page/landing-page.scss => +catalog/catalog.scss} (100%) rename src/renderer/components/{+landing-page/landing-page.tsx => +catalog/catalog.tsx} (92%) create mode 100644 src/renderer/components/+catalog/index.tsx delete mode 100644 src/renderer/components/+landing-page/index.tsx delete mode 100644 src/renderer/components/+landing-page/landing-page.route.ts diff --git a/integration/__tests__/cluster-pages.tests.ts b/integration/__tests__/cluster-pages.tests.ts index ed2340f86f..e8a9468bde 100644 --- a/integration/__tests__/cluster-pages.tests.ts +++ b/integration/__tests__/cluster-pages.tests.ts @@ -26,6 +26,7 @@ describe("Lens cluster pages", () => { const addCluster = async () => { await utils.clickWhatsNew(app); await utils.clickWelcomeNotification(app); + await app.client.waitUntilTextExists("h5", "Catalog"); await addMinikubeCluster(app); await waitForMinikubeDashboard(app); await app.client.click('a[href="/nodes"]'); diff --git a/integration/__tests__/workspace.tests.ts b/integration/__tests__/workspace.tests.ts deleted file mode 100644 index 6ad56d5255..0000000000 --- a/integration/__tests__/workspace.tests.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { Application } from "spectron"; -import * as utils from "../helpers/utils"; -import { addMinikubeCluster, minikubeReady } from "../helpers/minikube"; -import { exec } from "child_process"; -import * as util from "util"; - -export const promiseExec = util.promisify(exec); - -jest.setTimeout(60000); - -describe("Lens integration tests", () => { - let app: Application; - const ready = minikubeReady("workspace-int-tests"); - - utils.describeIf(ready)("workspaces", () => { - utils.beforeAllWrapped(async () => { - app = await utils.appStart(); - await utils.clickWhatsNew(app); - }); - - utils.afterAllWrapped(async () => { - if (app?.isRunning()) { - return utils.tearDown(app); - } - }); - - const switchToWorkspace = async (name: string) => { - await app.client.click("[data-test-id=current-workspace]"); - await app.client.keys(name); - await app.client.keys("Enter"); - await app.client.waitUntilTextExists("[data-test-id=current-workspace-name]", name); - }; - - const createWorkspace = async (name: string) => { - await app.client.click("[data-test-id=current-workspace]"); - await app.client.keys("add workspace"); - await app.client.keys("Enter"); - await app.client.keys(name); - await app.client.keys("Enter"); - await app.client.waitUntilTextExists("[data-test-id=current-workspace-name]", name); - }; - - it("creates new workspace", async () => { - const name = "test-workspace"; - - await createWorkspace(name); - await app.client.waitUntilTextExists("[data-test-id=current-workspace-name]", name); - }); - - it("edits current workspaces", async () => { - await createWorkspace("to-be-edited"); - await app.client.click("[data-test-id=current-workspace]"); - await app.client.keys("edit current workspace"); - await app.client.keys("Enter"); - await app.client.keys("edited-workspace"); - await app.client.keys("Enter"); - await app.client.waitUntilTextExists("[data-test-id=current-workspace-name]", "edited-workspace"); - }); - - it("adds cluster in default workspace", async () => { - await switchToWorkspace("default"); - await addMinikubeCluster(app); - await app.client.waitUntilTextExists("pre.kube-auth-out", "Authentication proxy started"); - await app.client.waitForExist(`iframe[name="minikube"]`); - await app.client.waitForVisible(".ClustersMenu .ClusterIcon.active"); - }); - - it("adds cluster in test-workspace", async () => { - await switchToWorkspace("test-workspace"); - await addMinikubeCluster(app); - await app.client.waitUntilTextExists("pre.kube-auth-out", "Authentication proxy started"); - await app.client.waitForExist(`iframe[name="minikube"]`); - }); - }); -}); diff --git a/integration/helpers/utils.ts b/integration/helpers/utils.ts index c7fd4e8ddb..cdc277220f 100644 --- a/integration/helpers/utils.ts +++ b/integration/helpers/utils.ts @@ -80,7 +80,7 @@ export async function appStart() { export async function clickWhatsNew(app: Application) { await app.client.waitUntilTextExists("h1", "What's new?"); await app.client.click("button.primary"); - await app.client.waitUntilTextExists("h2", "default"); + await app.client.waitUntilTextExists("h5", "Catalog"); } export async function clickWelcomeNotification(app: Application) { diff --git a/src/common/hotbar-store.ts b/src/common/hotbar-store.ts index 146559fde3..42cdc0a8b1 100644 --- a/src/common/hotbar-store.ts +++ b/src/common/hotbar-store.ts @@ -35,7 +35,10 @@ export class HotbarStore extends BaseStore { } @action protected async fromStore(data: Partial = {}) { - this.hotbars = data.hotbars || []; + this.hotbars = data.hotbars || [{ + name: "default", + items: [] + }]; } getByName(name: string) { diff --git a/src/main/menu.ts b/src/main/menu.ts index 1225c38a1e..1dcd320584 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -7,7 +7,7 @@ import { preferencesURL } from "../renderer/components/+preferences/preferences. import { whatsNewURL } from "../renderer/components/+whats-new/whats-new.route"; import { clusterSettingsURL } from "../renderer/components/+cluster-settings/cluster-settings.route"; import { extensionsURL } from "../renderer/components/+extensions/extensions.route"; -import { landingURL } from "../renderer/components/+landing-page/landing-page.route"; +import { catalogURL } from "../renderer/components/+catalog/catalog.route"; import { menuRegistry } from "../extensions/registries/menu-registry"; import logger from "./logger"; import { exitApp } from "./exit-app"; @@ -180,7 +180,7 @@ export function buildMenu(windowManager: WindowManager) { label: "Catalog", accelerator: "Shift+CmdOrCtrl+C", click() { - navigate(landingURL()); + navigate(catalogURL()); } }, { diff --git a/src/renderer/components/+landing-page/catalog-entity.store.ts b/src/renderer/components/+catalog/catalog-entity.store.ts similarity index 100% rename from src/renderer/components/+landing-page/catalog-entity.store.ts rename to src/renderer/components/+catalog/catalog-entity.store.ts diff --git a/src/renderer/components/+catalog/catalog.route.ts b/src/renderer/components/+catalog/catalog.route.ts new file mode 100644 index 0000000000..68d4c3d022 --- /dev/null +++ b/src/renderer/components/+catalog/catalog.route.ts @@ -0,0 +1,8 @@ +import type { RouteProps } from "react-router"; +import { buildURL } from "../../../common/utils/buildUrl"; + +export const catalogRoute: RouteProps = { + path: "/catalog" +}; + +export const catalogURL = buildURL(catalogRoute.path); diff --git a/src/renderer/components/+landing-page/landing-page.scss b/src/renderer/components/+catalog/catalog.scss similarity index 100% rename from src/renderer/components/+landing-page/landing-page.scss rename to src/renderer/components/+catalog/catalog.scss diff --git a/src/renderer/components/+landing-page/landing-page.tsx b/src/renderer/components/+catalog/catalog.tsx similarity index 92% rename from src/renderer/components/+landing-page/landing-page.tsx rename to src/renderer/components/+catalog/catalog.tsx index 51e110a59f..c0c8d1f462 100644 --- a/src/renderer/components/+landing-page/landing-page.tsx +++ b/src/renderer/components/+catalog/catalog.tsx @@ -1,4 +1,4 @@ -import "./landing-page.scss"; +import "./catalog.scss"; import React from "react"; import { observer } from "mobx-react"; import { ItemListLayout } from "../item-object-list"; @@ -14,6 +14,7 @@ import { Badge } from "../badge"; import { hotbarStore } from "../../../common/hotbar-store"; import { addClusterURL } from "../+add-cluster"; import { autobind } from "../../utils"; +import { Notifications } from "../notifications"; enum sortBy { name = "name", @@ -22,7 +23,7 @@ enum sortBy { } @observer -export class LandingPage extends React.Component { +export class Catalog extends React.Component { @observable private catalogEntityStore?: CatalogEntityStore; @observable.deep private contextMenu: CatalogEntityContextMenuContext; private disposers: IReactionDisposer[] = []; @@ -34,6 +35,13 @@ export class LandingPage extends React.Component { }; this.catalogEntityStore = new CatalogEntityStore(); this.disposers.push(this.catalogEntityStore.watch()); + + if (this.catalogEntityStore.items.length === 0) { + Notifications.info(<>Welcome!

Get started by associating one or more clusters to Lens

, { + timeout: 30_000, + id: "landing-welcome" + }); + } } componentWillUnmount() { diff --git a/src/renderer/components/+catalog/index.tsx b/src/renderer/components/+catalog/index.tsx new file mode 100644 index 0000000000..207fed72d0 --- /dev/null +++ b/src/renderer/components/+catalog/index.tsx @@ -0,0 +1,2 @@ +export * from "./catalog.route"; +export * from "./catalog"; diff --git a/src/renderer/components/+landing-page/index.tsx b/src/renderer/components/+landing-page/index.tsx deleted file mode 100644 index c7eacf1bd0..0000000000 --- a/src/renderer/components/+landing-page/index.tsx +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./landing-page.route"; -export * from "./landing-page"; diff --git a/src/renderer/components/+landing-page/landing-page.route.ts b/src/renderer/components/+landing-page/landing-page.route.ts deleted file mode 100644 index 5fa9f2321e..0000000000 --- a/src/renderer/components/+landing-page/landing-page.route.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { RouteProps } from "react-router"; -import { buildURL } from "../../../common/utils/buildUrl"; - -export const landingRoute: RouteProps = { - path: "/landing" -}; - -export const landingURL = buildURL(landingRoute.path); diff --git a/src/renderer/components/cluster-manager/cluster-actions.tsx b/src/renderer/components/cluster-manager/cluster-actions.tsx index 93bde6d80d..5015abbcac 100644 --- a/src/renderer/components/cluster-manager/cluster-actions.tsx +++ b/src/renderer/components/cluster-manager/cluster-actions.tsx @@ -1,7 +1,7 @@ import React from "react"; import uniqueId from "lodash/uniqueId"; import { clusterSettingsURL } from "../+cluster-settings"; -import { landingURL } from "../+landing-page"; +import { catalogURL } from "../+catalog"; import { clusterStore } from "../../../common/cluster-store"; import { broadcastMessage, requestMain } from "../../../common/ipc"; @@ -25,7 +25,7 @@ export const ClusterActions = (cluster: Cluster) => ({ })), disconnect: async () => { clusterStore.deactivate(cluster.id); - navigate(landingURL()); + navigate(catalogURL()); await requestMain(clusterDisconnectHandler, cluster.id); }, remove: () => { @@ -40,7 +40,7 @@ export const ClusterActions = (cluster: Cluster) => ({ ok: () => { clusterStore.deactivate(cluster.id); clusterStore.removeById(cluster.id); - navigate(landingURL()); + navigate(catalogURL()); }, message:

Are you sure want to remove cluster {cluster.name}? diff --git a/src/renderer/components/cluster-manager/cluster-manager.tsx b/src/renderer/components/cluster-manager/cluster-manager.tsx index a30e141956..6fb6646d32 100644 --- a/src/renderer/components/cluster-manager/cluster-manager.tsx +++ b/src/renderer/components/cluster-manager/cluster-manager.tsx @@ -5,7 +5,7 @@ import { Redirect, Route, Switch } from "react-router"; import { comparer, reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { BottomBar } from "./bottom-bar"; -import { LandingPage, landingRoute, landingURL } from "../+landing-page"; +import { Catalog, catalogRoute, catalogURL } from "../+catalog"; import { Preferences, preferencesRoute } from "../+preferences"; import { AddCluster, addClusterRoute } from "../+add-cluster"; import { ClusterView } from "./cluster-view"; @@ -44,7 +44,7 @@ export class ClusterManager extends React.Component { } get startUrl() { - return landingURL(); + return catalogURL(); } render() { @@ -53,7 +53,7 @@ export class ClusterManager extends React.Component {

- + diff --git a/src/renderer/components/hotbar/hotbar-menu.tsx b/src/renderer/components/hotbar/hotbar-menu.tsx index aa5ae4bcd0..6bbc75cd7c 100644 --- a/src/renderer/components/hotbar/hotbar-menu.tsx +++ b/src/renderer/components/hotbar/hotbar-menu.tsx @@ -17,6 +17,11 @@ export class HotbarMenu extends React.Component { render() { const { className } = this.props; const hotbar = hotbarStore.getByName("default"); // FIXME + + if (!hotbar) { + return null; + } + const items = hotbar.items.map((item) => catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item.entity.uid)).filter(Boolean); const runContext = { navigate: (url: string) => navigate(url) diff --git a/src/renderer/protocol-handler/app-handlers.ts b/src/renderer/protocol-handler/app-handlers.ts index 4e92cda291..84dd3ce9ec 100644 --- a/src/renderer/protocol-handler/app-handlers.ts +++ b/src/renderer/protocol-handler/app-handlers.ts @@ -1,7 +1,7 @@ import { addClusterURL } from "../components/+add-cluster"; import { clusterSettingsURL } from "../components/+cluster-settings"; import { extensionsURL } from "../components/+extensions"; -import { landingURL } from "../components/+landing-page"; +import { catalogURL } from "../components/+catalog"; import { preferencesURL } from "../components/+preferences"; import { clusterViewURL } from "../components/cluster-manager/cluster-view.route"; import { LensProtocolRouterRenderer } from "./router"; @@ -15,10 +15,10 @@ export function bindProtocolAddRouteHandlers() { navigate(preferencesURL({ fragment: highlight })); }) .addInternalHandler("/", () => { - navigate(landingURL()); + navigate(catalogURL()); }) - .addInternalHandler("/landing", () => { - navigate(landingURL()); + .addInternalHandler("/catalog", () => { + navigate(catalogURL()); }) .addInternalHandler("/cluster", () => { navigate(addClusterURL());