From 8675d28e96b3dc955205b223ef49ee022b8962e5 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Thu, 7 Dec 2023 13:25:31 -0500 Subject: [PATCH] fix typescript and show badge of type of edit --- .../src/components/history/HistoryDisplay.tsx | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/history/HistoryDisplay.tsx b/frontend/src/components/history/HistoryDisplay.tsx index 8f0a06b..9f4d8fc 100644 --- a/frontend/src/components/history/HistoryDisplay.tsx +++ b/frontend/src/components/history/HistoryDisplay.tsx @@ -1,4 +1,4 @@ -import { History } from "./history_types"; +import { History, HistoryItemType } from "./history_types"; import toast from "react-hot-toast"; import classNames from "classnames"; import { @@ -6,6 +6,7 @@ import { HoverCardTrigger, HoverCardContent, } from "../ui/hover-card"; +import { Badge } from "../ui/badge"; interface Props { history: History; @@ -14,17 +15,18 @@ interface Props { shouldDisableReverts: boolean; } -// function displayHistoryItemType(itemType: HistoryItemType) { -// switch (itemType) { -// case "ai_create": -// return "Create"; -// case "ai_edit": -// return "Edit"; -// default: -// // TODO: Error out since this is exhaustive -// return "Unknown"; -// } -// } +function displayHistoryItemType(itemType: HistoryItemType) { + switch (itemType) { + case "ai_create": + return "Create"; + case "ai_edit": + return "Edit"; + default: { + const exhaustiveCheck: never = itemType; + throw new Error(`Unhandled case: ${exhaustiveCheck}`); + } + } +} export default function HistoryDisplay({ history, @@ -73,7 +75,10 @@ export default function HistoryDisplay({

v{index + 1}

- {item.type === "ai_edit" ? item.inputs.prompt : "Create"} +
+ {item.type === "ai_edit" ? item.inputs.prompt : "Create"} +
+ {displayHistoryItemType(item.type)}