Skip to content

Commit

Permalink
feat(Handlebars): formatNumber and group helpers (#31261)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor-Avila authored Dec 3, 2024
1 parent 1e0c04f commit 77f3764
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"dependencies": {
"handlebars": "^4.7.8",
"handlebars-group-by": "^1.0.1",
"just-handlebars-helpers": "^1.0.19"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ declare module '*.png' {
}
declare module '*.jpg';
declare module 'just-handlebars-helpers';
declare module 'handlebars-group-by';

0 comments on commit 77f3764

Please sign in to comment.