diff --git a/project/frontend/src/components/ConfigTable.tsx b/project/frontend/src/components/ConfigTable.tsx index 3b7b6d4..f835021 100644 --- a/project/frontend/src/components/ConfigTable.tsx +++ b/project/frontend/src/components/ConfigTable.tsx @@ -7,7 +7,11 @@ import { getDisplayType } from "../types/kpi"; import { fetchKennzahlen as fetchK } from "../util/api"; import { API_HOST } from "../util/api"; -export function ConfigTable() { +type ConfigTableProps = { + from?: string; +}; + +export function ConfigTable({ from }: ConfigTableProps) { const navigate = useNavigate(); const [kennzahlen, setKennzahlen] = useState([]); const [draggedItem, setDraggedItem] = useState(null); @@ -161,12 +165,10 @@ export function ConfigTable() { return; } - 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() }, + search: from ? { from } : undefined, }); }; diff --git a/project/frontend/src/components/KennzahlenTable.tsx b/project/frontend/src/components/KennzahlenTable.tsx index db0a891..b6a19bb 100644 --- a/project/frontend/src/components/KennzahlenTable.tsx +++ b/project/frontend/src/components/KennzahlenTable.tsx @@ -34,6 +34,7 @@ interface KennzahlenTableProps { source: string; }[]; }; + from?: string; } export default function KennzahlenTable({ @@ -41,10 +42,11 @@ export default function KennzahlenTable({ data, pdfId, settings, + from }: KennzahlenTableProps) { const [editingIndex, setEditingIndex] = useState(""); const [editValue, setEditValue] = useState(""); - const navigate = useNavigate({ from: "/extractedResult/$pitchBook" }); + const navigate = useNavigate(); const queryClient = useQueryClient(); @@ -120,6 +122,7 @@ export default function KennzahlenTable({ pitchBook: pdfId, kpi: settingName, }, + search: { from: from ?? undefined }, }); }; @@ -297,18 +300,22 @@ export default function KennzahlenTable({ )} - - onPageClick?.( - Number(row.extractedValues.at(0)?.page), - row.extractedValues.at(0)?.entity || "", - ) - } - sx={{ cursor: "pointer" }} - > - {row.extractedValues.at(0)?.page} - + {(row.extractedValues.at(0)?.page ?? 0) > 0 ? ( + { + const extractedValue = row.extractedValues.at(0); + if (extractedValue?.page && extractedValue.page > 0) { + onPageClick?.(Number(extractedValue.page), extractedValue.entity || ""); + } + }} + sx={{ cursor: "pointer" }} + > + {row.extractedValues.at(0)?.page} + + ) : ( + "" + )} ); diff --git a/project/frontend/src/components/PitchBooksTable.tsx b/project/frontend/src/components/PitchBooksTable.tsx new file mode 100644 index 0000000..7a86ada --- /dev/null +++ b/project/frontend/src/components/PitchBooksTable.tsx @@ -0,0 +1,186 @@ +import { Box, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography, CircularProgress, Chip } from "@mui/material"; +import { useSuspenseQuery } from "@tanstack/react-query"; +import { useNavigate } from "@tanstack/react-router"; +import { pitchBooksQueryOptions } from "../util/query"; +import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf'; +import CheckCircleIcon from '@mui/icons-material/CheckCircle'; +import HourglassEmptyIcon from '@mui/icons-material/HourglassEmpty'; + +interface PitchBook { + id: number; + filename: string; + created_at: string; + kpi?: string | { + [key: string]: { + label: string; + entity: string; + page: number; + status: string; + source: string; + }[]; + }; + status?: 'processing' | 'completed'; +} + +export function PitchBooksTable() { + const navigate = useNavigate(); + const { data: pitchBooks, isLoading } = useSuspenseQuery(pitchBooksQueryOptions()); + + const handleRowClick = (pitchBookId: number) => { + navigate({ + to: "/extractedResult/$pitchBook", + params: { pitchBook: pitchBookId.toString() }, + search: { from: "overview" } + }); + }; + + const getKPIValue = (pitchBook: PitchBook, fieldName: string): string => { + if (!pitchBook.kpi || typeof pitchBook.kpi === 'string') { + try { + const parsedKPI = JSON.parse(pitchBook.kpi as string); + // Convert array to object format if needed + const kpiObj = Array.isArray(parsedKPI) ? + parsedKPI.reduce((acc: any, item: any) => { + if (!acc[item.label]) acc[item.label] = []; + acc[item.label].push(item); + return acc; + }, {}) : parsedKPI; + + return kpiObj[fieldName]?.[0]?.entity || 'N/A'; + } catch { + return 'N/A'; + } + } + + return (pitchBook.kpi as any)[fieldName]?.[0]?.entity || 'N/A'; + }; + + const getStatus = (pitchBook: PitchBook) => { + if (pitchBook.kpi && + ((typeof pitchBook.kpi === 'string' && pitchBook.kpi !== '{}') || + (typeof pitchBook.kpi === 'object' && Object.keys(pitchBook.kpi).length > 0))) { + return 'completed'; + } + return 'processing'; + }; + + if (isLoading) { + return ( + + + + ); + } + + return ( + + + + + + Fondsname + Fondsmanager + Dateiname + Status + + + + {pitchBooks.map((pitchBook: PitchBook) => { + const status = getStatus(pitchBook); + const fundName = getKPIValue(pitchBook, 'FONDSNAME') || + getKPIValue(pitchBook, 'FUND_NAME') || + getKPIValue(pitchBook, 'NAME'); + + const manager = getKPIValue(pitchBook, 'FONDSMANAGER') || + getKPIValue(pitchBook, 'MANAGER') || + getKPIValue(pitchBook, 'PORTFOLIO_MANAGER'); + + return ( + handleRowClick(pitchBook.id)} + sx={{ + cursor: "pointer", + "&:hover": { + backgroundColor: "#f9f9f9", + }, + }} + > + + + + + + + + {fundName} + + + {manager} + + + {pitchBook.filename} + + + + {status === 'completed' ? ( + } + label="Abgeschlossen" + size="small" + sx={{ + backgroundColor: "#e8f5e9", + color: "#2e7d32", + "& .MuiChip-icon": { + color: "#2e7d32", + }, + }} + /> + ) : ( + } + label="In Bearbeitung" + size="small" + sx={{ + backgroundColor: "#fff3e0", + color: "#e65100", + "& .MuiChip-icon": { + color: "#e65100", + }, + }} + /> + )} + + + ); + })} + +
+ {pitchBooks.length === 0 && ( + + + Keine Pitch Books vorhanden + + + )} +
+ ); +} \ No newline at end of file diff --git a/project/frontend/src/components/UploadPage.tsx b/project/frontend/src/components/UploadPage.tsx index 20d6f7b..95b4f09 100644 --- a/project/frontend/src/components/UploadPage.tsx +++ b/project/frontend/src/components/UploadPage.tsx @@ -179,6 +179,19 @@ export default function UploadPage() { > Kennzahlen extrahieren + ); diff --git a/project/frontend/src/routeTree.gen.ts b/project/frontend/src/routeTree.gen.ts index 489b1cf..5377387 100644 --- a/project/frontend/src/routeTree.gen.ts +++ b/project/frontend/src/routeTree.gen.ts @@ -11,6 +11,7 @@ // Import Routes import { Route as rootRoute } from './routes/__root' +import { Route as PitchbooksImport } from './routes/pitchbooks' import { Route as ConfigAddImport } from './routes/config-add' import { Route as ConfigImport } from './routes/config' import { Route as IndexImport } from './routes/index' @@ -20,6 +21,12 @@ import { Route as ExtractedResultPitchBookKpiImport } from './routes/extractedRe // Create/Update Routes +const PitchbooksRoute = PitchbooksImport.update({ + id: '/pitchbooks', + path: '/pitchbooks', + getParentRoute: () => rootRoute, +} as any) + const ConfigAddRoute = ConfigAddImport.update({ id: '/config-add', path: '/config-add', @@ -82,6 +89,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ConfigAddImport parentRoute: typeof rootRoute } + '/pitchbooks': { + id: '/pitchbooks' + path: '/pitchbooks' + fullPath: '/pitchbooks' + preLoaderRoute: typeof PitchbooksImport + parentRoute: typeof rootRoute + } '/config-detail/$kpiId': { id: '/config-detail/$kpiId' path: '/config-detail/$kpiId' @@ -112,6 +126,7 @@ export interface FileRoutesByFullPath { '/': typeof IndexRoute '/config': typeof ConfigRoute '/config-add': typeof ConfigAddRoute + '/pitchbooks': typeof PitchbooksRoute '/config-detail/$kpiId': typeof ConfigDetailKpiIdRoute '/extractedResult/$pitchBook': typeof ExtractedResultPitchBookRoute '/extractedResult/$pitchBook/$kpi': typeof ExtractedResultPitchBookKpiRoute @@ -121,6 +136,7 @@ export interface FileRoutesByTo { '/': typeof IndexRoute '/config': typeof ConfigRoute '/config-add': typeof ConfigAddRoute + '/pitchbooks': typeof PitchbooksRoute '/config-detail/$kpiId': typeof ConfigDetailKpiIdRoute '/extractedResult/$pitchBook': typeof ExtractedResultPitchBookRoute '/extractedResult/$pitchBook/$kpi': typeof ExtractedResultPitchBookKpiRoute @@ -131,6 +147,7 @@ export interface FileRoutesById { '/': typeof IndexRoute '/config': typeof ConfigRoute '/config-add': typeof ConfigAddRoute + '/pitchbooks': typeof PitchbooksRoute '/config-detail/$kpiId': typeof ConfigDetailKpiIdRoute '/extractedResult/$pitchBook': typeof ExtractedResultPitchBookRoute '/extractedResult_/$pitchBook/$kpi': typeof ExtractedResultPitchBookKpiRoute @@ -142,6 +159,7 @@ export interface FileRouteTypes { | '/' | '/config' | '/config-add' + | '/pitchbooks' | '/config-detail/$kpiId' | '/extractedResult/$pitchBook' | '/extractedResult/$pitchBook/$kpi' @@ -150,6 +168,7 @@ export interface FileRouteTypes { | '/' | '/config' | '/config-add' + | '/pitchbooks' | '/config-detail/$kpiId' | '/extractedResult/$pitchBook' | '/extractedResult/$pitchBook/$kpi' @@ -158,6 +177,7 @@ export interface FileRouteTypes { | '/' | '/config' | '/config-add' + | '/pitchbooks' | '/config-detail/$kpiId' | '/extractedResult/$pitchBook' | '/extractedResult_/$pitchBook/$kpi' @@ -168,6 +188,7 @@ export interface RootRouteChildren { IndexRoute: typeof IndexRoute ConfigRoute: typeof ConfigRoute ConfigAddRoute: typeof ConfigAddRoute + PitchbooksRoute: typeof PitchbooksRoute ConfigDetailKpiIdRoute: typeof ConfigDetailKpiIdRoute ExtractedResultPitchBookRoute: typeof ExtractedResultPitchBookRoute ExtractedResultPitchBookKpiRoute: typeof ExtractedResultPitchBookKpiRoute @@ -177,6 +198,7 @@ const rootRouteChildren: RootRouteChildren = { IndexRoute: IndexRoute, ConfigRoute: ConfigRoute, ConfigAddRoute: ConfigAddRoute, + PitchbooksRoute: PitchbooksRoute, ConfigDetailKpiIdRoute: ConfigDetailKpiIdRoute, ExtractedResultPitchBookRoute: ExtractedResultPitchBookRoute, ExtractedResultPitchBookKpiRoute: ExtractedResultPitchBookKpiRoute, @@ -195,6 +217,7 @@ export const routeTree = rootRoute "/", "/config", "/config-add", + "/pitchbooks", "/config-detail/$kpiId", "/extractedResult/$pitchBook", "/extractedResult_/$pitchBook/$kpi" @@ -209,6 +232,9 @@ export const routeTree = rootRoute "/config-add": { "filePath": "config-add.tsx" }, + "/pitchbooks": { + "filePath": "pitchbooks.tsx" + }, "/config-detail/$kpiId": { "filePath": "config-detail.$kpiId.tsx" }, diff --git a/project/frontend/src/routes/config-add.tsx b/project/frontend/src/routes/config-add.tsx index 5d536bd..26bc90a 100644 --- a/project/frontend/src/routes/config-add.tsx +++ b/project/frontend/src/routes/config-add.tsx @@ -7,10 +7,23 @@ import { API_HOST } from "../util/api"; export const Route = createFileRoute("/config-add")({ component: ConfigAddPage, + validateSearch: (search: Record): { from?: string } => { + return { + from: search.from as string | undefined, + }; + }, }); function ConfigAddPage() { const navigate = useNavigate(); + const { from } = Route.useSearch(); + + const handleBack = () => { + navigate({ + to: "/config", + search: from ? { from } : undefined, + }); + }; const handleSave = async (formData: Partial) => { try { @@ -69,7 +82,7 @@ function ConfigAddPage() { mb={4} > - navigate({ to: "/config" })}> + diff --git a/project/frontend/src/routes/config-detail.$kpiId.tsx b/project/frontend/src/routes/config-detail.$kpiId.tsx index 92a647f..04ef98c 100644 --- a/project/frontend/src/routes/config-detail.$kpiId.tsx +++ b/project/frontend/src/routes/config-detail.$kpiId.tsx @@ -10,16 +10,29 @@ import { API_HOST } from "../util/api"; export const Route = createFileRoute("/config-detail/$kpiId")({ component: KPIDetailPage, + validateSearch: (search: Record): { from?: string } => { + return { + from: search.from as string | undefined, + }; + }, }); function KPIDetailPage() { const { kpiId } = Route.useParams(); const navigate = useNavigate(); + const { from } = Route.useSearch(); const [kennzahl, setKennzahl] = useState(null); const [isEditing, setIsEditing] = useState(false); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const handleBack = () => { + navigate({ + to: "/config", + search: from ? { from } : undefined + }); + }; + useEffect(() => { const fetchKennzahl = async () => { try { @@ -139,7 +152,7 @@ function KPIDetailPage() { mb={4} > - navigate({ to: "/config" })}> + @@ -250,7 +263,7 @@ function KPIDetailPage() { mb={4} > - navigate({ to: "/config" })}> + diff --git a/project/frontend/src/routes/config.tsx b/project/frontend/src/routes/config.tsx index eddf16e..ac64c3d 100644 --- a/project/frontend/src/routes/config.tsx +++ b/project/frontend/src/routes/config.tsx @@ -6,13 +6,29 @@ import { ConfigTable } from "../components/ConfigTable"; export const Route = createFileRoute("/config")({ component: ConfigPage, + validateSearch: (search: Record): { from?: string } => { + const from = typeof search.from === "string" ? search.from : undefined; + return { from }; + } }); function ConfigPage() { const navigate = useNavigate(); + const { from } = Route.useSearch(); const handleAddNewKPI = () => { - navigate({ to: "/config-add" }); + navigate({ + to: "/config-add", + search: from ? { from } : undefined + }); + }; + + const handleBack = () => { + if (from === "pitchbooks") { + navigate({ to: "/pitchbooks" }); + } else { + navigate({ to: "/" }); + } }; return ( @@ -34,7 +50,7 @@ function ConfigPage() { px={4} > - navigate({ to: "/" })}> + @@ -53,7 +69,7 @@ function ConfigPage() { - + ); diff --git a/project/frontend/src/routes/extractedResult.$pitchBook.tsx b/project/frontend/src/routes/extractedResult.$pitchBook.tsx index 63b3c96..d579338 100644 --- a/project/frontend/src/routes/extractedResult.$pitchBook.tsx +++ b/project/frontend/src/routes/extractedResult.$pitchBook.tsx @@ -1,24 +1,39 @@ import ContentPasteIcon from "@mui/icons-material/ContentPaste"; -import { Box, Button, Paper, Typography, Snackbar, Alert } from "@mui/material"; +import { Box, Button, Paper, Typography, Snackbar, Alert, IconButton } from "@mui/material"; +import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import { useSuspenseQuery } from "@tanstack/react-query"; import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { useCallback, useState, useMemo } from "react"; import KennzahlenTable from "../components/KennzahlenTable"; import PDFViewer from "../components/pdfViewer"; import { kpiQueryOptions, settingsQueryOptions } from "../util/query"; +import { redirect } from "@tanstack/react-router"; export const Route = createFileRoute("/extractedResult/$pitchBook")({ component: ExtractedResultsPage, - loader: ({ context: { queryClient }, params: { pitchBook } }) => - Promise.allSettled([ + validateSearch: (search: Record): { from?: string } => { + return { + from: search.from as string | undefined, + }; + }, + loader: async ({ context: { queryClient }, params: { pitchBook } }) => { + const results = await Promise.allSettled([ queryClient.ensureQueryData(kpiQueryOptions(pitchBook)), queryClient.ensureQueryData(settingsQueryOptions()), - ]), + ]); + if (results[0].status === "rejected") { + throw redirect({ + to: "/" + }); + } + return results; + } }); function ExtractedResultsPage() { const { pitchBook } = Route.useParams(); const navigate = useNavigate(); + const { from } = Route.useSearch(); const [currentPage, setCurrentPage] = useState(1); const [copied, setCopied] = useState(false); const [snackbarOpen, setSnackbarOpen] = useState(false); @@ -124,6 +139,14 @@ function ExtractedResultsPage() { return ( + {from === "overview" && ( + navigate({ to: "/pitchbooks" })} + sx={{ ml: -1 }} + > + + + )} - queryClient.ensureQueryData(kpiQueryOptions(pitchBook)), + validateSearch: (search: Record) => { + return { + from: typeof search.from === "string" ? search.from : undefined, + }; + }, + loader: async ({ context: { queryClient }, params: { pitchBook } }) => { + try { + return await queryClient.ensureQueryData(kpiQueryOptions(pitchBook)); + } catch (err) { + throw redirect({ + to: "/" + }); + } + }, }); function ExtractedResultsPage() { @@ -42,6 +55,7 @@ function ExtractedResultsPage() { const { pitchBook, kpi } = params; const navigate = useNavigate(); const queryClient = useQueryClient(); + const { from } = Route.useSearch(); const { data: kpiData } = useSuspenseQuery(kpiQueryOptions(pitchBook)); @@ -62,9 +76,21 @@ function ExtractedResultsPage() { const { mutate: updateKPI } = useMutation({ mutationFn: () => { const updatedData = { ...kpiData }; + let baseObject; + if (selectedIndex >= 0) { + baseObject = kpiValues[selectedIndex]; + } else { + baseObject = { + label: kpi.toUpperCase(), + entity: selectedValue, + page: 0, + status: "single-source", + source: "manual", + }; + } updatedData[kpi.toUpperCase()] = [ { - ...kpiValues[0], + ...baseObject, entity: selectedValue, }, ]; @@ -77,6 +103,7 @@ function ExtractedResultsPage() { navigate({ to: "/extractedResult/$pitchBook", params: { pitchBook }, + search: from ? { from } : undefined }); }, onError: (error) => { @@ -117,6 +144,7 @@ function ExtractedResultsPage() { navigate({ to: "/extractedResult/$pitchBook", params: { pitchBook }, + search: from ? { from } : undefined }); } }; @@ -126,6 +154,7 @@ function ExtractedResultsPage() { navigate({ to: "/extractedResult/$pitchBook", params: { pitchBook }, + search: from ? { from } : undefined }); }; @@ -385,4 +414,4 @@ function ExtractedResultsPage() { ); -} +} \ No newline at end of file diff --git a/project/frontend/src/routes/pitchbooks.tsx b/project/frontend/src/routes/pitchbooks.tsx new file mode 100644 index 0000000..e0d2da0 --- /dev/null +++ b/project/frontend/src/routes/pitchbooks.tsx @@ -0,0 +1,59 @@ +import { createFileRoute } from "@tanstack/react-router"; +import { Box, Typography, IconButton } from "@mui/material"; +import ArrowBackIcon from "@mui/icons-material/ArrowBack"; +import SettingsIcon from "@mui/icons-material/Settings"; +import { useNavigate } from "@tanstack/react-router"; +import { PitchBooksTable } from "../components/PitchBooksTable"; +import { pitchBooksQueryOptions } from "../util/query"; + +export const Route = createFileRoute("/pitchbooks")({ + component: PitchBooksPage, + loader: ({ context: { queryClient } }) => + queryClient.ensureQueryData(pitchBooksQueryOptions()), +}); + +function PitchBooksPage() { + const navigate = useNavigate(); + + return ( + + + + navigate({ to: "/" })}> + + + + Übersicht aller Pitch Books + + + navigate({ + to: "/config", + search: { from: "pitchbooks" } + })} + > + + + + + + + + ); +} \ No newline at end of file diff --git a/project/frontend/src/util/api.ts b/project/frontend/src/util/api.ts index 6ba0d6e..65d3b2e 100644 --- a/project/frontend/src/util/api.ts +++ b/project/frontend/src/util/api.ts @@ -111,3 +111,11 @@ export const fetchKennzahlen = async (): Promise => { const data = await response.json(); return data; }; + +export async function fetchPitchBooks() { + const response = await fetch(`${API_HOST}/api/pitch_book/`); + if (!response.ok) { + throw new Error("Failed to fetch pitch books"); + } + return response.json(); +} diff --git a/project/frontend/src/util/query.ts b/project/frontend/src/util/query.ts index 0821301..db07917 100644 --- a/project/frontend/src/util/query.ts +++ b/project/frontend/src/util/query.ts @@ -1,5 +1,5 @@ import { queryOptions } from "@tanstack/react-query"; -import { fetchKPI, fetchKennzahlen } from "./api"; +import { fetchKPI, fetchKennzahlen, fetchPitchBooks } from "./api"; export const kpiQueryOptions = (pitchBookId: string) => queryOptions({ @@ -12,3 +12,10 @@ export const settingsQueryOptions = () => queryKey: ["pitchBookSettings"], queryFn: () => fetchKennzahlen(), }); + +export const pitchBooksQueryOptions = () => + queryOptions({ + queryKey: ["pitchBooks"], + queryFn: fetchPitchBooks, + staleTime: 30000, + }); \ No newline at end of file