feat(extraction): édition et suppression des entités directement dans l’onglet Extraction
This commit is contained in:
parent
c380ce31f0
commit
a2b6e70e38
@ -5,6 +5,7 @@ import { useAppDispatch, useAppSelector } from '../store'
|
||||
import { setCurrentResultIndex } from '../store/documentSlice'
|
||||
import { clearFolderCache, reprocessFolder } from '../services/folderApi'
|
||||
import { Layout } from '../components/Layout'
|
||||
import { deleteEntity, updateEntity } from '../services/folderApi'
|
||||
|
||||
export default function ExtractionView() {
|
||||
const dispatch = useAppDispatch()
|
||||
@ -15,6 +16,7 @@ export default function ExtractionView() {
|
||||
|
||||
// Utiliser les résultats du dossier pour la navigation
|
||||
const currentResult = folderResults[currentIndex]
|
||||
const [savingKey, setSavingKey] = useState<string | null>(null)
|
||||
|
||||
const gotoResult = (index: number) => {
|
||||
if (index >= 0 && index < folderResults.length) {
|
||||
@ -194,17 +196,28 @@ export default function ExtractionView() {
|
||||
Personnes ({extraction.extraction.entities.persons.length})
|
||||
</Typography>
|
||||
<List dense>
|
||||
{extraction.extraction.entities.persons.map((person: any, index: number) => {
|
||||
const label =
|
||||
typeof person === 'string'
|
||||
? person
|
||||
: [person.firstName, person.lastName].filter(Boolean).join(' ') || person?.id || 'Personne'
|
||||
return (
|
||||
<ListItem key={index}>
|
||||
<ListItemText primary={label} secondary="Personne détectée" />
|
||||
</ListItem>
|
||||
)
|
||||
})}
|
||||
{extraction.extraction.entities.persons.map((p: any, i: number) => (
|
||||
<ListItem key={`p-${i}`} secondaryAction={
|
||||
<Box sx={{ display: 'flex', gap: 1 }}>
|
||||
<Button size="small" variant="outlined" disabled={savingKey===`p-${i}`}
|
||||
onClick={async ()=>{
|
||||
try{
|
||||
setSavingKey(`p-${i}`)
|
||||
await updateEntity(currentFolderHash!, extraction.fileHash, 'person', { index: i, id: p.id, patch: { firstName: p.firstName, lastName: p.lastName } })
|
||||
} finally { setSavingKey(null) }
|
||||
}}>Enregistrer</Button>
|
||||
<Button size="small" color="error"
|
||||
onClick={async ()=>{
|
||||
await deleteEntity(currentFolderHash!, extraction.fileHash, 'person', { index: i, id: p.id })
|
||||
}}>Supprimer</Button>
|
||||
</Box>
|
||||
}>
|
||||
<Box sx={{ display: 'flex', gap: 1 }}>
|
||||
<input style={{ padding: 4, width: 120 }} defaultValue={p.firstName} onChange={(e)=> (p.firstName=e.target.value)} />
|
||||
<input style={{ padding: 4, width: 140 }} defaultValue={p.lastName} onChange={(e)=> (p.lastName=e.target.value)} />
|
||||
</Box>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@ -219,19 +232,30 @@ export default function ExtractionView() {
|
||||
Adresses ({extraction.extraction.entities.addresses.length})
|
||||
</Typography>
|
||||
<List dense>
|
||||
{extraction.extraction.entities.addresses.map((address: any, index: number) => {
|
||||
const label =
|
||||
typeof address === 'string'
|
||||
? address
|
||||
: [address.street, address.postalCode, address.city]
|
||||
.filter((v) => !!v && String(v).trim().length > 0)
|
||||
.join(' ') || address?.id || 'Adresse'
|
||||
return (
|
||||
<ListItem key={index}>
|
||||
<ListItemText primary={label} secondary="Adresse détectée" />
|
||||
</ListItem>
|
||||
)
|
||||
})}
|
||||
{extraction.extraction.entities.addresses.map((a: any, i: number) => (
|
||||
<ListItem key={`a-${i}`} secondaryAction={
|
||||
<Box sx={{ display: 'flex', gap: 1 }}>
|
||||
<Button size="small" variant="outlined" disabled={savingKey===`a-${i}`}
|
||||
onClick={async ()=>{
|
||||
try{
|
||||
setSavingKey(`a-${i}`)
|
||||
await updateEntity(currentFolderHash!, extraction.fileHash, 'address', { index: i, id: a.id, patch: { street: a.street, city: a.city, postalCode: a.postalCode, country: a.country } })
|
||||
} finally { setSavingKey(null) }
|
||||
}}>Enregistrer</Button>
|
||||
<Button size="small" color="error"
|
||||
onClick={async ()=>{
|
||||
await deleteEntity(currentFolderHash!, extraction.fileHash, 'address', { index: i, id: a.id })
|
||||
}}>Supprimer</Button>
|
||||
</Box>
|
||||
}>
|
||||
<Box sx={{ display: 'flex', gap: 1, flexWrap: 'wrap' }}>
|
||||
<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>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@ -246,14 +270,27 @@ export default function ExtractionView() {
|
||||
Entreprises ({extraction.extraction.entities.companies.length})
|
||||
</Typography>
|
||||
<List dense>
|
||||
{extraction.extraction.entities.companies.map((company: any, index: number) => {
|
||||
const label = typeof company === 'string' ? company : company?.name || company?.id || 'Entreprise'
|
||||
return (
|
||||
<ListItem key={index}>
|
||||
<ListItemText primary={label} secondary="Entreprise détectée" />
|
||||
</ListItem>
|
||||
)
|
||||
})}
|
||||
{extraction.extraction.entities.companies.map((c: any, i: number) => (
|
||||
<ListItem key={`c-${i}`} secondaryAction={
|
||||
<Box sx={{ display: 'flex', gap: 1 }}>
|
||||
<Button size="small" variant="outlined" disabled={savingKey===`c-${i}`}
|
||||
onClick={async ()=>{
|
||||
try{
|
||||
setSavingKey(`c-${i}`)
|
||||
await updateEntity(currentFolderHash!, extraction.fileHash, 'company', { index: i, id: c.id, patch: { name: c.name } })
|
||||
} finally { setSavingKey(null) }
|
||||
}}>Enregistrer</Button>
|
||||
<Button size="small" color="error"
|
||||
onClick={async ()=>{
|
||||
await deleteEntity(currentFolderHash!, extraction.fileHash, 'company', { index: i, id: c.id })
|
||||
}}>Supprimer</Button>
|
||||
</Box>
|
||||
}>
|
||||
<Box sx={{ display: 'flex', gap: 1 }}>
|
||||
<input style={{ padding: 4, width: 260 }} defaultValue={c.name} onChange={(e)=> (c.name=e.target.value)} />
|
||||
</Box>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user