improve history UX

This commit is contained in:
Abi Raja 2023-12-13 12:20:44 -05:00
parent b88320177e
commit a615f25fd7
4 changed files with 55 additions and 29 deletions

View File

@ -17,6 +17,7 @@
"@radix-ui/react-accordion": "^1.1.2", "@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5", "@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.5", "@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-hover-card": "^1.0.7", "@radix-ui/react-hover-card": "^1.0.7",
"@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-icons": "^1.3.0",

View File

@ -1,13 +1,16 @@
import { History } from "./history_types"; import { History } from "./history_types";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import classNames from "classnames"; import classNames from "classnames";
import {
HoverCard,
HoverCardTrigger,
HoverCardContent,
} from "../ui/hover-card";
import { Badge } from "../ui/badge"; import { Badge } from "../ui/badge";
import { renderHistory } from "./utils"; import { renderHistory } from "./utils";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "../ui/collapsible";
import { Button } from "../ui/button";
import { CaretSortIcon } from "@radix-ui/react-icons";
interface Props { interface Props {
history: History; history: History;
@ -30,16 +33,19 @@ export default function HistoryDisplay({
<ul className="space-y-0 flex flex-col-reverse"> <ul className="space-y-0 flex flex-col-reverse">
{renderedHistory.map((item, index) => ( {renderedHistory.map((item, index) => (
<li key={index}> <li key={index}>
<HoverCard> <Collapsible>
<HoverCardTrigger <div
className={classNames( className={classNames(
"flex items-center justify-between space-x-2 p-2", "flex items-center justify-between space-x-2 w-full pr-2",
"border-b cursor-pointer", "border-b cursor-pointer",
{ {
" hover:bg-black hover:text-white": !item.isActive, " hover:bg-black hover:text-white": !item.isActive,
"bg-slate-500 text-white": item.isActive, "bg-slate-500 text-white": item.isActive,
} }
)} )}
>
<div
className="flex justify-between truncate flex-1 p-2"
onClick={() => onClick={() =>
shouldDisableReverts shouldDisableReverts
? toast.error( ? toast.error(
@ -48,20 +54,30 @@ export default function HistoryDisplay({
: revertToVersion(index) : revertToVersion(index)
} }
> >
{" "}
<div className="flex gap-x-1 truncate"> <div className="flex gap-x-1 truncate">
<h2 className="text-sm truncate">{item.summary}</h2> <h2 className="text-sm truncate">{item.summary}</h2>
{item.parentVersion !== null && ( {item.parentVersion !== null && (
<h2 className="text-sm">(parent: {item.parentVersion})</h2> <h2 className="text-sm">
(parent: {item.parentVersion})
</h2>
)} )}
</div> </div>
<h2 className="text-sm">v{index + 1}</h2> <h2 className="text-sm">v{index + 1}</h2>
</HoverCardTrigger> </div>
<HoverCardContent> <CollapsibleTrigger asChild>
<div>{item.summary}</div> <Button variant="ghost" size="sm" className="h-6">
<CaretSortIcon className="h-4 w-4" />
<span className="sr-only">Toggle</span>
</Button>
</CollapsibleTrigger>
</div>
<CollapsibleContent className="w-full bg-slate-300 p-2">
<div>Full prompt: {item.summary}</div>
<div className="flex justify-end">
<Badge>{item.type}</Badge> <Badge>{item.type}</Badge>
</HoverCardContent> </div>
</HoverCard> </CollapsibleContent>
</Collapsible>
</li> </li>
))} ))}
</ul> </ul>

View File

@ -0,0 +1,9 @@
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
const Collapsible = CollapsiblePrimitive.Root
const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger
const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent
export { Collapsible, CollapsibleTrigger, CollapsibleContent }

View File

@ -804,7 +804,7 @@
"@radix-ui/react-use-previous" "1.0.1" "@radix-ui/react-use-previous" "1.0.1"
"@radix-ui/react-use-size" "1.0.1" "@radix-ui/react-use-size" "1.0.1"
"@radix-ui/react-collapsible@1.0.3": "@radix-ui/react-collapsible@1.0.3", "@radix-ui/react-collapsible@^1.0.3":
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/@radix-ui/react-collapsible/-/react-collapsible-1.0.3.tgz#df0e22e7a025439f13f62d4e4a9e92c4a0df5b81" resolved "https://registry.yarnpkg.com/@radix-ui/react-collapsible/-/react-collapsible-1.0.3.tgz#df0e22e7a025439f13f62d4e4a9e92c4a0df5b81"
integrity sha512-UBmVDkmR6IvDsloHVN+3rtx4Mi5TFvylYXpluuv0f37dtaz3H99bp8No0LGXRigVpl3UAT4l9j6bIchh42S/Gg== integrity sha512-UBmVDkmR6IvDsloHVN+3rtx4Mi5TFvylYXpluuv0f37dtaz3H99bp8No0LGXRigVpl3UAT4l9j6bIchh42S/Gg==