From 11d84a3c3fe3bad30861041c3f63ab2122997d30 Mon Sep 17 00:00:00 2001 From: minnakt <47064971+minnakt@users.noreply.github.com> Date: Wed, 24 Jan 2024 17:31:38 -0500 Subject: [PATCH] DEVPROD-797: Update host events table (#2237) --- cypress/integration/host/host_events.ts | 8 +-- src/pages/host/HostTable.tsx | 83 ++++++++++++++----------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/cypress/integration/host/host_events.ts b/cypress/integration/host/host_events.ts index 8a851c7063..df5d40f853 100644 --- a/cypress/integration/host/host_events.ts +++ b/cypress/integration/host/host_events.ts @@ -2,7 +2,7 @@ import { clickOnPageSizeBtnAndAssertURLandTableSize } from "../../utils"; describe("Host events", () => { const pathWithEvents = "/host/i-0f81a2d39744003dd"; - const dataCyTableRows = "[data-cy=host-events-table] .ant-table-row"; + const dataCyTableRows = "[data-cy=host-events-table]"; beforeEach(() => { cy.window().then((win) => { @@ -217,9 +217,9 @@ describe("Host events", () => { cy.contains("Hawaii").click(); cy.contains("button", "Save Changes").click(); cy.visit(pathWithEvents); - cy.dataCy("HOST_JASPER_RESTARTING-time").contains( - "Sep 30, 2017, 9:11:16 AM", - ); + cy.dataCy("leafygreen-table-row") + .first() + .contains("Sep 30, 2017, 9:11:16 AM"); // Reset timezone so re-running this test works. cy.visit("/preferences"); cy.contains("Hawaii").click(); diff --git a/src/pages/host/HostTable.tsx b/src/pages/host/HostTable.tsx index 4beb3a4e89..8a6119321f 100644 --- a/src/pages/host/HostTable.tsx +++ b/src/pages/host/HostTable.tsx @@ -1,25 +1,22 @@ -import { useMemo } from "react"; +import { useMemo, useRef } from "react"; import { ApolloError } from "@apollo/client"; import styled from "@emotion/styled"; -import { - V10Table as Table, - V10TableHeader as TableHeader, - V10HeaderRow as HeaderRow, - V10Row as Row, - V10Cell as Cell, - V11Adapter, -} from "@leafygreen-ui/table"; +import { useLeafyGreenTable, LGColumnDef } from "@leafygreen-ui/table"; import { Subtitle, SubtitleProps } from "@leafygreen-ui/typography"; import { useHostsTableAnalytics } from "analytics"; import PageSizeSelector, { usePageSizeSelector, } from "components/PageSizeSelector"; import Pagination from "components/Pagination"; +import { BaseTable } from "components/Table/BaseTable"; import { size } from "constants/tokens"; import { HostEventsQuery } from "gql/generated/types"; import { useDateFormat } from "hooks"; import { HostCard } from "pages/host/HostCard"; import { HostEventString } from "pages/host/HostEventString"; +import { Unpacked } from "types/utils"; + +type HostEvent = Unpacked; export const HostTable: React.FC<{ loading: boolean; @@ -43,10 +40,42 @@ export const HostTable: React.FC<{ hostsTableAnalytics.sendEvent({ name: "Change Page Size" }); }; + const columns: LGColumnDef[] = useMemo( + () => [ + { + header: "Date", + accessorKey: "timestamp", + cell: ({ getValue }) => getDateCopy(getValue() as Date), + }, + { + header: "Event", + accessorKey: "eventType", + cell: ({ getValue, row }) => ( + + ), + }, + ], + [getDateCopy], + ); + + const tableContainerRef = useRef(null); + const table = useLeafyGreenTable({ + columns, + containerRef: tableContainerRef, + data: logEntries ?? [], + defaultColumn: { + enableColumnFilter: false, + }, + manualPagination: true, + }); + return ( - Recent Events + Recent Events - - - - - - } - > - {({ datum }) => ( - - - {getDateCopy(datum.timestamp)} - - - - - - )} -
-
+
); };