-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update time column in inputs table to show date in age or UTC format (#…
…74) Co-authored-by: nevendiulgerov <[email protected]>
- Loading branch information
1 parent
99b06a6
commit 43cf277
Showing
6 changed files
with
177 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use client"; | ||
import { Button, Table } from "@mantine/core"; | ||
import { FC, useCallback, useState } from "react"; | ||
import InputRow from "../components/inputRow"; | ||
import type { InputItemFragment } from "../graphql"; | ||
|
||
export interface InputsTableProps { | ||
inputs: InputItemFragment[]; | ||
} | ||
|
||
const InputsTable: FC<InputsTableProps> = ({ inputs }) => { | ||
const [timeType, setTimeType] = useState("age"); | ||
|
||
const onChangeTimeColumnType = useCallback(() => { | ||
setTimeType((timeType) => (timeType === "age" ? "timestamp" : "age")); | ||
}, []); | ||
|
||
return ( | ||
<Table> | ||
<Table.Thead> | ||
<Table.Tr> | ||
<Table.Th>From</Table.Th> | ||
<Table.Th></Table.Th> | ||
<Table.Th>To</Table.Th> | ||
<Table.Th>Method</Table.Th> | ||
<Table.Th>Index</Table.Th> | ||
<Table.Th> | ||
<Button | ||
variant="transparent" | ||
px={0} | ||
onClick={onChangeTimeColumnType} | ||
> | ||
{timeType === "age" ? "Age" : "Timestamp (UTC)"} | ||
</Button> | ||
</Table.Th> | ||
<Table.Th>Data</Table.Th> | ||
</Table.Tr> | ||
</Table.Thead> | ||
<Table.Tbody> | ||
{inputs.map((input) => ( | ||
<InputRow | ||
key={input.id} | ||
input={input} | ||
timeType={timeType} | ||
/> | ||
))} | ||
</Table.Tbody> | ||
</Table> | ||
); | ||
}; | ||
|
||
export default InputsTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { describe, it } from "vitest"; | ||
import type { FC } from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import InputRow, { InputRowProps } from "../../src/components/inputRow"; | ||
import { withMantineTheme } from "../utils/WithMantineTheme"; | ||
import { Table } from "@mantine/core"; | ||
import prettyMilliseconds from "pretty-ms"; | ||
|
||
const TableComponent: FC<InputRowProps> = (props) => ( | ||
<Table> | ||
<Table.Tbody> | ||
<InputRow {...props} /> | ||
</Table.Tbody> | ||
</Table> | ||
); | ||
|
||
const Component = withMantineTheme(TableComponent); | ||
|
||
const defaultProps: InputRowProps = { | ||
input: { | ||
id: "0xdb84080e7d2b4654a7e384de851a6cf7281643de-1", | ||
application: { | ||
id: "0xdb84080e7d2b4654a7e384de851a6cf7281643de", | ||
}, | ||
index: 1, | ||
payload: "0x68656c6c6f2032", | ||
msgSender: "0x8a12cf75000cd2e73ab16469826838d5f137f444", | ||
timestamp: 1700593992, | ||
transactionHash: | ||
"0x4ad73b8f46dc16bc27d75b3f8f584e8785a8cb6fdf97a6c2a5a5dcfbda3e75c0", | ||
erc20Deposit: null, | ||
}, | ||
timeType: "age", | ||
}; | ||
|
||
describe("InputRow component", () => { | ||
it("should display correct age", () => { | ||
render(<Component {...defaultProps} />); | ||
|
||
const age = `${prettyMilliseconds( | ||
Date.now() - defaultProps.input.timestamp * 1000, | ||
{ | ||
unitCount: 2, | ||
secondsDecimalDigits: 0, | ||
verbose: true, | ||
}, | ||
)} ago`; | ||
expect(screen.getByText(age)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display correct timestamp in UTC format", () => { | ||
render(<Component input={defaultProps.input} timeType="timestamp" />); | ||
|
||
const timestamp = new Date( | ||
defaultProps.input.timestamp * 1000, | ||
).toISOString(); | ||
expect(screen.getByText(timestamp)).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { describe, it } from "vitest"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import InputsTable, { | ||
InputsTableProps, | ||
} from "../../src/components/inputsTable"; | ||
import { withMantineTheme } from "../utils/WithMantineTheme"; | ||
|
||
const Component = withMantineTheme(InputsTable); | ||
|
||
const defaultProps: InputsTableProps = { | ||
inputs: [ | ||
{ | ||
id: "0xdb84080e7d2b4654a7e384de851a6cf7281643de-1", | ||
application: { | ||
id: "0xdb84080e7d2b4654a7e384de851a6cf7281643de", | ||
}, | ||
index: 1, | ||
payload: "0x68656c6c6f2032", | ||
msgSender: "0x8a12cf75000cd2e73ab16469826838d5f137f444", | ||
timestamp: 1700593992, | ||
transactionHash: | ||
"0x4ad73b8f46dc16bc27d75b3f8f584e8785a8cb6fdf97a6c2a5a5dcfbda3e75c0", | ||
erc20Deposit: null, | ||
}, | ||
], | ||
}; | ||
|
||
describe("InputsTable component", () => { | ||
it("should display time column with age label", () => { | ||
render(<Component {...defaultProps} />); | ||
expect(screen.getByText("Age")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display time column with timestamp label", () => { | ||
render(<Component {...defaultProps} />); | ||
|
||
const timeTypeButton = screen.getByText("Age"); | ||
fireEvent.click(timeTypeButton); | ||
|
||
expect(screen.getByText("Timestamp (UTC)")).toBeInTheDocument(); | ||
}); | ||
}); |
43cf277
There was a problem hiding this comment.
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:
rollups-explorer-sepolia – ./apps/web
rollups-explorer-sepolia.vercel.app
sepolia-rollups.vercel.app
rollups-explorer-sepolia-cartesi.vercel.app
sepolia.cartesiscan.io
rollups-explorer-sepolia-git-main-cartesi.vercel.app
43cf277
There was a problem hiding this comment.
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:
rollups-explorer-workshop – ./apps/workshop
rollups-explorer-workshop-cartesi.vercel.app
rollups-explorer-workshop-git-main-cartesi.vercel.app
rollups-explorer-workshop.vercel.app