Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions apps/webapp/app/components/runs/v3/RunFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const TaskRunListSearchFilters = z.object({
to: z.coerce.number().optional(),
rootOnly: z.coerce.boolean().optional(),
batchId: z.string().optional(),
runId: z.string().optional(),
runId: StringOrStringArray,
scheduleId: z.string().optional(),
});

Expand Down Expand Up @@ -199,7 +199,10 @@ export function getRunFiltersFromSearchParams(
from: searchParams.get("from") ?? undefined,
to: searchParams.get("to") ?? undefined,
rootOnly: searchParams.has("rootOnly") ? searchParams.get("rootOnly") === "true" : undefined,
runId: searchParams.get("runId") ?? undefined,
runId:
searchParams.getAll("runId").filter((v) => v.length > 0).length > 0
? searchParams.getAll("runId")
: undefined,
batchId: searchParams.get("batchId") ?? undefined,
scheduleId: searchParams.get("scheduleId") ?? undefined,
};
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/app/presenters/RunFilters.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function getRunFiltersFromRequest(request: Request) {
from,
to,
batchId,
runIds: runId ? [runId] : undefined,
runId,
scheduleId,
rootOnly: rootOnlyValue,
direction: direction,
Expand Down
6 changes: 5 additions & 1 deletion apps/webapp/app/presenters/v3/BulkActionPresenter.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export class BulkActionPresenter extends BasePresenter {
);

let mode: BulkActionMode = "filter";
if (filtersParsed.success && Object.keys(filtersParsed.data).length === 0) {
if (
filtersParsed.success &&
Object.keys(filtersParsed.data).length === 1 &&
filtersParsed.data.runId?.length
) {
mode = "selected";
}

Expand Down
17 changes: 10 additions & 7 deletions apps/webapp/app/presenters/v3/NextRunListPresenter.server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { ClickHouse } from "@internal/clickhouse";
import { PrismaClient, PrismaClientOrTransaction, type TaskRunStatus } from "@trigger.dev/database";
import { type ClickHouse } from "@internal/clickhouse";
import {
type PrismaClient,
type PrismaClientOrTransaction,
type TaskRunStatus,
} from "@trigger.dev/database";
import { type Direction } from "~/components/ListPagination";
import { timeFilters } from "~/components/runs/v3/SharedFilters";
import { findDisplayableEnvironment } from "~/models/runtimeEnvironment.server";
import { getAllTaskIdentifiers } from "~/models/task.server";
import { RunsRepository } from "~/services/runsRepository.server";
import { ServiceValidationError } from "~/v3/services/baseService.server";
import { isCancellableRunStatus, isFinalRunStatus, isPendingRunStatus } from "~/v3/taskStatus";
import parseDuration from "parse-duration";

export type RunListOptions = {
userId?: string;
Expand All @@ -25,7 +28,7 @@ export type RunListOptions = {
isTest?: boolean;
rootOnly?: boolean;
batchId?: string;
runIds?: string[];
runId?: string[];
//pagination
direction?: Direction;
cursor?: string;
Expand Down Expand Up @@ -60,7 +63,7 @@ export class NextRunListPresenter {
isTest,
rootOnly,
batchId,
runIds,
runId,
from,
to,
direction = "forward",
Expand All @@ -85,7 +88,7 @@ export class NextRunListPresenter {
(scheduleId !== undefined && scheduleId !== "") ||
(tags !== undefined && tags.length > 0) ||
batchId !== undefined ||
(runIds !== undefined && runIds.length > 0) ||
(runId !== undefined && runId.length > 0) ||
typeof isTest === "boolean" ||
rootOnly === true ||
!time.isDefault;
Expand Down Expand Up @@ -167,7 +170,7 @@ export class NextRunListPresenter {
isTest,
rootOnly,
batchId,
runIds,
runId,
bulkId,
page: {
size: pageSize,
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/app/presenters/v3/WaitpointPresenter.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class WaitpointPresenter extends BasePresenter {
environmentId,
{
projectId: projectId,
runIds: connectedRunIds,
runId: connectedRunIds,
pageSize: 5,
period: "31d",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ export default function Page() {

return (
<div className="grid h-full max-h-full grid-rows-[2.5rem_2.5rem_1fr_3.25rem] overflow-hidden bg-background-bright">
<div className="mx-3 flex items-center justify-between gap-2 border-b border-grid-dimmed">
<Header2 className={cn("whitespace-nowrap")}>
<div className="mx-3 flex items-center justify-between gap-2 overflow-x-hidden border-b border-grid-dimmed">
<Header2 className={cn("truncate whitespace-nowrap")}>
{bulkAction.name || bulkAction.friendlyId}
</Header2>
<LinkButton
Expand Down
17 changes: 11 additions & 6 deletions apps/webapp/app/services/runsRepository.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ const RunListInputOptionsSchema = z.object({
isTest: z.boolean().optional(),
rootOnly: z.boolean().optional(),
batchId: z.string().optional(),
runIds: z.array(z.string()).optional(),
runId: z.array(z.string()).optional(),
bulkId: z.string().optional(),
});

export type RunListInputOptions = z.infer<typeof RunListInputOptionsSchema>;
export type RunListInputFilters = Omit<
RunListInputOptions,
"organizationId" | "projectId" | "environmentId"
>;

type FilterRunsOptions = Omit<RunListInputOptions, "period"> & {
period: number | undefined;
Expand Down Expand Up @@ -256,13 +260,13 @@ export class RunsRepository {
convertedOptions.bulkId = BulkActionId.toId(options.bulkId);
}

if (options.runIds) {
if (options.runId) {
//convert to friendlyId
convertedOptions.runIds = options.runIds.map((runId) => RunId.toFriendlyId(runId));
convertedOptions.runId = options.runId.map((r) => RunId.toFriendlyId(r));
}

// Show all runs if we are filtering by batchId or runId
if (options.batchId || options.runIds?.length || options.scheduleId || options.tasks?.length) {
if (options.batchId || options.runId?.length || options.scheduleId || options.tasks?.length) {
convertedOptions.rootOnly = false;
}

Expand Down Expand Up @@ -342,9 +346,10 @@ function applyRunFiltersToQueryBuilder<T>(
});
}

if (options.runIds && options.runIds.length > 0) {
if (options.runId && options.runId.length > 0) {
// it's important that in the query it's "runIds", otherwise it clashes with the cursor which is called "runId"
queryBuilder.where("friendly_id IN {runIds: Array(String)}", {
runIds: options.runIds.map((runId) => RunId.toFriendlyId(runId)),
runIds: options.runId.map((runId) => RunId.toFriendlyId(runId)),
});
}
}
Expand Down
15 changes: 10 additions & 5 deletions apps/webapp/app/v3/services/bulk/BulkActionV2.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
import { getRunFiltersFromRequest } from "~/presenters/RunFilters.server";
import { type CreateBulkActionPayload } from "~/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.bulkaction";
import { clickhouseClient } from "~/services/clickhouseInstance.server";
import { parseRunListInputOptions, RunsRepository } from "~/services/runsRepository.server";
import {
parseRunListInputOptions,
type RunListInputFilters,
RunsRepository,
} from "~/services/runsRepository.server";
import { BaseService } from "../baseService.server";
import { commonWorker } from "~/v3/commonWorker.server";
import { env } from "~/env.server";
Expand Down Expand Up @@ -378,12 +382,13 @@ export class BulkActionService extends BaseService {
}
}

async function getFilters(payload: CreateBulkActionPayload, request: Request) {
async function getFilters(
payload: CreateBulkActionPayload,
request: Request
): Promise<RunListInputFilters> {
if (payload.mode === "selected") {
return {
runIds: payload.selectedRunIds,
cursor: undefined,
direction: undefined,
runId: payload.selectedRunIds,
};
}

Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/test/runsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ describe("RunsRepository", () => {
projectId: project.id,
environmentId: runtimeEnvironment.id,
organizationId: organization.id,
runIds: ["run_abc", "run_xyz"],
runId: ["run_abc", "run_xyz"],
});

expect(runs).toHaveLength(2);
Expand Down Expand Up @@ -1171,7 +1171,7 @@ describe("RunsRepository", () => {
projectId: project.id,
environmentId: runtimeEnvironment.id,
organizationId: organization.id,
runIds: [run1.friendlyId, run3.friendlyId],
runId: [run1.friendlyId, run3.friendlyId],
});

expect(runs).toHaveLength(2);
Expand Down