parent
a947de31bf
commit
60b303d92e
|
|
@ -26,7 +26,7 @@ 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 } from "react";
|
import React, { useEffect, useState } 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";
|
||||||
|
|
@ -66,19 +66,47 @@ function ExtractedResultsPage() {
|
||||||
const [hasChanges, setHasChanges] = useState(false);
|
const [hasChanges, setHasChanges] = useState(false);
|
||||||
const [customValue, setCustomValue] = useState("");
|
const [customValue, setCustomValue] = useState("");
|
||||||
const originalValue = kpiValues[0]?.entity || "";
|
const originalValue = kpiValues[0]?.entity || "";
|
||||||
const selectedValue =
|
|
||||||
selectedIndex === -1 ? customValue : kpiValues[selectedIndex]?.entity || "";
|
// Funktion, um gleiche Werte zusammenzufassen und die Seiten zu sammeln
|
||||||
|
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 {
|
||||||
|
map.get(key)!.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 || "";
|
||||||
|
|
||||||
|
// Um zu prüfen, ob der Wert nur aus Leerzeichen besteht
|
||||||
|
const isSelectedValueEmpty = selectedIndex === -1 ? customValue.trim() === "" : !groupedKpiValues[selectedIndex]?.entity;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setHasChanges(selectedValue !== originalValue);
|
setHasChanges(groupedKpiValues[selectedIndex]?.entity !== originalValue);
|
||||||
}, [selectedValue, originalValue]);
|
}, [groupedKpiValues, selectedIndex, originalValue]);
|
||||||
|
|
||||||
const { mutate: updateKPI } = useMutation({
|
const { mutate: updateKPI } = useMutation({
|
||||||
mutationFn: () => {
|
mutationFn: () => {
|
||||||
const updatedData = { ...kpiData };
|
const updatedData = { ...kpiData };
|
||||||
let baseObject;
|
let baseObject;
|
||||||
if (selectedIndex >= 0) {
|
if (selectedIndex >= 0) {
|
||||||
baseObject = kpiValues[selectedIndex];
|
// Das Originalobjekt mit allen Feldern für diesen Wert suchen
|
||||||
|
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(),
|
||||||
|
|
@ -118,7 +146,7 @@ function ExtractedResultsPage() {
|
||||||
} else {
|
} else {
|
||||||
const index = Number.parseInt(value);
|
const index = Number.parseInt(value);
|
||||||
setSelectedIndex(index);
|
setSelectedIndex(index);
|
||||||
setCurrentPage(kpiValues[index].page);
|
setCurrentPage(groupedKpiValues[index].pages[0]);
|
||||||
setCustomValue("");
|
setCustomValue("");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -132,7 +160,7 @@ function ExtractedResultsPage() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRowClick = (index: number) => {
|
const handleRowClick = (index: number) => {
|
||||||
setCurrentPage(kpiValues[index].page);
|
setCurrentPage(groupedKpiValues[index].pages[0]);
|
||||||
setSelectedIndex(index);
|
setSelectedIndex(index);
|
||||||
setCustomValue("");
|
setCustomValue("");
|
||||||
};
|
};
|
||||||
|
|
@ -207,14 +235,14 @@ function ExtractedResultsPage() {
|
||||||
<strong>Gefundene Werte</strong>
|
<strong>Gefundene Werte</strong>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
<strong>Seite</strong>
|
<strong>Seiten</strong>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{kpiValues.map((item, index) => (
|
{groupedKpiValues.map((item, index) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={`${item.entity}_${item.page}_${index}`}
|
key={`${item.entity}_${item.pages.join('_')}_${index}`}
|
||||||
sx={{
|
sx={{
|
||||||
"&:hover": { backgroundColor: "#f9f9f9" },
|
"&:hover": { backgroundColor: "#f9f9f9" },
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
|
|
@ -253,16 +281,19 @@ function ExtractedResultsPage() {
|
||||||
</Box>
|
</Box>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
|
{item.pages.map((page: number, i: number) => (
|
||||||
<Link
|
<Link
|
||||||
|
key={page}
|
||||||
component="button"
|
component="button"
|
||||||
onClick={(e: React.MouseEvent) => {
|
onClick={(e: React.MouseEvent) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
setCurrentPage(item.page);
|
setCurrentPage(page);
|
||||||
}}
|
}}
|
||||||
sx={{ cursor: "pointer" }}
|
sx={{ cursor: "pointer", ml: i > 0 ? 1 : 0 }}
|
||||||
>
|
>
|
||||||
{item.page}
|
{page}
|
||||||
</Link>
|
</Link>
|
||||||
|
))}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
|
|
@ -298,6 +329,7 @@ function ExtractedResultsPage() {
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<Box sx={{ width: '100%' }}>
|
||||||
<TextField
|
<TextField
|
||||||
placeholder="Einen abweichenden Wert eingeben..."
|
placeholder="Einen abweichenden Wert eingeben..."
|
||||||
value={customValue}
|
value={customValue}
|
||||||
|
|
@ -315,8 +347,11 @@ function ExtractedResultsPage() {
|
||||||
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>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableBody>
|
</TableBody>
|
||||||
|
|
@ -348,12 +383,12 @@ function ExtractedResultsPage() {
|
||||||
pitchBookId={pitchBook}
|
pitchBookId={pitchBook}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
onPageChange={setCurrentPage}
|
onPageChange={setCurrentPage}
|
||||||
highlight={Object.values(kpiValues)
|
highlight={groupedKpiValues
|
||||||
.flat()
|
.map((k) => k.pages.map((page: number) => ({ page, text: k.entity })))
|
||||||
.map((k) => ({ page: k.page, text: k.entity }))}
|
.reduce((acc, val) => acc.concat(val), [])}
|
||||||
focusHighlight={{
|
focusHighlight={{
|
||||||
page: kpiValues.at(selectedIndex)?.page || -1,
|
page: groupedKpiValues.at(selectedIndex)?.pages[0] || -1,
|
||||||
text: kpiValues.at(selectedIndex)?.entity || "",
|
text: groupedKpiValues.at(selectedIndex)?.entity || "",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
|
@ -361,7 +396,7 @@ function ExtractedResultsPage() {
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={handleAcceptReview}
|
onClick={handleAcceptReview}
|
||||||
disabled={!selectedValue}
|
disabled={isSelectedValueEmpty}
|
||||||
sx={{
|
sx={{
|
||||||
backgroundColor: "#383838",
|
backgroundColor: "#383838",
|
||||||
"&:hover": { backgroundColor: "#2e2e2e" },
|
"&:hover": { backgroundColor: "#2e2e2e" },
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue