Files
triggerdotdev--trigger.dev/apps/webapp/app/presenters/IntegrationClientPresenter.server.ts
James Ritchie 708ebbde14 Features: Disabling and deleting jobs (#381)
* Don’t show the Ready To Run Job prompt if you have an Integration that needs attention

* Don’t highlight the row red or green

* Improvements to the contrast of the app sections and dividers

* Removed the Jobs page title as it’s duped info

* using the new border variable

* Sticky last table cell

* Improved the sticky last table cell

* Make any last cell in a table sticky by adding isSticky to it

* Added a dropdown menu to the menu table cell

* table rows can be marked as disabled by adding disabled

* Using the jobTestPath function for the test path

* tidy up imports

* Removed un-used props

* Removed the green badge variant

* Added a new status badge to the Runs table

* Clicking the gradient clicks the row

* Delete Job triggers a modal popup

* Added a large danger button type

* Added some modal styling and started adding data

* Added more styling and data to the delete job modal

* A table can now be given a full width prop

* Large danger button added to Storybook

* Danger button disabled state looks disabled now

* New active badge component to display in the table and logic for showing the env data

* Style updates to the dialog component

* active and job status badges can now have a small size

* Added a new named icon

* The Job page shows the Job status in the PageInfoRow

* Small badge style update

* Runs table has a sticky right cell

* Created a JobStatusTable component

* Added some placeholder help panel content for disabling a Job

* WIP creating a Settings page

* Added a delete button that triggers the delete modal – just need data hooking up

* Implemented deleting jobs from the dashboard

---------

Co-authored-by: Eric Allam <eallam@icloud.com>
2023-08-24 10:30:00 +01:00

130 lines
3.3 KiB
TypeScript

import { User } from "@trigger.dev/database";
import { PrismaClient, prisma } from "~/db.server";
import { env } from "~/env.server";
import { Organization } from "~/models/organization.server";
import { Project } from "~/models/project.server";
import { integrationCatalog } from "~/services/externalApis/integrationCatalog.server";
import { Help, HelpSchema, OAuthClientSchema } from "~/services/externalApis/types";
import { getSecretStore } from "~/services/secrets/secretStore.server";
export class IntegrationClientPresenter {
#prismaClient: PrismaClient;
constructor(prismaClient: PrismaClient = prisma) {
this.#prismaClient = prismaClient;
}
public async call({
userId,
organizationSlug,
projectSlug,
clientSlug,
}: {
userId: User["id"];
organizationSlug: Organization["slug"];
projectSlug: Project["slug"];
clientSlug: string;
}) {
const integration = await this.#prismaClient.integration.findFirst({
select: {
id: true,
title: true,
slug: true,
authMethod: {
select: {
key: true,
type: true,
name: true,
help: true,
},
},
authSource: true,
definition: {
select: {
id: true,
name: true,
packageName: true,
icon: true,
},
},
connectionType: true,
customClientReference: {
select: {
key: true,
},
},
createdAt: true,
_count: {
select: {
jobIntegrations: {
where: {
job: {
project: {
slug: projectSlug,
},
internal: false,
deletedAt: null,
},
},
},
},
},
},
where: {
organization: {
slug: organizationSlug,
members: {
some: {
userId,
},
},
},
slug: clientSlug,
},
});
if (!integration) {
return undefined;
}
const secretStore = getSecretStore(env.SECRET_STORE, {
prismaClient: this.#prismaClient,
});
let clientId: String | undefined = undefined;
if (integration.customClientReference) {
const clientConfig = await secretStore.getSecret(
OAuthClientSchema,
integration.customClientReference.key
);
clientId = clientConfig?.id;
}
const help = integration.authMethod?.help
? HelpSchema.parse(integration.authMethod?.help)
: undefined;
return {
id: integration.id,
title: integration.title ?? integration.slug,
slug: integration.slug,
integrationIdentifier: integration.definition.id,
jobCount: integration._count.jobIntegrations,
createdAt: integration.createdAt,
customClientId: clientId,
type: integration.connectionType,
integration: {
identifier: integration.definition.id,
name: integration.definition.name,
packageName: integration.definition.packageName,
icon: integration.definition.icon,
},
authMethod: {
type: integration.authMethod?.type ?? "local",
name: integration.authMethod?.name ?? "Local Auth",
},
help,
};
}
}