Skip to content

Commit

Permalink
fix loop
Browse files Browse the repository at this point in the history
  • Loading branch information
enrichman committed Nov 28, 2023
1 parent 68a62d3 commit 57dfa6b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
18 changes: 16 additions & 2 deletions ui/src/epinio/Credentials.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from 'react'

function credsChanged(creds, update) {
return creds.username !== update.username || creds.password !== update.password
}

export function credentialsOK(creds) {
return creds && creds.username !== '-' && creds.password !== '-'
}
Expand All @@ -8,8 +12,18 @@ export function credentialsOK(creds) {
function Credentials(props) {
React.useEffect(() => {
const getCredentials = async () => {
// TODO: hardcoded user
props.onCredentialsChanged({ username: 'admin', password: 'password' })
try {
await epinioClient.login('admin', 'password')
const u = { username: 'admin', password: 'password' }
if (credsChanged(props.credentials, u)) {
props.onCredentialsChanged(u)
}
} catch (error) {
const u = { username: '-', password: '-' }
if (credsChanged(props.credentials, u)) {
props.onCredentialsChanged(u)
}
}
}
if (props.enabled) {
getCredentials()
Expand Down
49 changes: 23 additions & 26 deletions ui/src/epinio/Lister.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,34 @@ export function Lister({ apiDomain, enabled, credentials }) {
useEffect(() => {
const fetchApplications = () => {
const epinioClient = EpinioClient({ apiDomain, credentials })
epinioClient.login('admin', 'password')
.then(
epinioClient.listApplications('workspace')
.then(applications => {
const t = []
epinioClient.listApplications('workspace')
.then(applications => {
const t = []

for (let i = 0; i < applications.length; i++) {
const app = applications[i]
for (let i = 0; i < applications.length; i++) {
const app = applications[i]

t[i] = {
id: app.meta.name,
state: app.status,
instances: app.configuration.instances
}
t[i] = {
id: app.meta.name,
state: app.status,
instances: app.configuration.instances
}

if (app.deployment) {
t[i].dstatus = app.deployment.status
}
if (app.deployment) {
t[i].dstatus = app.deployment.status
}

if (app.configuration.routes.length > 0) {
t[i].route = app.configuration.routes[0]
}
}
if (app.configuration.routes.length > 0) {
t[i].route = app.configuration.routes[0]
}
}

setTable(t)
})
.catch(error => {
console.error('error listing applications', error)
setTable([])
})
)
setTable(t)
})
.catch(error => {
console.error('error listing applications', error)
setTable([])
})
}

if (enabled && credentialsOK(credentials)) {
Expand Down

0 comments on commit 57dfa6b

Please sign in to comment.