Skip to content

Commit

Permalink
Switched to SecretField.
Browse files Browse the repository at this point in the history
Signed-off-by: Yurii Vlasov <yuriy@vlasov.pro>
  • Loading branch information
vlasov-y committed Jan 7, 2025
1 parent f9bb57c commit ed991a3
Showing 1 changed file with 11 additions and 27 deletions.
38 changes: 11 additions & 27 deletions frontend/src/components/common/Resource/Resource.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Icon } from '@iconify/react';
import Editor from '@monaco-editor/react';
import { Visibility, VisibilityOff } from '@mui/icons-material'; // Material icons for eye
import { InputLabel, Snackbar } from '@mui/material';
import Box from '@mui/material/Box';
import Divider from '@mui/material/Divider';
Expand Down Expand Up @@ -474,7 +473,7 @@ export function SecretField(props: InputProps) {
}

return (
<Grid container alignItems="stretch" spacing={2}>
<Grid container alignItems={!!other?.disableUnderline ? 'center' : 'stretch'} spacing={2}>
<Grid item>
<IconButton
edge="end"
Expand All @@ -493,7 +492,7 @@ export function SecretField(props: InputProps) {
fullWidth
multiline={showPassword}
maxRows="20"
value={showPassword ? Base64.decode(value as string) : '******'}
value={showPassword ? Base64.decode(value as string) : '••••••••'}
{...other}
/>
</Grid>
Expand Down Expand Up @@ -582,7 +581,6 @@ export type EnvironmentVariable = {
export function GetEnvironmentVariables(props: EnvironmentVariablesProps) {
const { pod, container } = props;
const { t } = useTranslation();
const [revealedSecrets, setRevealedSecrets] = React.useState<Set<string>>(new Set());
const [copied, setCopied] = React.useState(false);

if (!container?.env && !container?.envFrom) {
Expand Down Expand Up @@ -617,15 +615,6 @@ export function GetEnvironmentVariables(props: EnvironmentVariablesProps) {
);
};

// Function to reveal or hide secret values
const toggleSecret = (key: string) => {
setRevealedSecrets(prev => {
const newSet = new Set(prev);
newSet.has(key) ? newSet.delete(key) : newSet.add(key);
return newSet;
});
};

// Function to parse ISO 8601 timestamps and compare them
function compareTimestamps(a: string | undefined, b: string | undefined): number {
if (!a || !b) {
Expand Down Expand Up @@ -1008,34 +997,29 @@ export function GetEnvironmentVariables(props: EnvironmentVariablesProps) {
{
label: t('translation|Value'),
getter: (data: any) => {
const isRevealed = revealedSecrets.has(data.key);
let displayValue = data.value;
if (!data.isError && data.isSecret) {
displayValue = isRevealed ? displayValue : '••••••••';
}
return (
<Box display="flex" alignItems="center">
{data.isError && (
<Box aria-label="hidden" display="flex" alignItems="center" px={1}>
<Icon icon="mdi:alert-outline" aria-label="error" />
<Typography color="error" sx={{ marginLeft: 1 }}>
{displayValue}
{data.value}
</Typography>
</Box>
)}
{!data.isError && (
<Box onClick={() => handleCopy(data.value)}>
<StatusLabel status="" sx={{ fontFamily: 'monospace' }}>
{displayValue}
</StatusLabel>
<SecretField
disableUnderline
value={btoa(data.value)}
sx={{ fontFamily: 'monospace' }}
/>
<Snackbar open={copied} message="Copied!" autoHideDuration={2000} />
</Box>
)}
{!data.isError && data.isSecret && (
<IconButton onClick={() => toggleSecret(data.key)} sx={{ marginLeft: 1 }}>
{isRevealed ? <VisibilityOff /> : <Visibility />}
</IconButton>
)}
{/* {!data.isError && data.isSecret && (
)} */}
</Box>
);
},
Expand Down

0 comments on commit ed991a3

Please sign in to comment.