|
@@ -10,6 +10,7 @@ import ButtonEnablePREnvironments from "./components/ButtonEnablePREnvironments"
|
|
|
import ConnectNewRepo from "./components/ConnectNewRepo";
|
|
import ConnectNewRepo from "./components/ConnectNewRepo";
|
|
|
import Loading from "components/Loading";
|
|
import Loading from "components/Loading";
|
|
|
import pr_icon from "assets/pull_request_icon.svg";
|
|
import pr_icon from "assets/pull_request_icon.svg";
|
|
|
|
|
+import _ from "lodash";
|
|
|
|
|
|
|
|
export type PRDeployment = {
|
|
export type PRDeployment = {
|
|
|
id: number,
|
|
id: number,
|
|
@@ -18,6 +19,7 @@ export type PRDeployment = {
|
|
|
environment_id: number,
|
|
environment_id: number,
|
|
|
pull_request_id: number,
|
|
pull_request_id: number,
|
|
|
namespace: string,
|
|
namespace: string,
|
|
|
|
|
+ git_installation_id?: number,
|
|
|
gh_pr_name: string,
|
|
gh_pr_name: string,
|
|
|
gh_repo_owner: string,
|
|
gh_repo_owner: string,
|
|
|
gh_repo_name: string,
|
|
gh_repo_name: string,
|
|
@@ -73,7 +75,6 @@ const EnvironmentList = () => {
|
|
|
if (!Array.isArray(data)) {
|
|
if (!Array.isArray(data)) {
|
|
|
throw Error("Data is not an array");
|
|
throw Error("Data is not an array");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
setEnvironmentList(data);
|
|
setEnvironmentList(data);
|
|
|
})
|
|
})
|
|
|
.catch((err) => {
|
|
.catch((err) => {
|
|
@@ -88,18 +89,20 @@ const EnvironmentList = () => {
|
|
|
};
|
|
};
|
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const getDeployments = (git_installation_id: number) => {
|
|
|
let isSubscribed = true;
|
|
let isSubscribed = true;
|
|
|
- // TODO: Replace get mock data by endpoint
|
|
|
|
|
- api
|
|
|
|
|
|
|
+ return api
|
|
|
.getPRDeploymentList(
|
|
.getPRDeploymentList(
|
|
|
"<token>",
|
|
"<token>",
|
|
|
{},
|
|
{},
|
|
|
{
|
|
{
|
|
|
project_id: currentProject.id,
|
|
project_id: currentProject.id,
|
|
|
cluster_id: currentCluster.id,
|
|
cluster_id: currentCluster.id,
|
|
|
|
|
+ git_installation_id: git_installation_id,
|
|
|
}
|
|
}
|
|
|
- ).then(({ data }) => {
|
|
|
|
|
|
|
+ )
|
|
|
|
|
+ .then(({ data }) => {
|
|
|
if (!isSubscribed) {
|
|
if (!isSubscribed) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -108,25 +111,52 @@ const EnvironmentList = () => {
|
|
|
throw Error("Data is not an array");
|
|
throw Error("Data is not an array");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- setDeploymentList(data);
|
|
|
|
|
- })
|
|
|
|
|
- .catch((err) => {
|
|
|
|
|
- console.error(err);
|
|
|
|
|
- if (isSubscribed) {
|
|
|
|
|
- setHasError(true);
|
|
|
|
|
- setDeploymentList([]);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ data = data.forEach((d) => {
|
|
|
|
|
+ d.git_installation_id = git_installation_id;
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ return Promise.resolve(data);
|
|
|
})
|
|
})
|
|
|
- .finally(() => {
|
|
|
|
|
- if (isSubscribed) {
|
|
|
|
|
- setIsLoading(false);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ .catch((err) => {
|
|
|
|
|
+ console.error(err);
|
|
|
|
|
+ if (isSubscribed) {
|
|
|
|
|
+ // setHasError(true);
|
|
|
|
|
+ setDeploymentList([]);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Promise.resolve([]);
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ let isSubscribed = true;
|
|
|
|
|
+
|
|
|
|
|
+ let gitInstallations = environmentList.map((e) => {
|
|
|
|
|
+ return e.git_installation_id
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ let uniqueIds = _.uniq(gitInstallations);
|
|
|
|
|
+
|
|
|
|
|
+ let promises = uniqueIds.map((git_installation_id) => {
|
|
|
|
|
+ return getDeployments(git_installation_id)
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ Promise.all(promises).then((data) => {
|
|
|
|
|
+ let result:PRDeployment[] = []
|
|
|
|
|
+ data.forEach((d) => {
|
|
|
|
|
+ result.concat(d)
|
|
|
});
|
|
});
|
|
|
|
|
+ setDeploymentList(result);
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- return () => {
|
|
|
|
|
- isSubscribed = false;
|
|
|
|
|
- };
|
|
|
|
|
- }, []);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (isSubscribed) {
|
|
|
|
|
+ setIsLoading(false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return () => {
|
|
|
|
|
+ isSubscribed = false;
|
|
|
|
|
+ };
|
|
|
|
|
+ }, [environmentList]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const action = getQueryParam({ location }, "action");
|
|
const action = getQueryParam({ location }, "action");
|
|
@@ -169,8 +199,6 @@ const EnvironmentList = () => {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
let renderDeploymentList = () => {
|
|
let renderDeploymentList = () => {
|
|
|
if (!deploymentList.length) {
|
|
if (!deploymentList.length) {
|
|
|
return (
|
|
return (
|
|
@@ -217,7 +245,7 @@ const EnvironmentList = () => {
|
|
|
</DataContainer>
|
|
</DataContainer>
|
|
|
<Flex>
|
|
<Flex>
|
|
|
<RowButton
|
|
<RowButton
|
|
|
- to={`${currentUrl}/pr-env-detail/${d.namespace}`}
|
|
|
|
|
|
|
+ to={`${currentUrl}/pr-env-detail/${d.namespace}?git_installation_id=${d.git_installation_id}`}
|
|
|
key={d.id}
|
|
key={d.id}
|
|
|
>
|
|
>
|
|
|
<i className="material-icons-outlined">info</i>
|
|
<i className="material-icons-outlined">info</i>
|