From 33b159af5cd8aff29b96c3e3f2ee031f14b3328d Mon Sep 17 00:00:00 2001 From: sutigit Date: Mon, 3 Feb 2025 11:19:11 +0200 Subject: [PATCH] refactor table component --- .../components/V1/Generic/TableComponent.tsx | 67 +++++++++++++++++++ .../components/V1/Overview/DataComponent.tsx | 47 ++----------- 2 files changed, 73 insertions(+), 41 deletions(-) create mode 100644 client/components/V1/Generic/TableComponent.tsx diff --git a/client/components/V1/Generic/TableComponent.tsx b/client/components/V1/Generic/TableComponent.tsx new file mode 100644 index 00000000..c7200e86 --- /dev/null +++ b/client/components/V1/Generic/TableComponent.tsx @@ -0,0 +1,67 @@ +import React from 'react' + +/* +This component is a table for displaying data designed for this project. + +Example usage: + <> + + + Header 1 + Header 2 + Header 3 + + + + Item 1 + Item 2 + Item 3 + +
+ +*/ + +export const Table = ({ children }: { children: React.ReactNode }) => { + return ( +
{children}
+ ) +} + + +export const TableRow = ({ children, isHeader = false }: { children: React.ReactNode, isHeader?: boolean }) => { + return ( +
+ {React.Children.map(children, (child, index) => ( +
+ {child} +
+ ))} +
+ ) +} + + +export const TableCell = ({ children, isKey = false }: { children?: React.ReactNode, isKey?: boolean }) => { + return ( +
{children}
+ ) +} \ No newline at end of file diff --git a/client/components/V1/Overview/DataComponent.tsx b/client/components/V1/Overview/DataComponent.tsx index 790e264e..a4303c6f 100644 --- a/client/components/V1/Overview/DataComponent.tsx +++ b/client/components/V1/Overview/DataComponent.tsx @@ -4,47 +4,12 @@ import useFetchKeyData from '../../../hooks/useFetchKeyData' import { Link } from 'react-router-dom' import { ProgrammeLevel } from '../enums' import { TrafficLight } from '../Generic/TrafficLightComponent' -import React, { useMemo } from 'react' +import { useMemo } from 'react' -const TableCell = ({ children, isKey = false }: { children?: React.ReactNode, isKey?: boolean }) => { - return ( -
{children}
- ) -} - -const TableRow = ({ children, isHeader = false }: { children: React.ReactNode, isHeader?: boolean }) => { - return ( -
- {React.Children.map(children, (child, index) => ( -
- {child} -
- ))} -
- ) -} +import { Table, TableRow, TableCell } from '../Generic/TableComponent' -const Table = ({ children }: { children: React.ReactNode }) => { - return ( -
{children}
- ) -} -const DataComponent = ({ programLevel, faculty, year}: {programLevel: string | null, faculty: string | null, year: number | null}) => { +const DataComponent = ({ programLevel, faculty, year }: { programLevel: string | null, faculty: string | null, year: number | null }) => { const fetchedKeyData = useFetchKeyData() const keyData = useMemo(() => fetchedKeyData, [fetchedKeyData]) @@ -70,7 +35,7 @@ const DataComponent = ({ programLevel, faculty, year}: {programLevel: string | n <> - Programme + Attractiveness Throughput and Graduation Student Feedback and Employment @@ -80,8 +45,8 @@ const DataComponent = ({ programLevel, faculty, year}: {programLevel: string | n {programmeData.map((programmeData: KeyDataProgramme) => ( - - + + {programmeData.koulutusohjelma}