From ec49fd01e72346f624a80109103d1d7857431d4d Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 17 Nov 2024 19:22:30 +0100 Subject: [PATCH] Remove component that renders groups in a tree structure --- app/dashboard/guests/page.tsx | 3 -- app/ui/guests/affinity-groups-tree.tsx | 65 -------------------------- 2 files changed, 68 deletions(-) delete mode 100644 app/ui/guests/affinity-groups-tree.tsx diff --git a/app/dashboard/guests/page.tsx b/app/dashboard/guests/page.tsx index fe46b0e..6337d0b 100644 --- a/app/dashboard/guests/page.tsx +++ b/app/dashboard/guests/page.tsx @@ -5,7 +5,6 @@ import { Group, Guest } from '@/app/lib/definitions'; import CreationDialog from '@/app/ui/components/creation-dialog'; import GroupsTable from '@/app/ui/groups/table'; -import AffinityGroupsTree from '@/app/ui/guests/affinity-groups-tree'; import SkeletonTable from '@/app/ui/guests/skeleton-row'; import GuestsTable from '@/app/ui/guests/table'; import { TabPanel, TabView } from 'primereact/tabview'; @@ -39,8 +38,6 @@ export default function Page() { return (
- -
diff --git a/app/ui/guests/affinity-groups-tree.tsx b/app/ui/guests/affinity-groups-tree.tsx deleted file mode 100644 index 0082070..0000000 --- a/app/ui/guests/affinity-groups-tree.tsx +++ /dev/null @@ -1,65 +0,0 @@ -/* Copyright (C) 2024 Manuel Bustillo*/ - -'use client' - -import React, { useState, useEffect, Suspense } from 'react'; -import { Tree } from 'primereact/tree'; -import { PrimeIcons } from 'primereact/api'; -import { debug } from 'console'; -import { Group } from '@/app/lib/definitions'; - -export default function AffinityGroupsTree() { - const [nodes, setNodes] = useState([]); - - const groupToNode = (group: Group): any => { - return({ - key: group.id, - label: `${group.name} (${group.guest_count})`, - icon: group.icon, - children: group.children.map((child) => groupToNode(child)), - className: "px-4", - }) - } - - const parseNode = (record: any, included: any[]): Group => { - if (!record.attributes) { - record = included.find((a) => a.id === record.id); - } - - const children: Group[] = (record?.relationships?.children?.data || []).map((child: any) => { - return (parseNode(child, included)); - }); - - const children_guest_count: number = children.reduce((acc: number, child: Group) => acc + child.guest_count, 0); - - return ({ - id: record.id, - name: record.attributes.name, - guest_count: record.attributes.guest_count + children_guest_count, - icon: record.attributes.icon, - children: children, - }) - } - - - useEffect(() => { - if (nodes.length > 0) { - return; - } - fetch("/api/groups.json") - .then((response) => response.json()) - .then((data) => { - setNodes(data.data.map((record: any) => { - return (groupToNode(parseNode(record, data.included))); - })) - }); - }); - - return ( -
- - setNodes(e.value as any)} className="w-full md:w-30rem" /> - -
- ) -} \ No newline at end of file