From c31b5c5b1478938d97aae7f61ccea71ff2bb9c3d Mon Sep 17 00:00:00 2001 From: Tobias Hopp Date: Wed, 16 Apr 2025 15:39:13 +0200 Subject: [PATCH] Refactor relationship types to single class and add more Took 38 minutes --- frontend/src/components/FriendshipNetwork.tsx | 28 ++++++++++--------- frontend/src/hooks/useFriendshipNetwork.ts | 4 +-- frontend/src/types/RelationShipTypes.ts | 26 +++++++++-------- src/controllers/auth.controller.ts | 10 +++---- src/models/relationship.model.ts | 9 ++++-- src/routes/relationship.routes.ts | 12 +++----- 6 files changed, 48 insertions(+), 41 deletions(-) diff --git a/frontend/src/components/FriendshipNetwork.tsx b/frontend/src/components/FriendshipNetwork.tsx index 5bce85c..2dcc967 100644 --- a/frontend/src/components/FriendshipNetwork.tsx +++ b/frontend/src/components/FriendshipNetwork.tsx @@ -47,7 +47,7 @@ import { // Import visible canvas graph component import CanvasGraph from './CanvasGraph'; -import { RELATIONSHIP_COLORS, RELATIONSHIP_LABELS, RELATIONSHIP_TYPES } from '../types/RelationShipTypes'; +import { getRelationshipColor, RELATIONSHIP_TYPES, RELATIONSHIPS } from '../types/RelationShipTypes'; import { FormErrors, PersonNode } from '../interfaces/IPersonNode'; @@ -112,7 +112,7 @@ const FriendshipNetwork: React.FC = () => { const [editPerson, setEditPerson] = useState(null); const [newRelationship, setNewRelationship] = useState({ - source: '', target: '', type: 'freund' as RELATIONSHIP_TYPES, customType: '', notes: '', bidirectional: true, + source: '', target: '', type: 'friend' as RELATIONSHIP_TYPES, customType: '', notes: '', bidirectional: true, }); // Filter states @@ -375,7 +375,7 @@ const FriendshipNetwork: React.FC = () => { // Create edges const graphEdges = relationships.map(rel => { - const color = RELATIONSHIP_COLORS[rel.type] || RELATIONSHIP_COLORS.custom; + const color = RELATIONSHIPS[rel.type as RELATIONSHIP_TYPES]?.color || RELATIONSHIPS.custom.color; const width = rel.type === 'partner' ? 4 : rel.type === 'familie' ? 3 : 2; // Highlight edges connected to selected node @@ -515,7 +515,7 @@ const FriendshipNetwork: React.FC = () => { // Reset form and close modal setNewRelationship({ - source: '', target: '', type: 'freund', customType: '', notes: '', bidirectional: true, + source: '', target: '', type: 'friend', customType: '', notes: '', bidirectional: true, }); setRelationshipModalOpen(false); @@ -751,14 +751,14 @@ const FriendshipNetwork: React.FC = () => {

Legend

- {Object.entries(RELATIONSHIP_COLORS).map(([type, color]) => ( + {Object.entries(RELATIONSHIPS).map(([type, { label, color }]) => (
- {RELATIONSHIP_LABELS[type as RELATIONSHIP_TYPES]} + {RELATIONSHIPS[type]?.label}
))}
@@ -892,7 +892,7 @@ const FriendshipNetwork: React.FC = () => { > All Types - {Object.entries(RELATIONSHIP_COLORS).map(([type, color]) => ())} @@ -947,10 +947,10 @@ const FriendshipNetwork: React.FC = () => {
- {rel.type === 'custom' ? rel.customType : RELATIONSHIP_LABELS[rel.type]} + {rel.type === 'custom' ? rel.customType : RELATIONSHIPS[rel.type as RELATIONSHIP_TYPES]?.label}
@@ -1253,7 +1253,7 @@ const FriendshipNetwork: React.FC = () => { ...newRelationship, type: e.target.value as RELATIONSHIP_TYPES, })} > - {Object.entries(RELATIONSHIP_LABELS).map(([value, label]) => ())} @@ -1449,7 +1449,7 @@ const FriendshipNetwork: React.FC = () => {
{isSource ? 'To: ' : 'From: '} @@ -1466,7 +1466,9 @@ const FriendshipNetwork: React.FC = () => { > {otherPerson.firstName} {otherPerson.lastName} - {rel.type === 'custom' ? ` (${rel.customType})` : ` (${RELATIONSHIP_LABELS[rel.type]})`} + {rel.type === 'custom' + ? ` (${rel.customType})` + : ` (${RELATIONSHIPS[rel.type as RELATIONSHIP_TYPES]?.label})`}