Fix being able to view clusters outside the current workspace (#2355)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-04-14 09:49:14 -04:00
1 parent da6b5d6bde
commit b6c3ce7d28
36 files changed
+583 -240

No files matched your search

@@ -1,38 +1,58 @@
import "./landing-page.scss";
import React from "react";
import { computed, observable } from "mobx";
import { observer } from "mobx-react";
import { computed, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react";
import { clusterStore } from "../../../common/cluster-store";
import { workspaceStore } from "../../../common/workspace-store";
import { WorkspaceId, workspaceStore } from "../../../common/workspace-store";
import { WorkspaceOverview } from "./workspace-overview";
import { PageLayout } from "../layout/page-layout";
import { Notifications } from "../notifications";
import { Icon } from "../icon";
import { createStorage } from "../../utils";
@observer
export class LandingPage extends React.Component {
@observable showHint = true;
private static storage = createStorage<WorkspaceId[]>("seen_workspaces", []);
@computed
get clusters() {
return clusterStore.getByWorkspaceId(workspaceStore.currentWorkspaceId);
@computed get workspace() {
return workspaceStore.currentWorkspace;
}
componentDidMount() {
const noClustersInScope = !this.clusters.length;
const showStartupHint = this.showHint;
// ignore workspaces that don't exist
const seenWorkspaces = new Set(
LandingPage
.storage
.get()
.filter(id => workspaceStore.getById(id))
);
if (showStartupHint && noClustersInScope) {
Notifications.info(<><b>Welcome!</b><p>Get started by associating one or more clusters to Lens</p></>, {
timeout: 30_000,
id: "landing-welcome"
});
}
disposeOnUnmount(this, [
reaction(() => this.workspace, workspace => {
const showWelcomeNotification = !(
seenWorkspaces.has(workspace.id)
|| workspace.isManaged
|| clusterStore.getByWorkspaceId(workspace.id).length
);
if (showWelcomeNotification) {
Notifications.info(<><b>Welcome!</b><p>Get started by associating one or more clusters to Lens</p></>, {
timeout: 30_000,
id: "landing-welcome"
});
}
seenWorkspaces.add(workspace.id);
LandingPage.storage.set(Array.from(seenWorkspaces));
}, {
fireImmediately: true,
}),
]);
}
render() {
const showBackButton = this.clusters.length > 0;
const header = <><Icon svg="logo-lens" big /> <h2>{workspaceStore.currentWorkspace.name}</h2></>;
const showBackButton = Boolean(this.workspace.activeClusterId);
const header = <><Icon svg="logo-lens" big /> <h2>{this.workspace.name}</h2></>;
return (
<PageLayout className="LandingOverview flex" header={header} provideBackButtonNavigation={showBackButton} showOnTop={true}>