Get the example data for the test page
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import { User } from ".prisma/client";
|
||||
import { PrismaClient, prisma } from "~/db.server";
|
||||
import { env } from "~/env.server";
|
||||
import { Job } from "~/models/job.server";
|
||||
import { Organization } from "~/models/organization.server";
|
||||
import { Project } from "~/models/project.server";
|
||||
import { apiAuthenticationRepository } from "~/services/externalApis/apiAuthenticationRepository.server";
|
||||
import {
|
||||
ConnectionMetadataSchema,
|
||||
OAuthClientSchema,
|
||||
} from "~/services/externalApis/types";
|
||||
import { getSecretStore } from "~/services/secrets/secretStore.server";
|
||||
|
||||
export class TestJobPresenter {
|
||||
#prismaClient: PrismaClient;
|
||||
|
||||
constructor(prismaClient: PrismaClient = prisma) {
|
||||
this.#prismaClient = prismaClient;
|
||||
}
|
||||
|
||||
public async call({
|
||||
userId,
|
||||
organizationSlug,
|
||||
projectSlug,
|
||||
jobSlug,
|
||||
}: {
|
||||
userId: User["id"];
|
||||
organizationSlug: Organization["slug"];
|
||||
projectSlug: Project["slug"];
|
||||
jobSlug: Job["slug"];
|
||||
}) {
|
||||
const job = await this.#prismaClient.job.findFirst({
|
||||
select: {
|
||||
aliases: {
|
||||
select: {
|
||||
version: {
|
||||
select: {
|
||||
version: true,
|
||||
examples: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
icon: true,
|
||||
payload: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
environment: {
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
orgMember: {
|
||||
select: {
|
||||
userId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
where: {
|
||||
name: "latest",
|
||||
},
|
||||
},
|
||||
},
|
||||
where: {
|
||||
organization: {
|
||||
slug: organizationSlug,
|
||||
members: {
|
||||
some: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
slug: jobSlug,
|
||||
},
|
||||
});
|
||||
|
||||
if (!job) {
|
||||
throw new Error("Job not found");
|
||||
}
|
||||
|
||||
return {
|
||||
environments: job.aliases.map((alias) => ({
|
||||
id: alias.environment.id,
|
||||
type: alias.environment.type,
|
||||
userId: alias.environment.orgMember?.userId,
|
||||
examples: alias.version.examples,
|
||||
})),
|
||||
};
|
||||
}
|
||||
}
|
||||
+39
-1
@@ -1,6 +1,28 @@
|
||||
import { LoaderArgs } from "@remix-run/server-runtime";
|
||||
import { typedjson, useTypedLoaderData } from "remix-typedjson";
|
||||
import { JSONEditor } from "~/components/code/JSONEditor";
|
||||
import { useOrganization } from "~/hooks/useOrganizations";
|
||||
import { useProject } from "~/hooks/useProject";
|
||||
import { TestJobPresenter } from "~/presenters/TestJobPresenter.server";
|
||||
import { requireUserId } from "~/services/session.server";
|
||||
import { Handle } from "~/utils/handle";
|
||||
import { JobParamsSchema, ProjectParamSchema } from "~/utils/pathBuilder";
|
||||
|
||||
export const loader = async ({ request, params }: LoaderArgs) => {
|
||||
const userId = await requireUserId(request);
|
||||
const { organizationSlug, projectParam, jobParam } =
|
||||
JobParamsSchema.parse(params);
|
||||
|
||||
const presenter = new TestJobPresenter();
|
||||
const { environments } = await presenter.call({
|
||||
userId,
|
||||
organizationSlug,
|
||||
projectSlug: projectParam,
|
||||
jobSlug: jobParam,
|
||||
});
|
||||
|
||||
return typedjson({ environments });
|
||||
};
|
||||
|
||||
export const handle: Handle = {
|
||||
breadcrumb: {
|
||||
@@ -8,9 +30,25 @@ export const handle: Handle = {
|
||||
},
|
||||
};
|
||||
|
||||
//create an Action
|
||||
//save the chosen environment to a cookie (for that user), use it to default the env dropdown
|
||||
//create a TestEventService class
|
||||
// 1. create an EventRecord
|
||||
// 2. Then use CreateRun. Update it so call can accept an optional transaction (that it uses)
|
||||
// 3. It should return the run, so we can redirect to the run page
|
||||
|
||||
export default function Page() {
|
||||
const { environments } = useTypedLoaderData<typeof loader>();
|
||||
const organization = useOrganization();
|
||||
const project = useProject();
|
||||
|
||||
return <div>Test page</div>;
|
||||
console.log(environments);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* //todo add examples dropdown */}
|
||||
<JSONEditor content={"{}"} readOnly={false} basicSetup />
|
||||
{/* //todo add environments as a dropdown next to the test button */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user