From 51615145f6ccfaee75e6551086fced43fa647ef8 Mon Sep 17 00:00:00 2001 From: s8613 Date: Wed, 4 Jun 2025 21:07:43 +0200 Subject: [PATCH] Added table to config.tsx --- project/frontend/src/routes/config.tsx | 206 +++++++++++++++++++++++-- 1 file changed, 193 insertions(+), 13 deletions(-) diff --git a/project/frontend/src/routes/config.tsx b/project/frontend/src/routes/config.tsx index 5ddecdb..6ba17e6 100644 --- a/project/frontend/src/routes/config.tsx +++ b/project/frontend/src/routes/config.tsx @@ -1,24 +1,91 @@ import { createFileRoute } from "@tanstack/react-router"; -import { Box, Button, IconButton, Paper, Typography } from "@mui/material"; +import { Box, Button, IconButton, Typography } from "@mui/material"; import ArrowBackIcon from "@mui/icons-material/ArrowBack"; +import DragIndicatorIcon from "@mui/icons-material/DragIndicator"; import { useNavigate } from "@tanstack/react-router"; +import { useState } from "react"; export const Route = createFileRoute("/config")({ component: ConfigPage, }); +interface Kennzahl { + id: number; + name: string; + format: string; + active: boolean; +} + +const mockKennzahlen: Kennzahl[] = [ + { id: 1, name: "Fondsname", format: "Text", active: true }, + { id: 2, name: "Fondsmanager", format: "Text", active: true }, + { id: 3, name: "AIFM", format: "Text", active: false }, + { id: 4, name: "Datum", format: "Datum", active: true }, + { id: 5, name: "Risikoprofil", format: "Text", active: true }, + { id: 6, name: "Artikel", format: "Ja/Nein", active: true }, + { id: 7, name: "Zielrendite", format: "Zahl", active: true }, + { id: 8, name: "Rendite", format: "Zahl", active: true }, + { id: 9, name: "Zielausschüttung", format: "Zahl", active: true }, + { id: 10, name: "Ausschüttung", format: "Zahl", active: true }, + { id: 11, name: "Laufzeit", format: "Text", active: true }, + { id: 12, name: "LTV", format: "Zahl", active: true }, + { id: 13, name: "Managementgebühren", format: "Zahl", active: true }, + { id: 14, name: "Sektorenallokation", format: "Liste (mehrfach)", active: true }, + { id: 15, name: "Länderallokation", format: "Liste (mehrfach)", active: true }, +]; + function ConfigPage() { const navigate = useNavigate(); + const [kennzahlen, setKennzahlen] = useState(mockKennzahlen); + const [draggedItem, setDraggedItem] = useState(null); + + const handleToggleActive = (id: number) => { + setKennzahlen(prev => + prev.map(item => + item.id === id ? { ...item, active: !item.active } : item + ) + ); + }; + + const handleDragStart = (e: React.DragEvent, item: Kennzahl) => { + setDraggedItem(item); + e.dataTransfer.effectAllowed = "move"; + }; + + const handleDragOver = (e: React.DragEvent) => { + e.preventDefault(); + e.dataTransfer.dropEffect = "move"; + }; + + const handleDrop = (e: React.DragEvent, 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 newKennzahlen = [...kennzahlen]; + const [removed] = newKennzahlen.splice(draggedIndex, 1); + newKennzahlen.splice(targetIndex, 0, removed); + + setKennzahlen(newKennzahlen); + setDraggedItem(null); + }; + + const handleDragEnd = () => { + setDraggedItem(null); + }; return ( - - To-do: Table hierhin - + + + + + + + + + + + {kennzahlen.map((kennzahl) => ( + handleDragStart(e, kennzahl)} + onDragOver={handleDragOver} + onDrop={(e) => handleDrop(e, kennzahl)} + onDragEnd={handleDragEnd} + style={{ + borderBottom: "1px solid #e0e0e0", + cursor: "move", + backgroundColor: draggedItem?.id === kennzahl.id ? "#f0f0f0" : "white", + opacity: draggedItem?.id === kennzahl.id ? 0.5 : 1 + }} + onMouseEnter={(e) => { + if (!draggedItem) { + e.currentTarget.style.backgroundColor = "#f9f9f9"; + } + }} + onMouseLeave={(e) => { + if (!draggedItem) { + e.currentTarget.style.backgroundColor = "white"; + } + }} + > + + + + + + ))} + +
+ + + Aktiv + + Name + + Format +
+ + + handleToggleActive(kennzahl.id)} + style={{ + width: "18px", + height: "18px", + cursor: "pointer", + accentColor: "#383838" + }} + onClick={(e) => e.stopPropagation()} + /> + + {kennzahl.name} + + + {kennzahl.format} + +
+
); } \ No newline at end of file