From da7d2498dd3dcd54d527ff3c0103da0060d68bb3 Mon Sep 17 00:00:00 2001 From: Alireza Safaierad Date: Thu, 10 Aug 2023 01:45:38 +0400 Subject: [PATCH] refactor table --- app/components/MemberForm/MemberForm.tsx | 4 +- .../HouseholdList/HouseholdList.tsx | 8 +-- .../HouseholdList/HouseholdTableColumn.tsx | 61 +++++++++++-------- .../ProjectList/ProjectTableColumn.tsx | 6 +- libs/icons/index.ts | 4 +- 5 files changed, 44 insertions(+), 39 deletions(-) diff --git a/app/components/MemberForm/MemberForm.tsx b/app/components/MemberForm/MemberForm.tsx index 0672a3e6..263edaf3 100644 --- a/app/components/MemberForm/MemberForm.tsx +++ b/app/components/MemberForm/MemberForm.tsx @@ -20,7 +20,7 @@ import { nationalities, religions, } from '@camp/domain'; -import { ArrowDownIcon, CheckIcon, EditIcon, TrashIcon } from '@camp/icons'; +import { CheckIcon, ChevronDownIcon, EditIcon, TrashIcon } from '@camp/icons'; import { messages } from '@camp/messages'; import { createTestAttr } from '@camp/test'; import { @@ -146,7 +146,7 @@ export const MemberForm = ({ - + } right={ diff --git a/app/pages/Dashboard/Households/HouseholdList/HouseholdList.tsx b/app/pages/Dashboard/Households/HouseholdList/HouseholdList.tsx index a8545ac1..4e331094 100644 --- a/app/pages/Dashboard/Households/HouseholdList/HouseholdList.tsx +++ b/app/pages/Dashboard/Households/HouseholdList/HouseholdList.tsx @@ -101,10 +101,6 @@ export const HouseholdList = () => { if (isNull(households)) return null; if (isEmpty(households)) return ; - const householdRow = ; - - const householdColumn = ; - return ( } @@ -112,8 +108,8 @@ export const HouseholdList = () => { > } + rows={} /> ); diff --git a/app/pages/Dashboard/Households/HouseholdList/HouseholdTableColumn.tsx b/app/pages/Dashboard/Households/HouseholdList/HouseholdTableColumn.tsx index ed563f7d..3dbb1cca 100644 --- a/app/pages/Dashboard/Households/HouseholdList/HouseholdTableColumn.tsx +++ b/app/pages/Dashboard/Households/HouseholdList/HouseholdTableColumn.tsx @@ -1,42 +1,49 @@ import type { HouseholdKeys, HouseholdListItem } from '@camp/domain'; +import type { Icon } from '@camp/icons'; +import { ArrowDownIcon, ArrowUpIcon } from '@camp/icons'; import { Text } from '@mantine/core'; import type { Table } from '@tanstack/react-table'; import { flexRender } from '@tanstack/react-table'; -import { ArrowDown, ArrowUp } from 'react-feather'; interface Props { col: Table; } +const iconMap: Record = { + asc: ArrowUpIcon, + desc: ArrowDownIcon, +} as const; + export const HouseholdTableColumn = ({ col }: Props) => { return col.getHeaderGroups().map(headerGroup => ( - {headerGroup.headers.map(header => ( - - ))} + {headerGroup.headers.map(header => { + const Icon = iconMap[header.column.getIsSorted() as string]; + const canSort = header.column.getCanSort(); + + return ( + + ); + })} )); }; diff --git a/app/pages/Dashboard/Projects/ProjectList/ProjectTableColumn.tsx b/app/pages/Dashboard/Projects/ProjectList/ProjectTableColumn.tsx index eb5465f1..58e45250 100644 --- a/app/pages/Dashboard/Projects/ProjectList/ProjectTableColumn.tsx +++ b/app/pages/Dashboard/Projects/ProjectList/ProjectTableColumn.tsx @@ -1,8 +1,8 @@ import type { ProjectKeys, ProjectListItem } from '@camp/domain'; +import { ArrowDownIcon, ArrowUpIcon } from '@camp/icons'; import { Title } from '@mantine/core'; import type { Table } from '@tanstack/react-table'; import { flexRender } from '@tanstack/react-table'; -import { ArrowDown, ArrowUp } from 'react-feather'; interface Props { col: Table; @@ -17,8 +17,8 @@ export const ProjectTableColumn = ({ col }: Props) => { {flexRender(header.column.columnDef.header, header.getContext())} {{ - asc: <ArrowUp />, - desc: <ArrowDown />, + asc: <ArrowUpIcon />, + desc: <ArrowDownIcon />, }[header.column.getIsSorted() as string] ?? null} )} diff --git a/libs/icons/index.ts b/libs/icons/index.ts index cf69e991..ef51714b 100644 --- a/libs/icons/index.ts +++ b/libs/icons/index.ts @@ -1,8 +1,10 @@ +export type { Icon } from 'react-feather'; export { - ChevronDown as ArrowDownIcon, + ArrowDown as ArrowDownIcon, ArrowUp as ArrowUpIcon, Calendar as CalendarIcon, Check as CheckIcon, + ChevronDown as ChevronDownIcon, ChevronLeft as ChevronLeftIcon, Home as DashboardIcon, Edit as EditIcon,
- {header.isPlaceholder ? null : ( - - {flexRender(header.column.columnDef.header, header.getContext())} - {{ - asc: , - desc: , - }[header.column.getIsSorted() as string] ?? null} - - )} - + {header.isPlaceholder ? null : ( + + {flexRender( + header.column.columnDef.header, + header.getContext(), + )} + {Icon ? : null} + + )} +