Skip to content

Commit

Permalink
pr comment updates
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Aug 24, 2020
1 parent 3362754 commit 79171d9
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions kotsadm/web/src/components/gitops/GitOpsDeploymentManager.jsx
Expand Up @@ -67,15 +67,14 @@ class GitOpsDeploymentManager extends React.Component {
providerError: null,
finishingSetup: false,
appsList: [],
gitops: {},
}

componentDidMount() {
this.getAppsList();
this.getGitopsState();
}

componentDidUpdate(lastProps) {}

getAppsList = async () => {
try {
const res = await fetch(`${window.env.API_ENDPOINT}/apps`, {
Expand All @@ -86,6 +85,10 @@ class GitOpsDeploymentManager extends React.Component {
method: "GET",
});
if (!res.ok) {
if (res.status === 401) {
Utilities.logoutUser();
return;
}
console.log("failed to get apps list, unexpected status code", res.status);
return;
}
Expand All @@ -104,7 +107,7 @@ class GitOpsDeploymentManager extends React.Component {
getGitopsState = async () => {
const freshGitops = await this.getGitops()

if (freshGitops.enabled) {
if (freshGitops?.enabled) {
const selectedService = find(SERVICES, service => service.value === freshGitops.provider);
this.setState({
selectedService: selectedService ? selectedService : this.state.selectedService,
Expand All @@ -128,6 +131,10 @@ class GitOpsDeploymentManager extends React.Component {
method: "GET",
});
if (!res.ok) {
if (res.status === 401) {
Utilities.logoutUser();
return;
}
console.log("failed to get gitops settings, unexpected status code", res.status);
return;
}
Expand Down Expand Up @@ -192,13 +199,10 @@ class GitOpsDeploymentManager extends React.Component {
const gitOpsInput = this.getGitOpsInput(provider, repoUri, branch, path, format, action, hostname);

try {
const getGitOpsRepo = await this.getGitops();
if (getGitOpsRepo?.enabled) {
if (this.providerChanged()) {
const success = await this.resetGitOps();
if (!success) {
return false;
}
if (this.providerChanged()) {
const success = await this.resetGitOps();
if (!success) {
return false;
}
}

Expand All @@ -218,7 +222,7 @@ class GitOpsDeploymentManager extends React.Component {
} else {
this.setState({ step: "", finishingSetup: false });
this.getAppsList();
this.getGitops();
this.getGitopsState();
}

return true;
Expand Down Expand Up @@ -288,12 +292,11 @@ class GitOpsDeploymentManager extends React.Component {
return;
}

const freshGitops = await this.getGitops();
if (!freshGitops) {
if (!this.state.gitops) {
return;
}

const { provider, hostname, uri } = freshGitops;
const { provider, hostname, uri } = this.state.gitops;
const branch = "master";
const path = "";
const format = "single";
Expand Down Expand Up @@ -563,11 +566,10 @@ class GitOpsDeploymentManager extends React.Component {
);
}

const gitopsRepo = this.state.gitops;
const activeStep = find(STEPS, { step: this.state.step });
return (
<div className="GitOpsDeploymentManager--wrapper flex-column flex1">
{gitopsRepo && gitopsRepo.enabled && this.state.step !== "action" ?
{this.state.gitops?.enabled && this.state.step !== "action" ?
this.renderConfiguredGitOps()
: activeStep &&
this.renderActiveStep(activeStep)
Expand Down

0 comments on commit 79171d9

Please sign in to comment.