veza/apps/web/src/components/developer/APIPlaygroundView.tsx
senke 559cfbee3e refactor(web): zero out 3 ESLint warning buckets (storybook + react-refresh + non-null-assertion)
Three rules cleaned in parallel passes — 187 fewer warnings, 0 TS
errors, 0 behaviour change beyond one incidental auth bugfix
flagged below.

storybook/no-redundant-story-name (23 → 0) — 14 stories files
  Storybook v7+ infers the story name from the variable name, so
  `name: 'Default'` next to `export const Default: Story = …` is
  pure noise. Removed only when the name was redundant ;
  preserved when the label was a French translation
  ('Par défaut', 'Chargement', 'Avec erreur', etc.) since those
  are intentional.

react-refresh/only-export-components (25 → 0) — 21 files
  Each warning marks a file that exports a React component AND a
  hook / context / constant / barrel re-export. Suppressed
  per-line with the suppression-with-justification pattern :
    // eslint-disable-next-line react-refresh/only-export-components -- <kind>; refactor would split a tightly-coupled API
  The justification matters — every comment names the specific
  thing being co-located (hook / context / CVA constant / lazy
  registry / route config / test util / backward-compat barrel).
  Splitting these would create 21 new files for a HMR-only DX
  win that's already a non-issue in practice.

@typescript-eslint/no-non-null-assertion (139 → 0) — 43 files
  Distribution of fixes :
    ~85 cases : refactored to explicit guard
                `if (!x) throw new Error('invariant: …')`
                or hoisted into local with narrowing.
    ~36 cases : helper extraction (one tooltip test had 16
                `wrapper!` patterns reduced to a single
                `getWrapper()` helper).
    ~18 cases : suppressed with specific reason :
                static literal arrays where index is provably
                in bounds, mock fixtures with structural
                guarantees, filter-then-map patterns where the
                filter excludes the null branch.
  One incidental find : services/api/auth.ts threw on missing
  tokens but didn't guard `user` ; added the missing check while
  refactoring the `user!` to a guard.

baseline post-commit : 921 warnings, 0 errors, 0 TS errors.
The remaining buckets are no-restricted-syntax (757, design-system
guardrail), no-explicit-any (115), exhaustive-deps (49).

CI --max-warnings will be lowered to 921 in the follow-up commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 23:30:22 +02:00

160 lines
5.9 KiB
TypeScript

import React, { useState } from 'react';
import { Card } from '../ui/card';
import { Button } from '../ui/button';
import { Play, RotateCcw, Copy } from 'lucide-react';
import { useToast } from '../../components/feedback/ToastProvider';
const ENDPOINTS = [
{ method: 'GET', path: '/v1/user/profile', desc: 'Get current user profile' },
{ method: 'GET', path: '/v1/tracks', desc: 'List tracks' },
{ method: 'POST', path: '/v1/tracks/upload', desc: 'Upload a new track' },
{ method: 'GET', path: '/v1/sales/history', desc: 'Get sales history' },
];
export const APIPlaygroundView: React.FC = () => {
const { addToast } = useToast();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- ENDPOINTS is a non-empty static literal
const [selectedEndpoint, setSelectedEndpoint] = useState(ENDPOINTS[0]!);
const [params, setParams] = useState('{\n "limit": 10,\n "offset": 0\n}');
const [response, setResponse] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const handleSend = () => {
setLoading(true);
setResponse(null);
// Simulate network request
setTimeout(() => {
setLoading(false);
setResponse(
JSON.stringify(
{
status: 200,
data: {
message: 'Success',
timestamp: new Date().toISOString(),
result: [
{ id: 1, name: 'Sample Item' },
{ id: 2, name: 'Another Item' },
],
},
},
null,
2,
),
);
addToast('Request successful', 'success');
}, 800);
};
return (
<div className="space-y-6 animate-fadeIn pb-20">
<h2 className="text-2xl font-bold text-foreground mb-6">API PLAYGROUND</h2>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{/* Request Builder */}
<div className="space-y-4">
<Card variant="default">
<h3 className="font-bold text-foreground mb-4">Request</h3>
<div className="space-y-4">
<div>
<label className="block text-xs font-bold text-muted-foreground uppercase mb-2">
Endpoint
</label>
<select
className="w-full bg-card border border-border rounded p-4 text-foreground focus:border-border outline-none font-mono text-sm"
value={selectedEndpoint.path}
onChange={(e) => {
const ep = ENDPOINTS.find((p) => p.path === e.target.value);
if (ep) setSelectedEndpoint(ep);
}}
>
{ENDPOINTS.map((ep) => (
<option key={ep.path} value={ep.path}>
{ep.method} {ep.path}
</option>
))}
</select>
<p className="text-xs text-muted-foreground mt-1">
{selectedEndpoint.desc}
</p>
</div>
<div>
<label className="block text-xs font-bold text-muted-foreground uppercase mb-2">
Body (JSON)
</label>
<textarea
className="w-full bg-card border border-border rounded p-4 text-foreground focus:border-border outline-none font-mono text-xs h-48 resize-none"
value={params}
onChange={(e) => setParams(e.target.value)}
/>
</div>
<div className="flex justify-end gap-2">
<Button
variant="ghost"
onClick={() => setParams('{}')}
icon={<RotateCcw className="w-4 h-4" />}
>
Reset
</Button>
<Button
variant="primary"
onClick={handleSend}
disabled={loading}
icon={<Play className="w-4 h-4 fill-current" />}
>
{loading ? 'Sending...' : 'Send Request'}
</Button>
</div>
</div>
</Card>
</div>
{/* Response Viewer */}
<div className="space-y-4 h-full">
<Card variant="glass" className="h-full flex flex-col">
<div className="flex justify-between items-center mb-4">
<h3 className="font-bold text-foreground">Response</h3>
{response && (
<div className="flex gap-2">
<span className="text-xs font-bold text-success bg-success/10 px-2 py-1 rounded">
200 OK
</span>
<span className="text-xs font-bold text-muted-foreground bg-white/10 px-2 py-1 rounded">
45ms
</span>
</div>
)}
</div>
<div className="flex-1 bg-black/30 rounded shadow-[0_0_8px_rgba(26,26,30,0.05)] p-4 relative group">
{response ? (
<>
<pre className="text-xs text-success font-mono whitespace-pre-wrap overflow-auto h-full max-h-layout-drawer">
{response}
</pre>
<button
className="absolute top-2 right-2 p-2 bg-muted rounded text-muted-foreground hover:text-foreground opacity-0 group-hover:opacity-100 transition-opacity"
onClick={() => {
navigator.clipboard.writeText(response);
addToast('Copied JSON');
}}
>
<Copy className="w-4 h-4" />
</button>
</>
) : (
<div className="flex flex-col items-center justify-center h-full text-muted-foreground">
<p className="text-sm">Waiting for request...</p>
</div>
)}
</div>
</Card>
</div>
</div>
</div>
);
};