Skip to content

Commit 9d7bb4e

Browse files
authored
Merge branch 'main' into lewis/comp-tp-ui-fixes
2 parents 3e390f5 + a376b22 commit 9d7bb4e

File tree

64 files changed

+1135
-1031
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1135
-1031
lines changed

apps/app/src/actions/organization/lib/utils.ts

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
type PolicyStatus,
77
RequirementId,
88
TaskStatus,
9-
TaskEntityType,
109
TaskFrequency,
1110
Departments,
1211
ArtifactType,
@@ -516,6 +515,8 @@ export async function createOrganizationTasks(
516515
);
517516
}
518517

518+
let tasksCreatedCount = 0;
519+
519520
for (const control of relevantControls) {
520521
const dbControl = dbControls.get(control.name);
521522
if (!dbControl) continue;
@@ -534,42 +535,44 @@ export async function createOrganizationTasks(
534535
continue; // Skip if template doesn't exist
535536
}
536537

537-
// Create one task per control that requires this type of task
538-
tasksToCreateData.push({
539-
organizationId,
540-
title: taskTemplate.name, // Use template name
541-
description: taskTemplate.description, // Use template desc
542-
status: TaskStatus.todo,
543-
entityId: dbControl.id, // Link to the Control ID
544-
entityType: TaskEntityType.control,
545-
frequency: taskTemplate.frequency ?? TaskFrequency.quarterly, // Use template freq
546-
assigneeId: memberRecord?.id || null,
547-
department: taskTemplate.department ?? Departments.none, // Use template department
548-
});
538+
try {
539+
// Create one task per control that requires this type of task
540+
await prisma.task.create({
541+
data: {
542+
organizationId,
543+
title: taskTemplate.name, // Use template name
544+
description: taskTemplate.description, // Use template desc
545+
status: TaskStatus.todo,
546+
// entityId: dbControl.id, // Link to the Control ID
547+
// entityType: TaskEntityType.control,
548+
controls: { connect: { id: dbControl.id } },
549+
frequency: taskTemplate.frequency ?? TaskFrequency.quarterly, // Use template freq
550+
assigneeId: memberRecord?.id || null,
551+
department: taskTemplate.department ?? Departments.none, // Use template department
552+
},
553+
});
554+
tasksCreatedCount++;
555+
} catch (error) {
556+
console.error(
557+
`Error creating task for control ${control.name} with template ${taskTemplateId}`,
558+
{ error },
559+
);
560+
// Continue with next task even if one fails
561+
continue;
562+
}
549563
}
550564
}
551565

552-
if (tasksToCreateData.length === 0) {
566+
if (tasksCreatedCount === 0) {
553567
console.info("No tasks required for the selected controls.");
554568
return { tasksCreatedCount: 0 };
555569
}
556-
console.info("Tasks to be created", {
557-
organizationId,
558-
count: tasksToCreateData.length,
559-
});
560-
try {
561-
await prisma.task.createMany({ data: tasksToCreateData });
562-
console.info(
563-
`Batch created ${tasksToCreateData.length} task records for org ${organizationId}`,
564-
);
565-
} catch (error) {
566-
console.error(
567-
`Error batch creating task records for org ${organizationId}`,
568-
{ error },
569-
);
570-
throw new Error("Failed to create organization tasks");
571-
}
572-
return { tasksCreatedCount: tasksToCreateData.length };
570+
571+
console.info(
572+
`Created ${tasksCreatedCount} task records for org ${organizationId}`,
573+
);
574+
575+
return { tasksCreatedCount };
573576
}
574577

575578
/**

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/controls/[controlId]/data/getControl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const getControl = async (id: string) => {
3030
frameworkInstance: true,
3131
},
3232
},
33+
tasks: true,
3334
},
3435
});
3536

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/controls/[controlId]/data/getOrganizationControlProgress.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { auth } from "@/utils/auth";
44
import { db } from "@comp/db";
5-
import { TaskEntityType } from "@comp/db/types";
65
import { ArtifactType } from "@prisma/client";
76
import { headers } from "next/headers";
87

@@ -48,6 +47,7 @@ export const getOrganizationControlProgress = async (controlId: string) => {
4847
policy: true,
4948
},
5049
},
50+
tasks: true,
5151
},
5252
});
5353

@@ -58,14 +58,7 @@ export const getOrganizationControlProgress = async (controlId: string) => {
5858
}
5959

6060
const artifacts = control.artifacts;
61-
const tasks = await db.task.findMany({
62-
where: {
63-
organizationId: orgId,
64-
entityId: controlId,
65-
entityType: "control",
66-
},
67-
});
68-
61+
const tasks = control.tasks;
6962
const progress: ControlProgressResponse = {
7063
total: artifacts.length + tasks.length,
7164
completed: 0,
@@ -107,28 +100,21 @@ export const getOrganizationControlProgress = async (controlId: string) => {
107100

108101
for (const task of tasks) {
109102
// Initialize type counters if not exists
110-
if (!progress.byType[task.entityType]) {
111-
progress.byType[task.entityType] = {
103+
if (!progress.byType["control"]) {
104+
progress.byType["control"] = {
112105
total: 0,
113106
completed: 0,
114107
};
115108
}
116109

117-
progress.byType[task.entityType].total++;
110+
progress.byType["control"].total++;
118111

119-
// Check completion based on task type
120-
let isCompleted = false;
121-
switch (task.entityType) {
122-
case TaskEntityType.control:
123-
isCompleted = task.status === "done";
124-
break;
125-
default:
126-
isCompleted = false;
127-
}
112+
// Check completion based on task status (all tasks here are implicitly control-related)
113+
const isCompleted = task.status === "done";
128114

129115
if (isCompleted) {
130116
progress.completed++;
131-
progress.byType[task.entityType].completed++;
117+
progress.byType["control"].completed++;
132118
}
133119
}
134120

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/controls/[controlId]/data/getRelatedTasks.ts

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

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/controls/[controlId]/page.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { SingleControl } from "./components/SingleControl";
66
import { getControl } from "./data/getControl";
77
import { getOrganizationControlProgress } from "./data/getOrganizationControlProgress";
88
import type { ControlProgressResponse } from "./data/getOrganizationControlProgress";
9-
import { getRelatedTasks } from "./data/getRelatedTasks";
109
import { getRelatedArtifacts } from "./data/getRelatedArtifacts";
1110

1211
interface ControlPageProps {
@@ -54,10 +53,6 @@ export default async function ControlPage({ params }: ControlPageProps) {
5453
controlId: controlId,
5554
});
5655

57-
const relatedTasks = await getRelatedTasks({
58-
controlId: controlId,
59-
});
60-
6156
return (
6257
<PageWithBreadcrumb
6358
breadcrumbs={[
@@ -69,7 +64,7 @@ export default async function ControlPage({ params }: ControlPageProps) {
6964
control={control}
7065
controlProgress={controlProgress}
7166
relatedArtifacts={relatedArtifacts}
72-
relatedTasks={relatedTasks}
67+
relatedTasks={control.tasks}
7368
/>
7469
</PageWithBreadcrumb>
7570
);

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/frameworks/[frameworkInstanceId]/components/FrameworkOverview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import { Progress } from "@comp/ui/progress";
66
import { getFrameworkDetails } from "../../lib/getFrameworkDetails";
77
import { getControlStatus } from "../../lib/utils";
88
import { FrameworkInstanceWithControls } from "../../types";
9-
import { Task } from "@comp/db/types";
9+
import { Control, Task } from "@comp/db/types";
1010

1111
interface FrameworkOverviewProps {
1212
frameworkInstanceWithControls: FrameworkInstanceWithControls;
13-
tasks: Task[];
13+
tasks: (Task & { controls: Control[] })[];
1414
}
1515

1616
export function FrameworkOverview({

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/frameworks/[frameworkInstanceId]/page.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getFrameworkDetails } from "../lib/getFrameworkDetails";
77
import { FrameworkOverview } from "./components/FrameworkOverview";
88
import { FrameworkRequirements } from "./components/FrameworkRequirements";
99
import { db } from "@comp/db";
10-
import { TaskEntityType } from "@comp/db/types";
10+
1111
interface PageProps {
1212
params: Promise<{
1313
frameworkInstanceId: string;
@@ -48,7 +48,14 @@ export default async function FrameworkPage({ params }: PageProps) {
4848
const tasks = await db.task.findMany({
4949
where: {
5050
organizationId,
51-
entityType: TaskEntityType.control,
51+
controls: {
52+
some: {
53+
id: frameworkInstanceWithControls.id,
54+
},
55+
},
56+
},
57+
include: {
58+
controls: true,
5259
},
5360
});
5461

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/frameworks/[frameworkInstanceId]/requirements/[requirementKey]/components/RequirementControls.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { FrameworkId } from "@comp/db/types";
66
import { Card, CardContent, CardHeader, CardTitle } from "@comp/ui/card";
77
import { FrameworkInstanceWithControls } from "../../../../types";
88
import { RequirementControlsTable } from "./table/RequirementControlsTable";
9-
import type { Task } from "@comp/db/types";
9+
import type { Control, Task } from "@comp/db/types";
1010

1111
interface RequirementControlsProps {
1212
requirement: Requirement;
1313
requirementKey: string;
1414
frameworkInstanceWithControls: FrameworkInstanceWithControls;
15-
tasks: Task[];
15+
tasks: (Task & { controls: Control[] })[];
1616
}
1717

1818
export function RequirementControls({

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/frameworks/[frameworkInstanceId]/requirements/[requirementKey]/components/table/RequirementControlsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface RequirementControlsTableProps {
2727
policy: Policy | null;
2828
})[];
2929
})[];
30-
tasks: Task[];
30+
tasks: (Task & { controls: Control[] })[];
3131
}
3232

3333
export function RequirementControlsTable({

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/frameworks/[frameworkInstanceId]/requirements/[requirementKey]/components/table/RequirementControlsTableColumns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type OrganizationControlType = Control & {
2626
export function RequirementControlsTableColumns({
2727
tasks,
2828
}: {
29-
tasks: Task[];
29+
tasks: (Task & { controls: Control[] })[];
3030
}): ColumnDef<OrganizationControlType>[] {
3131
const t = useI18n();
3232
const { orgId } = useParams<{ orgId: string }>();

0 commit comments

Comments
 (0)