Skip to content

Commit ca59b6b

Browse files
committed
Fix requested changes
1 parent 62e3bb9 commit ca59b6b

5 files changed

Lines changed: 69 additions & 125 deletions

File tree

apps/webapp/app/presenters/IntegrationClientJobsPresenter.server.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

apps/webapp/app/presenters/JobListPresenter.server.ts

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
DisplayPropertySchema,
44
EventSpecificationSchema,
55
} from "@trigger.dev/internal";
6-
import { PrismaClient, prisma } from "~/db.server";
6+
import { PrismaClient, Prisma, prisma } from "~/db.server";
7+
import { Organization } from "~/models/organization.server";
78
import { Project } from "~/models/project.server";
89
import { User } from "~/models/user.server";
910
import { z } from "zod";
@@ -17,81 +18,91 @@ export class JobListPresenter {
1718

1819
public async call({
1920
userId,
20-
slug,
21-
}: Pick<Project, "slug"> & {
21+
projectSlug,
22+
organizationSlug,
23+
integrationSlug,
24+
}: {
2225
userId: User["id"];
26+
projectSlug: Project["slug"];
27+
organizationSlug?: Organization["slug"];
28+
integrationSlug?: string;
2329
}) {
24-
const project = await this.#prismaClient.project.findFirst({
30+
const orgWhere: Prisma.JobWhereInput["organization"] = organizationSlug
31+
? { slug: organizationSlug, members: { some: { userId } } }
32+
: { members: { some: { userId } } };
33+
34+
const integrationsWhere: Prisma.JobWhereInput["integrations"] =
35+
integrationSlug
36+
? { some: { integration: { slug: integrationSlug } } }
37+
: {};
38+
39+
const jobs = await this.#prismaClient.job.findMany({
2540
select: {
26-
jobs: {
41+
id: true,
42+
slug: true,
43+
title: true,
44+
aliases: {
2745
select: {
28-
id: true,
29-
slug: true,
30-
title: true,
31-
aliases: {
46+
version: {
3247
select: {
33-
version: {
48+
version: true,
49+
eventSpecification: true,
50+
properties: true,
51+
runs: {
3452
select: {
35-
version: true,
36-
eventSpecification: true,
37-
properties: true,
38-
runs: {
39-
select: {
40-
createdAt: true,
41-
status: true,
42-
},
43-
take: 1,
44-
orderBy: [{ createdAt: "desc" }],
45-
},
46-
integrations: {
47-
select: {
48-
key: true,
49-
integration: {
50-
select: {
51-
slug: true,
52-
definition: true,
53-
setupStatus: true,
54-
},
55-
},
56-
},
57-
},
53+
createdAt: true,
54+
status: true,
5855
},
56+
take: 1,
57+
orderBy: [{ createdAt: "desc" }],
5958
},
60-
environment: {
59+
integrations: {
6160
select: {
62-
type: true,
63-
orgMember: {
61+
key: true,
62+
integration: {
6463
select: {
65-
userId: true,
64+
slug: true,
65+
definition: true,
66+
setupStatus: true,
6667
},
6768
},
6869
},
6970
},
7071
},
71-
where: {
72-
name: "latest",
73-
},
7472
},
75-
dynamicTriggers: {
73+
environment: {
7674
select: {
7775
type: true,
76+
orgMember: {
77+
select: {
78+
userId: true,
79+
},
80+
},
7881
},
7982
},
8083
},
8184
where: {
82-
internal: false,
85+
name: "latest",
8386
},
84-
orderBy: [{ title: "asc" }],
8587
},
88+
dynamicTriggers: {
89+
select: {
90+
type: true,
91+
},
92+
},
93+
},
94+
where: {
95+
internal: false,
96+
organization: orgWhere,
97+
project: {
98+
slug: projectSlug,
99+
},
100+
integrations: integrationsWhere,
86101
},
87-
where: { slug, organization: { members: { some: { userId } } } },
102+
orderBy: [{ title: "asc" }],
88103
});
89104

90-
if (!project) {
91-
return [];
92-
}
93-
94-
return project.jobs
105+
return jobs
95106
.map((job) => {
96107
//the best alias to select:
97108
// 1. Logged-in user dev

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam._index/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const loader = async ({ request, params }: LoaderArgs) => {
3939

4040
try {
4141
const presenter = new JobListPresenter();
42-
const jobs = await presenter.call({ userId, slug: projectParam });
42+
const jobs = await presenter.call({ userId, projectSlug: projectParam });
4343

4444
return typedjson({
4545
jobs,

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.integrations_.$clientParam._index/route.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { Help, HelpContent, HelpTrigger } from "~/components/primitives/Help";
1010
import { Input } from "~/components/primitives/Input";
1111
import { useFilterJobs } from "~/hooks/useFilterJobs";
1212
import { useIntegrationClient } from "~/hooks/useIntegrationClient";
13-
import { IntegrationClientJobsPresenter } from "~/presenters/IntegrationClientJobsPresenter.server";
1413
import { JobListPresenter } from "~/presenters/JobListPresenter.server";
1514
import { requireUserId } from "~/services/session.server";
1615
import { cn } from "~/utils/cn";
@@ -26,25 +25,16 @@ export const loader = async ({ request, params }: LoaderArgs) => {
2625
const { organizationSlug, projectParam, clientParam } =
2726
IntegrationClientParamSchema.parse(params);
2827

29-
const integrationPresenter = new IntegrationClientJobsPresenter();
3028
const jobsPresenter = new JobListPresenter();
3129

32-
const [integrationJobs, userJobs] = await Promise.all([
33-
integrationPresenter.call({
34-
userId: userId,
35-
organizationSlug,
36-
projectSlug: projectParam,
37-
clientSlug: clientParam,
38-
}),
39-
jobsPresenter.call({ userId, slug: projectParam }),
40-
]);
30+
const jobs = await jobsPresenter.call({
31+
userId,
32+
projectSlug: projectParam,
33+
organizationSlug,
34+
integrationSlug: clientParam,
35+
});
4136

42-
const integrationJobIds = integrationJobs.jobs.map((job) => job.id);
43-
const filteredJobs = userJobs.filter((job) =>
44-
integrationJobIds.includes(job.id)
45-
);
46-
47-
return typedjson({ jobs: filteredJobs });
37+
return typedjson({ jobs });
4838
};
4939

5040
export const handle: Handle = {

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.jobs.$jobParam/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const loader = async ({ request, params }: LoaderArgs) => {
5050
projectSlug: projectParam,
5151
organizationSlug,
5252
}),
53-
jobsPresenter.call({ userId, slug: projectParam }),
53+
jobsPresenter.call({ userId, projectSlug: projectParam }),
5454
]);
5555

5656
if (job === null) {

0 commit comments

Comments
 (0)