From fb4f216342e6de4fe1ab72ba71c9b919defc5fc7 Mon Sep 17 00:00:00 2001 From: Kacper Wojciechowski <39823706+jog1t@users.noreply.github.com> Date: Sun, 26 Oct 2025 23:48:38 +0100 Subject: [PATCH] fix(fe): redirect engine users to connect page when there's no actors --- .../projects.$project/ns.$namespace/index.tsx | 34 +++++++++++-------- .../_context/_engine/ns.$namespace/index.tsx | 13 +++++-- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/frontend/src/routes/_context/_cloud/orgs.$organization/projects.$project/ns.$namespace/index.tsx b/frontend/src/routes/_context/_cloud/orgs.$organization/projects.$project/ns.$namespace/index.tsx index f601ee95ec..e9f5e6a0c3 100644 --- a/frontend/src/routes/_context/_cloud/orgs.$organization/projects.$project/ns.$namespace/index.tsx +++ b/frontend/src/routes/_context/_cloud/orgs.$organization/projects.$project/ns.$namespace/index.tsx @@ -1,13 +1,16 @@ +import type { QueryClient } from "@tanstack/react-query"; import { CatchBoundary, createFileRoute, - type InferAllContext, notFound, redirect, } from "@tanstack/react-router"; import { Actors } from "@/app/actors"; import { BuildPrefiller } from "@/app/build-prefiller"; -import { useDataProvider } from "@/components/actors"; +import { + useDataProvider, + type useEngineCompatDataProvider, +} from "@/components/actors"; export const Route = createFileRoute( "/_context/_cloud/orgs/$organization/projects/$project/ns/$namespace/", @@ -18,15 +21,18 @@ export const Route = createFileRoute( throw notFound(); } - const isVisible = await shouldDisplayActors(context); + const shouldDisplay = await shouldDisplayActors(context); - if (!isVisible) { + if (!shouldDisplay) { throw redirect({ from: Route.to, replace: true, to: "./connect" }); } }, }); -async function shouldDisplayActors(context: InferAllContext) { +export async function shouldDisplayActors(context: { + queryClient: QueryClient; + dataProvider: ReturnType; +}) { try { const infiniteBuilds = await context.queryClient.fetchInfiniteQuery( context.dataProvider.buildsQueryOptions(), @@ -65,16 +71,14 @@ export function RouteComponent() { } return ( - <> - actorId ?? "no-actor-id"}> - - n?.join(",") ?? "no-build-name"} - errorComponent={() => null} - > - {!n ? : null} - + actorId ?? "no-actor-id"}> + + n?.join(",") ?? "no-build-name"} + errorComponent={() => null} + > + {!n ? : null} - + ); } diff --git a/frontend/src/routes/_context/_engine/ns.$namespace/index.tsx b/frontend/src/routes/_context/_engine/ns.$namespace/index.tsx index 14beeb2739..965e8e3213 100644 --- a/frontend/src/routes/_context/_engine/ns.$namespace/index.tsx +++ b/frontend/src/routes/_context/_engine/ns.$namespace/index.tsx @@ -1,10 +1,12 @@ import { CatchBoundary, createFileRoute, + redirect, useSearch, } from "@tanstack/react-router"; import { Actors } from "@/app/actors"; import { BuildPrefiller } from "@/app/build-prefiller"; +import { shouldDisplayActors } from "../../_cloud/orgs.$organization/projects.$project/ns.$namespace/index"; export const Route = createFileRoute("/_context/_engine/ns/$namespace/")({ component: RouteComponent, @@ -12,6 +14,12 @@ export const Route = createFileRoute("/_context/_engine/ns/$namespace/")({ if (context.__type !== "engine") { throw new Error("Invalid context type for this route"); } + + const shouldDisplay = await shouldDisplayActors(context); + + if (!shouldDisplay) { + throw redirect({ from: Route.to, replace: true, to: "./connect" }); + } }, }); @@ -19,15 +27,14 @@ export function RouteComponent() { const { actorId, n } = useSearch({ from: "/_context" }); return ( - <> + actorId ?? "no-actor-id"}> - n?.join(",") ?? "no-build-name"} errorComponent={() => null} > {!n ? : null} - + ); }