From 15087f6bcdd0705aa3ff4071de8bb96270f5a5b5 Mon Sep 17 00:00:00 2001 From: Kyle Corbitt Date: Mon, 26 Jun 2023 11:05:49 -0700 Subject: [PATCH] hiding and reordering scenarios --- .../OutputsTable/ScenarioEditor.tsx | 187 +++++++++++++----- src/components/OutputsTable/VariantHeader.tsx | 6 +- src/components/OutputsTable/index.tsx | 5 +- .../api/routers/promptVariants.router.ts | 10 +- src/server/api/routers/scenarios.router.ts | 76 +++++++ 5 files changed, 219 insertions(+), 65 deletions(-) diff --git a/src/components/OutputsTable/ScenarioEditor.tsx b/src/components/OutputsTable/ScenarioEditor.tsx index 6e0342b..febd102 100644 --- a/src/components/OutputsTable/ScenarioEditor.tsx +++ b/src/components/OutputsTable/ScenarioEditor.tsx @@ -1,3 +1,4 @@ +import { type DragEvent } from "react"; import { api } from "~/utils/api"; import { isEqual } from "lodash"; import { type Scenario } from "./types"; @@ -5,12 +6,21 @@ import { useExperiment, useHandledAsyncCallback } from "~/utils/hooks"; import { useState } from "react"; import ResizeTextarea from "react-textarea-autosize"; -import { Box, Button, Flex, HStack, Stack, Textarea } from "@chakra-ui/react"; +import { Box, Button, Flex, HStack, Icon, Stack, Textarea, Tooltip } from "@chakra-ui/react"; import { cellPadding } from "../constants"; +import { BsX } from "react-icons/bs"; +import { RiDraggable } from "react-icons/ri"; -export default function ScenarioEditor({ scenario }: { scenario: Scenario }) { +export default function ScenarioEditor({ + scenario, + hovered, +}: { + scenario: Scenario; + hovered: boolean; +}) { const savedValues = scenario.variableValues as Record; const utils = api.useContext(); + const [isDragTarget, setIsDragTarget] = useState(false); const [values, setValues] = useState>(savedValues); @@ -30,60 +40,133 @@ export default function ScenarioEditor({ scenario }: { scenario: Scenario }) { await utils.scenarios.list.invalidate(); }, [mutation, values]); + const hideMutation = api.scenarios.hide.useMutation(); + const [onHide] = useHandledAsyncCallback(async () => { + await hideMutation.mutateAsync({ + id: scenario.id, + }); + await utils.scenarios.list.invalidate(); + }, [hideMutation, scenario.id]); + + const reorderMutation = api.scenarios.reorder.useMutation(); + const [onReorder] = useHandledAsyncCallback( + async (e: DragEvent) => { + e.preventDefault(); + setIsDragTarget(false); + const draggedId = e.dataTransfer.getData("text/plain"); + const droppedId = scenario.id; + if (!draggedId || !droppedId || draggedId === droppedId) return; + await reorderMutation.mutateAsync({ + draggedId, + droppedId, + }); + await utils.scenarios.list.invalidate(); + }, + [reorderMutation, scenario.id] + ); + return ( - - {variableLabels.map((key) => { - const value = values[key] ?? ""; - const layoutDirection = value.length > 20 ? "column" : "row"; - return ( - - - {key} - -