From 48bd56be826ad91665954cb2508b2f2b371f2202 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Wed, 1 Jun 2022 18:43:03 +0800 Subject: [PATCH] Update Table component to read rows as a map --- packages/web/components/elements/Table.tsx | 65 +++++++++++++++++----- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/packages/web/components/elements/Table.tsx b/packages/web/components/elements/Table.tsx index 38ba1587f..e19bf9595 100644 --- a/packages/web/components/elements/Table.tsx +++ b/packages/web/components/elements/Table.tsx @@ -3,7 +3,7 @@ import { styled } from '../tokens/stitches.config' import { StyledText } from './StyledText' import { InfoLink } from './InfoLink' import { Button } from './Button' -import { Plus, Trash } from 'phosphor-react' +import { PencilSimple, Plus, Trash } from 'phosphor-react' import { isDarkTheme } from '../../lib/themeUpdater' interface TableProps { @@ -11,8 +11,9 @@ interface TableProps { infoLink?: string onAdd?: () => void headers: string[] - rows: string[][] + rows: Map onDelete?: (id: string) => void + onEdit?: (id: string) => void } const HeaderWrapper = styled(Box, { @@ -164,7 +165,7 @@ export function Table(props: TableProps): JSX.Element { ))} - {props.rows.map((row, index) => ( + {Array.from(props.rows.keys()).map((key, index) => ( @@ -191,7 +191,7 @@ export function Table(props: TableProps): JSX.Element { }, }} > - {row.map((cell, index) => ( + {props.rows.get(key)?.map((cell, index) => ( ))} - {props.onDelete && ( - { - props.onDelete && props.onDelete(row[0]) + {props.onEdit && ( + + )} + {props.onDelete && ( + )}