Skip to content

Commit c4d0d4d

Browse files
committed
Redesigned the API keys page
1 parent 642b87a commit c4d0d4d

File tree

7 files changed

+398
-158
lines changed

7 files changed

+398
-158
lines changed

apps/webapp/app/components/BlankStatePanels.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,15 +551,15 @@ export function BranchesNoBranches({
551551
);
552552
}
553553

554-
function SwitcherPanel() {
554+
export function SwitcherPanel({ title = "Switch to a deployed environment" }: { title?: string }) {
555555
const organization = useOrganization();
556556
const project = useProject();
557557
const environment = useEnvironment();
558558

559559
return (
560560
<div className="flex items-center rounded-md border border-grid-bright bg-background-bright p-3">
561561
<Paragraph variant="small" className="grow">
562-
Switch to a deployed environment
562+
{title}
563563
</Paragraph>
564564
<EnvironmentSelector
565565
organization={organization}

apps/webapp/app/components/environments/EnvironmentLabel.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ export function EnvironmentIcon({
4848
export function EnvironmentCombo({
4949
environment,
5050
className,
51+
iconClassName,
5152
}: {
5253
environment: Environment;
5354
className?: string;
55+
iconClassName?: string;
5456
}) {
5557
return (
5658
<span className={cn("flex items-center gap-1.5 text-sm text-text-bright", className)}>
57-
<EnvironmentIcon environment={environment} className="size-[1.125rem]" />
59+
<EnvironmentIcon environment={environment} className={cn("size-4.5", iconClassName)} />
5860
<EnvironmentLabel environment={environment} />
5961
</span>
6062
);
Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { type RuntimeEnvironment } from "@trigger.dev/database";
12
import { type PrismaClient, prisma } from "~/db.server";
23
import { type Project } from "~/models/project.server";
34
import { type User } from "~/models/user.server";
4-
import { sortEnvironments } from "~/utils/environmentSort";
55

66
export class ApiKeysPresenter {
77
#prismaClient: PrismaClient;
@@ -10,12 +10,19 @@ export class ApiKeysPresenter {
1010
this.#prismaClient = prismaClient;
1111
}
1212

13-
public async call({ userId, projectSlug }: { userId: User["id"]; projectSlug: Project["slug"] }) {
14-
const environments = await this.#prismaClient.runtimeEnvironment.findMany({
13+
public async call({
14+
userId,
15+
projectSlug,
16+
environmentSlug,
17+
}: {
18+
userId: User["id"];
19+
projectSlug: Project["slug"];
20+
environmentSlug: RuntimeEnvironment["slug"];
21+
}) {
22+
const environment = await this.#prismaClient.runtimeEnvironment.findFirst({
1523
select: {
1624
id: true,
1725
apiKey: true,
18-
pkApiKey: true,
1926
type: true,
2027
slug: true,
2128
updatedAt: true,
@@ -24,13 +31,11 @@ export class ApiKeysPresenter {
2431
userId: true,
2532
},
2633
},
27-
backgroundWorkers: {
34+
branchName: true,
35+
parentEnvironment: {
2836
select: {
29-
version: true,
30-
},
31-
take: 1,
32-
orderBy: {
33-
version: "desc",
37+
id: true,
38+
apiKey: true,
3439
},
3540
},
3641
},
@@ -45,31 +50,25 @@ export class ApiKeysPresenter {
4550
},
4651
},
4752
},
48-
parentEnvironmentId: null,
53+
slug: environmentSlug,
54+
orgMember:
55+
environmentSlug === "dev"
56+
? {
57+
userId,
58+
}
59+
: undefined,
4960
},
5061
});
5162

52-
//filter out environments the only development ones belong to the current user
53-
const filtered = environments.filter((environment) => {
54-
if (environment.type === "DEVELOPMENT") {
55-
return environment.orgMember?.userId === userId;
56-
}
57-
return true;
58-
});
63+
if (!environment) {
64+
throw new Error("Environment not found");
65+
}
5966

6067
return {
61-
environments: sortEnvironments(
62-
filtered.map((environment) => ({
63-
id: environment.id,
64-
apiKey: environment.apiKey,
65-
pkApiKey: environment.pkApiKey,
66-
type: environment.type,
67-
slug: environment.slug,
68-
updatedAt: environment.updatedAt,
69-
latestVersion: environment.backgroundWorkers.at(0)?.version,
70-
}))
71-
),
72-
hasStaging: environments.some((environment) => environment.type === "STAGING"),
68+
environment: {
69+
...environment,
70+
apiKey: environment?.parentEnvironment?.apiKey ?? environment?.apiKey,
71+
},
7372
};
7473
}
7574
}

0 commit comments

Comments
 (0)