feat: dashboard overhaul, chargeability reports, dispo import enhancements, UI polish

Dashboard: expanded chargeability widget, resource/project table widgets
with sorting and filters, stat cards with formatMoney integration.

Chargeability: new report client with filtering, chargeability-bookings
use case, updated dashboard overview logic.

Dispo import: TBD project handling, parse-dispo-matrix improvements,
stage-dispo-projects resource value scores, new tests.

Estimates: CommercialTermsEditor component, commercial-terms engine
module, expanded estimate schemas and types.

UI: AppShell navigation updates, timeline filter/toolbar enhancements,
role management improvements, signin page redesign, Tailwind/globals
polish, SystemSettings SMTP section, anonymization support.

Tests: new router tests (anonymization, chargeability, effort-rule,
entitlement, estimate, experience-multiplier, notification, resource,
staffing, vacation).

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
2026-03-14 23:29:07 +01:00
parent ad0855902b
commit 625a842d89
74 changed files with 11680 additions and 1583 deletions
@@ -0,0 +1,523 @@
import { SystemRole } from "@planarchy/shared";
import { ResourceType } from "@planarchy/shared";
import { beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("@planarchy/application", async (importOriginal) => {
const actual = await importOriginal<typeof import("@planarchy/application")>();
return {
...actual,
isChargeabilityActualBooking: actual.isChargeabilityActualBooking,
isChargeabilityRelevantProject: actual.isChargeabilityRelevantProject,
listAssignmentBookings: vi.fn(),
recomputeResourceValueScores: vi.fn(),
};
});
import { listAssignmentBookings } from "@planarchy/application";
import { resourceRouter } from "../router/resource.js";
import { createCallerFactory } from "../trpc.js";
const createCaller = createCallerFactory(resourceRouter);
function createControllerCaller(db: Record<string, unknown>) {
return createCaller({
session: {
user: { email: "controller@example.com", name: "Controller", image: null, role: "CONTROLLER" },
expires: "2026-03-14T00:00:00.000Z",
},
db: db as never,
dbUser: {
id: "user_controller",
systemRole: SystemRole.CONTROLLER,
permissionOverrides: null,
},
});
}
function createProtectedCaller(db: Record<string, unknown>) {
return createCaller({
session: {
user: { email: "user@example.com", name: "User", image: null, role: "USER" },
expires: "2026-03-14T00:00:00.000Z",
},
db: db as never,
dbUser: {
id: "user_1",
systemRole: SystemRole.USER,
permissionOverrides: null,
},
});
}
describe("resource router", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("filters proposed utilization rows unless explicitly requested", async () => {
const resource = {
id: "resource_1",
eid: "E-001",
displayName: "Alice",
email: "alice@example.com",
chapter: "CGI",
lcrCents: 5000,
ucrCents: 9000,
currency: "EUR",
chargeabilityTarget: 80,
availability: {
monday: 8,
tuesday: 8,
wednesday: 8,
thursday: 8,
friday: 8,
},
skills: [],
dynamicFields: {},
blueprintId: null,
isActive: true,
createdAt: new Date("2026-03-01"),
updatedAt: new Date("2026-03-01"),
roleId: null,
portfolioUrl: null,
postalCode: null,
federalState: null,
valueScore: null,
valueScoreBreakdown: null,
valueScoreUpdatedAt: null,
userId: null,
};
const db = {
resource: {
findMany: vi.fn().mockResolvedValue([resource]),
},
};
vi.mocked(listAssignmentBookings).mockResolvedValue([
{
id: "assignment_confirmed",
projectId: "project_1",
resourceId: "resource_1",
startDate: new Date("2026-03-02T00:00:00.000Z"),
endDate: new Date("2026-03-06T00:00:00.000Z"),
hoursPerDay: 4,
dailyCostCents: 0,
status: "CONFIRMED",
project: {
id: "project_1",
name: "Project 1",
shortCode: "P1",
status: "ACTIVE",
orderType: "CLIENT",
dynamicFields: null,
},
resource: { id: "resource_1", displayName: "Alice", chapter: "CGI" },
},
{
id: "assignment_proposed",
projectId: "project_2",
resourceId: "resource_1",
startDate: new Date("2026-03-02T00:00:00.000Z"),
endDate: new Date("2026-03-06T00:00:00.000Z"),
hoursPerDay: 4,
dailyCostCents: 0,
status: "PROPOSED",
project: {
id: "project_2",
name: "Project 2",
shortCode: "P2",
status: "ACTIVE",
orderType: "CLIENT",
dynamicFields: null,
},
resource: { id: "resource_1", displayName: "Alice", chapter: "CGI" },
},
]);
const caller = createControllerCaller(db);
const strict = await caller.listWithUtilization({
startDate: "2026-03-02T00:00:00.000Z",
endDate: "2026-03-08T00:00:00.000Z",
});
const withProposed = await caller.listWithUtilization({
startDate: "2026-03-02T00:00:00.000Z",
endDate: "2026-03-08T00:00:00.000Z",
includeProposed: true,
});
expect(strict[0]).toMatchObject({
bookingCount: 1,
bookedHours: 20,
utilizationPercent: 50,
});
expect(withProposed[0]).toMatchObject({
bookingCount: 2,
bookedHours: 40,
utilizationPercent: 100,
});
});
it("uses a composite displayName/id cursor for stable pagination", async () => {
const db = {
resource: {
findMany: vi.fn().mockResolvedValue([
{ id: "2", displayName: "Alex", eid: "E-002", email: "alex2@example.com" },
{ id: "3", displayName: "Bea", eid: "E-003", email: "bea@example.com" },
]),
count: vi.fn().mockResolvedValue(3),
},
};
const caller = createProtectedCaller(db);
const result = await caller.list({
limit: 1,
cursor: JSON.stringify({ displayName: "Alex", id: "1" }),
});
expect(db.resource.findMany).toHaveBeenCalledWith(
expect.objectContaining({
where: expect.objectContaining({
AND: expect.arrayContaining([
{
OR: [
{ displayName: { gt: "Alex" } },
{ displayName: "Alex", id: { gt: "1" } },
],
},
]),
}),
orderBy: [{ displayName: "asc" }, { id: "asc" }],
take: 2,
}),
);
expect(result.nextCursor).toBe(JSON.stringify({ displayName: "Alex", id: "2" }));
});
it("resolves resource ownership server-side without exposing linked user email", async () => {
const db = {
resource: {
findUnique: vi.fn().mockResolvedValue({
id: "resource_1",
eid: "E-001",
displayName: "Alice",
email: "alice@example.com",
chapter: "CGI",
lcrCents: 5000,
ucrCents: 9000,
currency: "EUR",
chargeabilityTarget: 80,
availability: {
monday: 8,
tuesday: 8,
wednesday: 8,
thursday: 8,
friday: 8,
},
skills: [],
dynamicFields: {},
blueprint: null,
blueprintId: null,
isActive: true,
createdAt: new Date("2026-03-01"),
updatedAt: new Date("2026-03-01"),
resourceRoles: [],
areaRole: null,
portfolioUrl: null,
roleId: null,
aiSummary: null,
aiSummaryUpdatedAt: null,
skillMatrixUpdatedAt: null,
valueScore: null,
valueScoreBreakdown: null,
valueScoreUpdatedAt: null,
userId: "user_1",
}),
findMany: vi.fn().mockResolvedValue([]),
},
systemSettings: {
findUnique: vi.fn().mockResolvedValue(null),
},
};
const caller = createProtectedCaller(db);
const result = await caller.getById({ id: "resource_1" });
expect(result).toMatchObject({
id: "resource_1",
displayName: "Alice",
eid: "E-001",
email: "alice@example.com",
isOwnedByCurrentUser: true,
});
expect(result).not.toHaveProperty("user");
expect(db.resource.findUnique).toHaveBeenCalledWith(
expect.objectContaining({
include: expect.not.objectContaining({
user: expect.anything(),
}),
}),
);
});
it("counts imported TBD draft projects in chargeability stats only when proposed work is enabled", async () => {
const db = {
resource: {
findMany: vi.fn().mockResolvedValue([
{
id: "resource_1",
eid: "E-001",
displayName: "Alice",
chapter: "CGI",
chargeabilityTarget: 80,
availability: {
monday: 8,
tuesday: 8,
wednesday: 8,
thursday: 8,
friday: 8,
},
},
]),
},
};
vi.mocked(listAssignmentBookings).mockResolvedValue([
{
id: "assignment_tbd",
projectId: "project_tbd",
resourceId: "resource_1",
startDate: new Date("2026-03-02T00:00:00.000Z"),
endDate: new Date("2026-03-06T00:00:00.000Z"),
hoursPerDay: 4,
dailyCostCents: 0,
status: "PROPOSED",
project: {
id: "project_tbd",
name: "TBD Project",
shortCode: "TBD-P1",
status: "DRAFT",
orderType: "CLIENT",
dynamicFields: { dispoImport: { isTbd: true } },
},
resource: { id: "resource_1", displayName: "Alice", chapter: "CGI" },
},
]);
const caller = createControllerCaller(db);
const strict = await caller.getChargeabilityStats({});
const withProposed = await caller.getChargeabilityStats({ includeProposed: true });
expect(strict[0]?.actualChargeability).toBe(0);
expect(strict[0]?.expectedChargeability).toBeGreaterThan(0);
expect(withProposed[0]?.actualChargeability).toBeGreaterThan(strict[0]?.actualChargeability ?? 0);
expect(withProposed[0]?.expectedChargeability).toBe(strict[0]?.expectedChargeability);
});
it("applies country filters including explicit no-country toggle", async () => {
const db = {
resource: {
findMany: vi.fn().mockResolvedValue([]),
count: vi.fn().mockResolvedValue(0),
},
};
const caller = createProtectedCaller(db);
await caller.list({
countryIds: ["country_de", "country_us"],
includeWithoutCountry: false,
});
expect(db.resource.findMany).toHaveBeenCalledWith(
expect.objectContaining({
where: {
AND: expect.arrayContaining([
{ isActive: true },
{ countryId: { in: ["country_de", "country_us"] } },
]),
},
}),
);
});
it("excludes disabled countries while leaving all others visible", async () => {
const db = {
resource: {
findMany: vi.fn().mockResolvedValue([]),
count: vi.fn().mockResolvedValue(0),
},
};
const caller = createProtectedCaller(db);
await caller.list({
excludedCountryIds: ["country_fr"],
includeWithoutCountry: true,
});
expect(db.resource.findMany).toHaveBeenCalledWith(
expect.objectContaining({
where: {
AND: expect.arrayContaining([
{ isActive: true },
{ NOT: { countryId: { in: ["country_fr"] } } },
]),
},
}),
);
});
it("applies resource type filters while keeping unspecified rows when requested", async () => {
const db = {
resource: {
findMany: vi.fn().mockResolvedValue([]),
count: vi.fn().mockResolvedValue(0),
},
};
const caller = createProtectedCaller(db);
await caller.list({
resourceTypes: [ResourceType.EMPLOYEE, ResourceType.INTERN],
includeWithoutResourceType: true,
});
expect(db.resource.findMany).toHaveBeenCalledWith(
expect.objectContaining({
where: {
AND: expect.arrayContaining([
{ isActive: true },
{
OR: [
{ resourceType: { in: [ResourceType.EMPLOYEE, ResourceType.INTERN] } },
{ resourceType: null },
],
},
]),
},
}),
);
});
it("excludes disabled resource types while leaving all others visible", async () => {
const db = {
resource: {
findMany: vi.fn().mockResolvedValue([]),
count: vi.fn().mockResolvedValue(0),
},
};
const caller = createProtectedCaller(db);
await caller.list({
excludedResourceTypes: [ResourceType.FREELANCER],
includeWithoutResourceType: true,
});
expect(db.resource.findMany).toHaveBeenCalledWith(
expect.objectContaining({
where: {
AND: expect.arrayContaining([
{ isActive: true },
{ NOT: { resourceType: { in: [ResourceType.FREELANCER] } } },
]),
},
}),
);
});
it("applies rolled-off and departed filters", async () => {
const db = {
resource: {
findMany: vi.fn().mockResolvedValue([]),
count: vi.fn().mockResolvedValue(0),
},
};
const caller = createProtectedCaller(db);
await caller.list({
rolledOff: true,
departed: false,
});
expect(db.resource.findMany).toHaveBeenCalledWith(
expect.objectContaining({
where: {
AND: expect.arrayContaining([
{ isActive: true },
{ rolledOff: true },
{ departed: false },
]),
},
}),
);
});
it("applies multi-select chapter filters", async () => {
const db = {
resource: {
findMany: vi.fn().mockResolvedValue([]),
count: vi.fn().mockResolvedValue(0),
},
};
const caller = createProtectedCaller(db);
await caller.list({
chapters: ["Art Direction", "Project Management"],
});
expect(db.resource.findMany).toHaveBeenCalledWith(
expect.objectContaining({
where: {
AND: expect.arrayContaining([
{ isActive: true },
{ chapter: { in: ["Art Direction", "Project Management"] } },
]),
},
}),
);
});
it("supports stable anonymized identities and alias-based filtering", async () => {
const resource = {
id: "resource_anon_1",
eid: "h.noerenberg",
displayName: "Hartmut Noerenberg",
email: "h.noerenberg@accenture.com",
chapter: "Art Direction",
lcrCents: 15000,
isActive: true,
createdAt: new Date("2026-03-01"),
updatedAt: new Date("2026-03-01"),
};
const db = {
systemSettings: {
findUnique: vi.fn().mockResolvedValue({
anonymizationEnabled: true,
anonymizationDomain: "superhartmut.de",
anonymizationSeed: null,
anonymizationMode: "global",
}),
},
resource: {
findMany: vi.fn().mockResolvedValue([resource]),
count: vi.fn(),
},
};
const caller = createProtectedCaller(db);
const first = await caller.list({ limit: 10 });
const alias = first.resources[0];
expect(alias).toBeDefined();
expect(alias?.displayName).not.toBe(resource.displayName);
expect(alias?.eid).not.toBe(resource.eid);
expect(alias?.email).toBe(`${alias?.eid}@superhartmut.de`);
const byAlias = await caller.list({ eids: [alias!.eid], limit: 10 });
const byAliasSearch = await caller.list({ search: alias!.displayName.slice(0, 4), limit: 10 });
expect(byAlias.resources).toHaveLength(1);
expect(byAlias.resources[0]?.id).toBe(resource.id);
expect(byAliasSearch.resources).toHaveLength(1);
expect(byAliasSearch.resources[0]?.id).toBe(resource.id);
});
});