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
@@ -101,6 +101,39 @@ test('the actual summary click stores release A and filters until a new detail i
ui.openRecords(null,'black');assert.equal(ui.get().releaseId,'release-B');assert.equal(ui.get().month,2);
});
test('product monthly drilldown keeps the product and clicked month for source requests and export',async()=>{
const source=read('QueryPage.tsx'),start=source.indexOf(' const openRecords = useCallback');
const callback=source.slice(start,source.indexOf(' const summaryMetricsError',start));
const query={year:2026,quarter:1,view:'product',department:'产业部',group:'业务分组',product:'18X15X4+T',extraFilters:{customer:['001']}};
const ui=new Function('freezeSourceRecordsQuery','query',transpile(`
const summaryMetricsData={release:{id:'release-A'}},queryParams={...query,product:undefined},defectQueryParams=query;
const drilledProduct='18X15X4+T',view='product',message={info(){}},useCallback=fn=>fn;
let snapshot;
const setRecordQuerySnapshot=value=>snapshot=value,setSelectedRecord=()=>{},setRecordStage=()=>{},setRecordMonth=()=>{},setRecordsOpen=()=>{};
${callback}
return {openRecords,get:()=>snapshot};
`))(freezeSourceRecordsQuery,query);
for(const month of [1,2]) {
const key=`2026-0${month}`;
ui.openRecords({key,label:key,month:key,product:null},'black',month);
const frozen=ui.get();
assert.equal(frozen.product,'18X15X4+T');assert.equal(frozen.month,month);assert.equal(frozen.quarter,undefined);
assert.equal(frozen.department,query.department);assert.equal(frozen.group,query.group);
assert.deepEqual(frozen.extraFilters,query.extraFilters);assert.equal(frozen.releaseId,'release-A');
const drawer=drawerFixture();drawer.props.query=frozen;
for(const stage of ['black','bright']) {
drawer.props.stage=stage;drawer.render();const request=drawer.requests.at(-1);
assert.equal(request.params.product,'18X15X4+T');assert.equal(request.params.month,month);assert.equal(request.params.stage,stage);
request.resolve({rows:[{id:stage,raw:{规格:'18X15X4+T'}}],total:1,pageSize:20,page:1});await tick();
}
const tree=drawer.render();
await find(tree,n=>n.type==='Button'&&textOf(n)==='导出明细 Excel').props.onClick();
assert.equal(drawer.exports[0].params.product,'18X15X4+T');assert.equal(drawer.exports[0].params.month,month);
assert.equal(drawer.exports[0].params.releaseId,'release-A');drawer.unmount();
}
assert.equal(query.quarter,1);assert.equal(query.month,undefined);
});
function drawerFixture() {
const source=read('QueryPage.tsx');const code=source.slice(source.indexOf('function RecordsDrawer(')).replace(/export \{ fullYearTrend \};/, '');
const requests=[],exports=[];let downloaded=0,refreshKey=0;
@@ -119,6 +152,26 @@ function drawerFixture() {
return {requests,exports,props,render:()=>renderer.render(props),unmount:()=>renderer.unmount(),invalidate(){refreshKey++;},get downloaded(){return downloaded;}};
}
test('single-stage detail callback freezes the clicked quarterly/yearly row instead of selecting unassigned product',()=>{
const source=read('StageProductPage.tsx'),start=source.indexOf(' const openDetail=');
const callback=source.slice(start,source.indexOf(' const runExport=',start));
for(const stage of ['black','bright']) {
const ui=new Function('freezeSourceRecordsQuery','stage',transpile(`
const applied={year:2026,month:10,product:'产品A',stage,columnFilters:[{field:'customer',stages:[stage],operator:'in',values:['001']}]};
const current={release:{id:'release-A'}},drilledProduct='产品A';let records;
const setRecordVisible=()=>{},setRecords=value=>records=value;
${callback}
return {openDetail,get:()=>records};
`))(freezeSourceRecordsQuery,stage);
for(const period of ['2026-Q2','2025']) {
ui.openDetail({key:period,month:period,period,product:null},stage);
const query=ui.get().query;assert.equal(query.product,'产品A');assert.equal(query.month,undefined);
assert.equal(query.year,period==='2025'?2025:2026);assert.equal(query.quarter,period==='2025'?undefined:2);
assert.equal(query.columnFilters[0].stages[0],stage);assert.equal(query.releaseId,'release-A');
}
}
});
test('actual drawer retains prior rows without enabling stale actions and retries the same frozen release',async()=>{
const ui=drawerFixture();ui.render();assert.equal(ui.requests[0].params.page,1);assert.equal(ui.requests[0].params.releaseId,'release-A');
ui.requests[0].resolve({rows:[{id:'A-1',raw:{field:'value'}}],total:45,pageSize:20,page:1});await tick();let tree=ui.render();