korbit-ai[bot] commented on code in PR #36050:
URL: https://github.com/apache/superset/pull/36050#discussion_r2508298844
##########
superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx:
##########
@@ -348,6 +418,86 @@ export class TableRenderer extends Component {
return spans;
}
+ calculateGroups(pivotData, visibleColKey, columnIndex) {
+ const groups = {};
+ const rows = pivotData.rowKeys;
+ rows.forEach(rowKey => {
+ let current = groups;
+ let sumGroup = 0;
+ rowKey.forEach(key => {
+ if (!current[key]) {
+ current[key] = { currentVal: 0 };
+ }
+ sumGroup += pivotData
+ .getAggregator(rowKey, visibleColKey[columnIndex])
+ .value();
+ current[key].currentVal = sumGroup;
+ current = current[key];
+ });
+ });
+ return groups;
+ }
+
+ sortAndCacheData(groups, sortOrder, subtotals, maxRowIndex) {
+ const { rowEnabled, rowPartialOnTop } = subtotals;
+ const sortedGroups = sortHierarchicalObject(
+ groups,
+ sortOrder,
+ rowPartialOnTop,
+ );
+ return convertToArray(
+ sortedGroups,
+ rowEnabled,
+ rowPartialOnTop,
+ maxRowIndex,
+ );
+ }
+
+ sortData(columnIndex, visibleColKeys, pivotData, maxRowIndex) {
+ this.setState(state => {
+ const { sortingOrder, activeSortColumn } = state;
+
+ const newSortingOrder = [];
+ let newDirection = 'asc';
+
+ if (activeSortColumn === columnIndex) {
+ newDirection = sortingOrder[columnIndex] === 'asc' ? 'desc' : 'asc';
+ }
+
+ newSortingOrder[columnIndex] = newDirection;
+
+ const cacheKey = `${columnIndex}-${newDirection}`;
+ let newRowKeys;
+ if (this.sortCache.has(cacheKey)) {
+ const cachedRowKeys = this.sortCache.get(cacheKey);
+ newRowKeys = cachedRowKeys;
+ } else {
+ const groups = this.calculateGroups(
+ pivotData,
+ visibleColKeys,
+ columnIndex,
+ );
Review Comment:
Great, thank you for addressing that issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]