diff --git a/ui/src/console/SecretToggle.js b/ui/src/console/SecretToggle.js new file mode 100644 index 00000000..4088cee8 --- /dev/null +++ b/ui/src/console/SecretToggle.js @@ -0,0 +1,29 @@ +import {useState} from "react"; +import Icon from "@mdi/react"; +import {mdiEyeOffOutline, mdiEyeOutline} from "@mdi/js"; + +const SecretToggle = (props) => { + const [showSecret, setShowSecret] = useState(false); + + const secretString = (s) => { + let out = ""; + for(let i = 0; i < s.length; i++) { + out += "*"; + } + return out; + } + + const toggleShow = () => setShowSecret(!showSecret); + + if(showSecret) { + return ( + {props.secret} + ); + } else { + return ( + {secretString(props.secret)} + ) + } +}; + +export default SecretToggle; \ No newline at end of file diff --git a/ui/src/console/Utils.js b/ui/src/console/Utils.js deleted file mode 100644 index e55fb654..00000000 --- a/ui/src/console/Utils.js +++ /dev/null @@ -1,7 +0,0 @@ -export const secretString = (s) => { - let out = ""; - for(let i = 0; i < s.length; i++) { - out += "*"; - } - return out; -} \ No newline at end of file diff --git a/ui/src/console/detail/account/AccountDetail.js b/ui/src/console/detail/account/AccountDetail.js index 9af02a1b..a2c0a627 100644 --- a/ui/src/console/detail/account/AccountDetail.js +++ b/ui/src/console/detail/account/AccountDetail.js @@ -2,20 +2,11 @@ import {mdiCardAccountDetails, mdiEyeOutline, mdiEyeOffOutline} from "@mdi/js"; import Icon from "@mdi/react"; import PropertyTable from "../../PropertyTable"; import {Tab, Tabs} from "react-bootstrap"; -import {useState} from "react"; -import {secretString} from "../../Utils"; +import SecretToggle from "../../SecretToggle"; const AccountDetail = (props) => { - const [showToken, setShowToken] = useState(false); - const customProperties = { - token: row => { - if(showToken) { - return {row.value} setShowToken(false)} /> - } else { - return {secretString(row.value)} setShowToken(true)} /> - } - } + token: row => } return ( diff --git a/ui/src/console/detail/environment/DetailTab.js b/ui/src/console/detail/environment/DetailTab.js index 90006cf3..458b7977 100644 --- a/ui/src/console/detail/environment/DetailTab.js +++ b/ui/src/console/detail/environment/DetailTab.js @@ -1,20 +1,9 @@ import PropertyTable from "../../PropertyTable"; -import Icon from "@mdi/react"; -import {mdiEyeOffOutline, mdiEyeOutline} from "@mdi/js"; -import {secretString} from "../../Utils"; -import {useState} from "react"; +import SecretToggle from "../../SecretToggle"; const DetailTab = (props) => { - const [showZId, setShowZId] = useState(false); - const customProperties = { - zId: row => { - if(showZId) { - return {row.value} setShowZId(false)} /> - } else { - return {secretString(row.value)} setShowZId(true)} /> - } - } + zId: row => } return ( diff --git a/ui/src/console/detail/share/ShareDetail.js b/ui/src/console/detail/share/ShareDetail.js index 641fa6aa..dbbf820a 100644 --- a/ui/src/console/detail/share/ShareDetail.js +++ b/ui/src/console/detail/share/ShareDetail.js @@ -1,16 +1,15 @@ import * as metadata from "../../../api/metadata"; import {Sparklines, SparklinesLine, SparklinesSpots} from "react-sparklines"; import {useEffect, useState} from "react"; -import {mdiEyeOffOutline, mdiEyeOutline, mdiShareVariant} from "@mdi/js"; +import {mdiShareVariant} from "@mdi/js"; import Icon from "@mdi/react"; import PropertyTable from "../../PropertyTable"; import {Tab, Tabs} from "react-bootstrap"; -import {secretString} from "../../Utils"; import ActionsTab from "./ActionsTab"; +import SecretToggle from "../../SecretToggle"; const ShareDetail = (props) => { const [detail, setDetail] = useState({}); - const [showZId, setShowZId] = useState(false); useEffect(() => { metadata.getShareDetail(props.selection.id) @@ -53,13 +52,7 @@ const ShareDetail = (props) => { } return row.value; }, - zId: row => { - if(showZId) { - return {row.value} setShowZId(false)} /> - } else { - return {secretString(row.value)} setShowZId(true)} /> - } - } + zId: row => } if(detail) {