Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Table component to components/ui, add Storybook #17171

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useNavigate } from "react-router-dom";
import { CellProps } from "react-table";
import styled from "styled-components";

import Table from "components/Table";
import { Table } from "components/ui/Table";

import { ConnectionScheduleType } from "core/request/AirbyteClient";
import { FeatureItem, useFeature } from "hooks/services/Feature";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FormattedMessage } from "react-intl";
import { useNavigate } from "react-router-dom";
import { CellProps } from "react-table";

import Table from "components/Table";
import { Table } from "components/ui/Table";

import { useQuery } from "hooks/useQuery";

Expand Down
3 changes: 0 additions & 3 deletions airbyte-webapp/src/components/Table/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ interface PaddingProps {
right?: number;
}

type IHeaderProps = {
interface HeaderProps extends ColumnInstance<Record<string, unknown>> {
headerHighlighted?: boolean;
collapse?: boolean;
customWidth?: number;
customPadding?: PaddingProps;
} & ColumnInstance<Record<string, unknown>>;
}

type ICellProps = {
column: IHeaderProps;
} & Cell;
interface CellProps extends Cell {
column: HeaderProps;
}

type IThProps = {
interface TableHeaderProps extends React.ThHTMLAttributes<HTMLTableHeaderCellElement> {
highlighted?: boolean;
collapse?: boolean;
customWidth?: number;
customPadding?: PaddingProps;
light?: boolean;
} & React.ThHTMLAttributes<HTMLTableHeaderCellElement>;
}

const TableView = styled(Card).attrs({ as: "table" })<{ light?: boolean }>`
border-spacing: 0;
Expand Down Expand Up @@ -77,7 +77,7 @@ const Td = styled.td<{
}
`;

const Th = styled.th<IThProps>`
const Th = styled.th<TableHeaderProps>`
background: ${({ theme, light }) => (light ? "none" : theme.textColor)};
padding: ${({ customPadding }) => `9px ${customPadding?.right ?? 13}px 10px ${customPadding?.left ?? 13}px`};
text-align: left;
Expand All @@ -100,9 +100,9 @@ const Th = styled.th<IThProps>`
}
`;

interface IProps {
interface TableProps {
light?: boolean;
columns: Array<IHeaderProps | Column<Record<string, unknown>>>;
columns: Array<HeaderProps | Column<Record<string, unknown>>>;
erroredRows?: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any[];
Expand All @@ -112,7 +112,7 @@ interface IProps {
sortBy?: Array<SortingRule<any>>;
}

const Table: React.FC<IProps> = ({ columns, data, onClickRow, erroredRows, sortBy, light }) => {
export const Table: React.FC<TableProps> = memo(({ columns, data, onClickRow, erroredRows, sortBy, light }) => {
const [plugins, config] = useMemo(() => {
const pl = [];
const plConfig: Record<string, unknown> = {};
Expand All @@ -137,7 +137,7 @@ const Table: React.FC<IProps> = ({ columns, data, onClickRow, erroredRows, sortB
<thead>
{headerGroups.map((headerGroup, key) => (
<tr {...headerGroup.getHeaderGroupProps()} key={`table-header-${key}`}>
{headerGroup.headers.map((column: IHeaderProps, columnKey) => (
{headerGroup.headers.map((column: HeaderProps, columnKey) => (
<Th
{...column.getHeaderProps()}
highlighted={column.headerHighlighted}
Expand All @@ -164,7 +164,7 @@ const Table: React.FC<IProps> = ({ columns, data, onClickRow, erroredRows, sortB
onClick={() => onClickRow?.(row.original)}
erroredRows={erroredRows && !!row.original.error}
>
{row.cells.map((cell: ICellProps, key) => {
{row.cells.map((cell: CellProps, key) => {
return (
<Td
{...cell.getCellProps()}
Expand All @@ -183,6 +183,4 @@ const Table: React.FC<IProps> = ({ columns, data, onClickRow, erroredRows, sortB
</tbody>
</TableView>
);
};

export default memo(Table);
});
44 changes: 44 additions & 0 deletions airbyte-webapp/src/components/ui/Table/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ComponentStory, ComponentMeta } from "@storybook/react";
import { CellProps } from "react-table";

import { Table } from "./Table";

export default {
title: "UI/Table",
component: Table,
argTypes: {},
} as ComponentMeta<typeof Table>;

const Template: ComponentStory<typeof Table> = (args) => <Table {...args} />;

interface Item {
name: string;
value: number;
}

const data: Item[] = [
{ name: "2017", value: 100 },
{ name: "2018", value: 300 },
{ name: "2019", value: 500 },
{ name: "2020", value: 400 },
{ name: "2021", value: 200 },
];

const columns = [
{
Header: "Name",
accessor: "name",
Cell: ({ cell }: CellProps<Item>) => <strong>{cell.value}</strong>,
},
{
Header: "Value",
accessor: "value",
Cell: ({ cell }: CellProps<Item>) => <>{cell.value}</>,
},
];

export const Primary = Template.bind({});
Primary.args = {
data,
columns,
};
1 change: 1 addition & 0 deletions airbyte-webapp/src/components/ui/Table/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Table";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styled from "styled-components";

import SortButton from "components/EntityTable/components/SortButton";
import { SortOrderEnum } from "components/EntityTable/types";
import Table from "components/Table";
import { Table } from "components/ui/Table";

import { useQuery } from "hooks/useQuery";
import { CreditConsumptionByConnector } from "packages/cloud/lib/domain/cloudWorkspaces/types";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CellProps } from "react-table";
import { useToggle } from "react-use";

import { Button, H5, LoadingButton } from "components";
import Table from "components/Table";
import { Table } from "components/ui/Table";

import { useTrackPage, PageTrackingCodes } from "hooks/services/Analytics";
import { useConfirmationModalService } from "hooks/services/ConfirmationModal";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormattedMessage } from "react-intl";
import { CellProps } from "react-table";

import HeadTitle from "components/HeadTitle";
import Table from "components/Table";
import { Table } from "components/ui/Table";

import { Connector, ConnectorDefinition } from "core/domain/connector";
import { DestinationDefinitionRead, SourceDefinitionRead } from "core/request/AirbyteClient";
Expand Down