Skip to content

Commit fb4f216

Browse files
committed
fix(fe): redirect engine users to connect page when there's no actors
1 parent a2e4140 commit fb4f216

File tree

2 files changed

+29
-18
lines changed
  • frontend/src/routes/_context
    • _cloud/orgs.$organization/projects.$project/ns.$namespace
    • _engine/ns.$namespace

2 files changed

+29
-18
lines changed

frontend/src/routes/_context/_cloud/orgs.$organization/projects.$project/ns.$namespace/index.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import type { QueryClient } from "@tanstack/react-query";
12
import {
23
CatchBoundary,
34
createFileRoute,
4-
type InferAllContext,
55
notFound,
66
redirect,
77
} from "@tanstack/react-router";
88
import { Actors } from "@/app/actors";
99
import { BuildPrefiller } from "@/app/build-prefiller";
10-
import { useDataProvider } from "@/components/actors";
10+
import {
11+
useDataProvider,
12+
type useEngineCompatDataProvider,
13+
} from "@/components/actors";
1114

1215
export const Route = createFileRoute(
1316
"/_context/_cloud/orgs/$organization/projects/$project/ns/$namespace/",
@@ -18,15 +21,18 @@ export const Route = createFileRoute(
1821
throw notFound();
1922
}
2023

21-
const isVisible = await shouldDisplayActors(context);
24+
const shouldDisplay = await shouldDisplayActors(context);
2225

23-
if (!isVisible) {
26+
if (!shouldDisplay) {
2427
throw redirect({ from: Route.to, replace: true, to: "./connect" });
2528
}
2629
},
2730
});
2831

29-
async function shouldDisplayActors(context: InferAllContext<typeof Route>) {
32+
export async function shouldDisplayActors(context: {
33+
queryClient: QueryClient;
34+
dataProvider: ReturnType<typeof useEngineCompatDataProvider>;
35+
}) {
3036
try {
3137
const infiniteBuilds = await context.queryClient.fetchInfiniteQuery(
3238
context.dataProvider.buildsQueryOptions(),
@@ -65,16 +71,14 @@ export function RouteComponent() {
6571
}
6672

6773
return (
68-
<>
69-
<CatchBoundary getResetKey={() => actorId ?? "no-actor-id"}>
70-
<Actors actorId={actorId} />
71-
<CatchBoundary
72-
getResetKey={() => n?.join(",") ?? "no-build-name"}
73-
errorComponent={() => null}
74-
>
75-
{!n ? <BuildPrefiller /> : null}
76-
</CatchBoundary>
74+
<CatchBoundary getResetKey={() => actorId ?? "no-actor-id"}>
75+
<Actors actorId={actorId} />
76+
<CatchBoundary
77+
getResetKey={() => n?.join(",") ?? "no-build-name"}
78+
errorComponent={() => null}
79+
>
80+
{!n ? <BuildPrefiller /> : null}
7781
</CatchBoundary>
78-
</>
82+
</CatchBoundary>
7983
);
8084
}
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
import {
22
CatchBoundary,
33
createFileRoute,
4+
redirect,
45
useSearch,
56
} from "@tanstack/react-router";
67
import { Actors } from "@/app/actors";
78
import { BuildPrefiller } from "@/app/build-prefiller";
9+
import { shouldDisplayActors } from "../../_cloud/orgs.$organization/projects.$project/ns.$namespace/index";
810

911
export const Route = createFileRoute("/_context/_engine/ns/$namespace/")({
1012
component: RouteComponent,
1113
beforeLoad: async ({ context }) => {
1214
if (context.__type !== "engine") {
1315
throw new Error("Invalid context type for this route");
1416
}
17+
18+
const shouldDisplay = await shouldDisplayActors(context);
19+
20+
if (!shouldDisplay) {
21+
throw redirect({ from: Route.to, replace: true, to: "./connect" });
22+
}
1523
},
1624
});
1725

1826
export function RouteComponent() {
1927
const { actorId, n } = useSearch({ from: "/_context" });
2028

2129
return (
22-
<>
30+
<CatchBoundary getResetKey={() => actorId ?? "no-actor-id"}>
2331
<Actors actorId={actorId} />
24-
2532
<CatchBoundary
2633
getResetKey={() => n?.join(",") ?? "no-build-name"}
2734
errorComponent={() => null}
2835
>
2936
{!n ? <BuildPrefiller /> : null}
3037
</CatchBoundary>
31-
</>
38+
</CatchBoundary>
3239
);
3340
}

0 commit comments

Comments
 (0)