Fix merge conflict

pull/80/head
Zainab2604 2025-06-22 13:41:45 +02:00
parent 61dcc76203
commit f6747e45ac
1 changed files with 97 additions and 11 deletions

View File

@ -1,4 +1,5 @@
import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import EditIcon from "@mui/icons-material/Edit";
import { import {
Box, Box,
Button, Button,
@ -26,7 +27,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 React, { useEffect, useState } from "react"; import { useEffect, useState, 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";
@ -65,9 +66,12 @@ function ExtractedResultsPage() {
const [showConfirmDialog, setShowConfirmDialog] = useState(false); const [showConfirmDialog, setShowConfirmDialog] = useState(false);
const [hasChanges, setHasChanges] = useState(false); const [hasChanges, setHasChanges] = useState(false);
const [customValue, setCustomValue] = useState(""); const [customValue, setCustomValue] = useState("");
const originalValue = kpiValues[0]?.entity || ""; const [customPage, setCustomPage] = useState("");
const [editingCustomPage, setEditingCustomPage] = useState(false);
const originalValue = kpiValues[0]?.entity || "";
const originalPage = kpiValues[0]?.page || 0;
// 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 }> { 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 }>(); const map = new Map<string, { entity: string; pages: number[]; [key: string]: any }>();
values.forEach((item: { entity: string; page: number; [key: string]: any }) => { values.forEach((item: { entity: string; page: number; [key: string]: any }) => {
@ -88,20 +92,25 @@ function ExtractedResultsPage() {
const selectedValue: string = const selectedValue: string =
selectedIndex === -1 ? customValue : groupedKpiValues[selectedIndex]?.entity || ""; selectedIndex === -1 ? customValue : groupedKpiValues[selectedIndex]?.entity || "";
const selectedPage =
selectedIndex === -1
? (parseInt(customPage) > 0 ? parseInt(customPage) : 1)
: groupedKpiValues[selectedIndex]?.pages[0] || 1;
// Um zu prüfen, ob der Wert nur aus Leerzeichen besteht const isSelectedValueEmpty = selectedIndex === -1 ? customValue.trim() === "" : !selectedValue;
const isSelectedValueEmpty = selectedIndex === -1 ? customValue.trim() === "" : !groupedKpiValues[selectedIndex]?.entity;
useEffect(() => { useEffect(() => {
setHasChanges(groupedKpiValues[selectedIndex]?.entity !== originalValue); const valueChanged = selectedValue !== originalValue;
}, [groupedKpiValues, selectedIndex, originalValue]); const pageChanged = selectedPage !== originalPage;
setHasChanges(valueChanged || pageChanged);
}, [selectedValue, selectedPage, originalValue, originalPage]);
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) {
// 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; const original = kpiValues.find(v => v.entity.toLowerCase() === groupedKpiValues[selectedIndex].entity.toLowerCase()) as { status?: string; source?: string } | undefined;
baseObject = { baseObject = {
label: kpi.toUpperCase(), label: kpi.toUpperCase(),
@ -114,7 +123,7 @@ function ExtractedResultsPage() {
baseObject = { baseObject = {
label: kpi.toUpperCase(), label: kpi.toUpperCase(),
entity: selectedValue, entity: selectedValue,
page: 0, page: selectedPage,
status: "single-source", status: "single-source",
source: "manual", source: "manual",
}; };
@ -123,6 +132,7 @@ function ExtractedResultsPage() {
{ {
...baseObject, ...baseObject,
entity: selectedValue, entity: selectedValue,
page: selectedPage,
}, },
]; ];
return fetchPutKPI(Number(pitchBook), updatedData); return fetchPutKPI(Number(pitchBook), updatedData);
@ -151,6 +161,7 @@ function ExtractedResultsPage() {
setSelectedIndex(index); setSelectedIndex(index);
setCurrentPage(groupedKpiValues[index].pages[0]); setCurrentPage(groupedKpiValues[index].pages[0]);
setCustomValue(""); setCustomValue("");
setCustomPage("");
} }
}; };
@ -162,10 +173,20 @@ function ExtractedResultsPage() {
setSelectedIndex(-1); setSelectedIndex(-1);
}; };
const handleCustomPageChange = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
const value = event.target.value;
if (value === '' || (/^\d+$/.test(value) && parseInt(value) > 0)) {
setCustomPage(value);
}
};
const handleRowClick = (index: number) => { const handleRowClick = (index: number) => {
setCurrentPage(groupedKpiValues[index].pages[0]); setCurrentPage(groupedKpiValues[index].pages[0]);
setSelectedIndex(index); setSelectedIndex(index);
setCustomValue(""); setCustomValue("");
setCustomPage("");
}; };
const handleBackClick = () => { const handleBackClick = () => {
@ -197,6 +218,16 @@ function ExtractedResultsPage() {
updateKPI(); updateKPI();
}; };
const startCustomPageEditing = () => {
setEditingCustomPage(true);
};
const handleCustomPageKeyPress = (e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter" || e.key === "Escape") {
setEditingCustomPage(false);
}
};
return ( return (
<Box p={4}> <Box p={4}>
<Box sx={{ display: "flex", alignItems: "center", mb: 3 }}> <Box sx={{ display: "flex", alignItems: "center", mb: 3 }}>
@ -234,10 +265,10 @@ function ExtractedResultsPage() {
<Table> <Table>
<TableHead> <TableHead>
<TableRow> <TableRow>
<TableCell> <TableCell width="85%">
<strong>Gefundene Werte</strong> <strong>Gefundene Werte</strong>
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center" width="15%">
<strong>Seiten</strong> <strong>Seiten</strong>
</TableCell> </TableCell>
</TableRow> </TableRow>
@ -356,6 +387,61 @@ function ExtractedResultsPage() {
</Box> </Box>
</Box> </Box>
</TableCell> </TableCell>
<TableCell align="center">
{editingCustomPage ? (
<TextField
value={customPage}
onChange={handleCustomPageChange}
onKeyDown={handleCustomPageKeyPress}
onBlur={() => setEditingCustomPage(false)}
autoFocus
size="small"
variant="standard"
sx={{
width: "60px",
"& .MuiInput-input": {
textAlign: "center"
}
}}
inputProps={{
min: 0,
style: { textAlign: 'center' }
}}
/>
) : (
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
gap: 1,
cursor: "pointer",
minHeight: "24px",
minWidth: "100px",
margin: "0 auto",
}}
onClick={(e: React.MouseEvent) => {
e.stopPropagation();
startCustomPageEditing();
}}
>
<span>{customPage || "..."}</span>
<EditIcon
fontSize="small"
sx={{
color: "#666",
opacity: 0.7,
transition: "opacity 0.2s ease",
ml: 1
}}
onClick={(e) => {
e.stopPropagation();
startCustomPageEditing();
}}
/>
</Box>
)}
</TableCell>
</TableRow> </TableRow>
</TableBody> </TableBody>
</Table> </Table>