feat(entities): édition/suppression visibles aussi pour les images

This commit is contained in:
4NK IA 2025-09-18 14:02:45 +00:00
parent 43ebc94b5b
commit c380ce31f0

View File

@ -165,6 +165,138 @@ export const FilePreview: React.FC<FilePreviewProps> = ({ document, onClose }) =
</Box>
)}
</Box>
{/* Données extraites (images): édition/suppression */}
<Box sx={{ mt: 2 }}>
<Typography variant="subtitle1" gutterBottom>
Données extraites
</Typography>
<Box sx={{ display: 'grid', gridTemplateColumns: { xs: '1fr', md: '1fr 1fr' }, gap: 2 }}>
{/* Personnes */}
<Box>
<Typography variant="subtitle2">Personnes</Typography>
<Box>
{Array.isArray((fullResult?.extraction?.entities?.persons)) && fullResult.extraction.entities.persons.length > 0 ? (
fullResult.extraction.entities.persons.map((p: any, i: number) => (
<Box key={`pimg-${i}`} display="flex" alignItems="center" justifyContent="space-between" sx={{ py: 0.5, gap: 1 }}>
<Box display="flex" alignItems="center" gap={1}>
<input style={{ padding: 4 }} defaultValue={p.firstName} onChange={(e) => (p.firstName = e.target.value)} />
<input style={{ padding: 4 }} defaultValue={p.lastName} onChange={(e) => (p.lastName = e.target.value)} />
</Box>
<Box display="flex" gap={1}>
<Button size="small" variant="outlined" disabled={!currentFolderHash || savingKey === `pimg-${i}`}
onClick={async () => {
if (!currentFolderHash) return
try {
setSavingKey(`pimg-${i}`)
await updateEntity(currentFolderHash, document.id, 'person', { index: i, id: p.id, patch: { firstName: p.firstName, lastName: p.lastName } })
await dispatch(loadFolderResults(currentFolderHash)).unwrap()
} finally { setSavingKey(null) }
}}>Enregistrer</Button>
<Button size="small" color="error"
onClick={async () => {
if (!currentFolderHash) return
try {
await deleteEntity(currentFolderHash, document.id, 'person', { index: i, id: p.id })
await dispatch(loadFolderResults(currentFolderHash)).unwrap()
const copy = JSON.parse(JSON.stringify(fullResult))
copy.extraction.entities.persons.splice(i, 1)
setFullResult(copy)
} catch {}
}}>Supprimer</Button>
</Box>
</Box>
))
) : (
<Typography variant="caption" color="text.secondary">Aucune personne</Typography>
)}
</Box>
</Box>
{/* Adresses */}
<Box>
<Typography variant="subtitle2">Adresses</Typography>
<Box>
{Array.isArray((fullResult?.extraction?.entities?.addresses)) && fullResult.extraction.entities.addresses.length > 0 ? (
fullResult.extraction.entities.addresses.map((a: any, i: number) => (
<Box key={`aimg-${i}`} display="flex" alignItems="center" justifyContent="space-between" sx={{ py: 0.5, gap: 1 }}>
<Box display="flex" alignItems="center" gap={1}>
<input style={{ padding: 4, width: 220 }} defaultValue={a.street} onChange={(e) => (a.street = e.target.value)} />
<input style={{ padding: 4, width: 100 }} defaultValue={a.postalCode} onChange={(e) => (a.postalCode = e.target.value)} />
<input style={{ padding: 4, width: 160 }} defaultValue={a.city} onChange={(e) => (a.city = e.target.value)} />
<input style={{ padding: 4, width: 120 }} defaultValue={a.country || ''} onChange={(e) => (a.country = e.target.value)} />
</Box>
<Box display="flex" gap={1}>
<Button size="small" variant="outlined" disabled={!currentFolderHash || savingKey === `aimg-${i}`}
onClick={async () => {
if (!currentFolderHash) return
try {
setSavingKey(`aimg-${i}`)
await updateEntity(currentFolderHash, document.id, 'address', { index: i, id: a.id, patch: { street: a.street, city: a.city, postalCode: a.postalCode, country: a.country } })
await dispatch(loadFolderResults(currentFolderHash)).unwrap()
} finally { setSavingKey(null) }
}}>Enregistrer</Button>
<Button size="small" color="error"
onClick={async () => {
if (!currentFolderHash) return
try {
await deleteEntity(currentFolderHash, document.id, 'address', { index: i, id: a.id })
await dispatch(loadFolderResults(currentFolderHash)).unwrap()
const copy = JSON.parse(JSON.stringify(fullResult))
copy.extraction.entities.addresses.splice(i, 1)
setFullResult(copy)
} catch {}
}}>Supprimer</Button>
</Box>
</Box>
))
) : (
<Typography variant="caption" color="text.secondary">Aucune adresse</Typography>
)}
</Box>
</Box>
{/* Entreprises */}
<Box>
<Typography variant="subtitle2">Entreprises</Typography>
<Box>
{Array.isArray((fullResult?.extraction?.entities?.companies)) && fullResult.extraction.entities.companies.length > 0 ? (
fullResult.extraction.entities.companies.map((c: any, i: number) => (
<Box key={`cimg-${i}`} display="flex" alignItems="center" justifyContent="space-between" sx={{ py: 0.5, gap: 1 }}>
<Box display="flex" alignItems="center" gap={1}>
<input style={{ padding: 4, width: 260 }} defaultValue={c.name} onChange={(e) => (c.name = e.target.value)} />
</Box>
<Box display="flex" gap={1}>
<Button size="small" variant="outlined" disabled={!currentFolderHash || savingKey === `cimg-${i}`}
onClick={async () => {
if (!currentFolderHash) return
try {
setSavingKey(`cimg-${i}`)
await updateEntity(currentFolderHash, document.id, 'company', { index: i, id: c.id, patch: { name: c.name } })
await dispatch(loadFolderResults(currentFolderHash)).unwrap()
} finally { setSavingKey(null) }
}}>Enregistrer</Button>
<Button size="small" color="error"
onClick={async () => {
if (!currentFolderHash) return
try {
await deleteEntity(currentFolderHash, document.id, 'company', { index: i, id: c.id })
await dispatch(loadFolderResults(currentFolderHash)).unwrap()
const copy = JSON.parse(JSON.stringify(fullResult))
copy.extraction.entities.companies.splice(i, 1)
setFullResult(copy)
} catch {}
}}>Supprimer</Button>
</Box>
</Box>
))
) : (
<Typography variant="caption" color="text.secondary">Aucune entreprise</Typography>
)}
</Box>
</Box>
</Box>
</Box>
</DialogContent>
<DialogActions>
<Button onClick={onClose}>Fermer</Button>