This is an automated email from the ASF dual-hosted git repository.

vavila pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 77f3764fea feat(Handlebars): formatNumber and group helpers (#31261)
77f3764fea is described below

commit 77f3764fea7ca0fdd95285794758a6ada4d4a608
Author: Vitor Avila <[email protected]>
AuthorDate: Tue Dec 3 17:55:57 2024 -0300

    feat(Handlebars): formatNumber and group helpers (#31261)
---
 superset-frontend/package-lock.json                       | 15 +++++++++++++++
 .../plugins/plugin-chart-handlebars/package.json          |  1 +
 .../src/components/Handlebars/HandlebarsViewer.tsx        | 12 ++++++++++++
 .../plugins/plugin-chart-handlebars/types/external.d.ts   |  1 +
 4 files changed, 29 insertions(+)

diff --git a/superset-frontend/package-lock.json 
b/superset-frontend/package-lock.json
index ea457bfec6..1b211ee904 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 3db9ff58e4..c432215852 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 45a191757f..737416e196 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 ae61945f05..cd32b201fc 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';

Reply via email to