diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index ea457bfec6b87..1b211ee90451a 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -28030,6 +28030,14 @@ "uglify-js": "^3.1.4" } }, + "node_modules/handlebars-group-by": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/handlebars-group-by/-/handlebars-group-by-1.0.1.tgz", + "integrity": "sha512-qwVVDVAJMBKdmnQU8jcEXGOu+4/2YJX1RP3pUw6Ee9t6gdkxt+dJEWDudSFTgqb35KXrktw/Nn/Dp3Rx5muHpg==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/handlebars/node_modules/source-map": { "version": "0.6.1", "license": "BSD-3-Clause", @@ -58569,6 +58577,7 @@ "license": "Apache-2.0", "dependencies": { "handlebars": "^4.7.8", + "handlebars-group-by": "^1.0.1", "just-handlebars-helpers": "^1.0.19" }, "devDependencies": { @@ -69180,6 +69189,7 @@ "@types/jest": "^29.5.12", "@types/lodash": "^4.17.7", "handlebars": "^4.7.8", + "handlebars-group-by": "*", "jest": "^29.7.0", "just-handlebars-helpers": "^1.0.19" }, @@ -79832,6 +79842,11 @@ } } }, + "handlebars-group-by": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/handlebars-group-by/-/handlebars-group-by-1.0.1.tgz", + "integrity": "sha512-qwVVDVAJMBKdmnQU8jcEXGOu+4/2YJX1RP3pUw6Ee9t6gdkxt+dJEWDudSFTgqb35KXrktw/Nn/Dp3Rx5muHpg==" + }, "har-schema": { "version": "2.0.0", "dev": true diff --git a/superset-frontend/plugins/plugin-chart-handlebars/package.json b/superset-frontend/plugins/plugin-chart-handlebars/package.json index 3db9ff58e4f68..c432215852239 100644 --- a/superset-frontend/plugins/plugin-chart-handlebars/package.json +++ b/superset-frontend/plugins/plugin-chart-handlebars/package.json @@ -28,6 +28,7 @@ }, "dependencies": { "handlebars": "^4.7.8", + "handlebars-group-by": "^1.0.1", "just-handlebars-helpers": "^1.0.19" }, "peerDependencies": { diff --git a/superset-frontend/plugins/plugin-chart-handlebars/src/components/Handlebars/HandlebarsViewer.tsx b/superset-frontend/plugins/plugin-chart-handlebars/src/components/Handlebars/HandlebarsViewer.tsx index 45a191757fd01..737416e196751 100644 --- a/superset-frontend/plugins/plugin-chart-handlebars/src/components/Handlebars/HandlebarsViewer.tsx +++ b/superset-frontend/plugins/plugin-chart-handlebars/src/components/Handlebars/HandlebarsViewer.tsx @@ -22,6 +22,7 @@ import moment from 'moment'; import { useMemo, useState } from 'react'; import { isPlainObject } from 'lodash'; import Helpers from 'just-handlebars-helpers'; +import HandlebarsGroupBy from 'handlebars-group-by'; export interface HandlebarsViewerProps { templateSource: string; @@ -88,4 +89,15 @@ Handlebars.registerHelper('stringify', (obj: any, obj2: any) => { return isPlainObject(obj) ? JSON.stringify(obj) : String(obj); }); +Handlebars.registerHelper( + 'formatNumber', + function (number: any, locale = 'en-US') { + if (typeof number !== 'number') { + return number; + } + return number.toLocaleString(locale); + }, +); + Helpers.registerHelpers(Handlebars); +HandlebarsGroupBy.register(Handlebars); diff --git a/superset-frontend/plugins/plugin-chart-handlebars/types/external.d.ts b/superset-frontend/plugins/plugin-chart-handlebars/types/external.d.ts index ae61945f05350..cd32b201fc5be 100644 --- a/superset-frontend/plugins/plugin-chart-handlebars/types/external.d.ts +++ b/superset-frontend/plugins/plugin-chart-handlebars/types/external.d.ts @@ -22,3 +22,4 @@ declare module '*.png' { } declare module '*.jpg'; declare module 'just-handlebars-helpers'; +declare module 'handlebars-group-by';