|
|
@@ -1,46 +1,46 @@
|
|
|
-import React, { Component } from 'react';
|
|
|
-import posthog from 'posthog-js';
|
|
|
-import styled from 'styled-components';
|
|
|
-
|
|
|
-import { Context } from 'shared/Context';
|
|
|
-import api from 'shared/api';
|
|
|
-import { ClusterType, ProjectType } from 'shared/types';
|
|
|
-
|
|
|
-import Sidebar from './sidebar/Sidebar';
|
|
|
-import Dashboard from './dashboard/Dashboard';
|
|
|
-import ClusterDashboard from './cluster-dashboard/ClusterDashboard';
|
|
|
-import Loading from 'components/Loading';
|
|
|
-import Templates from './templates/Templates';
|
|
|
+import React, { Component } from "react";
|
|
|
+import posthog from "posthog-js";
|
|
|
+import styled from "styled-components";
|
|
|
+
|
|
|
+import { Context } from "shared/Context";
|
|
|
+import api from "shared/api";
|
|
|
+import { ClusterType, ProjectType } from "shared/types";
|
|
|
+
|
|
|
+import Sidebar from "./sidebar/Sidebar";
|
|
|
+import Dashboard from "./dashboard/Dashboard";
|
|
|
+import ClusterDashboard from "./cluster-dashboard/ClusterDashboard";
|
|
|
+import Loading from "components/Loading";
|
|
|
+import Templates from "./templates/Templates";
|
|
|
import Integrations from "./integrations/Integrations";
|
|
|
-import UpdateClusterModal from './modals/UpdateClusterModal';
|
|
|
-import ClusterInstructionsModal from './modals/ClusterInstructionsModal';
|
|
|
-import IntegrationsModal from './modals/IntegrationsModal';
|
|
|
-import IntegrationsInstructionsModal from './modals/IntegrationsInstructionsModal';
|
|
|
-import NewProject from './new-project/NewProject';
|
|
|
-import Navbar from './navbar/Navbar';
|
|
|
-import ProjectSettings from './project-settings/ProjectSettings';
|
|
|
-import ConfirmOverlay from 'components/ConfirmOverlay';
|
|
|
-import Modal from './modals/Modal';
|
|
|
-import * as FullStory from '@fullstory/browser';
|
|
|
-import { Redirect, RouteComponentProps, withRouter } from 'react-router';
|
|
|
-import {PorterUrls} from 'shared/urls';
|
|
|
+import UpdateClusterModal from "./modals/UpdateClusterModal";
|
|
|
+import ClusterInstructionsModal from "./modals/ClusterInstructionsModal";
|
|
|
+import IntegrationsModal from "./modals/IntegrationsModal";
|
|
|
+import IntegrationsInstructionsModal from "./modals/IntegrationsInstructionsModal";
|
|
|
+import NewProject from "./new-project/NewProject";
|
|
|
+import Navbar from "./navbar/Navbar";
|
|
|
+import ProjectSettings from "./project-settings/ProjectSettings";
|
|
|
+import ConfirmOverlay from "components/ConfirmOverlay";
|
|
|
+import Modal from "./modals/Modal";
|
|
|
+import * as FullStory from "@fullstory/browser";
|
|
|
+import { Redirect, RouteComponentProps, withRouter } from "react-router";
|
|
|
+import { PorterUrls } from "shared/urls";
|
|
|
|
|
|
type PropsType = RouteComponentProps & {
|
|
|
- logOut: () => void,
|
|
|
- currentProject: ProjectType,
|
|
|
- currentCluster: ClusterType,
|
|
|
- currentRoute: PorterUrls,
|
|
|
+ logOut: () => void;
|
|
|
+ currentProject: ProjectType;
|
|
|
+ currentCluster: ClusterType;
|
|
|
+ currentRoute: PorterUrls;
|
|
|
};
|
|
|
|
|
|
type StateType = {
|
|
|
- forceSidebar: boolean,
|
|
|
- showWelcome: boolean,
|
|
|
- handleDO: boolean, // Trigger DO infra calls after oauth flow if needed
|
|
|
- forceRefreshClusters: boolean, // For updating ClusterSection from modal on deletion
|
|
|
- templateNamespace: string,
|
|
|
+ forceSidebar: boolean;
|
|
|
+ showWelcome: boolean;
|
|
|
+ handleDO: boolean; // Trigger DO infra calls after oauth flow if needed
|
|
|
+ ghRedirect: boolean;
|
|
|
+ forceRefreshClusters: boolean; // For updating ClusterSection from modal on deletion
|
|
|
+
|
|
|
// Track last project id for refreshing clusters on project change
|
|
|
- prevProjectId: number | null,
|
|
|
- ghRedirect: boolean,
|
|
|
+ prevProjectId: number | null;
|
|
|
};
|
|
|
|
|
|
// TODO: Handle cluster connected but with some failed infras (no successful set)
|
|
|
@@ -48,181 +48,202 @@ class Home extends Component<PropsType, StateType> {
|
|
|
state = {
|
|
|
forceSidebar: true,
|
|
|
showWelcome: false,
|
|
|
- ghRedirect: false,
|
|
|
prevProjectId: null as number | null,
|
|
|
forceRefreshClusters: false,
|
|
|
- templateNamespace: '',
|
|
|
sidebarReady: false,
|
|
|
handleDO: false,
|
|
|
- }
|
|
|
+ ghRedirect: false,
|
|
|
+ };
|
|
|
|
|
|
// TODO: Refactor and prevent flash + multiple reload
|
|
|
initializeView = () => {
|
|
|
let { currentProject } = this.props;
|
|
|
-
|
|
|
+
|
|
|
if (!currentProject) return;
|
|
|
|
|
|
if (this.state.ghRedirect) {
|
|
|
this.props.history.push("integrations");
|
|
|
this.setState({ ghRedirect: false });
|
|
|
} else {
|
|
|
- this.props.history.push("dashboard");
|
|
|
+ if (this.props.currentRoute !== "dashboard")
|
|
|
+ this.props.history.push("dashboard");
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
getProjects = (id?: number) => {
|
|
|
let { user, setProjects } = this.context;
|
|
|
let { currentProject } = this.props;
|
|
|
- api.getProjects('<token>', {}, { id: user.userId }, (err: any, res: any) => {
|
|
|
- if (err) {
|
|
|
- console.log(err);
|
|
|
- } else if (res.data) {
|
|
|
- if (res.data.length === 0) {
|
|
|
- this.props.history.push("new-project");
|
|
|
- } else if (res.data.length > 0 && !currentProject) {
|
|
|
- setProjects(res.data);
|
|
|
-
|
|
|
- let foundProject = null;
|
|
|
- if (id) {
|
|
|
- res.data.forEach((project: ProjectType, i: number) => {
|
|
|
- if (project.id === id) {
|
|
|
- foundProject = project;
|
|
|
- }
|
|
|
- });
|
|
|
- this.context.setCurrentProject(foundProject);
|
|
|
- }
|
|
|
-
|
|
|
- if (!foundProject) {
|
|
|
- res.data.forEach((project: ProjectType, i: number) => {
|
|
|
- if (project.id.toString() === localStorage.getItem('currentProject')) {
|
|
|
- foundProject = project;
|
|
|
- }
|
|
|
- })
|
|
|
- this.context.setCurrentProject(foundProject ? foundProject : res.data[0]);
|
|
|
- this.initializeView();
|
|
|
+ api.getProjects(
|
|
|
+ "<token>",
|
|
|
+ {},
|
|
|
+ { id: user.userId },
|
|
|
+ (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+ } else if (res.data) {
|
|
|
+ if (res.data.length === 0) {
|
|
|
+ this.props.history.push("new-project");
|
|
|
+ } else if (res.data.length > 0 && !currentProject) {
|
|
|
+ setProjects(res.data);
|
|
|
+
|
|
|
+ let foundProject = null;
|
|
|
+ if (id) {
|
|
|
+ res.data.forEach((project: ProjectType, i: number) => {
|
|
|
+ if (project.id === id) {
|
|
|
+ foundProject = project;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.context.setCurrentProject(foundProject);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!foundProject) {
|
|
|
+ res.data.forEach((project: ProjectType, i: number) => {
|
|
|
+ if (
|
|
|
+ project.id.toString() ===
|
|
|
+ localStorage.getItem("currentProject")
|
|
|
+ ) {
|
|
|
+ foundProject = project;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.context.setCurrentProject(
|
|
|
+ foundProject ? foundProject : res.data[0]
|
|
|
+ );
|
|
|
+ this.initializeView();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
+ );
|
|
|
+ };
|
|
|
|
|
|
provisionDOCR = (integrationId: number, tier: string, callback?: any) => {
|
|
|
- console.log('Provisioning DOCR...');
|
|
|
- api.createDOCR('<token>', {
|
|
|
- do_integration_id: integrationId,
|
|
|
- docr_name: this.props.currentProject.name,
|
|
|
- docr_subscription_tier: tier,
|
|
|
- }, {
|
|
|
- project_id: this.props.currentProject.id
|
|
|
- }, (err: any, res: any) => {
|
|
|
- if (err) {
|
|
|
- console.log(err);
|
|
|
- return;
|
|
|
+ console.log("Provisioning DOCR...");
|
|
|
+ api.createDOCR(
|
|
|
+ "<token>",
|
|
|
+ {
|
|
|
+ do_integration_id: integrationId,
|
|
|
+ docr_name: this.props.currentProject.name,
|
|
|
+ docr_subscription_tier: tier,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ project_id: this.props.currentProject.id,
|
|
|
+ },
|
|
|
+ (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ callback && callback();
|
|
|
}
|
|
|
- callback && callback();
|
|
|
- });
|
|
|
- }
|
|
|
+ );
|
|
|
+ };
|
|
|
|
|
|
provisionDOKS = (integrationId: number, region: string) => {
|
|
|
- console.log('Provisioning DOKS...');
|
|
|
- api.createDOKS('<token>', {
|
|
|
- do_integration_id: integrationId,
|
|
|
- doks_name: this.props.currentProject.name,
|
|
|
- do_region: region,
|
|
|
- }, {
|
|
|
- project_id: this.props.currentProject.id
|
|
|
- }, (err: any, res: any) => {
|
|
|
- if (err) {
|
|
|
- console.log(err);
|
|
|
- return;
|
|
|
+ console.log("Provisioning DOKS...");
|
|
|
+ api.createDOKS(
|
|
|
+ "<token>",
|
|
|
+ {
|
|
|
+ do_integration_id: integrationId,
|
|
|
+ doks_name: this.props.currentProject.name,
|
|
|
+ do_region: region,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ project_id: this.props.currentProject.id,
|
|
|
+ },
|
|
|
+ (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.props.history.push("dashboard?tab=provisioner");
|
|
|
}
|
|
|
- <Redirect to="provisioner"></Redirect>
|
|
|
- });
|
|
|
- }
|
|
|
+ );
|
|
|
+ };
|
|
|
|
|
|
checkDO = () => {
|
|
|
let { currentProject } = this.props;
|
|
|
if (this.state.handleDO && currentProject?.id) {
|
|
|
- api.getOAuthIds('<token>', {}, {
|
|
|
- project_id: currentProject.id
|
|
|
- }, (err: any, res: any) => {
|
|
|
- if (err) {
|
|
|
- console.log(err);
|
|
|
- return;
|
|
|
- }
|
|
|
- let tgtIntegration = res.data.find((integration: any) => {
|
|
|
- return integration.client === 'do'
|
|
|
- });
|
|
|
- let queryString = window.location.search;
|
|
|
- let urlParams = new URLSearchParams(queryString);
|
|
|
- let tier = urlParams.get('tier');
|
|
|
- let region = urlParams.get('region');
|
|
|
- let infras = urlParams.getAll('infras');
|
|
|
- if (infras.length === 2) {
|
|
|
- this.provisionDOCR(tgtIntegration.id, tier, () => {
|
|
|
- this.provisionDOKS(tgtIntegration.id, region);
|
|
|
- });
|
|
|
- } else if (infras[0] === 'docr') {
|
|
|
- this.provisionDOCR(tgtIntegration.id, tier, () => {
|
|
|
- <Redirect to="provisioner"></Redirect>
|
|
|
+ api.getOAuthIds(
|
|
|
+ "<token>",
|
|
|
+ {},
|
|
|
+ {
|
|
|
+ project_id: currentProject.id,
|
|
|
+ },
|
|
|
+ (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let tgtIntegration = res.data.find((integration: any) => {
|
|
|
+ return integration.client === "do";
|
|
|
});
|
|
|
- } else {
|
|
|
- this.provisionDOKS(tgtIntegration.id, region);
|
|
|
+ let queryString = window.location.search;
|
|
|
+ let urlParams = new URLSearchParams(queryString);
|
|
|
+ let tier = urlParams.get("tier");
|
|
|
+ let region = urlParams.get("region");
|
|
|
+ let infras = urlParams.getAll("infras");
|
|
|
+ if (infras.length === 2) {
|
|
|
+ this.provisionDOCR(tgtIntegration.id, tier, () => {
|
|
|
+ this.provisionDOKS(tgtIntegration.id, region);
|
|
|
+ });
|
|
|
+ } else if (infras[0] === "docr") {
|
|
|
+ this.provisionDOCR(tgtIntegration.id, tier, () => {
|
|
|
+ this.props.history.push("dashboard?tab=provisioner");
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.provisionDOKS(tgtIntegration.id, region);
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
+ );
|
|
|
this.setState({ handleDO: false });
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
componentDidMount() {
|
|
|
let { user } = this.context;
|
|
|
- FullStory.identify(user.email)
|
|
|
+ FullStory.identify(user.email);
|
|
|
|
|
|
// Handle redirect from DO
|
|
|
let queryString = window.location.search;
|
|
|
let urlParams = new URLSearchParams(queryString);
|
|
|
|
|
|
- let err = urlParams.get('error');
|
|
|
+ let err = urlParams.get("error");
|
|
|
if (err) {
|
|
|
this.context.setCurrentError(err);
|
|
|
}
|
|
|
|
|
|
- let provision = urlParams.get('provision');
|
|
|
+ let provision = urlParams.get("provision");
|
|
|
let defaultProjectId = null;
|
|
|
- if (provision === 'do') {
|
|
|
- defaultProjectId = parseInt(urlParams.get('project_id'));
|
|
|
+ if (provision === "do") {
|
|
|
+ defaultProjectId = parseInt(urlParams.get("project_id"));
|
|
|
this.setState({ handleDO: true });
|
|
|
this.checkDO();
|
|
|
}
|
|
|
|
|
|
// initialize posthog on non-localhosts. Gracefully fail when env vars are not set.
|
|
|
- this.setState({ ghRedirect: urlParams.get('gh_oauth') !== null });
|
|
|
- urlParams.delete('gh_oauth');
|
|
|
-
|
|
|
- window.location.href.indexOf('localhost') === -1 && posthog.init(process.env.POSTHOG_API_KEY || 'placeholder', {
|
|
|
- api_host: process.env.POSTHOG_HOST || 'placeholder',
|
|
|
- loaded: function(posthog: any) {
|
|
|
- posthog.identify(user.userId)
|
|
|
- posthog.people.set({ email: user.email })
|
|
|
- }
|
|
|
- })
|
|
|
+ this.setState({ ghRedirect: urlParams.get("gh_oauth") !== null });
|
|
|
+ urlParams.delete("gh_oauth");
|
|
|
+
|
|
|
+ window.location.href.indexOf("localhost") === -1 &&
|
|
|
+ posthog.init(process.env.POSTHOG_API_KEY || "placeholder", {
|
|
|
+ api_host: process.env.POSTHOG_HOST || "placeholder",
|
|
|
+ loaded: function (posthog: any) {
|
|
|
+ posthog.identify(user.userId);
|
|
|
+ posthog.people.set({ email: user.email });
|
|
|
+ },
|
|
|
+ });
|
|
|
|
|
|
this.getProjects(defaultProjectId);
|
|
|
}
|
|
|
|
|
|
- handleTemplateDeploy = (namespace: string) => {
|
|
|
- this.setState({ templateNamespace: namespace });
|
|
|
- // Add routing
|
|
|
- }
|
|
|
-
|
|
|
// TODO: Need to handle the following cases. Do a deep rearchitecture (Prov -> Dashboard?) if need be:
|
|
|
// 1. Make sure clicking cluster in drawer shows cluster-dashboard
|
|
|
// 2. Make sure switching projects shows appropriate initial view (dashboard || provisioner)
|
|
|
// 3. Make sure initializing from URL (DO oauth) displays the appropriate initial view
|
|
|
componentDidUpdate(prevProps: PropsType) {
|
|
|
if (
|
|
|
- prevProps.currentProject !== this.props.currentProject
|
|
|
- || (!prevProps.currentCluster && this.props.currentCluster)
|
|
|
+ prevProps.currentProject !== this.props.currentProject ||
|
|
|
+ (!prevProps.currentCluster && this.props.currentCluster)
|
|
|
) {
|
|
|
if (this.state.handleDO) {
|
|
|
this.checkDO();
|
|
|
@@ -239,219 +260,254 @@ class Home extends Component<PropsType, StateType> {
|
|
|
return (
|
|
|
<DashboardWrapper>
|
|
|
<Placeholder>
|
|
|
- <Bold>Porter - Getting Started</Bold><br /><br />
|
|
|
- 1. Navigate to <A onClick={() => setCurrentModal('ClusterConfigModal')}>+ Add a Cluster</A> and provide a kubeconfig. *<br /><br />
|
|
|
- 2. Choose which contexts you would like to use from the <A onClick={() => {
|
|
|
- setCurrentModal('ClusterConfigModal', { currentTab: 'select' });
|
|
|
- }}>Select Clusters</A> tab.<br /><br />
|
|
|
- 3. For additional information, please refer to our <A>docs</A>.<br /><br /><br />
|
|
|
-
|
|
|
- * Make sure all fields are explicitly declared (e.g., certs and keys).
|
|
|
+ <Bold>Porter - Getting Started</Bold>
|
|
|
+ <br />
|
|
|
+ <br />
|
|
|
+ 1. Navigate to{" "}
|
|
|
+ <A onClick={() => setCurrentModal("ClusterConfigModal")}>
|
|
|
+ + Add a Cluster
|
|
|
+ </A>{" "}
|
|
|
+ and provide a kubeconfig. *<br />
|
|
|
+ <br />
|
|
|
+ 2. Choose which contexts you would like to use from the{" "}
|
|
|
+ <A
|
|
|
+ onClick={() => {
|
|
|
+ setCurrentModal("ClusterConfigModal", { currentTab: "select" });
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ Select Clusters
|
|
|
+ </A>{" "}
|
|
|
+ tab.
|
|
|
+ <br />
|
|
|
+ <br />
|
|
|
+ 3. For additional information, please refer to our <A>docs</A>.
|
|
|
+ <br />
|
|
|
+ <br />
|
|
|
+ <br />* Make sure all fields are explicitly declared (e.g., certs
|
|
|
+ and keys).
|
|
|
</Placeholder>
|
|
|
</DashboardWrapper>
|
|
|
);
|
|
|
} else if (!currentCluster) {
|
|
|
- return <Loading />
|
|
|
+ return <Loading />;
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
<DashboardWrapper>
|
|
|
<ClusterDashboard
|
|
|
currentCluster={currentCluster}
|
|
|
- namespace={this.state.templateNamespace}
|
|
|
- resetNamespace={() => this.setState({ templateNamespace: '' })}
|
|
|
setSidebar={(x: boolean) => this.setState({ forceSidebar: x })}
|
|
|
// setCurrentView={(x: string) => this.setState({ currentView: x })}
|
|
|
/>
|
|
|
</DashboardWrapper>
|
|
|
);
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
renderContents = () => {
|
|
|
let currentView = this.props.currentRoute;
|
|
|
- if (this.context.currentProject && currentView !== 'new-project') {
|
|
|
- if (currentView === 'cluster-dashboard') {
|
|
|
+ if (this.context.currentProject && currentView !== "new-project") {
|
|
|
+ if (currentView === "cluster-dashboard") {
|
|
|
return this.renderDashboard();
|
|
|
- } else if (currentView === 'dashboard') {
|
|
|
+ } else if (currentView === "dashboard") {
|
|
|
return (
|
|
|
<DashboardWrapper>
|
|
|
- <Dashboard
|
|
|
- projectId={this.context.currentProject?.id}
|
|
|
- />
|
|
|
+ <Dashboard projectId={this.context.currentProject?.id} />
|
|
|
</DashboardWrapper>
|
|
|
);
|
|
|
- } else if (currentView === 'integrations') {
|
|
|
+ } else if (currentView === "integrations") {
|
|
|
return <Integrations />;
|
|
|
- } else if (currentView === 'project-settings') {
|
|
|
- return (
|
|
|
- <ProjectSettings />
|
|
|
- )
|
|
|
+ } else if (currentView === "project-settings") {
|
|
|
+ return <ProjectSettings />;
|
|
|
}
|
|
|
|
|
|
- return (
|
|
|
- <Templates />
|
|
|
- );
|
|
|
- } else if (currentView === 'new-project') {
|
|
|
- return (
|
|
|
- <NewProject/>
|
|
|
- );
|
|
|
+ return <Templates />;
|
|
|
+ } else if (currentView === "new-project") {
|
|
|
+ return <NewProject />;
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
renderSidebar = () => {
|
|
|
if (this.context.projects.length > 0) {
|
|
|
-
|
|
|
- // Force sidebar closed on first provision
|
|
|
- if (this.props.currentRoute === 'provisioner' && this.state.forceSidebar) {
|
|
|
- this.setState({ forceSidebar: false });
|
|
|
- } else {
|
|
|
- return (
|
|
|
- <Sidebar
|
|
|
- key="sidebar"
|
|
|
- forceSidebar={this.state.forceSidebar}
|
|
|
- setWelcome={(x: boolean) => this.setState({ showWelcome: x })}
|
|
|
- currentView={this.props.currentRoute}
|
|
|
- forceRefreshClusters={this.state.forceRefreshClusters}
|
|
|
- setRefreshClusters={(x: boolean) => this.setState({ forceRefreshClusters: x })}
|
|
|
- />
|
|
|
- );
|
|
|
- }
|
|
|
+ return (
|
|
|
+ <Sidebar
|
|
|
+ key="sidebar"
|
|
|
+ forceSidebar={this.state.forceSidebar}
|
|
|
+ setWelcome={(x: boolean) => this.setState({ showWelcome: x })}
|
|
|
+ currentView={this.props.currentRoute}
|
|
|
+ forceRefreshClusters={this.state.forceRefreshClusters}
|
|
|
+ setRefreshClusters={(x: boolean) =>
|
|
|
+ this.setState({ forceRefreshClusters: x })
|
|
|
+ }
|
|
|
+ />
|
|
|
+ );
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
projectOverlayCall = () => {
|
|
|
let { user, setProjects } = this.context;
|
|
|
- api.getProjects('<token>', {}, { id: user.userId }, (err: any, res: any) => {
|
|
|
- if (err) {
|
|
|
- console.log(err)
|
|
|
- } else if (res.data) {
|
|
|
- setProjects(res.data);
|
|
|
- if (res.data.length > 0) {
|
|
|
- this.context.setCurrentProject(res.data[0]);
|
|
|
- // Redirect to dashboard
|
|
|
- } else {
|
|
|
- this.context.setCurrentProject(null);
|
|
|
- this.props.history.push("new-project");
|
|
|
+ api.getProjects(
|
|
|
+ "<token>",
|
|
|
+ {},
|
|
|
+ { id: user.userId },
|
|
|
+ (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+ } else if (res.data) {
|
|
|
+ setProjects(res.data);
|
|
|
+ if (res.data.length > 0) {
|
|
|
+ this.context.setCurrentProject(res.data[0]);
|
|
|
+ } else {
|
|
|
+ this.context.setCurrentProject(null);
|
|
|
+ this.props.history.push("new-project");
|
|
|
+ }
|
|
|
+ this.context.setCurrentModal(null, null);
|
|
|
}
|
|
|
- this.context.setCurrentModal(null, null);
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
+ );
|
|
|
+ };
|
|
|
|
|
|
handleDelete = () => {
|
|
|
let { setCurrentModal, currentProject } = this.context;
|
|
|
- localStorage.removeItem(currentProject.id + '-cluster');
|
|
|
- api.deleteProject('<token>', {}, { id: currentProject.id }, (err: any, res: any) => {
|
|
|
- if (err) {
|
|
|
- console.log(err)
|
|
|
- } else {
|
|
|
- this.projectOverlayCall();
|
|
|
+ localStorage.removeItem(currentProject.id + "-cluster");
|
|
|
+ api.deleteProject(
|
|
|
+ "<token>",
|
|
|
+ {},
|
|
|
+ { id: currentProject.id },
|
|
|
+ (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+ } else {
|
|
|
+ this.projectOverlayCall();
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
+ );
|
|
|
|
|
|
// Loop through and delete infra of all clusters we've provisioned
|
|
|
- api.getClusters('<token>', {}, { id: currentProject.id }, (err: any, res: any) => {
|
|
|
+ api.getClusters(
|
|
|
+ "<token>",
|
|
|
+ {},
|
|
|
+ { id: currentProject.id },
|
|
|
+ (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (err) {
|
|
|
- console.log(err);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- for (var i = 0; i < res.data.length; i++) {
|
|
|
- let cluster = res.data[i];
|
|
|
- if (!cluster.infra_id) continue;
|
|
|
-
|
|
|
- // Handle destroying infra we've provisioned
|
|
|
- switch (cluster.service) {
|
|
|
-
|
|
|
- case "eks":
|
|
|
- api.destroyEKS('<token>', { eks_name: cluster.name }, {
|
|
|
- project_id: currentProject.id,
|
|
|
- infra_id: cluster.infra_id,
|
|
|
- }, (err: any, res: any) => {
|
|
|
- if (err) {
|
|
|
- console.log(err)
|
|
|
- } else {
|
|
|
- console.log('destroyed provisioned infra:', cluster.infra_id);
|
|
|
- }
|
|
|
- });
|
|
|
- break;
|
|
|
-
|
|
|
- case 'gke':
|
|
|
- api.destroyGKE('<token>', { gke_name: cluster.name }, {
|
|
|
- project_id: currentProject.id,
|
|
|
- infra_id: cluster.infra_id,
|
|
|
- }, (err: any, res: any) => {
|
|
|
- if (err) {
|
|
|
- console.log(err)
|
|
|
- } else {
|
|
|
- console.log('destroyed provisioned infra.');
|
|
|
- }
|
|
|
- });
|
|
|
- break;
|
|
|
-
|
|
|
- case 'doks':
|
|
|
- api.destroyDOKS('<token>', { doks_name: cluster.name }, {
|
|
|
- project_id: currentProject.id,
|
|
|
- infra_id: cluster.infra_id,
|
|
|
- }, (err: any, res: any) => {
|
|
|
- if (err) {
|
|
|
- console.log(err)
|
|
|
- } else {
|
|
|
- console.log('destroyed provisioned infra.');
|
|
|
- }
|
|
|
- });
|
|
|
- break;
|
|
|
+ for (var i = 0; i < res.data.length; i++) {
|
|
|
+ let cluster = res.data[i];
|
|
|
+ if (!cluster.infra_id) continue;
|
|
|
+
|
|
|
+ // Handle destroying infra we've provisioned
|
|
|
+ switch (cluster.service) {
|
|
|
+ case "eks":
|
|
|
+ api.destroyEKS(
|
|
|
+ "<token>",
|
|
|
+ { eks_name: cluster.name },
|
|
|
+ {
|
|
|
+ project_id: currentProject.id,
|
|
|
+ infra_id: cluster.infra_id,
|
|
|
+ },
|
|
|
+ (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+ } else {
|
|
|
+ console.log(
|
|
|
+ "destroyed provisioned infra:",
|
|
|
+ cluster.infra_id
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "gke":
|
|
|
+ api.destroyGKE(
|
|
|
+ "<token>",
|
|
|
+ { gke_name: cluster.name },
|
|
|
+ {
|
|
|
+ project_id: currentProject.id,
|
|
|
+ infra_id: cluster.infra_id,
|
|
|
+ },
|
|
|
+ (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+ } else {
|
|
|
+ console.log("destroyed provisioned infra.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "doks":
|
|
|
+ api.destroyDOKS(
|
|
|
+ "<token>",
|
|
|
+ { doks_name: cluster.name },
|
|
|
+ {
|
|
|
+ project_id: currentProject.id,
|
|
|
+ infra_id: cluster.infra_id,
|
|
|
+ },
|
|
|
+ (err: any, res: any) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+ } else {
|
|
|
+ console.log("destroyed provisioned infra.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ );
|
|
|
setCurrentModal(null, null);
|
|
|
this.props.history.push("dashboard");
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
render() {
|
|
|
let { currentModal, setCurrentModal, currentProject } = this.context;
|
|
|
|
|
|
return (
|
|
|
<StyledHome>
|
|
|
- {currentModal === 'ClusterInstructionsModal' &&
|
|
|
+ {currentModal === "ClusterInstructionsModal" && (
|
|
|
<Modal
|
|
|
onRequestClose={() => setCurrentModal(null, null)}
|
|
|
- width='760px'
|
|
|
- height='650px'
|
|
|
+ width="760px"
|
|
|
+ height="650px"
|
|
|
>
|
|
|
<ClusterInstructionsModal />
|
|
|
</Modal>
|
|
|
- }
|
|
|
- {currentModal === 'UpdateClusterModal' &&
|
|
|
+ )}
|
|
|
+ {currentModal === "UpdateClusterModal" && (
|
|
|
<Modal
|
|
|
onRequestClose={() => setCurrentModal(null, null)}
|
|
|
- width='565px'
|
|
|
- height='275px'
|
|
|
+ width="565px"
|
|
|
+ height="275px"
|
|
|
>
|
|
|
- <UpdateClusterModal
|
|
|
- setRefreshClusters={(x: boolean) => this.setState({ forceRefreshClusters: x })}
|
|
|
+ <UpdateClusterModal
|
|
|
+ setRefreshClusters={(x: boolean) =>
|
|
|
+ this.setState({ forceRefreshClusters: x })
|
|
|
+ }
|
|
|
/>
|
|
|
</Modal>
|
|
|
- }
|
|
|
- {currentModal === 'IntegrationsModal' &&
|
|
|
+ )}
|
|
|
+ {currentModal === "IntegrationsModal" && (
|
|
|
<Modal
|
|
|
onRequestClose={() => setCurrentModal(null, null)}
|
|
|
- width='760px'
|
|
|
- height='725px'
|
|
|
+ width="760px"
|
|
|
+ height="725px"
|
|
|
>
|
|
|
<IntegrationsModal />
|
|
|
</Modal>
|
|
|
- }
|
|
|
- {currentModal === 'IntegrationsInstructionsModal' &&
|
|
|
+ )}
|
|
|
+ {currentModal === "IntegrationsInstructionsModal" && (
|
|
|
<Modal
|
|
|
onRequestClose={() => setCurrentModal(null, null)}
|
|
|
- width='760px'
|
|
|
- height='650px'
|
|
|
+ width="760px"
|
|
|
+ height="650px"
|
|
|
>
|
|
|
<IntegrationsInstructionsModal />
|
|
|
</Modal>
|
|
|
- }
|
|
|
+ )}
|
|
|
|
|
|
{this.renderSidebar()}
|
|
|
|
|
|
@@ -464,8 +520,12 @@ class Home extends Component<PropsType, StateType> {
|
|
|
</ViewWrapper>
|
|
|
|
|
|
<ConfirmOverlay
|
|
|
- show={currentModal === 'UpdateProjectModal'}
|
|
|
- message={(currentProject) ? `Are you sure you want to delete ${currentProject.name}?` : ''}
|
|
|
+ show={currentModal === "UpdateProjectModal"}
|
|
|
+ message={
|
|
|
+ currentProject
|
|
|
+ ? `Are you sure you want to delete ${currentProject.name}?`
|
|
|
+ : ""
|
|
|
+ }
|
|
|
onYes={this.handleDelete}
|
|
|
onNo={() => setCurrentModal(null, null)}
|
|
|
/>
|
|
|
@@ -500,7 +560,8 @@ const DashboardWrapper = styled.div`
|
|
|
const A = styled.a`
|
|
|
color: #ffffff;
|
|
|
text-decoration: underline;
|
|
|
- cursor: ${(props: { disabled?: boolean }) => props.disabled ? 'not-allowed' : 'pointer'};
|
|
|
+ cursor: ${(props: { disabled?: boolean }) =>
|
|
|
+ props.disabled ? "not-allowed" : "pointer"};
|
|
|
`;
|
|
|
|
|
|
const Placeholder = styled.div`
|
|
|
@@ -530,10 +591,12 @@ const StyledHome = styled.div`
|
|
|
|
|
|
@keyframes floatInModal {
|
|
|
from {
|
|
|
- opacity: 0; transform: translateY(30px);
|
|
|
+ opacity: 0;
|
|
|
+ transform: translateY(30px);
|
|
|
}
|
|
|
to {
|
|
|
- opacity: 1; transform: translateY(0px);
|
|
|
+ opacity: 1;
|
|
|
+ transform: translateY(0px);
|
|
|
}
|
|
|
}
|
|
|
-`;
|
|
|
+`;
|