Sfoglia il codice sorgente

patched default route

Jo Chuang 5 anni fa
parent
commit
ab535eee84
1 ha cambiato i file con 10 aggiunte e 7 eliminazioni
  1. 10 7
      dashboard/src/main/home/dashboard/Dashboard.tsx

+ 10 - 7
dashboard/src/main/home/dashboard/Dashboard.tsx

@@ -22,8 +22,8 @@ const tabOptions = [
   { label: "Project Overview", value: "overview" },
   { 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 = {
   infras: InfraType[];
@@ -61,6 +61,10 @@ class Dashboard extends Component<PropsType, StateType> {
     if (this.props.projectId && prevProps.projectId !== this.props.projectId) {
       this.refreshInfras();
     }
+
+    if (!tabOptionStrings.includes(this.currentTab())) {
+      this.setCurrentTab("overview");
+    }
   }
 
   onShowProjectSettings = () => {
@@ -91,6 +95,9 @@ class Dashboard extends Component<PropsType, StateType> {
     }
   };
 
+  setCurrentTab = (x: string) =>
+    this.props.history.push(setSearchParam(this.props.location, "tab", x));
+
   render() {
     let { currentProject } = this.context;
     let { onShowProjectSettings } = this;
@@ -128,11 +135,7 @@ class Dashboard extends Component<PropsType, StateType> {
 
             <TabRegion
               currentTab={this.currentTab()}
-              setCurrentTab={(x: TabType) =>
-                this.props.history.push(
-                  setSearchParam(this.props.location, "tab", x)
-                )
-              }
+              setCurrentTab={this.setCurrentTab}
               options={tabOptions}
             >
               {this.renderTabContents()}