Skip to content

Commit

Permalink
Add actions to table (#201)
Browse files Browse the repository at this point in the history
* Add actions to table

* Fix IconButton error

* Add gap to actions

* Add actions test cases

* Update naming checked to isSelected

* Update naming deleted to isDeleted

* Optimise table code

* Add delete table changes

* Add delete row changes
  • Loading branch information
vineethasok authored Nov 8, 2023
1 parent 65440e7 commit 0bd1ee3
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 47 deletions.
63 changes: 41 additions & 22 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,55 @@ import {
Text,
EllipsisContent,
Table,
TableRowType,
} from "@/components";
import { Dialog } from "@/components/Dialog/Dialog";
import ConfirmationDialog from "@/components/ConfirmationDialog/ConfirmationDialog";

const headers = [{ label: "Company" }, { label: "Contact" }, { label: "Country" }];
const rows = [
{
id: "row-1",
items: [
{ label: "Alfreds Futterkiste" },
{ label: "Maria Anders" },
{ label: "Germany" },
],
},
{
id: "row-2",
items: [
{ label: "Centro comercial Moctezuma" },
{ label: "Francisco Chang" },
{ label: "Mexico" },
],
},
];
const App = () => {
const [currentTheme, setCurrentTheme] = useState<ThemeName>("dark");
const [selectedButton, setSelectedButton] = useState("center1");
const [checked, setChecked] = useState(false);
const [disabled] = useState(false);
const [open, setOpen] = useState(false);
const ref = useRef(null);
const [rows, setRows] = useState<Array<TableRowType>>([
{
id: "row-1",
items: [
{ label: "Alfreds Futterkiste" },
{ label: "Maria Anders" },
{ label: "Germany" },
],
},
{
id: "row-2",
items: [
{ label: "Centro comercial Moctezuma" },
{ label: "Francisco Chang" },
{ label: "Mexico" },
],
},
{
id: "row-3",
isDisabled: true,
items: [
{ label: "Centro comercial Moctezuma" },
{ label: "Francisco Chang" },
{ label: "Mexico" },
],
},
]);

const onTableDelete = (row: TableRowType, index: number) => {
setRows(rows => {
rows[index] = row;
return [...rows];
});
};

console.log(currentTheme);
return (
<div style={{ padding: "6rem" }}>
<ClickUIProvider
Expand Down Expand Up @@ -449,11 +467,12 @@ const App = () => {
turpis ex imperdiet enim, ac finibus nunc ante non est. Ut mattis ex magna, ac
faucibus mi egestas interdum.
</EllipsisContent>
<Table
headers={headers}
rows={rows}
onDelete={onTableDelete}
/>
</ClickUIProvider>
<Table
headers={headers}
rows={rows}
/>
</div>
);
};
Expand Down
30 changes: 30 additions & 0 deletions src/components/Table/Table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,34 @@ describe("Table", () => {
fireEvent.click(selectAllCheckbox);
expect(onSelect).toBeCalledTimes(2);
});

it("should trigger onDelete on clicking closeButton", () => {
const onDelete = jest.fn();
const { queryByTestId, queryAllByTestId } = renderTable({
isSelectable: true,
onDelete,
});
expect(queryByTestId("table")).not.toBeNull();
expect(queryAllByTestId("table-row-delete")).toHaveLength(2);
expect(queryByTestId("table-row-edit")).toBeNull();
const rowCheckbox = queryAllByTestId("table-row-delete")[0];
expect(rowCheckbox).not.toBeNull();
fireEvent.click(rowCheckbox);
expect(onDelete).toBeCalledTimes(1);
});

it("should trigger onEdit on clicking editButton", () => {
const onEdit = jest.fn();
const { queryByTestId, queryAllByTestId } = renderTable({
isSelectable: true,
onEdit,
});
expect(queryByTestId("table")).not.toBeNull();
expect(queryAllByTestId("table-row-edit")).toHaveLength(2);
expect(queryByTestId("table-row-delete")).toBeNull();
const rowCheckbox = queryAllByTestId("table-row-edit")[0];
expect(rowCheckbox).not.toBeNull();
fireEvent.click(rowCheckbox);
expect(onEdit).toBeCalledTimes(1);
});
});
Loading

1 comment on commit 0bd1ee3

@vercel
Copy link

@vercel vercel bot commented on 0bd1ee3 Nov 8, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

click-ui – ./

click-ui.vercel.app
click-ui-clickhouse.vercel.app
click-ui-git-main-clickhouse.vercel.app

Please sign in to comment.