From b88320177ee928bd72c75ccba74ab7c9117f27c0 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Mon, 11 Dec 2023 21:47:07 -0500 Subject: [PATCH] Pre-process history for history display so we can write unit tests for it --- .../src/components/history/HistoryDisplay.tsx | 57 +++------ .../src/components/history/history_types.ts | 7 ++ frontend/src/components/history/utils.test.ts | 109 +++++++++++++++++- frontend/src/components/history/utils.ts | 66 ++++++++++- 4 files changed, 194 insertions(+), 45 deletions(-) diff --git a/frontend/src/components/history/HistoryDisplay.tsx b/frontend/src/components/history/HistoryDisplay.tsx index db0b74b..615aed8 100644 --- a/frontend/src/components/history/HistoryDisplay.tsx +++ b/frontend/src/components/history/HistoryDisplay.tsx @@ -1,4 +1,4 @@ -import { History, HistoryItemType } from "./history_types"; +import { History } from "./history_types"; import toast from "react-hot-toast"; import classNames from "classnames"; import { @@ -7,6 +7,7 @@ import { HoverCardContent, } from "../ui/hover-card"; import { Badge } from "../ui/badge"; +import { renderHistory } from "./utils"; interface Props { history: History; @@ -15,32 +16,19 @@ interface Props { shouldDisableReverts: boolean; } -function displayHistoryItemType(itemType: HistoryItemType) { - switch (itemType) { - case "ai_create": - return "Create"; - case "ai_edit": - return "Edit"; - case "code_create": - return "Imported from code"; - default: { - const exhaustiveCheck: never = itemType; - throw new Error(`Unhandled case: ${exhaustiveCheck}`); - } - } -} - export default function HistoryDisplay({ history, currentVersion, revertToVersion, shouldDisableReverts, }: Props) { - return history.length === 0 ? null : ( + const renderedHistory = renderHistory(history, currentVersion); + + return renderedHistory.length === 0 ? null : (

Versions