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

chore: refactor table widget UI code to use central context to reduce props drilling #39367

Open
wants to merge 26 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c68a681
refactor(TableWidget): Improve table header organization and context …
rahulbarwal Feb 18, 2025
5f1722c
refactor(TableWidget): Optimize table context and performance
rahulbarwal Feb 18, 2025
38a0e95
refactor(TableWidget): Simplify table header scrolling with SimpleBar
rahulbarwal Feb 19, 2025
ce66d9d
refactor(TableWidget): Simplify VirtualTable and Table component rend…
rahulbarwal Feb 19, 2025
4d0a08b
refactor(TableWidget): Simplify HeaderCell component with TableContext
rahulbarwal Feb 19, 2025
aecc93c
refactor(TableWidget): Simplify TableColumnHeader with TableContext
rahulbarwal Feb 19, 2025
0ea14d4
refactor(TableWidget): Simplify empty row rendering with TableContext
rahulbarwal Feb 19, 2025
0377009
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Feb 21, 2025
3e97431
refactor: Simplify StaticTable component and extract StaticTableBody
rahulbarwal Feb 21, 2025
03f8006
refactor: Restructure VirtualTable component for improved table rende…
rahulbarwal Feb 21, 2025
6e90439
refactor: Restructure TableWidgetV2 core components for improved virt…
rahulbarwal Feb 21, 2025
c318d54
test: Add comprehensive test suite for StaticTableBody component
rahulbarwal Feb 24, 2025
6b200f7
test: Add comprehensive test suite for TableContext component
rahulbarwal Feb 24, 2025
01b4bfa
refactor: Improve type safety in TableColumnHeader component
rahulbarwal Feb 27, 2025
3a402fb
refactor: Improve type safety in TableColumnHeader component
rahulbarwal Feb 27, 2025
03470d8
refactor: Simplify TableWidgetV2 header components using TableContext
rahulbarwal Feb 27, 2025
ce8da9d
refactor: Improve rendering of empty rows in TableWidgetV2
rahulbarwal Mar 3, 2025
f3dcf29
test: Refactor TableWidgetV2 Actions component tests with TableContext
rahulbarwal Mar 3, 2025
9c53de0
refactor: Improve EmptyRows component and update TableWidgetV2 imports
rahulbarwal Mar 4, 2025
ed5a94f
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Mar 7, 2025
fe09d8c
updates: Add itemCount prop to VirtualTableBodyComponent
rahulbarwal Mar 7, 2025
1f8cc34
updates: Reorder props in useAppsmithTable hook destructuring
rahulbarwal Mar 7, 2025
3cd678f
refactor: Rename StaticTableBody to StaticTableBodyComponent
rahulbarwal Mar 10, 2025
a972f6d
refactor: Rename StaticTableBody to StaticTableBodyComponent
rahulbarwal Mar 10, 2025
1a2e30b
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal Mar 10, 2025
524a846
fix: ensure table renders minimum page size rows
rahulbarwal Mar 10, 2025
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 @@ -54,6 +54,7 @@ export enum ImageSizes {
LARGE = "128px",
}

export const SCROLL_BAR_OFFSET = 2;
export const TABLE_SIZES: { [key: string]: TableSizes } = {
[CompactModeTypes.DEFAULT]: {
COLUMN_HEADER_HEIGHT: 32,
Expand Down
104 changes: 0 additions & 104 deletions app/client/src/widgets/TableWidgetV2/component/StaticTable.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Row } from "../../TableBodyCoreComponents/Row";

import React from "react";
import { useAppsmithTable } from "../../TableContext";
import { EmptyRows } from "../../cellComponents/EmptyCell";

export const StaticTableBodyComponent = () => {
const { getTableBodyProps, pageSize, subPage: rows } = useAppsmithTable();

return (
<div {...getTableBodyProps()} className="tbody body">
{rows.map((row, index) => {
return <Row index={index} key={index} row={row} />;
})}
{pageSize > rows.length && <EmptyRows rows={pageSize - rows.length} />}
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import StaticTable from "../index";
import { useAppsmithTable } from "../../TableContext";
import type SimpleBar from "simplebar-react";

// Mock SimpleBar
jest.mock("simplebar-react", () => {
return {
__esModule: true,
default: React.forwardRef<
HTMLDivElement,
{ children: React.ReactNode; style?: React.CSSProperties }
>((props, ref) => (
<div className="simplebar-content-wrapper" ref={ref} style={props.style}>
{props.children}
</div>
)),
};
});

// Mock the required dependencies
jest.mock("../../TableContext", () => ({
useAppsmithTable: jest.fn(),
}));

jest.mock("../../header/TableColumnHeader", () => ({
__esModule: true,
default: () => <div data-testid="mock-table-header">Table Header</div>,
}));

jest.mock("../StaticTableBody", () => ({
StaticTableBodyComponent: () => (
<div data-testid="mock-table-body">Table Body</div>
),
}));

describe("StaticTable", () => {
const mockScrollContainerStyles = {
height: 400,
width: 800,
};

beforeEach(() => {
(useAppsmithTable as jest.Mock).mockReturnValue({
scrollContainerStyles: mockScrollContainerStyles,
});
});

afterEach(() => {
jest.clearAllMocks();
});

it("renders the table with header and body components", () => {
const ref = React.createRef<SimpleBar>();

render(<StaticTable ref={ref} />);

expect(screen.getByTestId("mock-table-header")).toBeInTheDocument();
expect(screen.getByTestId("mock-table-body")).toBeInTheDocument();
});

it("applies correct scroll container styles from context", () => {
const ref = React.createRef<SimpleBar>();
const { container } = render(<StaticTable ref={ref} />);

const simpleBarElement = container.querySelector(
".simplebar-content-wrapper",
);

expect(simpleBarElement).toHaveStyle({
height: `${mockScrollContainerStyles.height}px`,
width: `${mockScrollContainerStyles.width}px`,
});
});

it("forwards ref correctly", () => {
const ref = React.createRef<SimpleBar>();

render(<StaticTable ref={ref} />);

expect(ref.current).toBeTruthy();
// Instead of instanceof check, verify the ref points to the correct element
expect(ref.current).toHaveClass("simplebar-content-wrapper");
});

it("throws error when used outside TableContext", () => {
const consoleErrorSpy = jest
.spyOn(console, "error")
.mockImplementation(() => {});

(useAppsmithTable as jest.Mock).mockImplementation(() => {
throw new Error("useTable must be used within a TableProvider");
});

const ref = React.createRef<SimpleBar>();

expect(() => render(<StaticTable ref={ref} />)).toThrow(
"useTable must be used within a TableProvider",
);

consoleErrorSpy.mockRestore();
});
});
Loading
Loading