From 3fea23d546c99495924c64a2802fc0210f7a469f Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Thu, 29 Aug 2024 17:59:17 +0100 Subject: [PATCH] Fix for the resizable panels on the run page --- .../route.tsx | 128 ++++++++++++------ 1 file changed, 87 insertions(+), 41 deletions(-) diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam/route.tsx index f20ddbc07..e0212b1a5 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam/route.tsx @@ -9,8 +9,8 @@ import { StopCircleIcon, } from "@heroicons/react/20/solid"; import type { Location } from "@remix-run/react"; -import { useLoaderData, useParams } from "@remix-run/react"; -import { LoaderFunctionArgs, SerializeFrom, json } from "@remix-run/server-runtime"; +import { useParams } from "@remix-run/react"; +import { LoaderFunctionArgs } from "@remix-run/server-runtime"; import { Virtualizer } from "@tanstack/react-virtual"; import { formatDurationMilliseconds, @@ -21,6 +21,7 @@ import { RuntimeEnvironmentType } from "@trigger.dev/database"; import { motion } from "framer-motion"; import { useCallback, useEffect, useRef, useState } from "react"; import { useHotkeys } from "react-hotkeys-hook"; +import { UseDataFunctionReturn, typedjson, useTypedLoaderData } from "remix-typedjson"; import { ShowParentIcon, ShowParentIconSelected } from "~/assets/icons/ShowParentIcon"; import tileBgPath from "~/assets/images/error-banner-tile@2x.png"; import { AdminDebugTooltip } from "~/components/admin/debugTooltip"; @@ -64,7 +65,7 @@ import { Shortcut, useShortcutKeys } from "~/hooks/useShortcutKeys"; import { Trace, TraceEvent, useTrace } from "~/hooks/useTrace"; import { useUser } from "~/hooks/useUser"; import { RunPresenter } from "~/presenters/v3/RunPresenter.server"; -import { getResizableRunSettings, setResizableRunSettings } from "~/services/resizablePanel"; +import { getResizableSnapshot } from "~/services/resizablePanel.server"; import { requireUserId } from "~/services/session.server"; import { cn } from "~/utils/cn"; import { lerp } from "~/utils/lerp"; @@ -77,7 +78,36 @@ import { } from "~/utils/pathBuilder"; import { useCurrentPlan } from "../_app.orgs.$organizationSlug/route"; import { SpanView } from "../resources.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam.spans.$spanParam/route"; -import { Spinner } from "~/components/primitives/Spinner"; + +const resizableSettings = { + parent: { + autosaveId: "panel-run-parent", + handleId: "parent-handle", + main: { + id: "run", + min: "100px" as const, + }, + inspector: { + id: "inspector", + default: "430px" as const, + min: "50px" as const, + }, + }, + tree: { + autosaveId: "panel-run-tree", + handleId: "tree-handle", + tree: { + id: "tree", + default: "50%" as const, + min: "50px" as const, + }, + timeline: { + id: "timeline", + default: "50%" as const, + min: "50px" as const, + }, + }, +}; export const loader = async ({ request, params }: LoaderFunctionArgs) => { const userId = await requireUserId(request); @@ -92,15 +122,19 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => { }); //resizable settings - const resizeSettings = await getResizableRunSettings(request); + const parent = await getResizableSnapshot(request, resizableSettings.parent.autosaveId); + const tree = await getResizableSnapshot(request, resizableSettings.tree.autosaveId); - return json({ + return typedjson({ run: result.run, - resizeSettings, + resizable: { + parent, + tree, + }, }); }; -type LoaderData = SerializeFrom; +type LoaderData = UseDataFunctionReturn; function getSpanId(location: Location): string | undefined { const search = new URLSearchParams(location.search); @@ -108,7 +142,7 @@ function getSpanId(location: Location): string | undefined { } export default function Page() { - const { run, resizeSettings } = useLoaderData(); + const { run, resizable } = useTypedLoaderData(); const appOrigin = useAppOrigin(); const { isUpToDate, trace } = useTrace({ origin: appOrigin, @@ -206,20 +240,20 @@ export default function Page() { {trace ? ( - + ) : ( - + )} ); } -type TraceData = Pick & { +type TraceData = Pick & { trace: Trace | undefined; }; -function TraceView({ run, trace, resizeSettings }: TraceData) { +function TraceView({ run, trace, resizable }: TraceData) { const { location, replaceSearchParam } = useReplaceLocation(); const selectedSpanId = getSpanId(location); @@ -236,15 +270,14 @@ function TraceView({ run, trace, resizeSettings }: TraceData) { return (
{ - if (layout.length !== 2) return; - if (!selectedSpanId) return; - setResizableRunSettings(document, layout); - }} > - + - + {selectedSpanId && ( - + { - if (layout.length !== 2) return; - setResizableRunSettings(document, layout); - }} > - +
{daysSinceCompleted === undefined ? ( @@ -354,8 +392,13 @@ function NoLogsView({ run, resizeSettings }: TraceData) { )}
- - + +
@@ -439,15 +482,14 @@ function TasksTreeView({ />
- { - if (layout.length !== 2) return; - setResizableRunSettings(document, layout); - }} - > + {/* Tree list */} - +
{parentRunFriendlyId ? ( @@ -549,9 +591,13 @@ function TasksTreeView({ />
- + {/* Timeline */} - +