|
|
@@ -1,20 +1,51 @@
|
|
|
import React, { useState } from "react";
|
|
|
-import styled from "styled-components";
|
|
|
-import { PRDeployment } from "../EnvironmentList";
|
|
|
+import styled, { keyframes } from "styled-components";
|
|
|
+import { Environment, PRDeployment } from "../EnvironmentList";
|
|
|
import pr_icon from "assets/pull_request_icon.svg";
|
|
|
import { integrationList } from "shared/common";
|
|
|
import { useRouteMatch } from "react-router";
|
|
|
import DynamicLink from "components/DynamicLink";
|
|
|
import { capitalize, readableDate } from "shared/string_utils";
|
|
|
+import api from "shared/api";
|
|
|
+import { useContext } from "react";
|
|
|
+import { Context } from "shared/Context";
|
|
|
|
|
|
-const EnvironmentCard: React.FC<{ deployment: PRDeployment }> = ({
|
|
|
- deployment,
|
|
|
-}) => {
|
|
|
+const EnvironmentCard: React.FC<{
|
|
|
+ deployment: PRDeployment;
|
|
|
+ environment: Environment;
|
|
|
+ onDelete: () => void;
|
|
|
+}> = ({ deployment, environment, onDelete }) => {
|
|
|
+ const { setCurrentOverlay } = useContext(Context);
|
|
|
const [showRepoTooltip, setShowRepoTooltip] = useState(false);
|
|
|
+ const [isDeleting, setIsDeleting] = useState(false);
|
|
|
const { url: currentUrl } = useRouteMatch();
|
|
|
|
|
|
let repository = `${deployment.gh_repo_owner}/${deployment.gh_repo_name}`;
|
|
|
|
|
|
+ const deleteDeployment = () => {
|
|
|
+ setIsDeleting(true);
|
|
|
+
|
|
|
+ api
|
|
|
+ .deletePRDeployment(
|
|
|
+ "<token>",
|
|
|
+ {
|
|
|
+ namespace: deployment.namespace,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ cluster_id: environment.cluster_id,
|
|
|
+ project_id: environment.project_id,
|
|
|
+ git_installation_id: environment.git_installation_id,
|
|
|
+ git_repo_owner: environment.git_repo_owner,
|
|
|
+ git_repo_name: environment.git_repo_name,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then(() => {
|
|
|
+ setIsDeleting(false);
|
|
|
+ onDelete();
|
|
|
+ setCurrentOverlay(null);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<EnvironmentCardWrapper key={deployment.id}>
|
|
|
<DataContainer>
|
|
|
@@ -52,27 +83,97 @@ const EnvironmentCard: React.FC<{ deployment: PRDeployment }> = ({
|
|
|
</Flex>
|
|
|
</DataContainer>
|
|
|
<Flex>
|
|
|
- <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>
|
|
|
+ {!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>
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ <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>
|
|
|
+ Deleting
|
|
|
+ <Dot delay="0s" />
|
|
|
+ <Dot delay="0.1s" />
|
|
|
+ <Dot delay="0.2s" />
|
|
|
+ </DeleteMessage>
|
|
|
+ )}
|
|
|
</Flex>
|
|
|
</EnvironmentCardWrapper>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
export default EnvironmentCard;
|
|
|
+
|
|
|
+const DeleteMessage = styled.div`
|
|
|
+ display: flex;
|
|
|
+ align-items: flex-end;
|
|
|
+ justify-content: center;
|
|
|
+`;
|
|
|
+
|
|
|
+export const DissapearAnimation = keyframes`
|
|
|
+ 0% {
|
|
|
+ background-color: #ffffff;
|
|
|
+ }
|
|
|
+
|
|
|
+ 25% {
|
|
|
+ background-color: #ffffff50;
|
|
|
+ }
|
|
|
+
|
|
|
+ 50% {
|
|
|
+ background-color: none;
|
|
|
+ }
|
|
|
+
|
|
|
+ 75% {
|
|
|
+ background-color: #ffffff50;
|
|
|
+ }
|
|
|
+
|
|
|
+ 100% {
|
|
|
+ background-color: #ffffff;
|
|
|
+ }
|
|
|
+`;
|
|
|
+
|
|
|
+const Dot = styled.div`
|
|
|
+ background-color: black;
|
|
|
+ border-radius: 50%;
|
|
|
+ width: 5px;
|
|
|
+ height: 5px;
|
|
|
+ margin: 0 0.25rem;
|
|
|
+ margin-bottom: 2px;
|
|
|
+ //Animation
|
|
|
+ animation: ${DissapearAnimation} 0.5s linear infinite;
|
|
|
+ animation-delay: ${(props: { delay: string }) => props.delay};
|
|
|
+`;
|
|
|
+
|
|
|
const Flex = styled.div`
|
|
|
display: flex;
|
|
|
align-items: center;
|