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

Migrate new UI to Chakra v3 #43523

Merged
merged 4 commits into from
Nov 1, 2024
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
7 changes: 3 additions & 4 deletions airflow/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
},
"dependencies": {
"@chakra-ui/anatomy": "^2.2.2",
"@chakra-ui/react": "^2.8.2",
"@chakra-ui/react": "^3.0.2",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@tanstack/react-query": "^5.52.1",
"@tanstack/react-table": "^8.20.1",
"axios": "^1.7.7",
"chakra-react-select": "^4.9.2",
"chakra-react-select": "6.0.0-next.2",
"dayjs": "^1.11.13",
"framer-motion": "^11.3.29",
"next-themes": "^0.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0",
Expand Down
3,127 changes: 1,626 additions & 1,501 deletions airflow/ui/pnpm-lock.yaml

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion airflow/ui/rules/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,10 @@ export const typescriptRules =
* ```
* @see [@typescript-eslint/strict-boolean-expressions](https://typescript-eslint.io/rules/strict-boolean-expressions/)
*/
[`${typescriptNamespace}/strict-boolean-expressions`]: ERROR,
[`${typescriptNamespace}/strict-boolean-expressions`]: [
ERROR,
{ allowNullableBoolean: true },
],

/**
* If you'll use switch, make sure to cover every possible value.
Expand Down
46 changes: 21 additions & 25 deletions airflow/ui/src/components/DataTable/CardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,24 @@ export const CardList = <TData,>({
cardDef,
isLoading,
table,
}: DataTableProps<TData>) => {
const defaultGridProps = { column: { base: 1 }, spacing: 2 };

return (
<Box overflow="auto" width="100%">
<SimpleGrid {...{ ...defaultGridProps, ...cardDef.gridProps }}>
{table.getRowModel().rows.map((row) => (
<Box key={row.id}>
{Boolean(isLoading) &&
(cardDef.meta?.customSkeleton ?? (
<Skeleton
data-testid="skeleton"
display="inline-block"
height={80}
width="100%"
/>
))}
{!Boolean(isLoading) &&
flexRender(cardDef.card, { row: row.original })}
</Box>
))}
</SimpleGrid>
</Box>
);
};
}: DataTableProps<TData>) => (
<Box overflow="auto" width="100%">
<SimpleGrid {...{ column: { base: 1 }, gap: 2, ...cardDef.gridProps }}>
{table.getRowModel().rows.map((row) => (
<Box key={row.id}>
{Boolean(isLoading) &&
(cardDef.meta?.customSkeleton ?? (
<Skeleton
data-testid="skeleton"
display="inline-block"
height={80}
width="100%"
/>
))}
{!Boolean(isLoading) &&
flexRender(cardDef.card, { row: row.original })}
</Box>
))}
</SimpleGrid>
</Box>
);
33 changes: 26 additions & 7 deletions airflow/ui/src/components/DataTable/DataTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";

import { ChakraWrapper } from "src/utils/ChakraWrapper.tsx";

import { DataTable } from "./DataTable.tsx";
import type { CardDef } from "./types.ts";

Expand Down Expand Up @@ -52,6 +54,9 @@ describe("DataTable", () => {
onStateChange={onStateChange}
total={2}
/>,
{
wrapper: ChakraWrapper,
},
);

expect(screen.getByText("John Doe")).toBeInTheDocument();
Expand All @@ -67,10 +72,12 @@ describe("DataTable", () => {
onStateChange={onStateChange}
total={2}
/>,
{
wrapper: ChakraWrapper,
},
);

expect(screen.getByText("<<")).toBeDisabled();
expect(screen.getByText("<")).toBeDisabled();
expect(screen.getByTestId("prev")).toBeDisabled();
});

it("disables next button when on last page", () => {
Expand All @@ -79,26 +86,32 @@ describe("DataTable", () => {
columns={columns}
data={data}
initialState={{
pagination: { pageIndex: 1, pageSize: 10 },
pagination: { pageIndex: 0, pageSize: 10 },
sorting: [],
}}
onStateChange={onStateChange}
total={2}
/>,
{
wrapper: ChakraWrapper,
},
);

expect(screen.getByText(">>")).toBeDisabled();
expect(screen.getByText(">")).toBeDisabled();
expect(screen.getByTestId("next")).toBeDisabled();
});

it("when isLoading renders skeleton columns", () => {
render(<DataTable columns={columns} data={data} isLoading />);
render(<DataTable columns={columns} data={data} isLoading />, {
wrapper: ChakraWrapper,
});

expect(screen.getAllByTestId("skeleton")).toHaveLength(10);
});

it("still displays table if mode is card but there is no cardDef", () => {
render(<DataTable columns={columns} data={data} displayMode="card" />);
render(<DataTable columns={columns} data={data} displayMode="card" />, {
wrapper: ChakraWrapper,
});

expect(screen.getByText("Name")).toBeInTheDocument();
});
Expand All @@ -111,6 +124,9 @@ describe("DataTable", () => {
data={data}
displayMode="card"
/>,
{
wrapper: ChakraWrapper,
},
);

expect(screen.getByText("My name is John Doe.")).toBeInTheDocument();
Expand All @@ -126,6 +142,9 @@ describe("DataTable", () => {
isLoading
skeletonCount={5}
/>,
{
wrapper: ChakraWrapper,
},
);

expect(screen.getAllByTestId("skeleton")).toHaveLength(5);
Expand Down
22 changes: 17 additions & 5 deletions airflow/ui/src/components/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Progress, Text } from "@chakra-ui/react";
import { HStack, Text } from "@chakra-ui/react";
import {
getCoreRowModel,
getExpandedRowModel,
Expand All @@ -30,9 +30,9 @@ import {
} from "@tanstack/react-table";
import React, { type ReactNode, useCallback, useRef } from "react";

import { ProgressBar, Pagination } from "../ui";
import { CardList } from "./CardList";
import { TableList } from "./TableList";
import { TablePaginator } from "./TablePaginator";
import { createSkeletonMock } from "./skeleton";
import type { CardDef, MetaColumn, TableState } from "./types";

Expand Down Expand Up @@ -122,8 +122,7 @@ export const DataTable = <TData,>({

return (
<>
<Progress
isIndeterminate
<ProgressBar
size="xs"
visibility={
Boolean(isFetching) && !Boolean(isLoading) ? "visible" : "hidden"
Expand All @@ -137,7 +136,20 @@ export const DataTable = <TData,>({
{display === "card" && cardDef !== undefined && (
<CardList cardDef={cardDef} isLoading={isLoading} table={table} />
)}
<TablePaginator table={table} />
<Pagination.Root
count={table.getRowCount()}
my={2}
onPageChange={(page) => table.setPageIndex(page.page - 1)}
page={table.getState().pagination.pageIndex + 1}
pageSize={table.getState().pagination.pageSize}
siblingCount={1}
>
<HStack>
<Pagination.PrevTrigger data-testid="prev" />
<Pagination.Items />
<Pagination.NextTrigger data-testid="next" />
</HStack>
</Pagination.Root>
</>
);
};
Loading