Compare commits

..

No commits in common. "41a37b3d7d0793ab511d52e6375d019007776716" and "2009d5b6f384e881b86fc96cbec819da6f3bccb7" have entirely different histories.

5 changed files with 321 additions and 377 deletions

View File

@ -1,10 +1,9 @@
import { Box, Tooltip, CircularProgress, Typography } from "@mui/material";
import DragIndicatorIcon from "@mui/icons-material/DragIndicator";
import { Box, CircularProgress, Tooltip, Typography } from "@mui/material";
import { useNavigate } from "@tanstack/react-router";
import { useEffect, useState } from "react";
import { useNavigate } from "@tanstack/react-router";
import type { Kennzahl } from "../types/kpi";
import { getDisplayType } from "../types/kpi";
import { fetchKennzahlen as fetchK } from "../util/api";
export function ConfigTable() {
const navigate = useNavigate();
@ -17,18 +16,21 @@ export function ConfigTable() {
const fetchKennzahlen = async () => {
while (true) {
try {
console.log("Fetching kennzahlen from API...");
const data = await fetchK();
console.log("Fetched kennzahlen:", data);
const sortedData = data.sort(
(a: Kennzahl, b: Kennzahl) => a.position - b.position,
);
console.log('Fetching kennzahlen from API...');
const response = await fetch(`http://localhost:5050/api/kpi_setting/`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log('Fetched kennzahlen:', data);
const sortedData = data.sort((a: Kennzahl, b: Kennzahl) => a.position - b.position);
setKennzahlen(sortedData);
setLoading(false);
break;
} catch (err) {
console.error("Error fetching kennzahlen:", err);
await new Promise((resolve) => setTimeout(resolve, 2000));
console.error('Error fetching kennzahlen:', err);
await new Promise(resolve => setTimeout(resolve, 2000));
}
}
};
@ -37,35 +39,36 @@ export function ConfigTable() {
}, []);
const handleToggleActive = async (id: number) => {
const kennzahl = kennzahlen.find((k) => k.id === id);
const kennzahl = kennzahlen.find(k => k.id === id);
if (!kennzahl) return;
try {
const response = await fetch(
`http://localhost:5050/api/kpi_setting/${id}`,
{
method: "PUT",
const response = await fetch(`http://localhost:5050/api/kpi_setting/${id}`, {
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify({
active: !kennzahl.active,
active: !kennzahl.active
}),
},
);
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const updatedKennzahl = await response.json();
setKennzahlen((prev) =>
prev.map((item) => (item.id === id ? updatedKennzahl : item)),
setKennzahlen(prev =>
prev.map(item =>
item.id === id ? updatedKennzahl : item
)
);
} catch (err) {
console.error("Error toggling active status:", err);
setKennzahlen((prev) =>
prev.map((item) => (item.id === id ? kennzahl : item)),
console.error('Error toggling active status:', err);
setKennzahlen(prev =>
prev.map(item =>
item.id === id ? kennzahl : item
)
);
}
};
@ -75,19 +78,16 @@ export function ConfigTable() {
try {
const positionUpdates = reorderedKennzahlen.map((kennzahl, index) => ({
id: kennzahl.id,
position: index + 1,
position: index + 1
}));
const response = await fetch(
`http://localhost:5050/api/kpi_setting/update-kpi-positions`,
{
method: "PUT",
const response = await fetch(`http://localhost:5050/api/kpi_setting/update-kpi-positions`, {
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(positionUpdates),
},
);
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
@ -96,17 +96,14 @@ export function ConfigTable() {
const updatedKennzahlen = await response.json();
setKennzahlen(updatedKennzahlen);
} catch (err) {
console.error("Error updating positions:", err);
console.error('Error updating positions:', err);
window.location.reload();
} finally {
setIsUpdatingPositions(false);
}
};
const handleDragStart = (
e: React.DragEvent<HTMLTableRowElement>,
item: Kennzahl,
) => {
const handleDragStart = (e: React.DragEvent<HTMLTableRowElement>, item: Kennzahl) => {
setDraggedItem(item);
e.dataTransfer.effectAllowed = "move";
};
@ -116,19 +113,12 @@ export function ConfigTable() {
e.dataTransfer.dropEffect = "move";
};
const handleDrop = async (
e: React.DragEvent<HTMLTableRowElement>,
targetItem: Kennzahl,
) => {
const handleDrop = async (e: React.DragEvent<HTMLTableRowElement>, targetItem: Kennzahl) => {
e.preventDefault();
if (!draggedItem || draggedItem.id === targetItem.id) return;
const draggedIndex = kennzahlen.findIndex(
(item) => item.id === draggedItem.id,
);
const targetIndex = kennzahlen.findIndex(
(item) => item.id === targetItem.id,
);
const draggedIndex = kennzahlen.findIndex(item => item.id === draggedItem.id);
const targetIndex = kennzahlen.findIndex(item => item.id === targetItem.id);
const newKennzahlen = [...kennzahlen];
const [removed] = newKennzahlen.splice(draggedIndex, 1);
@ -149,23 +139,20 @@ export function ConfigTable() {
}
const target = e.target as HTMLElement;
if (
target.tagName === "INPUT" &&
(target as HTMLInputElement).type === "checkbox"
) {
if (target.tagName === 'INPUT' && (target as HTMLInputElement).type === 'checkbox') {
return;
}
if (target.closest(".drag-handle")) {
if (target.closest('.drag-handle')) {
return;
}
console.log("Navigating to detail page for KPI:", kennzahl);
console.log("KPI ID:", kennzahl.id);
console.log('Navigating to detail page for KPI:', kennzahl);
console.log('KPI ID:', kennzahl.id);
navigate({
to: `/config-detail/$kpiId`,
params: { kpiId: kennzahl.id.toString() },
params: { kpiId: kennzahl.id.toString() }
});
};
@ -179,7 +166,7 @@ export function ConfigTable() {
flexDirection="column"
mt={8}
>
<CircularProgress sx={{ color: "#383838", mb: 2 }} />
<CircularProgress sx={{ color: '#383838', mb: 2 }} />
<Typography>Lade Kennzahlen-Konfiguration...</Typography>
</Box>
);
@ -195,56 +182,47 @@ export function ConfigTable() {
backgroundColor: "white",
overflow: "hidden",
opacity: isUpdatingPositions ? 0.7 : 1,
pointerEvents: isUpdatingPositions ? "none" : "auto",
pointerEvents: isUpdatingPositions ? 'none' : 'auto'
}}
>
<table
style={{
<table style={{
width: "100%",
borderCollapse: "collapse",
}}
>
borderCollapse: "collapse"
}}>
<thead>
<tr style={{ backgroundColor: "#f5f5f5" }}>
<th
style={{
<th style={{
padding: "16px 12px",
textAlign: "left",
fontWeight: "bold",
width: "60px",
borderBottom: "1px solid #e0e0e0",
}}
/>
<th
style={{
borderBottom: "1px solid #e0e0e0"
}}>
</th>
<th style={{
padding: "16px 12px",
textAlign: "left",
fontWeight: "bold",
width: "80px",
borderBottom: "1px solid #e0e0e0",
}}
>
borderBottom: "1px solid #e0e0e0"
}}>
Aktiv
</th>
<th
style={{
<th style={{
padding: "16px 12px",
textAlign: "left",
fontWeight: "bold",
borderBottom: "1px solid #e0e0e0",
}}
>
borderBottom: "1px solid #e0e0e0"
}}>
Name
</th>
<th
style={{
<th style={{
padding: "16px 12px",
textAlign: "left",
fontWeight: "bold",
width: "160px",
borderBottom: "1px solid #e0e0e0",
}}
>
borderBottom: "1px solid #e0e0e0"
}}>
Format
</th>
</tr>
@ -262,9 +240,8 @@ export function ConfigTable() {
style={{
borderBottom: "1px solid #e0e0e0",
cursor: isUpdatingPositions ? "default" : "pointer",
backgroundColor:
draggedItem?.id === kennzahl.id ? "#f0f0f0" : "white",
opacity: draggedItem?.id === kennzahl.id ? 0.5 : 1,
backgroundColor: draggedItem?.id === kennzahl.id ? "#f0f0f0" : "white",
opacity: draggedItem?.id === kennzahl.id ? 0.5 : 1
}}
onMouseEnter={(e) => {
if (!draggedItem && !isUpdatingPositions) {
@ -282,10 +259,8 @@ export function ConfigTable() {
<Tooltip
title={
<>
<b>Neuanordnung der Kennzahlen</b>
<br />
Hier können Sie die Kennzahlen nach Belieben per Drag
and Drop neu anordnen.
<b>Neuanordnung der Kennzahlen</b><br />
Hier können Sie die Kennzahlen nach Belieben per Drag and Drop neu anordnen.
</>
}
placement="left"
@ -295,9 +270,7 @@ export function ConfigTable() {
sx={{
color: isUpdatingPositions ? "#ccc" : "#999",
cursor: isUpdatingPositions ? "default" : "grab",
"&:active": {
cursor: isUpdatingPositions ? "default" : "grabbing",
},
"&:active": { cursor: isUpdatingPositions ? "default" : "grabbing" }
}}
/>
</Tooltip>
@ -313,34 +286,30 @@ export function ConfigTable() {
width: "18px",
height: "18px",
cursor: isUpdatingPositions ? "default" : "pointer",
accentColor: "#383838",
accentColor: "#383838"
}}
onClick={(e) => e.stopPropagation()}
/>
</td>
<td
style={{
<td style={{
padding: "12px",
fontSize: "14px",
color: "#333",
}}
>
color: "#333"
}}>
<span title={`Click to view details (ID: ${kennzahl.id})`}>
{kennzahl.name}
</span>
</td>
<td style={{ padding: "12px" }}>
<span
style={{
<span style={{
color: "#333",
padding: "4px 12px",
borderRadius: "16px",
fontSize: "12px",
fontWeight: "500",
border: "1px solid #ddd",
backgroundColor: "#f8f9fa",
}}
>
backgroundColor: "#f8f9fa"
}}>
{getDisplayType(kennzahl.type)}
</span>
</td>

View File

@ -1,4 +1,3 @@
import type { Kennzahl } from "@/types/kpi";
import EditIcon from "@mui/icons-material/Edit";
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
import SearchIcon from "@mui/icons-material/Search";
@ -21,10 +20,19 @@ import { useState } from "react";
import type { KeyboardEvent } from "react";
import { fetchPutKPI } from "../util/api";
const SETTINGS = [
{ name: "Rendite", position: 1, active: true, mandatory: true },
{ name: "Ausschüttungsrendite", position: 2, active: true, mandatory: true },
{ name: "Laufzeit", position: 3, active: true, mandatory: true },
{ name: "Länderallokation", position: 4, active: true, mandatory: true },
{ name: "Managmentgebühren", position: 5, active: true, mandatory: true },
{ name: "Risikoprofil", position: 6, active: false, mandatory: true },
{ name: "Irgendwas", position: 7, active: true, mandatory: true },
];
interface KennzahlenTableProps {
onPageClick?: (page: number) => void;
pdfId: string;
settings: Kennzahl[];
data: {
[key: string]: {
label: string;
@ -40,7 +48,6 @@ export default function KennzahlenTable({
onPageClick,
data,
pdfId,
settings,
}: KennzahlenTableProps) {
const [editingIndex, setEditingIndex] = useState<string>("");
const [editValue, setEditValue] = useState("");
@ -141,8 +148,7 @@ export default function KennzahlenTable({
</TableHead>
<TableBody>
{settings
.filter((setting) => setting.active)
{SETTINGS.filter((setting) => setting.active)
.sort((a, b) => a.position - b.position)
.map((setting) => ({
setting: setting,
@ -151,8 +157,7 @@ export default function KennzahlenTable({
.map((row) => {
let borderColor = "transparent";
const hasMultipleValues = row.extractedValues.length > 1;
const hasNoValue =
row.setting.mandatory &&
const hasNoValue = row.setting.mandatory &&
(row.extractedValues.length === 0 ||
row.extractedValues.at(0)?.entity === "");
@ -183,8 +188,7 @@ export default function KennzahlenTable({
<Tooltip
title={
<>
<b>Problem</b>
<br />
<b>Problem</b><br />
Mehrere Werte für die Kennzahl gefunden.
</>
}
@ -201,9 +205,9 @@ export default function KennzahlenTable({
justifyContent: "space-between",
width: "100%",
cursor: "pointer",
"&:hover": {
backgroundColor: "#f5f5f5",
},
'&:hover': {
backgroundColor: '#f5f5f5'
}
}}
>
<Box

View File

@ -5,15 +5,12 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { useState } from "react";
import KennzahlenTable from "../components/KennzahlenTable";
import PDFViewer from "../components/pdfViewer";
import { kpiQueryOptions, settingsQueryOptions } from "../util/query";
import { kpiQueryOptions } from "../util/query";
export const Route = createFileRoute("/extractedResult/$pitchBook")({
component: ExtractedResultsPage,
loader: ({ context: { queryClient }, params: { pitchBook } }) =>
Promise.allSettled([
queryClient.ensureQueryData(kpiQueryOptions(pitchBook)),
queryClient.ensureQueryData(settingsQueryOptions()),
]),
});
function ExtractedResultsPage() {
@ -29,7 +26,6 @@ function ExtractedResultsPage() {
}[status];
const { data: kpi } = useSuspenseQuery(kpiQueryOptions(pitchBook));
const { data: settings } = useSuspenseQuery(settingsQueryOptions());
return (
<Box p={4}>
@ -71,7 +67,6 @@ function ExtractedResultsPage() {
}}
>
<KennzahlenTable
settings={settings}
onPageClick={setCurrentPage}
data={kpi}
pdfId={pitchBook}
@ -84,7 +79,7 @@ function ExtractedResultsPage() {
gap={3}
sx={{
width: "55%",
maxHeight: "95%",
maxHeight: "95%"
}}
>
<Paper
@ -98,7 +93,7 @@ function ExtractedResultsPage() {
display: "flex",
flexDirection: "column",
overflow: "auto",
padding: 2,
padding: 2
}}
>
<PDFViewer
@ -107,13 +102,7 @@ function ExtractedResultsPage() {
onPageChange={setCurrentPage}
/>
</Paper>
<Box
mt={2}
display="flex"
justifyContent="flex-end"
gap={2}
sx={{ flexShrink: 0 }}
>
<Box mt={2} display="flex" justifyContent="flex-end" gap={2} sx={{ flexShrink: 0 }}>
<Button variant="contained" sx={{ backgroundColor: "#383838" }}>
<ContentPasteIcon sx={{ fontSize: 18, mr: 1 }} />
Kennzahlenzeile kopieren

View File

@ -1,5 +1,3 @@
import type { Kennzahl } from "@/types/kpi";
export const fetchKPI = async (
pitchBookId: string,
): Promise<{
@ -16,7 +14,7 @@ export const fetchKPI = async (
);
const data = await response.json();
return data.kpi ? getKPI(data.kpi) : {};
return getKPI(data.kpi);
};
export const fetchPutKPI = async (
@ -97,13 +95,3 @@ export const flattenKPIArray = (kpi: {
}) => {
return Object.values(kpi).flat();
};
export const fetchKennzahlen = async (): Promise<Kennzahl[]> => {
const response = await fetch("http://localhost:5050/api/kpi_setting/");
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
};

View File

@ -1,14 +1,8 @@
import { queryOptions } from "@tanstack/react-query";
import { fetchKPI, fetchKennzahlen } from "./api";
import { fetchKPI } from "./api";
export const kpiQueryOptions = (pitchBookId: string) =>
queryOptions({
queryKey: ["pitchBookKPI", pitchBookId],
queryFn: () => fetchKPI(pitchBookId),
});
export const settingsQueryOptions = () =>
queryOptions({
queryKey: ["pitchBookSettings"],
queryFn: () => fetchKennzahlen(),
});