diff --git a/superset-frontend/src/components/Chart/ChartRenderer.jsx b/superset-frontend/src/components/Chart/ChartRenderer.jsx index d93e30a107..f1c5e42034 100644 --- a/superset-frontend/src/components/Chart/ChartRenderer.jsx +++ b/superset-frontend/src/components/Chart/ChartRenderer.jsx @@ -78,7 +78,7 @@ const defaultProps = { onFilterMenuOpen: () => BLANK, onFilterMenuClose: () => BLANK, initialValues: BLANK, - setControlValue() {}, + setControlValue() { }, triggerRender: false, }; @@ -247,6 +247,29 @@ class ChartRenderer extends Component { } } + removeAggregations() { + if (Array.isArray(this.mutableQueriesResponse)) { + this.mutableQueriesResponse = this.mutableQueriesResponse.map(query => { + if (query.data && Array.isArray(query.data)) { + query.data = query.data.map(row => { + const cleanedRow = {}; + Object.entries(row).forEach(([key, value]) => { + // Regex to remove aggregation functions and brackets + const cleanedKey = key.replace(/^(MAX|MIN|SUM|AVG|COUNT|COUNT_DISTINCT)\((.*?)\)$/i, '$2'); + cleanedRow[cleanedKey] = value; + }); + return cleanedRow; + }); + } + return query; + }); + + console.log('Updated data with cleaned keys:', this.mutableQueriesResponse); + } else { + console.warn('mutableQueriesResponse is not an array or is undefined.'); + } + } + render() { const { chartAlert, chartStatus, chartId, emitCrossFilters } = this.props; @@ -288,13 +311,13 @@ class ChartRenderer extends Component { const webpackHash = process.env.WEBPACK_MODE === 'development' ? `-${ - // eslint-disable-next-line camelcase - typeof __webpack_require__ !== 'undefined' && - // eslint-disable-next-line camelcase, no-undef - typeof __webpack_require__.h === 'function' && - // eslint-disable-next-line no-undef, camelcase - __webpack_require__.h() - }` + // eslint-disable-next-line camelcase + typeof __webpack_require__ !== 'undefined' && + // eslint-disable-next-line camelcase, no-undef + typeof __webpack_require__.h === 'function' && + // eslint-disable-next-line no-undef, camelcase + __webpack_require__.h() + }` : ''; let noResultsComponent; @@ -302,8 +325,8 @@ class ChartRenderer extends Component { const noResultDescription = this.props.source === ChartSource.Explore ? t( - 'Make sure that the controls are configured properly and the datasource contains data for the selected time range', - ) + 'Make sure that the controls are configured properly and the datasource contains data for the selected time range', + ) : undefined; const noResultImage = 'chart.svg'; if (width > BIG_NO_RESULT_MIN_WIDTH && height > BIG_NO_RESULT_MIN_HEIGHT) {