|
@@ -1,4 +1,3 @@
|
|
|
-import { render } from "@testing-library/react";
|
|
|
|
|
import React, { Component } from "react";
|
|
import React, { Component } from "react";
|
|
|
import styled from "styled-components";
|
|
import styled from "styled-components";
|
|
|
|
|
|
|
@@ -9,10 +8,12 @@ import api from "shared/api";
|
|
|
|
|
|
|
|
import ProvisionerSettings from "../provisioner/ProvisionerSettings";
|
|
import ProvisionerSettings from "../provisioner/ProvisionerSettings";
|
|
|
import ClusterPlaceholderContainer from "./ClusterPlaceholderContainer";
|
|
import ClusterPlaceholderContainer from "./ClusterPlaceholderContainer";
|
|
|
-import { Redirect, RouteComponentProps, withRouter } from "react-router";
|
|
|
|
|
|
|
+import { RouteComponentProps, withRouter } from "react-router";
|
|
|
import TabRegion from "components/TabRegion";
|
|
import TabRegion from "components/TabRegion";
|
|
|
import Provisioner from "../provisioner/Provisioner";
|
|
import Provisioner from "../provisioner/Provisioner";
|
|
|
|
|
|
|
|
|
|
+import { setSearchParam } from "shared/routing";
|
|
|
|
|
+
|
|
|
type PropsType = RouteComponentProps & {
|
|
type PropsType = RouteComponentProps & {
|
|
|
projectId: number | null;
|
|
projectId: number | null;
|
|
|
};
|
|
};
|
|
@@ -21,19 +22,16 @@ const tabOptions = [
|
|
|
{ label: "Project Overview", value: "overview" },
|
|
{ label: "Project Overview", value: "overview" },
|
|
|
{ label: "Provisioner Status", value: "provisioner" },
|
|
{ label: "Provisioner Status", value: "provisioner" },
|
|
|
];
|
|
];
|
|
|
-// TODO: rethink this typing, should be coupled with tabOptions
|
|
|
|
|
-type TabType = "overview" | "provisioner"
|
|
|
|
|
|
|
+// TODO: rethink this list, should be coupled with tabOptions
|
|
|
|
|
+const tabOptionStrings = ["overview", "provisioner"];
|
|
|
|
|
|
|
|
type StateType = {
|
|
type StateType = {
|
|
|
infras: InfraType[];
|
|
infras: InfraType[];
|
|
|
- currentTab: TabType;
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-
|
|
|
|
|
class Dashboard extends Component<PropsType, StateType> {
|
|
class Dashboard extends Component<PropsType, StateType> {
|
|
|
state = {
|
|
state = {
|
|
|
infras: [] as InfraType[],
|
|
infras: [] as InfraType[],
|
|
|
- currentTab: "overview" as TabType,
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
refreshInfras = () => {
|
|
refreshInfras = () => {
|
|
@@ -63,21 +61,20 @@ class Dashboard extends Component<PropsType, StateType> {
|
|
|
if (this.props.projectId && prevProps.projectId !== this.props.projectId) {
|
|
if (this.props.projectId && prevProps.projectId !== this.props.projectId) {
|
|
|
this.refreshInfras();
|
|
this.refreshInfras();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (!tabOptionStrings.includes(this.currentTab())) {
|
|
|
|
|
+ this.setCurrentTab("overview");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
onShowProjectSettings = () => {
|
|
onShowProjectSettings = () => {
|
|
|
this.props.history.push("project-settings");
|
|
this.props.history.push("project-settings");
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- renderTabContents = () => {
|
|
|
|
|
- const currentTab = new URLSearchParams(this.props.location.search).get("tab")
|
|
|
|
|
- if (
|
|
|
|
|
- currentTab && currentTab !== this.state.currentTab
|
|
|
|
|
- ) {
|
|
|
|
|
- this.setState({ currentTab: currentTab as TabType });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ currentTab = () => new URLSearchParams(this.props.location.search).get("tab");
|
|
|
|
|
|
|
|
- if (this.state.currentTab === "provisioner") {
|
|
|
|
|
|
|
+ renderTabContents = () => {
|
|
|
|
|
+ if (this.currentTab() === "provisioner") {
|
|
|
return <Provisioner />;
|
|
return <Provisioner />;
|
|
|
} else {
|
|
} else {
|
|
|
return (
|
|
return (
|
|
@@ -98,9 +95,11 @@ class Dashboard extends Component<PropsType, StateType> {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ setCurrentTab = (x: string) =>
|
|
|
|
|
+ this.props.history.push(setSearchParam(this.props.location, "tab", x));
|
|
|
|
|
+
|
|
|
render() {
|
|
render() {
|
|
|
- let { currentProject, currentCluster } = this.context;
|
|
|
|
|
- let { infras } = this.state;
|
|
|
|
|
|
|
+ let { currentProject } = this.context;
|
|
|
let { onShowProjectSettings } = this;
|
|
let { onShowProjectSettings } = this;
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
@@ -135,8 +134,8 @@ class Dashboard extends Component<PropsType, StateType> {
|
|
|
</InfoSection>
|
|
</InfoSection>
|
|
|
|
|
|
|
|
<TabRegion
|
|
<TabRegion
|
|
|
- currentTab={this.state.currentTab}
|
|
|
|
|
- setCurrentTab={(x: TabType) => this.props.history.push(`dashboard?tab=${x}`)}
|
|
|
|
|
|
|
+ currentTab={this.currentTab()}
|
|
|
|
|
+ setCurrentTab={this.setCurrentTab}
|
|
|
options={tabOptions}
|
|
options={tabOptions}
|
|
|
>
|
|
>
|
|
|
{this.renderTabContents()}
|
|
{this.renderTabContents()}
|