feat: project colors, timeline filters, sidebar fix, GitLooper agent, and misc improvements
- Fix sidebar double-highlight on /vacations/my (Gitea #6): add isNavItemActive() helper - Add project color picker (schema + API + modal + timeline rendering) - Add ProjectCombobox/ResourceCombobox to timeline toolbar - Show PENDING vacations on timeline with dashed/dimmed style - Add "show demand projects" preference with localStorage persistence - Add ProjectAssignmentsTable with total hours/cost columns - Extend vacation API to accept status arrays - Add GitLooper formal YAML agent configuration - Extend user admin with permission overrides UI - Add delete-assignment use case tests - Add status-styles.ts shared badge constants - Centralize formatMoney/formatCents in format.ts Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -27,6 +27,7 @@ export const PROJECT_PLANNING_ALLOCATION_INCLUDE = {
|
||||
endDate: true,
|
||||
staffingReqs: true,
|
||||
responsiblePerson: true,
|
||||
color: true,
|
||||
},
|
||||
},
|
||||
roleEntity: {
|
||||
|
||||
@@ -134,6 +134,7 @@ export const projectRouter = createTRPCRouter({
|
||||
endDate: input.endDate,
|
||||
status: input.status,
|
||||
responsiblePerson: input.responsiblePerson,
|
||||
...(input.color !== undefined ? { color: input.color } : {}),
|
||||
staffingReqs: input.staffingReqs as unknown as import("@planarchy/db").Prisma.InputJsonValue,
|
||||
dynamicFields: input.dynamicFields as unknown as import("@planarchy/db").Prisma.InputJsonValue,
|
||||
blueprintId: input.blueprintId,
|
||||
@@ -185,6 +186,7 @@ export const projectRouter = createTRPCRouter({
|
||||
...(input.data.endDate !== undefined ? { endDate: input.data.endDate } : {}),
|
||||
...(input.data.status !== undefined ? { status: input.data.status } : {}),
|
||||
...(input.data.responsiblePerson !== undefined ? { responsiblePerson: input.data.responsiblePerson } : {}),
|
||||
...(input.data.color !== undefined ? { color: input.data.color } : {}),
|
||||
...(input.data.staffingReqs !== undefined ? { staffingReqs: input.data.staffingReqs as unknown as import("@planarchy/db").Prisma.InputJsonValue } : {}),
|
||||
...(input.data.dynamicFields !== undefined ? { dynamicFields: input.data.dynamicFields as unknown as import("@planarchy/db").Prisma.InputJsonValue } : {}),
|
||||
...(input.data.blueprintId !== undefined ? { blueprintId: input.data.blueprintId } : {}),
|
||||
|
||||
@@ -65,7 +65,7 @@ export const userRouter = createTRPCRouter({
|
||||
const { hash } = await import("@node-rs/argon2");
|
||||
const passwordHash = await hash(input.password);
|
||||
|
||||
return ctx.db.user.create({
|
||||
const user = await ctx.db.user.create({
|
||||
data: {
|
||||
email: input.email,
|
||||
name: input.name,
|
||||
@@ -74,6 +74,20 @@ export const userRouter = createTRPCRouter({
|
||||
},
|
||||
select: { id: true, name: true, email: true, systemRole: true },
|
||||
});
|
||||
|
||||
// Auto-link to a resource with matching email (if one exists and isn't already linked)
|
||||
const matchingResource = await ctx.db.resource.findFirst({
|
||||
where: { email: input.email, userId: null },
|
||||
select: { id: true },
|
||||
});
|
||||
if (matchingResource) {
|
||||
await ctx.db.resource.update({
|
||||
where: { id: matchingResource.id },
|
||||
data: { userId: user.id },
|
||||
});
|
||||
}
|
||||
|
||||
return user;
|
||||
}),
|
||||
|
||||
updateRole: adminProcedure
|
||||
@@ -91,6 +105,56 @@ export const userRouter = createTRPCRouter({
|
||||
});
|
||||
}),
|
||||
|
||||
// ─── Resource Linking ──────────────────────────────────────────────────
|
||||
|
||||
linkResource: adminProcedure
|
||||
.input(z.object({ userId: z.string(), resourceId: z.string().nullable() }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
if (input.resourceId) {
|
||||
// Unlink any resource previously linked to this user
|
||||
await ctx.db.resource.updateMany({
|
||||
where: { userId: input.userId },
|
||||
data: { userId: null },
|
||||
});
|
||||
// Link the new resource
|
||||
await ctx.db.resource.update({
|
||||
where: { id: input.resourceId },
|
||||
data: { userId: input.userId },
|
||||
});
|
||||
} else {
|
||||
// Unlink
|
||||
await ctx.db.resource.updateMany({
|
||||
where: { userId: input.userId },
|
||||
data: { userId: null },
|
||||
});
|
||||
}
|
||||
return { success: true };
|
||||
}),
|
||||
|
||||
autoLinkAllByEmail: adminProcedure.mutation(async ({ ctx }) => {
|
||||
// Find all users without a linked resource, then match by email
|
||||
const unlinkedUsers = await ctx.db.user.findMany({
|
||||
where: { resource: null },
|
||||
select: { id: true, email: true },
|
||||
});
|
||||
|
||||
let linked = 0;
|
||||
for (const user of unlinkedUsers) {
|
||||
const resource = await ctx.db.resource.findFirst({
|
||||
where: { email: user.email, userId: null },
|
||||
select: { id: true },
|
||||
});
|
||||
if (resource) {
|
||||
await ctx.db.resource.update({
|
||||
where: { id: resource.id },
|
||||
data: { userId: user.id },
|
||||
});
|
||||
linked++;
|
||||
}
|
||||
}
|
||||
return { linked, checked: unlinkedUsers.length };
|
||||
}),
|
||||
|
||||
getDashboardLayout: protectedProcedure.query(async ({ ctx }) => {
|
||||
const user = await ctx.db.user.findUnique({
|
||||
where: { email: ctx.session.user?.email ?? "" },
|
||||
|
||||
@@ -82,7 +82,7 @@ export const vacationRouter = createTRPCRouter({
|
||||
.input(
|
||||
z.object({
|
||||
resourceId: z.string().optional(),
|
||||
status: z.nativeEnum(VacationStatus).optional(),
|
||||
status: z.union([z.nativeEnum(VacationStatus), z.array(z.nativeEnum(VacationStatus))]).optional(),
|
||||
type: z.nativeEnum(VacationType).optional(),
|
||||
startDate: z.coerce.date().optional(),
|
||||
endDate: z.coerce.date().optional(),
|
||||
@@ -93,7 +93,7 @@ export const vacationRouter = createTRPCRouter({
|
||||
const vacations = await ctx.db.vacation.findMany({
|
||||
where: {
|
||||
...(input.resourceId ? { resourceId: input.resourceId } : {}),
|
||||
...(input.status ? { status: input.status } : {}),
|
||||
...(input.status ? { status: Array.isArray(input.status) ? { in: input.status } : input.status } : {}),
|
||||
...(input.type ? { type: input.type } : {}),
|
||||
...(input.startDate ? { endDate: { gte: input.startDate } } : {}),
|
||||
...(input.endDate ? { startDate: { lte: input.endDate } } : {}),
|
||||
|
||||
@@ -2,16 +2,21 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { deleteAssignment } from "../index.js";
|
||||
|
||||
describe("deleteAssignment", () => {
|
||||
it("deletes an explicit assignment row", async () => {
|
||||
it("deletes an assignment without demand link", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
demandRequirementId: null,
|
||||
}),
|
||||
delete: vi.fn().mockResolvedValue({}),
|
||||
},
|
||||
demandRequirement: {
|
||||
findUnique: vi.fn(),
|
||||
update: vi.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await deleteAssignment(db as never, "assignment_1");
|
||||
@@ -20,9 +25,76 @@ describe("deleteAssignment", () => {
|
||||
deletedId: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
reopenedDemandId: null,
|
||||
});
|
||||
expect(db.assignment.delete).toHaveBeenCalledWith({
|
||||
where: { id: "assignment_1" },
|
||||
});
|
||||
expect(db.demandRequirement.findUnique).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("re-opens a COMPLETED demand when its assignment is deleted", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
demandRequirementId: "demand_1",
|
||||
}),
|
||||
delete: vi.fn().mockResolvedValue({}),
|
||||
},
|
||||
demandRequirement: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "demand_1",
|
||||
headcount: 0,
|
||||
status: "COMPLETED",
|
||||
}),
|
||||
update: vi.fn().mockResolvedValue({}),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await deleteAssignment(db as never, "assignment_1");
|
||||
|
||||
expect(result).toEqual({
|
||||
deletedId: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
reopenedDemandId: "demand_1",
|
||||
});
|
||||
expect(db.demandRequirement.update).toHaveBeenCalledWith({
|
||||
where: { id: "demand_1" },
|
||||
data: { headcount: 1, status: "ACTIVE" },
|
||||
});
|
||||
});
|
||||
|
||||
it("increments headcount on an ACTIVE demand when its assignment is deleted", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
demandRequirementId: "demand_2",
|
||||
}),
|
||||
delete: vi.fn().mockResolvedValue({}),
|
||||
},
|
||||
demandRequirement: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "demand_2",
|
||||
headcount: 2,
|
||||
status: "ACTIVE",
|
||||
}),
|
||||
update: vi.fn().mockResolvedValue({}),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await deleteAssignment(db as never, "assignment_2");
|
||||
|
||||
expect(result.reopenedDemandId).toBe("demand_2");
|
||||
expect(db.demandRequirement.update).toHaveBeenCalledWith({
|
||||
where: { id: "demand_2" },
|
||||
data: { headcount: 3, status: "ACTIVE" },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import type { Prisma, PrismaClient } from "@planarchy/db";
|
||||
import { AllocationStatus } from "@planarchy/shared";
|
||||
|
||||
type DbClient =
|
||||
| Pick<PrismaClient, "assignment">
|
||||
| Pick<Prisma.TransactionClient, "assignment">;
|
||||
| Pick<PrismaClient, "assignment" | "demandRequirement">
|
||||
| Pick<Prisma.TransactionClient, "assignment" | "demandRequirement">;
|
||||
|
||||
export interface DeleteAssignmentResult {
|
||||
deletedId: string;
|
||||
projectId: string;
|
||||
resourceId: string;
|
||||
reopenedDemandId: string | null;
|
||||
}
|
||||
|
||||
export async function deleteAssignment(
|
||||
@@ -20,6 +22,7 @@ export async function deleteAssignment(
|
||||
id: true,
|
||||
projectId: true,
|
||||
resourceId: true,
|
||||
demandRequirementId: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -31,9 +34,31 @@ export async function deleteAssignment(
|
||||
where: { id: assignment.id },
|
||||
});
|
||||
|
||||
// Reverse demand fill progress: re-open the demand if the assignment was linked
|
||||
let reopenedDemandId: string | null = null;
|
||||
if (assignment.demandRequirementId) {
|
||||
const demand = await db.demandRequirement.findUnique({
|
||||
where: { id: assignment.demandRequirementId },
|
||||
select: { id: true, headcount: true, status: true },
|
||||
});
|
||||
|
||||
if (demand) {
|
||||
const wasCompleted = demand.status === AllocationStatus.COMPLETED;
|
||||
await db.demandRequirement.update({
|
||||
where: { id: demand.id },
|
||||
data: {
|
||||
headcount: wasCompleted ? 1 : demand.headcount + 1,
|
||||
status: AllocationStatus.ACTIVE,
|
||||
},
|
||||
});
|
||||
reopenedDemandId = demand.id;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
deletedId: assignment.id,
|
||||
projectId: assignment.projectId,
|
||||
resourceId: assignment.resourceId,
|
||||
reopenedDemandId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -806,6 +806,7 @@ model Project {
|
||||
endDate DateTime @db.Date
|
||||
status ProjectStatus @default(DRAFT)
|
||||
responsiblePerson String?
|
||||
color String? // Hex color for timeline display, e.g. "#3b82f6"
|
||||
|
||||
// staffingReqs: StaffingRequirement[]
|
||||
staffingReqs Json @db.JsonB @default("[]")
|
||||
|
||||
@@ -29,6 +29,7 @@ export const CreateProjectBaseSchema = z.object({
|
||||
blueprintId: z.string().optional(),
|
||||
status: z.nativeEnum(ProjectStatus).default(ProjectStatus.DRAFT),
|
||||
responsiblePerson: z.string().max(200).optional(),
|
||||
color: z.string().regex(/^#[0-9a-fA-F]{6}$/, "Must be a hex color like #3b82f6").optional(),
|
||||
utilizationCategoryId: z.string().optional(),
|
||||
clientId: z.string().optional(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user