|
|
@@ -1,5 +1,5 @@
|
|
|
import React, { useState } from "react";
|
|
|
-import styled, { keyframes } from "styled-components";
|
|
|
+import styled, { css, keyframes } from "styled-components";
|
|
|
import { Environment, PRDeployment } from "../types";
|
|
|
import pr_icon from "assets/pull_request_icon.svg";
|
|
|
import { integrationList } from "shared/common";
|
|
|
@@ -9,16 +9,24 @@ import { capitalize, readableDate } from "shared/string_utils";
|
|
|
import api from "shared/api";
|
|
|
import { useContext } from "react";
|
|
|
import { Context } from "shared/Context";
|
|
|
+import Loading from "components/Loading";
|
|
|
+import { ActionButton } from "../components/ActionButton";
|
|
|
|
|
|
const DeploymentCard: React.FC<{
|
|
|
deployment: PRDeployment;
|
|
|
- onDelete?: () => void;
|
|
|
-}> = ({ deployment, onDelete }) => {
|
|
|
- const { setCurrentOverlay, currentProject, currentCluster } = useContext(
|
|
|
- Context
|
|
|
- );
|
|
|
+ onDelete: () => void;
|
|
|
+ onReEnable: () => void;
|
|
|
+}> = ({ deployment, onDelete, onReEnable }) => {
|
|
|
+ const {
|
|
|
+ setCurrentOverlay,
|
|
|
+ currentProject,
|
|
|
+ currentCluster,
|
|
|
+ setCurrentError,
|
|
|
+ } = useContext(Context);
|
|
|
const [showRepoTooltip, setShowRepoTooltip] = useState(false);
|
|
|
const [isDeleting, setIsDeleting] = useState(false);
|
|
|
+ const [isLoading, setIsLoading] = useState(false);
|
|
|
+ const [hasErrorOnReEnabling, setHasErrorOnReEnabling] = useState(false);
|
|
|
const { url: currentUrl } = useRouteMatch();
|
|
|
|
|
|
let repository = `${deployment.gh_repo_owner}/${deployment.gh_repo_name}`;
|
|
|
@@ -43,6 +51,32 @@ const DeploymentCard: React.FC<{
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ const reEnablePreviewEnvironment = () => {
|
|
|
+ setIsLoading(true);
|
|
|
+ api
|
|
|
+ .reenablePreviewEnvironmentDeployment(
|
|
|
+ "<token>",
|
|
|
+ {},
|
|
|
+ {
|
|
|
+ cluster_id: currentCluster.id,
|
|
|
+ project_id: currentProject.id,
|
|
|
+ deployment_id: deployment.id,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then(() => {
|
|
|
+ setIsLoading(false);
|
|
|
+ onReEnable();
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ setHasErrorOnReEnabling(true);
|
|
|
+ setIsLoading(false);
|
|
|
+ setCurrentError(err);
|
|
|
+ setTimeout(() => {
|
|
|
+ setHasErrorOnReEnabling(false);
|
|
|
+ }, 500);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<DeploymentCardWrapper>
|
|
|
<DataContainer>
|
|
|
@@ -82,39 +116,57 @@ const DeploymentCard: React.FC<{
|
|
|
<Flex>
|
|
|
{!isDeleting ? (
|
|
|
<>
|
|
|
- {deployment.status !== "creating" && (
|
|
|
- <>
|
|
|
- <RowButton
|
|
|
- to={`${currentUrl}/pr-env-detail/${deployment.namespace}?environment_id=${deployment.environment_id}`}
|
|
|
- key={deployment.id}
|
|
|
- >
|
|
|
- <i className="material-icons-outlined">info</i>
|
|
|
- Details
|
|
|
- </RowButton>
|
|
|
- <RowButton
|
|
|
- to={deployment.subdomain}
|
|
|
- key={deployment.subdomain}
|
|
|
- target="_blank"
|
|
|
- >
|
|
|
- <i className="material-icons">open_in_new</i>
|
|
|
- View Live
|
|
|
- </RowButton>
|
|
|
- </>
|
|
|
+ {deployment.status !== "creating" &&
|
|
|
+ deployment.status !== "inactive" && (
|
|
|
+ <>
|
|
|
+ <RowButton
|
|
|
+ to={`${currentUrl}/pr-env-detail/${deployment.namespace}?environment_id=${deployment.environment_id}`}
|
|
|
+ key={deployment.id}
|
|
|
+ >
|
|
|
+ <i className="material-icons-outlined">info</i>
|
|
|
+ Details
|
|
|
+ </RowButton>
|
|
|
+ <RowButton
|
|
|
+ to={deployment.subdomain}
|
|
|
+ key={deployment.subdomain}
|
|
|
+ target="_blank"
|
|
|
+ >
|
|
|
+ <i className="material-icons">open_in_new</i>
|
|
|
+ View Live
|
|
|
+ </RowButton>
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ {deployment.status === "inactive" ? (
|
|
|
+ <ActionButton
|
|
|
+ onClick={reEnablePreviewEnvironment}
|
|
|
+ disabled={isLoading}
|
|
|
+ hasError={hasErrorOnReEnabling}
|
|
|
+ >
|
|
|
+ {isLoading ? (
|
|
|
+ <Loading width="198px" height="14px" />
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <i className="material-icons">play_arrow</i>
|
|
|
+ Activate preview environment
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ </ActionButton>
|
|
|
+ ) : (
|
|
|
+ <RowButton
|
|
|
+ to={"#"}
|
|
|
+ key={deployment.subdomain}
|
|
|
+ onClick={() =>
|
|
|
+ setCurrentOverlay({
|
|
|
+ message: `Are you sure you want to delete this deployment?`,
|
|
|
+ onYes: deleteDeployment,
|
|
|
+ onNo: () => setCurrentOverlay(null),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <i className="material-icons">delete</i>
|
|
|
+ Delete
|
|
|
+ </RowButton>
|
|
|
)}
|
|
|
- <RowButton
|
|
|
- to={"#"}
|
|
|
- key={deployment.subdomain}
|
|
|
- onClick={() =>
|
|
|
- setCurrentOverlay({
|
|
|
- message: `Are you sure you want to delete this deployment?`,
|
|
|
- onYes: deleteDeployment,
|
|
|
- onNo: () => setCurrentOverlay(null),
|
|
|
- })
|
|
|
- }
|
|
|
- >
|
|
|
- <i className="material-icons">delete</i>
|
|
|
- Delete
|
|
|
- </RowButton>
|
|
|
</>
|
|
|
) : (
|
|
|
<DeleteMessage>
|