feat: drill defect trends into detailed rates and preserve query context

This commit is contained in:
2026-11-13 13:37:32 +08:00
parent 48ae58e577
commit 63bf8c16d3
31 changed files with 1215 additions and 107 deletions
+19
View File
@@ -0,0 +1,19 @@
import type { DefectDrilldownResponse, MetricRow, QueryParams, TrendMetricRow } from './types';
export const defectRateLabel = (label: string) => label.endsWith('重量') ? `${label.slice(0,-2)}废率` : `${label}率`;
export function defectScope(query: QueryParams): Record<string, unknown> {
const {view: _view,trendGranularity: _granularity,...scope}=query;
return scope;
}
export function defectGroup(data: DefectDrilldownResponse, row: MetricRow) {
const period=row as TrendMetricRow;
const sourceKey=(row as MetricRow & {sourceMetricKey?:string}).sourceMetricKey??row.key;
const key=data.dimension==='period'?String(period.period??period.month):data.dimension==='overall'?'overall':sourceKey??'__UNASSIGNED__';
return data.groups.find(group=>group.key===key);
}
export function defectCell(data: DefectDrilldownResponse, row: MetricRow, field: string, display: 'weight'|'rate'): number|null {
const group=defectGroup(data,row);
if(field==='parent')return (display==='rate'?group?.parentRate:group?.parentWeight)??null;
const child=group?.children.find(value=>value.key===field);
return (display==='rate'?child?.rate:child?.weight)??null;
}