Compare commits

...

3 Commits

Author SHA1 Message Date
c8da77dbf2 Count started own lab cases on the dashboard and fit the gadgets to the screen.
Lab numbers now follow the same cases as Cases and Tasks: a case the lab started itself is included, and a step already handed to another lab is not. Day labels stay inside the charts, the grid follows the dashboard width, and the progress rings share one thin stroke.
2026-10-16 02:52:46 +03:30
3a851fb11f Merge pull request 'improvment: tab change terminating unfinished attachments uploads fixed.' (#99) from improvement/cases into master
All checks were successful
Registry — build, push, deploy / build-and-push (push) Successful in 9m28s
Registry — build, push, deploy / deploy (push) Successful in 56s
Reviewed-on: #99
Reviewed-by: aminmsvi <amn.mousavi@gmail.com>
2026-10-10 03:47:23 +03:30
c025022574 Merge pull request 'improvement/cases' (#98) from improvement/cases into master
All checks were successful
Registry — build, push, deploy / build-and-push (push) Successful in 10m30s
Registry — build, push, deploy / deploy (push) Successful in 53s
Reviewed-on: #98
Reviewed-by: aminmsvi <amn.mousavi@gmail.com>
2026-10-10 02:32:35 +03:30
15 changed files with 331 additions and 162 deletions

View File

@@ -35,7 +35,7 @@ Treatment-type colors and labels: `components/shared/treatmentTypeDisplay.ts` +
## Today dashboard
CLINIC + LAB KPIs/charts in `modules/today/today.service.ts`. Deep links: `components/today/today-deep-links.ts`. Task KPIs need `TAB_TASKS_READ` (no owner bypass). Skill: `.cursor/skills/today-dashboard/SKILL.md`.
CLINIC + LAB KPIs/charts in `modules/today/today.service.ts`. Lab gadgets count the same cases as Cases and Tasks (started own cases included; outsourced steps excluded). Deep links: `components/today/today-deep-links.ts`. Task KPIs need `TAB_TASKS_READ` (no owner bypass). Skill: `.cursor/skills/today-dashboard/SKILL.md`.
## Lab case share link

View File

@@ -31,13 +31,25 @@ KPIs with count `0` still register; `getVisibleTodayKpis` hides when `formatValu
Use `useRouter` from `@/i18n/navigation` for chart clicks. KPI cards use `Link`/`href` on `KpiCard`.
## Lab case scope
Lab gadgets use `visibleStartedToLabWhere` in `today.service.ts`, the same cases Cases and Tasks show:
- A received case has `sentAt` and a `LabCaseSend` for this lab (clinic dispatch or a received lab-to-lab case).
- A started own case is `LAB_INTERNAL`, `destinationOrganizationId` is this lab, and `startedAt` is set. Date windows use `startedAt` where a sent case uses `sentAt` (received today, activity “received”, partner chart).
- Unstarted drafts stay out.
- Task counts use `CURRENT_VISIBLE_TASK_FILTER`: current round only, and a step already handed to another lab is not counted.
- Partner chart name: the clinic, else `partnerClinicOrganizationId`, else the parent case’s lab for a received lab-to-lab case.
Clinic gadgets are unchanged.
## Charts (LAB examples)
- **Tasks by prosthesis** — `TodayBarChart` + `colorForCode` from prosthesis catalog; `canViewTasks`
- **Cases due** — forward day buckets (next 7 / 30); active sent cases with due date + in-progress task; `canViewCases`; empty card still shown
- **Lab task activity** — stacked lookback day chart (7 / 30); `canViewCases \|\| canViewTasks`
- **Cases due** — forward day buckets (next 7 / 30); a due date plus an in-progress task on a received or started own case; `canViewCases`; empty card still shown
- **Lab task activity** — stacked lookback day chart (7 / 30); `canViewCases \|\| canViewTasks`. “Received” adds a send’s tasks, and a started own case’s current tasks on `startedAt`.
Week/month day labels: `useTodayDayLabelFormatter` + `mapWeekChartBuckets`.
Day axis tick is month + day (`APP_DATE.chartAxisDay` via `mapWeekChartBuckets`). The tooltip keeps the full weekday label.
## Chart period dropdowns
@@ -50,6 +62,16 @@ Seven time-window charts support a compact header `<select>` via `ChartCard` `he
Do **not** put year on day-series charts. Backend: `daysForChartPeriod` + `buildLocalDayBuckets` in `today.service.ts`.
## Layout and rings
Columns follow the dashboard width, not the browser window (the sidebar sits beside it). See `.today-dashboard` in `globals.css`.
- Under 40rem: 1 column.
- 40rem up to 64rem: 2 columns. A width-2 chart spans the row.
- 64rem and up: the 4-column pack (`--today-gc` / `--today-gr`).
Subscription, Case Completion, and Treatment Plan Completion share the compact ring on `TodayRadialGaugeChart` (inner 88%, outer 98%, bar 6) and the circle sizes to the card height. Efficiency and billing pies are separate charts.
## Permissions (task KPIs)
`TAB_TASKS_READ` / `TAB_TASKS_EDIT` — **no owner bypass** (unlike Cases). LAB owner needs tasks participation opt-in for task gadgets.

View File

@@ -3,7 +3,13 @@ import {
Injectable,
} from '@nestjs/common';
import { AppException, ErrorCode } from '../../common/errors';
import { LabTaskStatus, LinkStatus, CatalogEntityKind } from '@prisma/client';
import {
CatalogEntityKind,
LabCaseOrigin,
LabTaskStatus,
LinkStatus,
Prisma,
} from '@prisma/client';
import { PrismaService } from '../../../prisma/prisma.service';
import {
isUnlimitedSeats,
@@ -18,6 +24,7 @@ import {
type CatalogLocale,
} from '../catalog/catalog-label.service';
import { startOfUtcDay } from '../../common/lab-case-due-date';
import { CURRENT_VISIBLE_TASK_FILTER } from '../cases/lab-case-outsource.rules';
import { TodaySummaryQueryDto } from './dto/today-summary-query.dto';
type ChartBucket = { code: string; label: string; count: number };
@@ -402,6 +409,47 @@ export class TodayService {
}));
}
/** Cases this lab is working: received sends, or a started own case. Drafts stay out. */
private visibleStartedToLabWhere(
labOrganizationId: string,
): Prisma.LabCaseWhereInput {
return {
OR: [
{
sentAt: { not: null },
sends: { some: { organizationId: labOrganizationId } },
},
{
origin: LabCaseOrigin.LAB_INTERNAL,
destinationOrganizationId: labOrganizationId,
startedAt: { not: null },
},
],
};
}
/** Sent cases use `sentAt`. Own cases use `startedAt` for the same window. */
private labCaseListedInRangeWhere(
labOrganizationId: string,
from: Date,
to: Date,
): Prisma.LabCaseWhereInput {
const range = { gte: from, lt: to };
return {
OR: [
{
sentAt: range,
sends: { some: { organizationId: labOrganizationId } },
},
{
origin: LabCaseOrigin.LAB_INTERNAL,
destinationOrganizationId: labOrganizationId,
startedAt: range,
},
],
};
}
private async loadTasksByProsthesis(
labOrganizationId: string,
locale: CatalogLocale,
@@ -411,11 +459,8 @@ export class TodayService {
by: ['prosthesisTypeCode'],
where: {
status: LabTaskStatus.IN_PROGRESS,
roundId: null,
labCase: {
sentAt: { not: null },
sends: { some: { organizationId: labOrganizationId } },
},
...CURRENT_VISIBLE_TASK_FILTER,
labCase: this.visibleStartedToLabWhere(labOrganizationId),
},
_count: { _all: true },
});
@@ -564,10 +609,7 @@ export class TodayService {
widgets: TodayWidgets,
) {
const count = await this.prisma.labCase.count({
where: {
sentAt: { gte: from, lt: to },
sends: { some: { organizationId: labOrganizationId } },
},
where: this.labCaseListedInRangeWhere(labOrganizationId, from, to),
});
widgets.casesReceivedToday = { count };
}
@@ -576,11 +618,8 @@ export class TodayService {
const count = await this.prisma.labCaseTask.count({
where: {
status: LabTaskStatus.IN_PROGRESS,
roundId: null,
labCase: {
sentAt: { not: null },
sends: { some: { organizationId: labOrganizationId } },
},
...CURRENT_VISIBLE_TASK_FILTER,
labCase: this.visibleStartedToLabWhere(labOrganizationId),
},
});
widgets.tasksInProgress = { count };
@@ -590,11 +629,10 @@ export class TodayService {
const count = await this.prisma.labCaseTask.count({
where: {
status: LabTaskStatus.IN_PROGRESS,
roundId: null,
...CURRENT_VISIBLE_TASK_FILTER,
labCase: {
isImportant: true,
sentAt: { not: null },
sends: { some: { organizationId: labOrganizationId } },
...this.visibleStartedToLabWhere(labOrganizationId),
},
},
});
@@ -604,10 +642,14 @@ export class TodayService {
private async loadOverdueCases(labOrganizationId: string, widgets: TodayWidgets) {
const count = await this.prisma.labCase.count({
where: {
sentAt: { not: null },
...this.visibleStartedToLabWhere(labOrganizationId),
dueDate: { not: null, lt: startOfUtcDay() },
sends: { some: { organizationId: labOrganizationId } },
tasks: { some: { status: LabTaskStatus.IN_PROGRESS, roundId: null } },
tasks: {
some: {
...CURRENT_VISIBLE_TASK_FILTER,
status: LabTaskStatus.IN_PROGRESS,
},
},
},
});
widgets.overdueCases = { count };
@@ -617,12 +659,9 @@ export class TodayService {
const count = await this.prisma.labCaseTask.count({
where: {
status: LabTaskStatus.IN_PROGRESS,
roundId: null,
...CURRENT_VISIBLE_TASK_FILTER,
assigneeUserId: null,
labCase: {
sentAt: { not: null },
sends: { some: { organizationId: labOrganizationId } },
},
labCase: this.visibleStartedToLabWhere(labOrganizationId),
},
});
widgets.unassignedTasks = { count };
@@ -750,9 +789,8 @@ export class TodayService {
changedAt: { gte: windowStart, lt: rangeEnd },
changedByUserId: { in: members.map((member) => member.userId) },
task: {
labCase: {
sends: { some: { organizationId: labOrganizationId } },
},
...CURRENT_VISIBLE_TASK_FILTER,
labCase: this.visibleStartedToLabWhere(labOrganizationId),
},
},
_count: { _all: true },
@@ -948,9 +986,13 @@ export class TodayService {
const cases = await this.prisma.labCase.findMany({
where: {
dueDate: { not: null, gte: weekStart, lt: weekEnd },
sentAt: { not: null },
sends: { some: { organizationId: labOrganizationId } },
tasks: { some: { status: LabTaskStatus.IN_PROGRESS, roundId: null } },
...this.visibleStartedToLabWhere(labOrganizationId),
tasks: {
some: {
...CURRENT_VISIBLE_TASK_FILTER,
status: LabTaskStatus.IN_PROGRESS,
},
},
},
select: { dueDate: true },
});
@@ -972,12 +1014,12 @@ export class TodayService {
private async loadCasesInProgress(labOrganizationId: string, widgets: TodayWidgets) {
const cases = await this.prisma.labCase.findMany({
where: {
sentAt: { not: null },
sends: { some: { organizationId: labOrganizationId } },
},
where: this.visibleStartedToLabWhere(labOrganizationId),
include: {
tasks: { where: { roundId: null }, select: { status: true } },
tasks: {
where: CURRENT_VISIBLE_TASK_FILTER,
select: { status: true },
},
},
});
@@ -995,11 +1037,8 @@ export class TodayService {
private async loadCaseCompletion(labOrganizationId: string, charts: TodayCharts) {
const tasks = await this.prisma.labCaseTask.findMany({
where: {
roundId: null,
labCase: {
sentAt: { not: null },
sends: { some: { organizationId: labOrganizationId } },
},
...CURRENT_VISIBLE_TASK_FILTER,
labCase: this.visibleStartedToLabWhere(labOrganizationId),
},
select: { status: true },
});
@@ -1146,11 +1185,9 @@ export class TodayService {
const completedTasks = await this.prisma.labCaseTask.findMany({
where: {
status: LabTaskStatus.COMPLETED,
roundId: null,
...CURRENT_VISIBLE_TASK_FILTER,
lastStatusChangedAt: { gte: weekStart, lt: weekEnd },
labCase: {
sends: { some: { organizationId: labOrganizationId } },
},
labCase: this.visibleStartedToLabWhere(labOrganizationId),
},
select: { lastStatusChangedAt: true },
});
@@ -1183,6 +1220,32 @@ export class TodayService {
}
}
const startedCases = await this.prisma.labCase.findMany({
where: {
origin: LabCaseOrigin.LAB_INTERNAL,
destinationOrganizationId: labOrganizationId,
startedAt: { gte: weekStart, lt: weekEnd },
},
select: {
startedAt: true,
tasks: {
where: CURRENT_VISIBLE_TASK_FILTER,
select: { id: true },
},
},
});
for (const labCase of startedCases) {
if (!labCase.startedAt) continue;
const dayKey = localDayKeyFromDate(labCase.startedAt, offsetMs);
if (receivedCounts.has(dayKey)) {
receivedCounts.set(
dayKey,
(receivedCounts.get(dayKey) ?? 0) + labCase.tasks.length,
);
}
}
charts.labTaskActivityWeek = dayBuckets.map((bucket) => ({
code: bucket.code,
label: bucket.label,
@@ -1205,25 +1268,27 @@ export class TodayService {
);
const cases = await this.prisma.labCase.findMany({
where: {
sentAt: { gte: rangeStart, lt: rangeEnd },
...(orgType === 'CLINIC'
where:
orgType === 'CLINIC'
? {
sentAt: { gte: rangeStart, lt: rangeEnd },
destinationOrganizationId: { not: null },
treatment: {
organizationId,
...(scopeToUser ? { providerUserId: userId } : {}),
},
}
: {
sends: { some: { organizationId } },
}),
},
: this.labCaseListedInRangeWhere(organizationId, rangeStart, rangeEnd),
select: {
destinationOrganizationId: true,
partnerClinicOrganizationId: true,
tasks: { where: { roundId: null }, select: { status: true } },
tasks: {
where:
orgType === 'LAB' ? CURRENT_VISIBLE_TASK_FILTER : { roundId: null },
select: { status: true },
},
treatment: { select: { organizationId: true } },
parentLabCase: { select: { destinationOrganizationId: true } },
},
});
@@ -1233,7 +1298,9 @@ export class TodayService {
const partnerId =
orgType === 'CLINIC'
? labCase.destinationOrganizationId
: labCase.treatment?.organizationId ?? labCase.partnerClinicOrganizationId;
: labCase.treatment?.organizationId ??
labCase.partnerClinicOrganizationId ??
labCase.parentLabCase?.destinationOrganizationId;
if (!partnerId) continue;
const isCompleted =

View File

@@ -7,11 +7,19 @@ import { APP_DATE, createAppDateFormatter } from '@/lib/i18n/format';
export function useTodayDayLabelFormatter() {
const locale = useLocale();
return useMemo(
() => createAppDateFormatter(locale, APP_DATE.chartDay),
() => ({
full: createAppDateFormatter(locale, APP_DATE.chartDay),
axis: createAppDateFormatter(locale, APP_DATE.chartAxisDay),
}),
[locale],
);
}
/** Pulls the plot in from the card edge so the first and last tick stay visible. */
export const TODAY_CHART_PLOT_MARGIN = { top: 8, right: 16, left: 4, bottom: 4 } as const;
export const TODAY_CHART_X_PADDING = { left: 12, right: 12 } as const;
export function formatTodayChartDayLabel(
code: string,
formatter: Intl.DateTimeFormat,
@@ -23,11 +31,12 @@ export function formatTodayChartDayLabel(
export function mapWeekChartBuckets<T extends { code: string; label: string }>(
buckets: T[],
formatter: Intl.DateTimeFormat,
): T[] {
formatters: { full: Intl.DateTimeFormat; axis: Intl.DateTimeFormat },
): Array<T & { axisLabel: string }> {
return buckets.map((bucket) => ({
...bucket,
label: formatTodayChartDayLabel(bucket.code, formatter),
label: formatTodayChartDayLabel(bucket.code, formatters.full),
axisLabel: formatTodayChartDayLabel(bucket.code, formatters.axis),
}));
}

View File

@@ -132,13 +132,10 @@ export function packedCellClassName(layout: TodayDashboardLayout): string {
const rowSpan =
layout.height === 3 ? 'row-span-3' : layout.height === 2 ? 'row-span-2' : 'row-span-1';
const colSpan =
layout.width === 2
? 'col-span-2 max-sm:col-span-1'
: 'col-span-1';
const colSpan = layout.width === 2 ? 'today-span-2' : 'today-span-1';
return `${colSpan} ${rowSpan} min-h-0 min-w-0 overflow-hidden flex flex-col max-lg:${colSpan}`;
return `${colSpan} ${rowSpan} min-h-0 min-w-0 overflow-hidden flex flex-col`;
}
export const TODAY_DASHBOARD_GRID_CLASS =
'today-dashboard-grid grid grid-cols-4 max-lg:grid-cols-2 max-sm:grid-cols-1 gap-4';
/** Column count comes from the dashboard container width in globals.css, not the viewport. */
export const TODAY_DASHBOARD_GRID_CLASS = 'today-dashboard-grid grid gap-4';

View File

@@ -17,7 +17,11 @@ import {
TODAY_CHART_PRIMARY_COLOR,
TODAY_CHART_TOOLTIP_STYLE,
} from '@/components/today/chart-theme';
import { todayChartDenseXAxisProps } from '@/components/today/chart-day-labels';
import {
TODAY_CHART_PLOT_MARGIN,
TODAY_CHART_X_PADDING,
todayChartDenseXAxisProps,
} from '@/components/today/chart-day-labels';
interface TodayAreaChartProps {
data: TodayChartBucket[];
@@ -33,11 +37,22 @@ export function TodayAreaChart({
showXAxis = true,
}: TodayAreaChartProps) {
const xAxis = todayChartDenseXAxisProps(data.length);
const chartData = data.map((row) => ({
...row,
axisLabel: row.axisLabel ?? row.label,
}));
return (
<TodayChartFrame>
<ResponsiveContainer width="100%" height="100%">
<AreaChart data={data} margin={{ top: 8, right: 8, left: -12, bottom: showXAxis ? 2 : -4 }}>
<AreaChart
data={chartData}
margin={
showXAxis
? TODAY_CHART_PLOT_MARGIN
: { ...TODAY_CHART_PLOT_MARGIN, bottom: 0 }
}
>
<defs>
<linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor={color} stopOpacity={0.45} />
@@ -47,7 +62,8 @@ export function TodayAreaChart({
<CartesianGrid stroke={TODAY_CHART_GRID_COLOR} vertical={false} />
{showXAxis ? (
<XAxis
dataKey="label"
dataKey="axisLabel"
padding={TODAY_CHART_X_PADDING}
tick={{ fill: TODAY_CHART_AXIS_COLOR, fontSize: xAxis.fontSize }}
axisLine={{ stroke: TODAY_CHART_GRID_COLOR }}
tickLine={false}
@@ -55,7 +71,7 @@ export function TodayAreaChart({
minTickGap={xAxis.minTickGap}
/>
) : (
<XAxis dataKey="label" hide />
<XAxis dataKey="axisLabel" hide />
)}
<YAxis
allowDecimals={false}
@@ -67,7 +83,10 @@ export function TodayAreaChart({
<Tooltip
cursor={{ stroke: 'rgba(0, 188, 255, 0.25)' }}
contentStyle={TODAY_CHART_TOOLTIP_STYLE}
labelFormatter={(label) => String(label)}
labelFormatter={(_label, payload) => {
const row = payload?.[0]?.payload as TodayChartBucket | undefined;
return row?.label ?? String(_label);
}}
/>
<Area
type="monotone"

View File

@@ -41,22 +41,17 @@ export function TodayCompletionGaugeKpiCard({
<Icon className="h-4 w-4 shrink-0 !text-current" aria-hidden />
</div>
<div className="mt-2 flex min-h-0 flex-1 items-center justify-center">
<div className="w-[58%] min-w-0">
<TodayRadialGaugeChart
size="sm"
compactClassName="h-[120px]"
innerRadius="72%"
compactBarSize={8}
percent={total > 0 ? percent : 0}
completed={completed}
total={total}
percentLabel={total > 0 ? percentLabel : '—'}
tasksLabel={ratioLabel}
fillColor={TODAY_CHART_COMPLETED_COLOR}
showRatio={total > 0}
/>
</div>
<div className="mt-1 flex min-h-0 flex-1 items-center justify-center">
<TodayRadialGaugeChart
size="sm"
percent={total > 0 ? percent : 0}
completed={completed}
total={total}
percentLabel={total > 0 ? percentLabel : '—'}
tasksLabel={ratioLabel}
fillColor={TODAY_CHART_COMPLETED_COLOR}
showRatio={total > 0}
/>
</div>
</Card>
</Link>

View File

@@ -21,24 +21,26 @@ export function TodayDashboardGrid({ cells, loading = false }: TodayDashboardGri
}
return (
<div
className={`${TODAY_DASHBOARD_GRID_CLASS} ${loading ? 'opacity-70 transition-opacity' : ''}`}
style={{ gridAutoRows: 'var(--today-grid-unit, 5.75rem)' }}
>
{packed.map((cell) => (
<div
key={cell.id}
className={`today-dashboard-cell ${packedCellClassName(cell.layout)}`}
style={
{
'--today-gc': cell.gridColumn,
'--today-gr': cell.gridRow,
} as CSSProperties
}
>
<div className="flex h-full min-h-0 flex-1 flex-col">{cell.content}</div>
</div>
))}
<div className={`today-dashboard ${loading ? 'opacity-70 transition-opacity' : ''}`}>
<div
className={TODAY_DASHBOARD_GRID_CLASS}
style={{ gridAutoRows: 'var(--today-grid-unit, 5.75rem)' }}
>
{packed.map((cell) => (
<div
key={cell.id}
className={`today-dashboard-cell ${packedCellClassName(cell.layout)}`}
style={
{
'--today-gc': cell.gridColumn,
'--today-gr': cell.gridRow,
} as CSSProperties
}
>
<div className="flex h-full min-h-0 flex-1 flex-col">{cell.content}</div>
</div>
))}
</div>
</div>
);
}

View File

@@ -17,11 +17,16 @@ import {
TODAY_CHART_RECEIVED_COLOR,
TODAY_CHART_TOOLTIP_STYLE,
} from '@/components/today/chart-theme';
import { todayChartDenseXAxisProps } from '@/components/today/chart-day-labels';
import {
TODAY_CHART_PLOT_MARGIN,
TODAY_CHART_X_PADDING,
todayChartDenseXAxisProps,
} from '@/components/today/chart-day-labels';
import type { TodayStackedDayBucket } from '@/types/today';
export type LabTaskActivityChartRow = {
label: string;
axisLabel: string;
completed: number;
received: number;
};
@@ -45,7 +50,7 @@ export function TodayLabTaskActivityChart({
<div className="flex h-full min-h-0 flex-col">
<div className="min-h-0 flex-1">
<ResponsiveContainer width="100%" height="100%">
<AreaChart data={data} margin={{ top: 8, right: 8, left: -12, bottom: 2 }}>
<AreaChart data={data} margin={TODAY_CHART_PLOT_MARGIN}>
<defs>
<linearGradient id="labTaskCompletedFill" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor={TODAY_CHART_COMPLETED_COLOR} stopOpacity={0.4} />
@@ -58,7 +63,8 @@ export function TodayLabTaskActivityChart({
</defs>
<CartesianGrid stroke={TODAY_CHART_GRID_COLOR} vertical={false} />
<XAxis
dataKey="label"
dataKey="axisLabel"
padding={TODAY_CHART_X_PADDING}
tick={{ fill: TODAY_CHART_AXIS_COLOR, fontSize: xAxis.fontSize }}
axisLine={{ stroke: TODAY_CHART_GRID_COLOR }}
tickLine={false}
@@ -75,7 +81,10 @@ export function TodayLabTaskActivityChart({
<Tooltip
cursor={{ stroke: 'rgba(0, 188, 255, 0.25)' }}
contentStyle={TODAY_CHART_TOOLTIP_STYLE}
labelFormatter={(label) => String(label)}
labelFormatter={(_label, payload) => {
const row = payload?.[0]?.payload as LabTaskActivityChartRow | undefined;
return row?.label ?? String(_label);
}}
/>
<Area
type="monotone"
@@ -129,6 +138,7 @@ export function mapLabTaskActivityChartData(
): LabTaskActivityChartRow[] {
return buckets.map((bucket) => ({
label: bucket.label,
axisLabel: bucket.axisLabel ?? bucket.label,
completed: bucket.completed,
received: bucket.received,
}));

View File

@@ -17,6 +17,10 @@ import {
TODAY_CHART_RECEIVED_COLOR,
TODAY_CHART_TOOLTIP_STYLE,
} from '@/components/today/chart-theme';
import {
TODAY_CHART_PLOT_MARGIN,
TODAY_CHART_X_PADDING,
} from '@/components/today/chart-day-labels';
import type { TodayPartnerCasesBucket } from '@/types/today';
interface TodayPartnerCasesStackedBarChartProps {
@@ -48,10 +52,11 @@ export function TodayPartnerCasesStackedBarChart({
<div className="flex h-full min-h-0 flex-col">
<div className="min-h-0 flex-1">
<ResponsiveContainer width="100%" height="100%">
<BarChart data={chartData} margin={{ top: 8, right: 8, left: -12, bottom: 0 }}>
<BarChart data={chartData} margin={TODAY_CHART_PLOT_MARGIN}>
<CartesianGrid stroke={TODAY_CHART_GRID_COLOR} vertical={false} />
<XAxis
dataKey="shortLabel"
padding={TODAY_CHART_X_PADDING}
tick={{ fill: TODAY_CHART_AXIS_COLOR, fontSize: 11 }}
axisLine={{ stroke: TODAY_CHART_GRID_COLOR }}
tickLine={false}

View File

@@ -24,6 +24,8 @@ interface TodayRadialGaugeChartProps {
compactClassName?: string;
/** Ring thickness when size is "sm". */
compactBarSize?: number;
/** How far the ring reaches. Compact default leaves a margin so the stroke stays inside. */
outerRadius?: string | number;
}
export function TodayRadialGaugeChart({
@@ -38,24 +40,27 @@ export function TodayRadialGaugeChart({
innerRadius,
compactClassName,
compactBarSize,
outerRadius,
}: TodayRadialGaugeChartProps) {
const isCompact = size === 'sm';
const clamped = Math.max(0, Math.min(100, percent));
const data = [{ name: 'progress', value: clamped, fill: fillColor }];
const resolvedInnerRadius = innerRadius ?? (isCompact ? '62%' : '68%');
const resolvedBarSize = isCompact ? (compactBarSize ?? 9) : 14;
const resolvedInnerRadius = innerRadius ?? (isCompact ? '88%' : '68%');
const resolvedBarSize = isCompact ? (compactBarSize ?? 6) : 14;
const wrapperClass = isCompact
? compactClassName ?? 'h-[108px]'
: 'h-full min-h-0 flex-1';
? compactClassName ?? 'aspect-square h-full w-auto max-w-full'
: 'h-full min-h-0 w-full flex-1';
return (
<div className={`relative w-full ${wrapperClass}`}>
<div
className={`relative min-w-0 ${isCompact ? 'overflow-hidden' : ''} ${wrapperClass}`}
>
<ResponsiveContainer width="100%" height="100%">
<RadialBarChart
cx="50%"
cy="50%"
innerRadius={resolvedInnerRadius}
outerRadius="100%"
outerRadius={outerRadius ?? (isCompact ? '98%' : '100%')}
barSize={resolvedBarSize}
data={data}
startAngle={90}
@@ -69,26 +74,30 @@ export function TodayRadialGaugeChart({
/>
</RadialBarChart>
</ResponsiveContainer>
<div
className={`pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center ${
innerRadius != null && isCompact ? 'px-2.5' : 'px-1'
}`}
>
<span
className={`font-semibold text-text-primary ${isCompact ? 'text-base leading-tight' : 'text-3xl'}`}
<div className="pointer-events-none absolute inset-0 flex items-center justify-center">
<div
className={`flex max-w-[62%] flex-col items-center text-center ${
isCompact ? 'px-0.5' : 'px-1'
}`}
>
{percentLabel}
</span>
<span className={`text-text-muted ${isCompact ? 'mt-0.5 text-[10px]' : 'mt-1 text-xs'}`}>
{tasksLabel}
</span>
{showRatio && total > 0 ? (
<span
className={`text-text-secondary ${isCompact ? 'mt-0.5 text-[10px]' : 'mt-0.5 text-[11px]'}`}
className={`font-semibold text-text-primary ${isCompact ? 'text-sm leading-tight' : 'text-3xl'}`}
>
{completed}/{total}
{percentLabel}
</span>
) : null}
<span
className={`text-text-muted ${isCompact ? 'mt-0.5 text-[10px] leading-tight' : 'mt-1 text-xs'}`}
>
{tasksLabel}
</span>
{showRatio && total > 0 ? (
<span
className={`text-text-secondary ${isCompact ? 'mt-0.5 text-[10px] leading-tight' : 'mt-0.5 text-[11px]'}`}
>
{completed}/{total}
</span>
) : null}
</div>
</div>
</div>
);

View File

@@ -53,30 +53,34 @@ export function TodaySubscriptionKpiCard({ subscription }: TodaySubscriptionKpiC
<CreditCard className="h-4 w-4 shrink-0 !text-current" aria-hidden />
</div>
<div className="mt-2 grid min-h-0 flex-1 grid-cols-2 gap-1 content-center">
<TodayRadialGaugeChart
size="sm"
percent={
subscription.seatsUnlimited || !subscription.hasActivePlan
? 0
: subscription.seatsPercent
}
completed={subscription.seatsUsed}
total={seatsRatioTotal}
percentLabel={seatsPercentLabel}
tasksLabel={seatsTasksLabel}
showRatio={!subscription.seatsUnlimited && seatsRatioTotal > 0}
/>
<TodayRadialGaugeChart
size="sm"
percent={subscription.hasActivePlan ? subscription.periodPercent : 0}
completed={subscription.periodElapsedDays}
total={subscription.hasActivePlan ? subscription.periodTotalDays : 0}
percentLabel={periodPercentLabel}
tasksLabel={t('subscriptionPeriodLabel')}
fillColor={PERIOD_GAUGE_COLOR}
showRatio={subscription.hasActivePlan}
/>
<div className="mt-1 grid min-h-0 min-w-0 flex-1 grid-cols-2 items-center gap-1">
<div className="flex h-full min-h-0 min-w-0 items-center justify-center">
<TodayRadialGaugeChart
size="sm"
percent={
subscription.seatsUnlimited || !subscription.hasActivePlan
? 0
: subscription.seatsPercent
}
completed={subscription.seatsUsed}
total={seatsRatioTotal}
percentLabel={seatsPercentLabel}
tasksLabel={seatsTasksLabel}
showRatio={!subscription.seatsUnlimited && seatsRatioTotal > 0}
/>
</div>
<div className="flex h-full min-h-0 min-w-0 items-center justify-center">
<TodayRadialGaugeChart
size="sm"
percent={subscription.hasActivePlan ? subscription.periodPercent : 0}
completed={subscription.periodElapsedDays}
total={subscription.hasActivePlan ? subscription.periodTotalDays : 0}
percentLabel={periodPercentLabel}
tasksLabel={t('subscriptionPeriodLabel')}
fillColor={PERIOD_GAUGE_COLOR}
showRatio={subscription.hasActivePlan}
/>
</div>
</div>
</Card>
</Link>

View File

@@ -50,6 +50,8 @@ export const APP_DATE = {
year: 'numeric',
} satisfies Intl.DateTimeFormatOptions,
chartDay: { weekday: 'short', month: 'short', day: 'numeric' } satisfies Intl.DateTimeFormatOptions,
/** Axis tick only. Tooltip keeps `chartDay`. */
chartAxisDay: { month: 'short', day: 'numeric' } satisfies Intl.DateTimeFormatOptions,
history: {
weekday: 'short',
month: 'short',

View File

@@ -361,8 +361,32 @@ select option {
border-radius: var(--radius-lg);
}
@media (min-width: 1024px) {
.today-dashboard-grid .today-dashboard-cell {
/* Column count follows the dashboard width, not the browser window (the sidebar sits beside it). */
.today-dashboard {
container-type: inline-size;
}
.today-dashboard-grid {
grid-template-columns: minmax(0, 1fr);
}
@container (min-width: 40rem) {
.today-dashboard-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.today-dashboard-grid .today-dashboard-cell.today-span-2 {
grid-column: span 2;
}
}
@container (min-width: 64rem) {
.today-dashboard-grid {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.today-dashboard-grid .today-dashboard-cell.today-span-1,
.today-dashboard-grid .today-dashboard-cell.today-span-2 {
grid-column: var(--today-gc);
grid-row: var(--today-gr);
}

View File

@@ -13,12 +13,16 @@ export type TodaySummaryActions = {
export type TodayChartBucket = {
code: string;
label: string;
/** Short tick (`Oct 10`). Tooltip uses `label`. */
axisLabel?: string;
count: number;
};
export type TodayStackedDayBucket = {
code: string;
label: string;
/** Short tick (`Oct 10`). Tooltip uses `label`. */
axisLabel?: string;
completed: number;
received: number;
};