|
|
@@ -1,53 +1,29 @@
|
|
|
-import DynamicLink from "components/DynamicLink";
|
|
|
import React, { useContext, useEffect, useState } from "react";
|
|
|
import { Context } from "shared/Context";
|
|
|
import api from "shared/api";
|
|
|
-import { useHistory, useLocation, useRouteMatch } from "react-router";
|
|
|
-import { getQueryParam } from "shared/routing";
|
|
|
import styled from "styled-components";
|
|
|
import Selector from "components/Selector";
|
|
|
|
|
|
-import ButtonEnablePREnvironments from "../components/ButtonEnablePREnvironments";
|
|
|
-import ConnectNewRepo from "../components/ConnectNewRepo";
|
|
|
import Loading from "components/Loading";
|
|
|
|
|
|
import _ from "lodash";
|
|
|
-import EnvironmentCard from "./DeploymentCard";
|
|
|
-import { Environment, PRDeployment } from "../types";
|
|
|
+import DeploymentCard from "./DeploymentCard";
|
|
|
+import { PRDeployment } from "../types";
|
|
|
|
|
|
const DeploymentList = () => {
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
const [hasError, setHasError] = useState(false);
|
|
|
- const [hasPermissions, setHasPermissions] = useState(false);
|
|
|
- const [hasPermissionsLoaded, setHasPermissionsLoaded] = useState(false);
|
|
|
- const [environmentList, setEnvironmentList] = useState<Environment[]>([]);
|
|
|
const [deploymentList, setDeploymentList] = useState<PRDeployment[]>([]);
|
|
|
const [statusSelectorVal, setStatusSelectorVal] = useState<string>("active");
|
|
|
|
|
|
- const [showConnectRepoFlow, setShowConnectRepoFlow] = useState(false);
|
|
|
const { currentProject, currentCluster, setCurrentModal } = useContext(
|
|
|
Context
|
|
|
);
|
|
|
|
|
|
- const { url: currentUrl } = useRouteMatch();
|
|
|
-
|
|
|
- const location = useLocation();
|
|
|
- const history = useHistory();
|
|
|
-
|
|
|
const getPRDeploymentList = () => {
|
|
|
- let status: string[] = [];
|
|
|
-
|
|
|
- if (statusSelectorVal == "active") {
|
|
|
- status = ["creating", "created", "failed"];
|
|
|
- } else if (statusSelectorVal == "inactive") {
|
|
|
- status = ["inactive"];
|
|
|
- }
|
|
|
-
|
|
|
return api.getPRDeploymentList(
|
|
|
"<token>",
|
|
|
- {
|
|
|
- status: status,
|
|
|
- },
|
|
|
+ {},
|
|
|
{
|
|
|
project_id: currentProject.id,
|
|
|
cluster_id: currentCluster.id,
|
|
|
@@ -55,84 +31,6 @@ const DeploymentList = () => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
- const checkGitRepoPermissions = async () => {
|
|
|
- // Get all the connected repos ids
|
|
|
- let gitRepos: number[] = null;
|
|
|
- try {
|
|
|
- gitRepos = await api
|
|
|
- .getGitRepos("<token>", {}, { project_id: currentProject.id })
|
|
|
- .then((res) => res.data);
|
|
|
- } catch (error) {
|
|
|
- console.error(error);
|
|
|
- }
|
|
|
-
|
|
|
- if (!gitRepos) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Check if all repo has enough permissions
|
|
|
- try {
|
|
|
- const repoPermissionsRequests = gitRepos.map((id) =>
|
|
|
- api
|
|
|
- .getGitRepoPermission(
|
|
|
- "<token>",
|
|
|
- {},
|
|
|
- { project_id: currentProject.id, git_repo_id: id }
|
|
|
- )
|
|
|
- .then((res) => res.data)
|
|
|
- );
|
|
|
-
|
|
|
- const permissions = await Promise.all(repoPermissionsRequests);
|
|
|
- let hasPermission =
|
|
|
- permissions.filter((val) => {
|
|
|
- return val.preview_environments;
|
|
|
- }).length >= 1;
|
|
|
-
|
|
|
- setHasPermissions(hasPermission);
|
|
|
- setHasPermissionsLoaded(true);
|
|
|
- } catch (error) {
|
|
|
- console.error(error);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- let isSubscribed = true;
|
|
|
- api
|
|
|
- .listEnvironments(
|
|
|
- "<token>",
|
|
|
- {},
|
|
|
- {
|
|
|
- project_id: currentProject.id,
|
|
|
- cluster_id: currentCluster.id,
|
|
|
- }
|
|
|
- )
|
|
|
- .then(({ data }) => {
|
|
|
- if (!isSubscribed) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (!Array.isArray(data)) {
|
|
|
- throw Error("Data is not an array");
|
|
|
- }
|
|
|
- setEnvironmentList(data);
|
|
|
- })
|
|
|
- .catch((err) => {
|
|
|
- console.error(err);
|
|
|
- if (isSubscribed) {
|
|
|
- setHasError(true);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return () => {
|
|
|
- isSubscribed = false;
|
|
|
- };
|
|
|
- }, [currentProject, currentCluster, location.search]);
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- setHasPermissionsLoaded(false);
|
|
|
- checkGitRepoPermissions();
|
|
|
- }, [currentProject, currentCluster]);
|
|
|
-
|
|
|
useEffect(() => {
|
|
|
let isSubscribed = true;
|
|
|
getPRDeploymentList()
|
|
|
@@ -141,11 +39,7 @@ const DeploymentList = () => {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (!Array.isArray(data)) {
|
|
|
- throw Error("Data is not an array");
|
|
|
- }
|
|
|
-
|
|
|
- setDeploymentList(data);
|
|
|
+ setDeploymentList(data.deployments);
|
|
|
setIsLoading(false);
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
@@ -160,15 +54,6 @@ const DeploymentList = () => {
|
|
|
};
|
|
|
}, [currentCluster, currentProject, statusSelectorVal]);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- const action = getQueryParam({ location }, "action");
|
|
|
- if (action === "connect-repo") {
|
|
|
- setShowConnectRepoFlow(true);
|
|
|
- } else {
|
|
|
- setShowConnectRepoFlow(false);
|
|
|
- }
|
|
|
- }, [location.search, history]);
|
|
|
-
|
|
|
const handleRefresh = () => {
|
|
|
setIsLoading(true);
|
|
|
getPRDeploymentList()
|
|
|
@@ -185,49 +70,11 @@ const DeploymentList = () => {
|
|
|
.finally(() => setIsLoading(false));
|
|
|
};
|
|
|
|
|
|
- if (showConnectRepoFlow) {
|
|
|
- return (
|
|
|
- <Container>
|
|
|
- <ConnectNewRepo />
|
|
|
- </Container>
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- if (hasPermissionsLoaded && !hasPermissions) {
|
|
|
- return (
|
|
|
- <Placeholder>
|
|
|
- Github App permissions are not up to date. Please review any pending
|
|
|
- requests to update Github App permissions.
|
|
|
- </Placeholder>
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- if (!hasPermissionsLoaded) {
|
|
|
- return (
|
|
|
- <Placeholder>
|
|
|
- <Loading />
|
|
|
- </Placeholder>
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
if (hasError) {
|
|
|
return <Placeholder>Error</Placeholder>;
|
|
|
}
|
|
|
|
|
|
- if (!environmentList.length) {
|
|
|
- return (
|
|
|
- <Placeholder>
|
|
|
- <Header>Preview environments are not enabled on this cluster</Header>
|
|
|
- <Subheader>
|
|
|
- In order to use preview environments, you must enable preview
|
|
|
- environments on this cluster.
|
|
|
- </Subheader>
|
|
|
- <ButtonEnablePREnvironments />
|
|
|
- </Placeholder>
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- let renderDeploymentList = () => {
|
|
|
+ const renderDeploymentList = () => {
|
|
|
if (isLoading) {
|
|
|
return (
|
|
|
<Placeholder>
|
|
|
@@ -246,29 +93,13 @@ const DeploymentList = () => {
|
|
|
}
|
|
|
|
|
|
return deploymentList.map((d) => {
|
|
|
- const environment = environmentList?.find((e) => {
|
|
|
- return e.id === d.environment_id;
|
|
|
- });
|
|
|
- return (
|
|
|
- <EnvironmentCard
|
|
|
- deployment={d}
|
|
|
- environment={environment}
|
|
|
- onDelete={handleRefresh}
|
|
|
- />
|
|
|
- );
|
|
|
+ return <DeploymentCard deployment={d} onDelete={handleRefresh} />;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
<Container>
|
|
|
<ControlRow>
|
|
|
- <Button
|
|
|
- to={`${currentUrl}?selected_tab=preview_environments&action=connect-repo`}
|
|
|
- onClick={() => console.log("launch repo")}
|
|
|
- >
|
|
|
- <i className="material-icons">add</i> Add Repository
|
|
|
- </Button>
|
|
|
-
|
|
|
<ActionsWrapper>
|
|
|
<RefreshButton color={"#7d7d81"} onClick={handleRefresh}>
|
|
|
<i className="material-icons">refresh</i>
|
|
|
@@ -391,67 +222,12 @@ const ControlRow = styled.div`
|
|
|
padding-left: 0px;
|
|
|
`;
|
|
|
|
|
|
-const Button = styled(DynamicLink)`
|
|
|
- display: flex;
|
|
|
- flex-direction: row;
|
|
|
- align-items: center;
|
|
|
- justify-content: space-between;
|
|
|
- font-size: 13px;
|
|
|
- cursor: pointer;
|
|
|
- font-family: "Work Sans", sans-serif;
|
|
|
- border-radius: 20px;
|
|
|
- color: white;
|
|
|
- height: 35px;
|
|
|
- padding: 0px 8px;
|
|
|
- padding-bottom: 1px;
|
|
|
- margin-right: 10px;
|
|
|
- font-weight: 500;
|
|
|
- padding-right: 15px;
|
|
|
- overflow: hidden;
|
|
|
- white-space: nowrap;
|
|
|
- text-overflow: ellipsis;
|
|
|
- box-shadow: 0 5px 8px 0px #00000010;
|
|
|
- cursor: ${(props: { disabled?: boolean }) =>
|
|
|
- props.disabled ? "not-allowed" : "pointer"};
|
|
|
-
|
|
|
- background: ${(props: { disabled?: boolean }) =>
|
|
|
- props.disabled ? "#aaaabbee" : "#616FEEcc"};
|
|
|
- :hover {
|
|
|
- background: ${(props: { disabled?: boolean }) =>
|
|
|
- props.disabled ? "" : "#505edddd"};
|
|
|
- }
|
|
|
-
|
|
|
- > i {
|
|
|
- color: white;
|
|
|
- width: 18px;
|
|
|
- height: 18px;
|
|
|
- font-weight: 600;
|
|
|
- font-size: 12px;
|
|
|
- border-radius: 20px;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- margin-right: 5px;
|
|
|
- justify-content: center;
|
|
|
- }
|
|
|
-`;
|
|
|
-
|
|
|
const EventsGrid = styled.div`
|
|
|
display: grid;
|
|
|
grid-row-gap: 20px;
|
|
|
grid-template-columns: 1;
|
|
|
`;
|
|
|
|
|
|
-const Label = styled.div`
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- margin-right: 12px;
|
|
|
-
|
|
|
- > i {
|
|
|
- margin-right: 8px;
|
|
|
- font-size: 18px;
|
|
|
- }
|
|
|
-`;
|
|
|
-
|
|
|
const StyledStatusSelector = styled.div`
|
|
|
display: flex;
|
|
|
align-items: center;
|