You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by va...@apache.org on 2024/12/02 21:39:37 UTC
(superset) branch feat/more-handlebars-helpers created (now feb4feeb49)
This is an automated email from the ASF dual-hosted git repository.
vavila pushed a change to branch feat/more-handlebars-helpers
in repository https://gitbox.apache.org/repos/asf/superset.git
at feb4feeb49 feat(Handlebars): formatNumber and group helpers
This branch includes the following new commits:
new feb4feeb49 feat(Handlebars): formatNumber and group helpers
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: feat(Handlebars): formatNumber and group helpers
Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vavila pushed a commit to branch feat/more-handlebars-helpers
in repository https://gitbox.apache.org/repos/asf/superset.git
commit feb4feeb49ccc43225bb57f2334f1b3d6f484e9c
Author: Vitor Avila <vi...@preset.io>
AuthorDate: Mon Dec 2 18:39:18 2024 -0300
feat(Handlebars): formatNumber and group helpers
---
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 93d801a70e..219a70e530 100644
--- a/superset-frontend/package-lock.json
+++ b/superset-frontend/package-lock.json
@@ -28029,6 +28029,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",
@@ -58568,6 +58576,7 @@
"license": "Apache-2.0",
"dependencies": {
"handlebars": "^4.7.8",
+ "handlebars-group-by": "^1.0.1",
"just-handlebars-helpers": "^1.0.19"
},
"devDependencies": {
@@ -69177,6 +69186,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"
},
@@ -79829,6 +79839,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..3061b3afa0 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: string = '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';