Skip to content

Commit

Permalink
refactor(#67): make baseTable accept an element instead of a string
Browse files Browse the repository at this point in the history
- do this change to allow the table to receive a more general element, instead of a string containing an id to be used in FormattedMessage
  • Loading branch information
mari1912 committed Jul 11, 2024
1 parent 30516d5 commit b69f114
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 13 additions & 7 deletions dashboard/src/components/Table/BaseTable.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import type { ReactElement } from 'react';

import { FormattedMessage } from 'react-intl';
import classNames from 'classnames';

import { Table, TableHead, TableHeader, TableRow } from '../ui/table';

interface IBaseTable {
headers: string[];
headers: ReactElement[];
body: ReactElement;
className?: string;
}

const BaseTable = ({ headers, body }: IBaseTable): JSX.Element => {
const BaseTable = ({ headers, body, className }: IBaseTable): JSX.Element => {
return (
<div>
<Table className="rounded-lg text-black bg-white w-full">
<div className="h-full">
<Table
className={classNames(
className,
'rounded-lg text-black bg-white w-full',
)}
>
<TableHeader className="bg-mediumGray">
<TableRow>
{headers.map(column => (
<TableHead className="text-black border-b" key={column}>
<FormattedMessage id={column} />
<TableHead className="text-black border-b" key={column.key}>
{column}
</TableHead>
))}
</TableRow>
Expand Down
9 changes: 8 additions & 1 deletion dashboard/src/components/Table/TreeTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useMemo } from 'react';

import { FormattedMessage } from 'react-intl';

import { TableRow, TableCell } from '../ui/table';

import { TreeTableBody } from '../../types/tree/Tree';
Expand Down Expand Up @@ -52,7 +54,12 @@ const TreeTable = ({ treeTableRows }: ITreeTable): JSX.Element => {
}, [treeTableRows]);

return (
<BaseTable headers={treeTableColumnsLabelId} body={<>{treeTableBody}</>} />
<BaseTable
headers={treeTableColumnsLabelId.map(columnLabelId => (
<FormattedMessage key={columnLabelId} id={columnLabelId} />
))}
body={<>{treeTableBody}</>}
/>
);
};

Expand Down

0 comments on commit b69f114

Please sign in to comment.