Skip to content

Commit 88221c0

Browse files
committed
test(chart): add drill option requst builder tests
1 parent c18503e commit 88221c0

File tree

2 files changed

+138
-1
lines changed

2 files changed

+138
-1
lines changed

frontend/src/app/models/ChartDataRequestBuilder.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,34 @@ export class ChartDataRequestBuilder {
381381

382382
if (this.aggregation === false) {
383383
if (
384-
cur.type === ChartDataSectionType.GROUP ||
385384
cur.type === ChartDataSectionType.COLOR ||
386385
cur.type === ChartDataSectionType.AGGREGATE ||
387386
cur.type === ChartDataSectionType.SIZE ||
388387
cur.type === ChartDataSectionType.INFO ||
389388
cur.type === ChartDataSectionType.MIXED
390389
) {
391390
return acc.concat(cur.rows);
391+
} else if (cur.type === ChartDataSectionType.GROUP) {
392+
if (cur.drillable) {
393+
if (
394+
!this.drillOption ||
395+
this.drillOption?.mode === DrillMode.Normal ||
396+
!this.drillOption?.getCurrentFields()
397+
) {
398+
return acc.concat(cur.rows?.[0] || []);
399+
}
400+
return acc.concat(
401+
cur.rows?.filter(field => {
402+
return Boolean(
403+
this.drillOption
404+
?.getCurrentFields()
405+
?.some(df => df.uid === field.uid),
406+
);
407+
}) || [],
408+
);
409+
} else {
410+
return acc.concat(cur.rows);
411+
}
392412
}
393413
}
394414

frontend/src/app/models/__tests__/ChartDataRequestBuilder.test.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
DataViewFieldType,
2424
FilterConditionType,
2525
} from 'app/constants';
26+
import { getChartDrillOption } from 'app/utils/internalChartHelper';
2627
import { FilterSqlOperator, RECOMMEND_TIME } from 'globalConstants';
2728
import moment from 'moment';
2829
import { ChartDataRequestBuilder } from '../ChartDataRequestBuilder';
@@ -1072,4 +1073,120 @@ describe('ChartDataRequestBuild Test', () => {
10721073
'name',
10731074
]);
10741075
});
1076+
1077+
test('should get select columns with drill option', () => {
1078+
const dataView = { id: 'view-id' } as any;
1079+
const chartDataConfigs = [
1080+
{
1081+
type: ChartDataSectionType.GROUP,
1082+
key: 'GROUP',
1083+
drillable: true,
1084+
rows: [
1085+
{
1086+
uid: 'group-r1',
1087+
colName: 'group-r1',
1088+
type: '',
1089+
category: '',
1090+
},
1091+
{
1092+
uid: 'group-r2',
1093+
colName: 'group-r2',
1094+
type: '',
1095+
category: '',
1096+
},
1097+
],
1098+
},
1099+
{
1100+
type: ChartDataSectionType.AGGREGATE,
1101+
key: 'aggregation',
1102+
rows: [
1103+
{
1104+
colName: 'amount',
1105+
type: '',
1106+
category: '',
1107+
},
1108+
],
1109+
},
1110+
{
1111+
type: ChartDataSectionType.SIZE,
1112+
key: 'size',
1113+
rows: [
1114+
{
1115+
colName: 'size',
1116+
type: '',
1117+
category: '',
1118+
},
1119+
],
1120+
},
1121+
{
1122+
type: ChartDataSectionType.INFO,
1123+
key: 'info',
1124+
rows: [
1125+
{
1126+
colName: 'info',
1127+
type: '',
1128+
category: '',
1129+
},
1130+
],
1131+
},
1132+
{
1133+
type: ChartDataSectionType.COLOR,
1134+
key: 'color',
1135+
rows: [
1136+
{
1137+
colName: 'color',
1138+
type: '',
1139+
category: '',
1140+
},
1141+
],
1142+
},
1143+
{
1144+
type: ChartDataSectionType.MIXED,
1145+
key: 'MIXED',
1146+
rows: [
1147+
{
1148+
colName: 'mix',
1149+
type: '',
1150+
category: '',
1151+
},
1152+
],
1153+
},
1154+
{
1155+
type: ChartDataSectionType.FILTER,
1156+
key: 'filter',
1157+
rows: [
1158+
{
1159+
colName: 'filter',
1160+
type: '',
1161+
category: '',
1162+
},
1163+
],
1164+
},
1165+
] as any;
1166+
const chartSettingConfigs = [];
1167+
const pageInfo = {};
1168+
const enableScript = false;
1169+
const enableAggregation = false;
1170+
const drillOption = getChartDrillOption(chartDataConfigs);
1171+
drillOption?.drillDown();
1172+
1173+
const builder = new ChartDataRequestBuilder(
1174+
dataView,
1175+
chartDataConfigs,
1176+
chartSettingConfigs,
1177+
pageInfo,
1178+
enableScript,
1179+
enableAggregation,
1180+
).addDrillOption(drillOption);
1181+
const requestParams = builder.build();
1182+
1183+
expect(requestParams.columns).toEqual([
1184+
'group-r2',
1185+
'amount',
1186+
'size',
1187+
'info',
1188+
'color',
1189+
'mix',
1190+
]);
1191+
});
10751192
});

0 commit comments

Comments
 (0)