feat(credentials): hide credential data until revealed
- add a RevealableCodeBlock ui component that renders its code only after the user clicks Reveal, with a storybook story - use it for the data section of the credential page - bump version to 1.21.1
This commit is contained in:
1 parent
2129708819
commit
f43d902297
9 files changed
+122
-6
No files matched your search
@@ -2,6 +2,18 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## 1.21.1 - 2026-10-01
|
||||||
|
|
||||||
|
Changes since 1.21.0:
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The credential page hides the credential data when it opens; a Reveal button shows it and Hide hides it again. The data is not rendered on the page until revealed.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- A `RevealableCodeBlock` UI component (a CodeBlock that starts hidden behind a Reveal/Hide button), with a Storybook story.
|
||||||
|
|
||||||
## 1.21.0 - 2026-10-01
|
## 1.21.0 - 2026-10-01
|
||||||
|
|
||||||
Changes since 1.20.2:
|
Changes since 1.20.2:
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { expect, userEvent, within } from 'storybook/test';
|
||||||
|
import { RevealableCodeBlock } from '../../src/ui/RevealableCodeBlock/RevealableCodeBlock';
|
||||||
|
|
||||||
|
const meta: Meta<typeof RevealableCodeBlock> = {
|
||||||
|
title: 'UI/RevealableCodeBlock',
|
||||||
|
component: RevealableCodeBlock,
|
||||||
|
parameters: { layout: 'padded' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof RevealableCodeBlock>;
|
||||||
|
|
||||||
|
export const Default: Story = {
|
||||||
|
args: {
|
||||||
|
language: 'json',
|
||||||
|
code: JSON.stringify({ username: 'admin', password: 's3cr3t-p4ss' }, null, 2),
|
||||||
|
},
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
// The code is not rendered until revealed, and hidden again on the second click
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
const toggle = canvas.getByRole('button');
|
||||||
|
await expect(canvasElement).not.toHaveTextContent('s3cr3t-p4ss');
|
||||||
|
await expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
||||||
|
|
||||||
|
await userEvent.click(toggle);
|
||||||
|
await expect(canvasElement.querySelector('code')).toHaveTextContent('s3cr3t-p4ss');
|
||||||
|
await expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
||||||
|
|
||||||
|
await userEvent.click(toggle);
|
||||||
|
await expect(canvasElement).not.toHaveTextContent('s3cr3t-p4ss');
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -229,6 +229,11 @@
|
|||||||
"light_mode": "Light mode",
|
"light_mode": "Light mode",
|
||||||
"dark_mode": "Dark mode"
|
"dark_mode": "Dark mode"
|
||||||
},
|
},
|
||||||
|
"revealable": {
|
||||||
|
"hidden": "Hidden so secrets aren't exposed on screen.",
|
||||||
|
"reveal": "Reveal",
|
||||||
|
"hide": "Hide"
|
||||||
|
},
|
||||||
"pagination": {
|
"pagination": {
|
||||||
"prev": "Previous page",
|
"prev": "Previous page",
|
||||||
"next": "Next page",
|
"next": "Next page",
|
||||||
|
|||||||
@@ -3,11 +3,18 @@ import { useNavigate, useParams } from 'react-router-dom';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { usePageTitle } from '../../hooks/usePageTitle';
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { Upload, Pencil, Trash2, KeyRound } from 'lucide-react';
|
import { Upload, Pencil, Trash2, KeyRound } from 'lucide-react';
|
||||||
import { CodeBlock } from '../../ui';
|
|
||||||
import { stringify as yamlStringify } from 'yaml';
|
import { stringify as yamlStringify } from 'yaml';
|
||||||
import { credentials } from '../../api';
|
import { credentials } from '../../api';
|
||||||
import type { Credential } from '../../api';
|
import type { Credential } from '../../api';
|
||||||
import { Breadcrumbs, Button, Card, DescriptionList, Timestamp, UuidBadge } from '../../ui';
|
import {
|
||||||
|
Breadcrumbs,
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
DescriptionList,
|
||||||
|
RevealableCodeBlock,
|
||||||
|
Timestamp,
|
||||||
|
UuidBadge,
|
||||||
|
} from '../../ui';
|
||||||
import { DeleteConfirmationModal } from '../../components/modals';
|
import { DeleteConfirmationModal } from '../../components/modals';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
@@ -117,7 +124,8 @@ export function CredentialDetailPage() {
|
|||||||
<div className={styles.stepsSection}>
|
<div className={styles.stepsSection}>
|
||||||
<h2 className={styles.sectionHeading}>{t('credentials.section_data')}</h2>
|
<h2 className={styles.sectionHeading}>{t('credentials.section_data')}</h2>
|
||||||
<Card>
|
<Card>
|
||||||
<CodeBlock
|
<RevealableCodeBlock
|
||||||
|
key={credential.id}
|
||||||
language="json"
|
language="json"
|
||||||
code={(() => {
|
code={(() => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
.wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: var(--space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.placeholder {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
font-size: var(--font-size-sm);
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { Eye, EyeOff } from 'lucide-react';
|
||||||
|
import { Button } from '../Button/Button';
|
||||||
|
import { CodeBlock } from '../CodeBlock/CodeBlock';
|
||||||
|
import styles from './RevealableCodeBlock.module.css';
|
||||||
|
|
||||||
|
export interface RevealableCodeBlockProps {
|
||||||
|
code: string;
|
||||||
|
language?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A CodeBlock that starts hidden; the code is only rendered after the user reveals it. */
|
||||||
|
export function RevealableCodeBlock({ code, language }: RevealableCodeBlockProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [revealed, setRevealed] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.wrapper}>
|
||||||
|
<div className={styles.content}>
|
||||||
|
{revealed ? (
|
||||||
|
<CodeBlock code={code} language={language} />
|
||||||
|
) : (
|
||||||
|
<p className={styles.placeholder}>{t('revealable.hidden')}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
aria-expanded={revealed}
|
||||||
|
onClick={() => setRevealed((r) => !r)}
|
||||||
|
>
|
||||||
|
{revealed ? <EyeOff size={14} /> : <Eye size={14} />}
|
||||||
|
{revealed ? t('revealable.hide') : t('revealable.reveal')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -43,6 +43,9 @@ export type { SearchProps } from './Search/Search';
|
|||||||
export { CodeBlock } from './CodeBlock/CodeBlock';
|
export { CodeBlock } from './CodeBlock/CodeBlock';
|
||||||
export type { CodeBlockProps } from './CodeBlock/CodeBlock';
|
export type { CodeBlockProps } from './CodeBlock/CodeBlock';
|
||||||
|
|
||||||
|
export { RevealableCodeBlock } from './RevealableCodeBlock/RevealableCodeBlock';
|
||||||
|
export type { RevealableCodeBlockProps } from './RevealableCodeBlock/RevealableCodeBlock';
|
||||||
|
|
||||||
export { CodeEditor } from './CodeEditor/CodeEditor';
|
export { CodeEditor } from './CodeEditor/CodeEditor';
|
||||||
export type { CodeEditorProps } from './CodeEditor/CodeEditor';
|
export type { CodeEditorProps } from './CodeEditor/CodeEditor';
|
||||||
|
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "liqa",
|
"name": "liqa",
|
||||||
"version": "1.21.0",
|
"version": "1.21.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "liqa",
|
"name": "liqa",
|
||||||
"version": "1.21.0",
|
"version": "1.21.1",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"server",
|
"server",
|
||||||
"client"
|
"client"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "liqa",
|
"name": "liqa",
|
||||||
"version": "1.21.0",
|
"version": "1.21.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=24"
|
"node": ">=24"
|
||||||
|
|||||||
Reference in new issue
Block a user