reynoldmorel commented on code in PR #37229:
URL: https://github.com/apache/superset/pull/37229#discussion_r2705335275
##########
superset-frontend/plugins/plugin-chart-echarts/src/utils/forecast.ts:
##########
@@ -26,6 +26,41 @@ import {
} from '../types';
import { sanitizeHtml } from './series';
+/**
+ * Enriches the verbose map by creating human-readable versions of compound
field names.
+ *
+ * @param label_map — a mapping of compound keys to arrays of component labels
(e.g., { "revenue_total_usd": ["revenue", "total", "usd"] })
+ * @param verboseMap — the existing mapping of field names to their display
labels
+ * @returns an updated verbose map that includes human-readable versions of
the compound keys
+ */
+export const addLabelMapToVerboseMap = (
+ label_map: Record<string, string[]>,
+ verboseMap: Record<string, string> = {},
+): Record<string, string> => {
+ /**
+ * Logic:
+ * 1. Iterates through each entry in label_map
+ * 2. For each compound key and its component labels, filters to only labels
that have verbose mappings
+ * 3. Replaces each component label in the key with its verbose name from
verboseMap
+ * 4. Stores the transformed key in a new map
+ * 5. Returns the original verboseMap merged with the new transformed entries
+ */
+ const newVerboseMap: Record<string, string> = {};
+
+ Object.entries(label_map).forEach(([key, labels]) => {
+ if (labels) {
+ labels
+ .filter(l => verboseMap[l])
+ .forEach(l => {
+ const newKey = key.replaceAll(l, verboseMap[l]);
+ newVerboseMap[key] = newKey;
+ });
Review Comment:
Addressed
--
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]