Skip to content

Commit e19cbef

Browse files
committed
fix: UUID generator that nashorn not supported
1 parent 0542d72 commit e19cbef

File tree

2 files changed

+12
-4
lines changed
  • frontend/src

2 files changed

+12
-4
lines changed

frontend/src/app/pages/DashBoardPage/components/WidgetManager/utils/init.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type {
2727
import { Widget } from 'app/pages/DashBoardPage/types/widgetTypes';
2828
import type { ChartStyleConfig } from 'app/types/ChartConfig';
2929
import { getInitialLocale } from 'locales/utils';
30-
import { uuidv4 } from 'utils/utils';
30+
import { universalUUID } from 'utils/utils';
3131

3232
export const initTitleTpl = () => {
3333
const titleTpl: ChartStyleConfig = {
@@ -472,7 +472,7 @@ export const initFreeWidgetRect = (): RectConfig => ({
472472

473473
export const widgetTpl = (): Widget => {
474474
return {
475-
id: uuidv4(),
475+
id: universalUUID(),
476476
dashboardId: '',
477477
datachartId: '',
478478
relations: [],
@@ -502,7 +502,7 @@ export const widgetTpl = (): Widget => {
502502
};
503503

504504
export const initClientId = () => {
505-
return 'client_' + uuidv4();
505+
return 'client_' + universalUUID();
506506
};
507507
export const initWidgetName = (i18nMap: object, local?: string) => {
508508
if (local && i18nMap[local]) {

frontend/src/utils/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ import {
1010
FONT_WEIGHT_REGULAR,
1111
} from 'styles/StyleConstants';
1212
import { APIResponse } from 'types';
13+
import { default as uuidv4 } from 'uuid/dist/umd/uuidv4.min';
1314
import { SaveFormModel } from '../app/pages/MainPage/pages/VizPage/SaveFormContext';
1415
import { removeToken } from './auth';
1516

16-
export { default as uuidv4 } from 'uuid/dist/umd/uuidv4.min';
17+
export { uuidv4 };
18+
19+
// For environments that do not support crypto.getRandomValues, such as nashorn.
20+
export function universalUUID() {
21+
return typeof crypto === 'undefined'
22+
? `_${Math.random().toString(36).substring(2)}`
23+
: uuidv4();
24+
}
1725

1826
export function errorHandle(error) {
1927
if (error?.response) {

0 commit comments

Comments
 (0)