Skip to content

Commit

Permalink
fix: 处理 getMultiData 在找不到数据时的报错信息
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo committed Dec 20, 2023
1 parent 1c5a076 commit 04942ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions packages/s2-core/src/data-set/pivot-data-set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
compact,
each,
every,
filter,
Expand Down Expand Up @@ -567,11 +568,15 @@ export class PivotDataSet extends BaseDataSet {
if (isMultiValue(current)) {
result = flattenIndexesData(result, queryType);
} else {
result = map(result, (item) => item[current]).filter(Boolean);
result = compact(
map(result, (item) => {
return item?.[current];
}),
);
}
} else if (isMultiValue(current)) {
hadMultiField = true;
result = [result];
result = compact([result]);
i--;
} else {
result = result?.[current];
Expand Down
7 changes: 4 additions & 3 deletions packages/s2-core/src/utils/dataset/pivot-data-set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
compact,
find,
flatMap,
forEach,
Expand Down Expand Up @@ -582,14 +583,14 @@ export function flattenIndexesData(
return [];
}
if (!isArray(data)) {
return [data];
return compact([data]);
}
return flatMap(data, (dimensionData) => {
if (!isArray(dimensionData)) {
return [dimensionData];
return compact([dimensionData]);
}
// 数组的第 0 项是总计/小计专位,从第 1 项开始是明细数据
const startIdx = queryType === QueryDataType.DetailOnly ? 1 : 0;
return dimensionData.slice(startIdx).filter(Boolean);
return compact(dimensionData.slice(startIdx));
});
}

0 comments on commit 04942ca

Please sign in to comment.