Skip to content

Commit

Permalink
simplify functions
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Aug 25, 2020
1 parent 79171d9 commit 8e1edd6
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions kotsadm/web/src/components/gitops/GitOpsDeploymentManager.jsx
Expand Up @@ -72,7 +72,7 @@ class GitOpsDeploymentManager extends React.Component {

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

getAppsList = async () => {
Expand Down Expand Up @@ -104,23 +104,6 @@ class GitOpsDeploymentManager extends React.Component {
}
}

getGitopsState = async () => {
const freshGitops = await this.getGitops()

if (freshGitops?.enabled) {
const selectedService = find(SERVICES, service => service.value === freshGitops.provider);
this.setState({
selectedService: selectedService ? selectedService : this.state.selectedService,
hostname: freshGitops.hostname || "",
gitops: freshGitops
})
} else {
this.setState({
gitops: freshGitops
})
}
}

getGitops = async () => {
try {
const res = await fetch(`${window.env.API_ENDPOINT}/gitops/get`, {
Expand All @@ -138,8 +121,23 @@ class GitOpsDeploymentManager extends React.Component {
console.log("failed to get gitops settings, unexpected status code", res.status);
return;
}

return await res.json();

const freshGitops = await res.json()

if (freshGitops?.enabled) {
const selectedService = find(SERVICES, service => service.value === freshGitops.provider);
this.setState({
selectedService: selectedService ? selectedService : this.state.selectedService,
hostname: freshGitops.hostname || "",
gitops: freshGitops
})
} else {
this.setState({
gitops: freshGitops
})
}

return freshGitops
} catch(err) {
console.log(err);
throw err;
Expand Down Expand Up @@ -199,7 +197,7 @@ class GitOpsDeploymentManager extends React.Component {
const gitOpsInput = this.getGitOpsInput(provider, repoUri, branch, path, format, action, hostname);

try {
if (this.providerChanged()) {
if (this.state.gitops?.enabled && this.providerChanged()) {
const success = await this.resetGitOps();
if (!success) {
return false;
Expand All @@ -222,7 +220,7 @@ class GitOpsDeploymentManager extends React.Component {
} else {
this.setState({ step: "", finishingSetup: false });
this.getAppsList();
this.getGitopsState();
this.getGitops();
}

return true;
Expand Down

0 comments on commit 8e1edd6

Please sign in to comment.