Skip to content

Commit

Permalink
fix(table-manager): to pass row type (#2667)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmenko authored Dec 14, 2023
1 parent 335534c commit 33cccc8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-onions-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-uikit/data-table-manager': patch
---

Table row type can be passed to `DataTableManager` and `TColumnProps`.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface TRow {
id: string;
}

export type TColumnProps = {
export type TColumnProps<Row extends TRow = TRow> = {
/**
* The unique key of the column that is used to identify your data type.
* You can use this value to determine which value from a row item should be rendered.
Expand Down Expand Up @@ -56,7 +56,7 @@ export type TColumnProps = {
* A callback function to render the content of cells under this column, overriding
* the default `itemRenderer` prop of the table.
*/
renderItem?: <T extends TRow>(row: T, isRowCollapsed: boolean) => ReactNode;
renderItem?: (row: Row, isRowCollapsed: boolean) => ReactNode;

/**
* Use this prop to place an `Icon` or `IconButton` on the left of the column label.
Expand Down Expand Up @@ -100,15 +100,15 @@ export type TColumnProps = {
shouldIgnoreRowClick?: boolean;
};

type TDataTableManagerProps = {
type TDataTableManagerProps<Row extends TRow = TRow> = {
/**
* Each object requires a unique `key` which should correspond to property key of
* the items of `rows` that you want to render under this column, and a `label`
* which defines the name shown on the header.
* The list of columns to be rendered.
* Each column can be customized (see properties below).
*/
columns: TColumnProps[];
columns: TColumnProps<Row>[];

/**
* Any React node. Usually you want to render the `<DataTable>` component.
Expand Down Expand Up @@ -146,7 +146,9 @@ type TDataTableManagerProps = {
managerTheme?: 'light' | 'dark';
};

const DataTableManager = (props: TDataTableManagerProps) => {
const DataTableManager = <Row extends TRow = TRow>(
props: TDataTableManagerProps<Row>
) => {
const areDisplaySettingsEnabled = Boolean(
props.displaySettings && !props.displaySettings.disableDisplaySettings
);
Expand Down

1 comment on commit 33cccc8

@vercel
Copy link

@vercel vercel bot commented on 33cccc8 Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.