Compare commits

..

No commits in common. "609ec5284aa7857dcf726d2e2eec1b542233cd2c" and "f70df881deadc794455d46ccdff93014da95ea0a" have entirely different histories.

1 changed files with 49 additions and 85 deletions

View File

@ -27,7 +27,8 @@ import {
useSuspenseQuery, useSuspenseQuery,
} from "@tanstack/react-query"; } from "@tanstack/react-query";
import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { useEffect, useState, type KeyboardEvent } from "react"; import { useEffect, useState } from "react";
import type { KeyboardEvent } from "react";
import PDFViewer from "../components/pdfViewer"; import PDFViewer from "../components/pdfViewer";
import { fetchPutKPI } from "../util/api"; import { fetchPutKPI } from "../util/api";
import { kpiQueryOptions } from "../util/query"; import { kpiQueryOptions } from "../util/query";
@ -71,36 +72,12 @@ function ExtractedResultsPage() {
const originalValue = kpiValues[0]?.entity || ""; const originalValue = kpiValues[0]?.entity || "";
const originalPage = kpiValues[0]?.page || 0; const originalPage = kpiValues[0]?.page || 0;
const selectedValue =
// Funktion, um gleiche Werte zusammenzufassen und die Seiten zu sammeln selectedIndex === -1 ? customValue : kpiValues[selectedIndex]?.entity || "";
function groupKpiValues(values: Array<{ entity: string; page: number; [key: string]: any }>): Array<{ entity: string; pages: number[]; [key: string]: any }> {
const map = new Map<string, { entity: string; pages: number[]; [key: string]: any }>();
values.forEach((item: { entity: string; page: number; [key: string]: any }) => {
const key = item.entity.toLowerCase();
if (!map.has(key)) {
map.set(key, { ...item, pages: [item.page] });
} else {
const existingEntry = map.get(key)!;
if (!existingEntry.pages.includes(item.page)) {
existingEntry.pages.push(item.page);
}
}
});
return Array.from(map.values());
}
const groupedKpiValues: Array<{ entity: string; pages: number[]; [key: string]: any }> = groupKpiValues(kpiValues);
const selectedValue: string =
selectedIndex === -1 ? customValue : groupedKpiValues[selectedIndex]?.entity || "";
const selectedPage = const selectedPage =
selectedIndex === -1 selectedIndex === -1
? (parseInt(customPage) > 0 ? parseInt(customPage) : 1) ? (parseInt(customPage) > 0 ? parseInt(customPage) : 1)
: groupedKpiValues[selectedIndex]?.pages[0] || 1; : kpiValues[selectedIndex]?.page || 1;
// Um zu prüfen, ob der Wert nur aus Leerzeichen besteht
const isSelectedValueEmpty = selectedIndex === -1 ? customValue.trim() === "" : !selectedValue;
useEffect(() => { useEffect(() => {
const valueChanged = selectedValue !== originalValue; const valueChanged = selectedValue !== originalValue;
@ -113,15 +90,7 @@ function ExtractedResultsPage() {
const updatedData = { ...kpiData }; const updatedData = { ...kpiData };
let baseObject; let baseObject;
if (selectedIndex >= 0) { if (selectedIndex >= 0) {
// Das Originalobjekt mit allen Feldern für diesen Wert suchen baseObject = kpiValues[selectedIndex];
const original = kpiValues.find(v => v.entity.toLowerCase() === groupedKpiValues[selectedIndex].entity.toLowerCase()) as { status?: string; source?: string } | undefined;
baseObject = {
label: kpi.toUpperCase(),
entity: groupedKpiValues[selectedIndex].entity,
page: groupedKpiValues[selectedIndex].pages[0],
status: original?.status || "single-source",
source: original?.source || "auto",
};
} else { } else {
baseObject = { baseObject = {
label: kpi.toUpperCase(), label: kpi.toUpperCase(),
@ -162,7 +131,7 @@ function ExtractedResultsPage() {
} else { } else {
const index = Number.parseInt(value); const index = Number.parseInt(value);
setSelectedIndex(index); setSelectedIndex(index);
setCurrentPage(groupedKpiValues[index].pages[0]); setCurrentPage(kpiValues[index].page);
setCustomValue(""); setCustomValue("");
setCustomPage(""); setCustomPage("");
} }
@ -187,7 +156,7 @@ function ExtractedResultsPage() {
}; };
const handleRowClick = (index: number) => { const handleRowClick = (index: number) => {
setCurrentPage(groupedKpiValues[index].pages[0]); setCurrentPage(kpiValues[index].page);
setSelectedIndex(index); setSelectedIndex(index);
setCustomValue(""); setCustomValue("");
setCustomPage(""); setCustomPage("");
@ -226,8 +195,10 @@ function ExtractedResultsPage() {
setEditingCustomPage(true); setEditingCustomPage(true);
}; };
const handleCustomPageKeyPress = (e: KeyboardEvent<HTMLInputElement>) => { const handleCustomPageKeyPress = (e: KeyboardEvent<HTMLDivElement>) => {
if (e.key === "Enter" || e.key === "Escape") { if (e.key === "Enter") {
setEditingCustomPage(false);
} else if (e.key === "Escape") {
setEditingCustomPage(false); setEditingCustomPage(false);
} }
}; };
@ -273,14 +244,14 @@ function ExtractedResultsPage() {
<strong>Gefundene Werte</strong> <strong>Gefundene Werte</strong>
</TableCell> </TableCell>
<TableCell align="center" width="15%"> <TableCell align="center" width="15%">
<strong>Seiten</strong> <strong>Seite</strong>
</TableCell> </TableCell>
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{groupedKpiValues.map((item, index) => ( {kpiValues.map((item, index) => (
<TableRow <TableRow
key={`${item.entity}_${item.pages.join('_')}_${index}`} key={`${item.entity}_${item.page}_${index}`}
sx={{ sx={{
"&:hover": { backgroundColor: "#f9f9f9" }, "&:hover": { backgroundColor: "#f9f9f9" },
cursor: "pointer", cursor: "pointer",
@ -319,19 +290,16 @@ function ExtractedResultsPage() {
</Box> </Box>
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
{item.pages.map((page: number, i: number) => ( <Link
<Link component="button"
key={page} onClick={(e: React.MouseEvent) => {
component="button" e.stopPropagation();
onClick={(e: React.MouseEvent) => { setCurrentPage(item.page);
e.stopPropagation(); }}
setCurrentPage(page); sx={{ cursor: "pointer" }}
}} >
sx={{ cursor: "pointer", ml: i > 0 ? 1 : 0 }} {item.page}
> </Link>
{page}
</Link>
))}
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ))}
@ -367,28 +335,24 @@ function ExtractedResultsPage() {
}, },
}} }}
/> />
<Box sx={{ width: '100%' }}> <TextField
<TextField placeholder="Einen abweichenden Wert eingeben..."
placeholder="Einen abweichenden Wert eingeben..." value={customValue}
value={customValue} onChange={handleCustomValueChange}
onChange={handleCustomValueChange} variant="standard"
variant="standard" fullWidth
fullWidth InputProps={{
InputProps={{ disableUnderline: true,
disableUnderline: true, }}
}} sx={{
sx={{ "& .MuiInput-input": {
"& .MuiInput-input": { padding: 0,
padding: 0, },
}, }}
}} onClick={(e: React.MouseEvent) => {
onClick={(e: React.MouseEvent) => { e.stopPropagation();
e.stopPropagation(); }}
}} />
error={selectedIndex === -1 && customValue !== "" && customValue.trim() === ""}
helperText={selectedIndex === -1 && customValue !== "" && customValue.trim() === "" ? "Der Wert, der angegeben wurde, ist leer." : ""}
/>
</Box>
</Box> </Box>
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
@ -476,12 +440,12 @@ function ExtractedResultsPage() {
pitchBookId={pitchBook} pitchBookId={pitchBook}
currentPage={currentPage} currentPage={currentPage}
onPageChange={setCurrentPage} onPageChange={setCurrentPage}
highlight={groupedKpiValues highlight={Object.values(kpiValues)
.map((k) => k.pages.map((page: number) => ({ page, text: k.entity }))) .flat()
.reduce((acc, val) => acc.concat(val), [])} .map((k) => ({ page: k.page, text: k.entity }))}
focusHighlight={{ focusHighlight={{
page: groupedKpiValues.at(selectedIndex)?.pages[0] || -1, page: kpiValues.at(selectedIndex)?.page || -1,
text: groupedKpiValues.at(selectedIndex)?.entity || "", text: kpiValues.at(selectedIndex)?.entity || "",
}} }}
/> />
</Paper> </Paper>
@ -489,7 +453,7 @@ function ExtractedResultsPage() {
<Button <Button
variant="contained" variant="contained"
onClick={handleAcceptReview} onClick={handleAcceptReview}
disabled={isSelectedValueEmpty} disabled={!selectedValue}
sx={{ sx={{
backgroundColor: "#383838", backgroundColor: "#383838",
"&:hover": { backgroundColor: "#2e2e2e" }, "&:hover": { backgroundColor: "#2e2e2e" },