Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont show secrets unless action is taken by user #153

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions packages/web/src/routes/secrets.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useRef, useState } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
import { cn } from '@/lib/utils';
import { getSecrets } from '@/lib/server';
import { Info, Trash2 } from 'lucide-react';
import { Info, Trash2, Eye, EyeOff } from 'lucide-react';
import { Form, useLoaderData, useRevalidator } from 'react-router-dom';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
Expand Down Expand Up @@ -148,7 +150,7 @@ function SecretRow(props: {
const passwordRef = useRef<HTMLInputElement>(null);

const [hovering, setHovering] = useState(false);
const [inputFocused, setInputFocused] = useState(false);
const [show, setShow] = useState(false);

function onNameKeydown(e: React.KeyboardEvent<HTMLInputElement>) {
if (e.key === 'Enter') {
Expand Down Expand Up @@ -185,7 +187,6 @@ function SecretRow(props: {
}

function onBlur() {
setInputFocused(false);
if (isValidSecretName(name)) {
props.onUpdate(props.name, name, value);
} else {
Expand Down Expand Up @@ -233,24 +234,41 @@ function SecretRow(props: {
onKeyDown={onNameKeydown}
onChange={(e) => setName(e.currentTarget.value.toUpperCase())}
autoComplete="off"
onFocus={() => setInputFocused(true)}
onBlur={onBlur}
className="border-transparent group-hover:border-border group-focus-within:border-border"
/>
</td>
<td className="h-10 text-left align-middle">
<td className="h-10 text-left align-middle relative">
<Input
ref={passwordRef}
type={inputFocused || hovering ? 'text' : 'password'}
type={show ? 'text' : 'password'}
autoComplete="off"
value={value}
onKeyDown={onPasswordKeydown}
onChange={(e) => setValue(e.currentTarget.value)}
required
onFocus={() => setInputFocused(true)}
onBlur={onBlur}
className="border-transparent group-hover:border-border group-focus-within:border-border"
className="border-transparent group-hover:border-border group-focus-within:border-border pr-8"
/>
{show ? (
<EyeOff
size={14}
className={cn(
'absolute right-3 top-3 cursor-pointer opacity-80 bg-background',
!hovering && 'hidden',
)}
onClick={() => setShow(false)}
/>
) : (
<Eye
size={14}
className={cn(
'absolute right-3 top-3 cursor-pointer opacity-80 bg-background',
!hovering && 'hidden',
)}
onClick={() => setShow(true)}
/>
)}
</td>
<td className="h-10 pl-3 text-right align-middle w-[52px]">
<Button variant="icon" onClick={() => setOpen(true)}>
Expand All @@ -264,13 +282,23 @@ function SecretRow(props: {
function NewSecretForm(props: {
setError: (message: string | null, clearAfter?: number | null) => void;
}) {
useHotkeys(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all cases I've seen thus far for inputs, i find this pattern to be less obvious (the code is located somewhere other than the Input) and heavier weight than:

onKeydown={(e) => e.key === 'Enter' && onSubmit()}

'mod+enter',
() => {
onSubmit();
},
{ enableOnFormTags: ['input'] },
);

const revalidator = useRevalidator();

const [name, setName] = useState('');
const [value, setValue] = useState('');

async function onSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
async function onSubmit(e?: React.FormEvent<HTMLFormElement>) {
if (e) {
e.preventDefault();
}

if (!isValidSecretName(name)) {
props.setError(
Expand Down
Loading