-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
396 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,5 +43,5 @@ html { | |
|
||
body { | ||
margin: 0px auto; | ||
width: 50vw; | ||
width: 100vw; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,91 @@ | ||
import * as ui5 from "@ui5/webcomponents-react"; | ||
import axios from "axios"; | ||
import { useEffect, useState } from "react"; | ||
import { Secrets } from "../shared/models"; | ||
import {useEffect, useState} from "react"; | ||
import {Secrets} from "../shared/models"; | ||
import Ok from "../shared/validator"; | ||
import api from "../shared/api"; | ||
import ServiceOfferingsView from "./ServiceOfferingsView"; | ||
|
||
function SecretsView(props: any) { | ||
const [secrets, setSecrets] = useState<Secrets>(); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState(null); | ||
const [secrets, setSecrets] = useState<Secrets>(); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState(null); | ||
|
||
useEffect(() => { | ||
axios | ||
.get<Secrets>(api("secrets")) | ||
.then((response) => { | ||
setSecrets(response.data); | ||
useEffect(() => { | ||
setLoading(true); | ||
axios | ||
.get<Secrets>(api("secrets")) | ||
.then((response) => { | ||
setLoading(false); | ||
setSecrets(response.data); | ||
if (Ok(response.data) && Ok(response.data.items)) { | ||
const secret = formatSecretText(response.data.items[0].name, response.data.items[0].namespace) | ||
props.handler(secret); | ||
props.setPageContent(<ServiceOfferingsView secret={secret} />); | ||
} else { | ||
props.handler(formatSecretText("", "")); | ||
} | ||
}) | ||
.catch((error) => { | ||
setLoading(false); | ||
setError(error); | ||
setSecrets(undefined); | ||
props.handler(formatSecretText("", "")); | ||
}); | ||
setLoading(false); | ||
props.handler( | ||
formatDisplay( | ||
response.data.items[0].name, | ||
response.data.items[0].namespace | ||
) | ||
); | ||
}) | ||
.catch((error) => { | ||
setError(error); | ||
setLoading(false); | ||
}); | ||
}, []); | ||
}, []); | ||
|
||
if (loading) { | ||
return <ui5.Loader progress="60%" /> | ||
} | ||
if (loading) { | ||
return <ui5.Loader progress="100%"/> | ||
} | ||
|
||
if (error) { | ||
return <ui5.Text>Error: {error}</ui5.Text>; | ||
} | ||
if (error) { | ||
props.handler(formatSecretText("", "")); | ||
return <ui5.IllustratedMessage name="UnableToLoad" /> | ||
} | ||
|
||
const renderData = () => { | ||
return secrets?.items.map((s, i) => { | ||
return ( | ||
<ui5.Option key={i}>{formatDisplay(s.name, s.namespace)}</ui5.Option> | ||
); | ||
}); | ||
}; | ||
const renderData = () => { | ||
// @ts-ignore | ||
if (!Ok(secrets) || !Ok(secrets.items)){ | ||
return <div> | ||
<> | ||
<ui5.Option key={0}>{formatSecretText("", "")}</ui5.Option> | ||
</> | ||
</div> | ||
} | ||
return secrets?.items.map((secret, index) => { | ||
return ( | ||
<ui5.Option key={index}>{formatSecretText(secret.name, secret.namespace)}</ui5.Option> | ||
); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<> | ||
return ( | ||
<div> | ||
<ui5.Select | ||
style={{ width: "20vw" }} | ||
onChange={(e) => { | ||
// @ts-ignore | ||
props.handler(e.target.value); | ||
}} | ||
> | ||
{renderData()} | ||
</ui5.Select> | ||
<> | ||
<div> | ||
<ui5.Select | ||
style={{width: "20vw"}} | ||
onChange={(e) => { | ||
// @ts-ignore | ||
const secret = e .target.value; | ||
props.handler(secret); | ||
props.setPageContent(<ServiceOfferingsView secret={secret} />); | ||
}} | ||
> | ||
{renderData()} | ||
</ui5.Select> | ||
</div> | ||
</> | ||
</div> | ||
</> | ||
</div> | ||
); | ||
); | ||
} | ||
|
||
function formatDisplay(secretName: string, secretNamespace: string) { | ||
return `${secretName} in (${secretNamespace})`; | ||
function formatSecretText(secretName: string, secretNamespace: string) { | ||
if (secretName === "" || secretNamespace === "") { | ||
return "No secret found" | ||
} | ||
return `${secretName} in (${secretNamespace})`; | ||
} | ||
|
||
export default SecretsView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.