Spaces:
Runtime error
Runtime error
Download frontend-react/src/components/workflow/ModifyDiffModal.jsx from Amitkasar/ai-api-testing: direct link, hf CLI and curl.
- Browser
- Download file 4.91 kB
-
https://huggingface.co/spaces/Amitkasar/ai-api-testing/resolve/ff7dddafe7cbd9b07c888ff8cdaca0bd4ff37668/frontend-react/src/components/workflow/ModifyDiffModal.jsx
- Command line
-
hf download hf://spaces/Amitkasar/ai-api-testing@ff7dddafe7cbd9b07c888ff8cdaca0bd4ff37668/frontend-react/src/components/workflow/ModifyDiffModal.jsx
-
curl -L -o ModifyDiffModal.jsx https://huggingface.co/spaces/Amitkasar/ai-api-testing/resolve/ff7dddafe7cbd9b07c888ff8cdaca0bd4ff37668/frontend-react/src/components/workflow/ModifyDiffModal.jsx
4.91 kB
| import React from 'react'; | |
| import { Edit3, X, Check } from 'lucide-react'; | |
| function DiffRow({ label, original, modified }) { | |
| const changed = JSON.stringify(original) !== JSON.stringify(modified); | |
| return ( | |
| <div style={{ marginBottom: 10 }}> | |
| <span style={{ fontSize: 10, textTransform: 'uppercase', letterSpacing: '0.08em', color: 'var(--fg-3)', fontWeight: 700 }}>{label}</span> | |
| <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8, marginTop: 4 }}> | |
| <div style={{ background: 'var(--bg-0)', border: `1px solid ${changed ? '#ef44442a' : 'var(--line-1)'}`, borderRadius: 5, padding: 8 }}> | |
| <div style={{ fontSize: 9, color: '#ef4444', fontWeight: 700, marginBottom: 4, textTransform: 'uppercase', letterSpacing: '0.08em' }}>Before</div> | |
| <pre style={{ fontSize: 11, color: 'var(--fg-2)', margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-all' }}> | |
| {original == null ? '(none)' : (typeof original === 'object' ? JSON.stringify(original, null, 2) : String(original))} | |
| </pre> | |
| </div> | |
| <div style={{ background: 'var(--bg-0)', border: `1px solid ${changed ? '#22c55e2a' : 'var(--line-1)'}`, borderRadius: 5, padding: 8 }}> | |
| <div style={{ fontSize: 9, color: '#22c55e', fontWeight: 700, marginBottom: 4, textTransform: 'uppercase', letterSpacing: '0.08em' }}>After</div> | |
| <pre style={{ fontSize: 11, color: 'var(--fg-2)', margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-all' }}> | |
| {modified == null ? '(none)' : (typeof modified === 'object' ? JSON.stringify(modified, null, 2) : String(modified))} | |
| </pre> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| export default function ModifyDiffModal({ original, changes, onConfirm, onCancel }) { | |
| const modified = { | |
| ...original, | |
| body: changes.body !== undefined ? { ...(original.body || {}), ...changes.body } : original.body, | |
| query_params: changes.query_params !== undefined ? { ...(original.query_params || {}), ...changes.query_params } : original.query_params, | |
| headers: changes.headers !== undefined ? { ...(original.headers || {}), ...changes.headers } : original.headers, | |
| path_params: changes.path_params !== undefined ? { ...(original.path_params || {}), ...changes.path_params } : original.path_params, | |
| ...Object.fromEntries(Object.entries(changes).filter(([k]) => !['body', 'query_params', 'headers', 'path_params'].includes(k))), | |
| }; | |
| return ( | |
| <div style={{ position: 'fixed', inset: 0, zIndex: 60, display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'rgba(0,0,0,0.75)', backdropFilter: 'blur(8px)', padding: 16 }}> | |
| <div style={{ background: 'var(--bg-1)', border: '1px solid var(--line-3)', borderRadius: 10, width: '100%', maxWidth: 680, maxHeight: '85vh', overflow: 'hidden', display: 'flex', flexDirection: 'column', boxShadow: 'var(--shadow-md)' }}> | |
| <div style={{ padding: '12px 16px', borderBottom: '1px solid var(--line-1)', display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexShrink: 0 }}> | |
| <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}> | |
| <Edit3 size={14} style={{ color: 'var(--accent)' }}/> | |
| <span style={{ fontSize: 13, fontWeight: 600, color: 'var(--fg-0)' }}>Review AI Modifications</span> | |
| <span style={{ fontSize: 11, color: 'var(--fg-3)' }}>Step {original.step}: {original.endpoint}</span> | |
| </div> | |
| <button onClick={onCancel} className="ico-btn"><X size={14}/></button> | |
| </div> | |
| <div style={{ flex: 1, overflowY: 'auto', padding: 20 }}> | |
| <p style={{ fontSize: 12, color: 'var(--fg-2)', marginBottom: 16, lineHeight: 1.6 }}> | |
| The AI proposed the following changes. Review the diff below before executing. | |
| </p> | |
| {['body', 'query_params', 'headers', 'path_params'].map(key => | |
| (changes[key] !== undefined || original[key]) ? ( | |
| <DiffRow | |
| key={key} | |
| label={key.replace('_', ' ')} | |
| original={original[key]} | |
| modified={modified[key]} | |
| /> | |
| ) : null | |
| )} | |
| {Object.entries(changes) | |
| .filter(([k]) => !['body', 'query_params', 'headers', 'path_params'].includes(k)) | |
| .map(([k, v]) => ( | |
| <DiffRow key={k} label={k} original={original[k]} modified={v}/> | |
| ))} | |
| </div> | |
| <div style={{ padding: '12px 20px', borderTop: '1px solid var(--line-1)', display: 'flex', gap: 8, justifyContent: 'flex-end', flexShrink: 0 }}> | |
| <button onClick={onCancel} className="btn">Cancel</button> | |
| <button onClick={() => onConfirm(modified)} className="btn btn-primary" style={{ gap: 6 }}> | |
| <Check size={13}/> Apply & Execute | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |