Skip to content

Commit b992319

Browse files
committed
added button for deleting all ocr data
1 parent 82a27de commit b992319

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

src/components/AnnotatorMenu.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ import DeleteObjectButton from "./MenuComponents/DeleteObjectButton";
1717
import ShowHelpRasterizationButton from "./MenuComponents/ShowHelpRasterizationButton";
1818
import PositionDisplay from "./MenuComponents/PositionDisplay";
1919
import ApplyPreAnnotatedDataButton from "./MenuComponents/ApplyPreAnnotatedDataButton";
20+
import DeleteOCRDataButton from "./MenuComponents/DeleteOCRDataButton";
2021

2122

2223
const AnnotatorMenu = () => {
2324
const isInSync = useStore(state => state.isInSync)
25+
const ocrView = useStore(state => state.ocrView)
2426

2527
return (<Box sx={{display: "flex", width: "100%", position: "fixed", "top": 0, "left": 0,
2628
zIndex: 99, background: "lightgrey"}}>
@@ -37,7 +39,7 @@ const AnnotatorMenu = () => {
3739
<SegmentTableButton/>
3840
<SetOCRViewButton/>
3941
<ApplyPreAnnotatedDataButton/>
40-
<DeleteObjectButton/>
42+
{ocrView ? <DeleteOCRDataButton/> : <DeleteObjectButton/>}
4143
{<SyncIndicator style={{background: isInSync ? "forestgreen" : "yellow"}}>💾</SyncIndicator>}
4244
</Box>)
4345
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import * as React from 'react';
2+
import Dialog from '@mui/material/Dialog';
3+
import DialogActions from '@mui/material/DialogActions';
4+
import DialogContent from '@mui/material/DialogContent';
5+
import DialogContentText from '@mui/material/DialogContentText';
6+
import DialogTitle from '@mui/material/DialogTitle';
7+
import Button from '@mui/material/Button';
8+
import DeleteSweepIcon from '@mui/icons-material/DeleteSweep';
9+
import {Tooltip} from "@mui/material";
10+
import {useStore} from "../../store";
11+
12+
const DeleteOCRDataButton = () => {
13+
const tables = useStore(state => state.tables)
14+
const ocrView = useStore(state => state.ocrView)
15+
const updateCellText = useStore(state => state.updateCellText)
16+
const selectedTable = useStore(state => state.selectedTable)
17+
const [open, setOpen] = React.useState(false);
18+
19+
const handleDeleteStart = () => {
20+
setOpen(true);
21+
};
22+
23+
const handleDeleteStop = () => {
24+
setOpen(false);
25+
};
26+
27+
const disabled = selectedTable === undefined || tables[selectedTable] === undefined || !ocrView
28+
const handleDelete = () => {
29+
if (disabled || selectedTable === undefined) return
30+
const table = tables[selectedTable]
31+
if (table === undefined) return
32+
table.cells.forEach((row, i) => {
33+
row.forEach((cell, j) => {
34+
updateCellText(i, j, "")
35+
})
36+
})
37+
setOpen(false);
38+
}
39+
40+
return <div>
41+
<Tooltip title="alle Texte löschen">
42+
<span>
43+
<Button disabled={disabled} variant="contained" onClick={handleDeleteStart}><DeleteSweepIcon/></Button>
44+
</span>
45+
</Tooltip>
46+
<Dialog
47+
open={open}
48+
onClose={handleDeleteStop}
49+
aria-labelledby="alert-dialog-title"
50+
aria-describedby="alert-dialog-description"
51+
>
52+
<DialogTitle id="alert-dialog-title">
53+
{"Alle Textdaten löschen?"}
54+
</DialogTitle>
55+
<DialogContent>
56+
<DialogContentText id="alert-dialog-description">
57+
Möchtest Du alle Textdaten in dieser Tabelle löschen?
58+
</DialogContentText>
59+
</DialogContent>
60+
<DialogActions>
61+
<Button onClick={handleDeleteStop}>Nein</Button>
62+
<Button onClick={handleDelete}>
63+
Ja 🗑️
64+
</Button>
65+
</DialogActions>
66+
</Dialog>
67+
</div>
68+
}
69+
70+
export default DeleteOCRDataButton
71+
72+

src/components/SplitTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const SplitTable = ({imageName}: SplitTableProps) => {
9999
height: `${Math.round(Math.max(height(cellRectangle)*1.3-4, 20))}px`}}
100100
onBlur={handleInputOnBlur(i, j)}
101101
// little hack to update default cell text when ocr text changes
102-
key={`${i}_${j}_cell_text_${cell.ocr_text}`}
102+
key={`${i}_${j}_cell_text_${cell.ocr_text}_${cell.human_text}`}
103103
/>
104104
</div>
105105
</div>

src/store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export type AnnotatorState = {
132132
setVirtualValueType: (valueIndex: number, label?: string) => void
133133
deleteVirtualValue: (valueIdnex: number) => void
134134
setVirtualValue: (valueIndex: number, value: string) => void
135+
135136
}
136137

137138
export const useStore = create<AnnotatorState>((set, get) => ({

0 commit comments

Comments
 (0)