57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
export interface AllocationVisibilityInput {
|
|
totalAssignments: number;
|
|
totalDemands: number;
|
|
visibleAssignments: number;
|
|
visibleDemands: number;
|
|
hidePastProjects: boolean;
|
|
hideCompletedProjects: boolean;
|
|
hideDraftProjects: boolean;
|
|
}
|
|
|
|
export interface AllocationEmptyState {
|
|
title: string;
|
|
detail: string;
|
|
showResetAction: boolean;
|
|
}
|
|
|
|
export function shouldAutoRelaxAllocationFilters(input: AllocationVisibilityInput): boolean {
|
|
const totalRows = input.totalAssignments + input.totalDemands;
|
|
const visibleRows = input.visibleAssignments + input.visibleDemands;
|
|
const hasActiveProjectFilters = input.hidePastProjects || input.hideCompletedProjects || input.hideDraftProjects;
|
|
|
|
return totalRows > 0 && visibleRows === 0 && hasActiveProjectFilters;
|
|
}
|
|
|
|
export function getAllocationEmptyState(input: AllocationVisibilityInput): AllocationEmptyState {
|
|
const totalRows = input.totalAssignments + input.totalDemands;
|
|
|
|
if (shouldAutoRelaxAllocationFilters(input)) {
|
|
const assignmentLabel = input.totalAssignments === 1 ? "assignment" : "assignments";
|
|
const demandLabel = input.totalDemands === 1 ? "demand" : "demands";
|
|
const hiddenSummary =
|
|
input.totalDemands > 0
|
|
? `${input.totalAssignments} ${assignmentLabel} and ${input.totalDemands} ${demandLabel} are hidden by the active project filters.`
|
|
: `${input.totalAssignments} ${assignmentLabel} are hidden by the active project filters.`;
|
|
|
|
return {
|
|
title: "No assignments match the active filters.",
|
|
detail: hiddenSummary,
|
|
showResetAction: true,
|
|
};
|
|
}
|
|
|
|
if (totalRows === 0) {
|
|
return {
|
|
title: "No assignments found.",
|
|
detail: "Create a planning entry or relax the current project filters once data is available.",
|
|
showResetAction: false,
|
|
};
|
|
}
|
|
|
|
return {
|
|
title: "No assignments found.",
|
|
detail: "No visible assignment rows remain after the current filters were applied.",
|
|
showResetAction: false,
|
|
};
|
|
}
|