-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Devan/eng 1242 add grid view of artifacts (#17018)
Co-authored-by: Devan Grose <=> Co-authored-by: Devin Villarosa <102188207+devinvillarosa@users.noreply.github.com>
- Loading branch information
1 parent
94dddf0
commit 0145cbb
Showing
9 changed files
with
1,326 additions
and
101 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,53 @@ | ||
import { Artifact } from "@/api/artifacts"; | ||
import { createFakeArtifact } from "@/mocks"; | ||
import { render } from "@testing-library/react"; | ||
import { createWrapper } from "@tests/utils"; | ||
import { describe, expect, it } from "vitest"; | ||
import { ArtifactCard } from "./artifact-card"; | ||
|
||
describe("Artifacts Card", () => { | ||
it("renders artifact card with description", () => { | ||
const artifact: Artifact = createFakeArtifact({ | ||
description: "This is a description", | ||
}); | ||
const { getByText } = render(<ArtifactCard artifact={artifact} />, { | ||
wrapper: createWrapper(), | ||
}); | ||
|
||
expect(getByText("This is a description")).toBeTruthy(); | ||
}); | ||
|
||
it("renders artifact card with updated date", () => { | ||
const artifact = createFakeArtifact({ | ||
updated: "2021-09-01T12:00:00Z", | ||
}); | ||
const { getByText } = render(<ArtifactCard artifact={artifact} />, { | ||
wrapper: createWrapper(), | ||
}); | ||
|
||
expect(getByText("Last Updated")).toBeTruthy(); | ||
expect(getByText("Sep 1st, 2021 at 12:00 PM")).toBeTruthy(); | ||
}); | ||
|
||
it("renders artifact card with key", () => { | ||
const artifact = createFakeArtifact({ | ||
key: "test-key", | ||
}); | ||
const { getByText } = render(<ArtifactCard artifact={artifact} />, { | ||
wrapper: createWrapper(), | ||
}); | ||
|
||
expect(getByText("test-key")).toBeTruthy(); | ||
}); | ||
|
||
it("renders artifact card with type", () => { | ||
const artifact = createFakeArtifact({ | ||
type: "test-type", | ||
}); | ||
const { getByText } = render(<ArtifactCard artifact={artifact} />, { | ||
wrapper: createWrapper(), | ||
}); | ||
|
||
expect(getByText("TEST-TYPE")).toBeTruthy(); | ||
}); | ||
}); |
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,51 @@ | ||
import { Artifact } from "@/api/artifacts"; | ||
import { formatDate } from "@/utils/date"; | ||
import { useMemo } from "react"; | ||
import Markdown from "react-markdown"; | ||
import { Card } from "../ui/card"; | ||
import { Typography } from "../ui/typography"; | ||
|
||
interface ArtifactsCardProps { | ||
artifact: Artifact; | ||
} | ||
|
||
export const ArtifactCard = ({ artifact }: ArtifactsCardProps) => { | ||
const date = useMemo(() => { | ||
const date = new Date(artifact.updated ?? ""); | ||
return formatDate(date, "dateTime"); | ||
}, [artifact.updated]); | ||
return ( | ||
<Card className="p-4 m-2"> | ||
<Typography | ||
variant="bodySmall" | ||
className="font-bold text-muted-foreground" | ||
> | ||
{artifact.type?.toUpperCase()} | ||
</Typography> | ||
<Typography variant="h3" className="font-bold"> | ||
{artifact.key} | ||
</Typography> | ||
<div className="flex justify-between mt-2"> | ||
<Typography variant="bodySmall" className="" fontFamily="mono"> | ||
{date} | ||
</Typography> | ||
<Typography variant="bodySmall" className="text-muted-foreground"> | ||
Last Updated | ||
</Typography> | ||
</div> | ||
<hr className="my-2" /> | ||
{artifact.description ? ( | ||
<div className="text-muted-foreground"> | ||
<Markdown>{artifact.description}</Markdown> | ||
</div> | ||
) : ( | ||
<Typography | ||
variant="bodySmall" | ||
className="text-muted-foreground italic" | ||
> | ||
No description | ||
</Typography> | ||
)} | ||
</Card> | ||
); | ||
}; |
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,37 @@ | ||
import { format } from "date-fns"; | ||
|
||
const dateFormat = "MMM do, yyyy"; | ||
const timeFormat = "hh:mm a"; | ||
const dateTimeFormat = `${dateFormat} 'at' ${timeFormat}`; | ||
|
||
const timeNumericFormat = "hh:mm:ss a"; | ||
const timeNumericShortFormat = "hh:mm a"; | ||
const dateNumericFormat = "yyyy/MM/dd"; | ||
const dateTimeNumericFormat = `${dateNumericFormat} ${timeNumericFormat}`; | ||
const dateTimeNumericShortFormat = `${dateNumericFormat} ${timeNumericShortFormat}`; | ||
|
||
export const dateFormats = { | ||
date: dateFormat, | ||
time: timeFormat, | ||
dateTime: dateTimeFormat, | ||
timeNumeric: timeNumericFormat, | ||
timeNumericShort: timeNumericShortFormat, | ||
dateNumeric: dateNumericFormat, | ||
dateTimeNumeric: dateTimeNumericFormat, | ||
dateTimeNumericShort: dateTimeNumericShortFormat, | ||
} as const; | ||
|
||
type DateFormat = keyof typeof dateFormats; | ||
|
||
function toDate(value: Date | string): Date { | ||
return new Date(value); | ||
} | ||
|
||
export function formatDate( | ||
value: Date | string, | ||
type: DateFormat = "date", | ||
): string { | ||
const date = toDate(value); | ||
|
||
return format(date, dateFormats[type]); | ||
} |
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