|
| 1 | +import { useLocation } from "@remix-run/react"; |
| 2 | +import { type LoaderFunctionArgs } from "@remix-run/server-runtime"; |
| 3 | +import { typedjson, useTypedLoaderData } from "remix-typedjson"; |
| 4 | +import { z } from "zod"; |
| 5 | +import { ExitIcon } from "~/assets/icons/ExitIcon"; |
| 6 | +import { LinkButton } from "~/components/primitives/Buttons"; |
| 7 | +import { Header2, Header3 } from "~/components/primitives/Headers"; |
| 8 | +import { useEnvironment } from "~/hooks/useEnvironment"; |
| 9 | +import { useOrganization } from "~/hooks/useOrganizations"; |
| 10 | +import { useProject } from "~/hooks/useProject"; |
| 11 | +import { findProjectBySlug } from "~/models/project.server"; |
| 12 | +import { findEnvironmentBySlug } from "~/models/runtimeEnvironment.server"; |
| 13 | +import { WaitpointPresenter } from "~/presenters/v3/WaitpointPresenter.server"; |
| 14 | +import { requireUserId } from "~/services/session.server"; |
| 15 | +import { cn } from "~/utils/cn"; |
| 16 | +import { |
| 17 | + EnvironmentParamSchema, |
| 18 | + v3WaitpointHttpCallbacksPath, |
| 19 | + v3WaitpointTokensPath, |
| 20 | +} from "~/utils/pathBuilder"; |
| 21 | +import { CompleteWaitpointForm } from "../resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.waitpoints.$waitpointFriendlyId.complete/route"; |
| 22 | +import { WaitpointDetailTable } from "~/components/runs/v3/WaitpointDetails"; |
| 23 | +import { TaskRunsTable } from "~/components/runs/v3/TaskRunsTable"; |
| 24 | +import { InfoIconTooltip } from "~/components/primitives/Tooltip"; |
| 25 | +import { logger } from "~/services/logger.server"; |
| 26 | + |
| 27 | +const Params = EnvironmentParamSchema.extend({ |
| 28 | + waitpointParam: z.string(), |
| 29 | +}); |
| 30 | + |
| 31 | +export const loader = async ({ request, params }: LoaderFunctionArgs) => { |
| 32 | + const userId = await requireUserId(request); |
| 33 | + const { organizationSlug, projectParam, envParam, waitpointParam } = Params.parse(params); |
| 34 | + |
| 35 | + const project = await findProjectBySlug(organizationSlug, projectParam, userId); |
| 36 | + if (!project) { |
| 37 | + throw new Response(undefined, { |
| 38 | + status: 404, |
| 39 | + statusText: "Project not found", |
| 40 | + }); |
| 41 | + } |
| 42 | + |
| 43 | + const environment = await findEnvironmentBySlug(project.id, envParam, userId); |
| 44 | + if (!environment) { |
| 45 | + throw new Response(undefined, { |
| 46 | + status: 404, |
| 47 | + statusText: "Environment not found", |
| 48 | + }); |
| 49 | + } |
| 50 | + |
| 51 | + try { |
| 52 | + const presenter = new WaitpointPresenter(); |
| 53 | + const result = await presenter.call({ |
| 54 | + friendlyId: waitpointParam, |
| 55 | + environmentId: environment.id, |
| 56 | + projectId: project.id, |
| 57 | + }); |
| 58 | + |
| 59 | + if (!result) { |
| 60 | + throw new Response(undefined, { |
| 61 | + status: 404, |
| 62 | + statusText: "Waitpoint not found", |
| 63 | + }); |
| 64 | + } |
| 65 | + |
| 66 | + return typedjson({ waitpoint: result }); |
| 67 | + } catch (error) { |
| 68 | + logger.error("Error loading waitpoint for inspector", { |
| 69 | + error, |
| 70 | + organizationSlug, |
| 71 | + projectParam, |
| 72 | + envParam, |
| 73 | + waitpointParam, |
| 74 | + }); |
| 75 | + throw new Response(undefined, { |
| 76 | + status: 400, |
| 77 | + statusText: "Something went wrong, if this problem persists please contact support.", |
| 78 | + }); |
| 79 | + } |
| 80 | +}; |
| 81 | + |
| 82 | +export default function Page() { |
| 83 | + const { waitpoint } = useTypedLoaderData<typeof loader>(); |
| 84 | + |
| 85 | + const location = useLocation(); |
| 86 | + |
| 87 | + const organization = useOrganization(); |
| 88 | + const project = useProject(); |
| 89 | + const environment = useEnvironment(); |
| 90 | + |
| 91 | + return ( |
| 92 | + <div |
| 93 | + className={cn( |
| 94 | + cn( |
| 95 | + "grid h-full max-h-full grid-rows-[2.5rem_1fr] overflow-hidden bg-background-bright", |
| 96 | + waitpoint.status === "WAITING" && "grid-rows-[2.5rem_1fr_auto]" |
| 97 | + ) |
| 98 | + )} |
| 99 | + > |
| 100 | + <div className="mx-3 flex items-center justify-between gap-2 border-b border-grid-dimmed"> |
| 101 | + <Header2 className={cn("whitespace-nowrap")}>{waitpoint.id}</Header2> |
| 102 | + <LinkButton |
| 103 | + to={`${v3WaitpointHttpCallbacksPath(organization, project, environment)}${ |
| 104 | + location.search |
| 105 | + }`} |
| 106 | + variant="minimal/small" |
| 107 | + TrailingIcon={ExitIcon} |
| 108 | + shortcut={{ key: "esc" }} |
| 109 | + shortcutPosition="before-trailing-icon" |
| 110 | + className="pl-1" |
| 111 | + /> |
| 112 | + </div> |
| 113 | + <div className="overflow-y-auto pt-3 scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600"> |
| 114 | + <div className="px-3"> |
| 115 | + <WaitpointDetailTable waitpoint={waitpoint} /> |
| 116 | + </div> |
| 117 | + <div className="flex flex-col gap-1 pt-6"> |
| 118 | + <div className="mb-1 flex items-center gap-1 pl-3"> |
| 119 | + <Header3>Related runs</Header3> |
| 120 | + <InfoIconTooltip content="These runs have been blocked by this waitpoint." /> |
| 121 | + </div> |
| 122 | + <TaskRunsTable |
| 123 | + total={waitpoint.connectedRuns.length} |
| 124 | + hasFilters={false} |
| 125 | + filters={{ |
| 126 | + tasks: [], |
| 127 | + versions: [], |
| 128 | + statuses: [], |
| 129 | + environments: [], |
| 130 | + from: undefined, |
| 131 | + to: undefined, |
| 132 | + }} |
| 133 | + runs={waitpoint.connectedRuns} |
| 134 | + isLoading={false} |
| 135 | + variant="bright" |
| 136 | + /> |
| 137 | + </div> |
| 138 | + </div> |
| 139 | + {waitpoint.status === "WAITING" && ( |
| 140 | + <div> |
| 141 | + <CompleteWaitpointForm waitpoint={waitpoint} /> |
| 142 | + </div> |
| 143 | + )} |
| 144 | + </div> |
| 145 | + ); |
| 146 | +} |
0 commit comments