@thoughtspot/ts-chart-sdk 0.0.2-alpha.23 → 0.0.2-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ts-chart-sdk.d.ts +82 -6
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/main/custom-chart-context.d.ts.map +1 -1
- package/lib/main/custom-chart-context.js +13 -9
- package/lib/main/custom-chart-context.js.map +1 -1
- package/lib/main/logger.d.ts +13 -0
- package/lib/main/logger.d.ts.map +1 -0
- package/lib/main/logger.js +64 -0
- package/lib/main/logger.js.map +1 -0
- package/lib/main/logger.spec.d.ts +2 -0
- package/lib/main/logger.spec.d.ts.map +1 -0
- package/lib/main/logger.spec.js +88 -0
- package/lib/main/logger.spec.js.map +1 -0
- package/lib/main/util.d.ts +2 -0
- package/lib/main/util.d.ts.map +1 -1
- package/lib/main/util.js +11 -0
- package/lib/main/util.js.map +1 -1
- package/lib/main/util.spec.js +43 -1
- package/lib/main/util.spec.js.map +1 -1
- package/lib/react/use-custom-chart-context.d.ts.map +1 -1
- package/lib/react/use-custom-chart-context.js +3 -1
- package/lib/react/use-custom-chart-context.js.map +1 -1
- package/lib/react/use-custom-chart-context.util.d.ts.map +1 -1
- package/lib/react/use-custom-chart-context.util.js +5 -3
- package/lib/react/use-custom-chart-context.util.js.map +1 -1
- package/lib/types/answer-column.types.d.ts +3 -3
- package/lib/types/answer-column.types.d.ts.map +1 -1
- package/lib/types/answer-column.types.js +3 -3
- package/lib/types/answer-column.types.js.map +1 -1
- package/lib/types/common.types.d.ts +6 -0
- package/lib/types/common.types.d.ts.map +1 -1
- package/lib/types/number-formatting.types.d.ts +2 -2
- package/lib/types/number-formatting.types.d.ts.map +1 -1
- package/lib/types/ts-to-chart-event.types.d.ts.map +1 -1
- package/lib/types/ts-to-chart-event.types.js.map +1 -1
- package/lib/types/visual-prop.types.d.ts +51 -1
- package/lib/types/visual-prop.types.d.ts.map +1 -1
- package/lib/types/visual-prop.types.js +32 -1
- package/lib/types/visual-prop.types.js.map +1 -1
- package/lib/utils/date-formatting.d.ts.map +1 -1
- package/lib/utils/date-formatting.js +4 -2
- package/lib/utils/date-formatting.js.map +1 -1
- package/lib/utils/globalize-Initializer/globalize-utils.d.ts +16 -0
- package/lib/utils/globalize-Initializer/globalize-utils.d.ts.map +1 -0
- package/lib/utils/globalize-Initializer/globalize-utils.js +101 -0
- package/lib/utils/globalize-Initializer/globalize-utils.js.map +1 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.d.ts +2 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.d.ts.map +1 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.js +149 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.d.ts +33 -0
- package/lib/utils/number-formatting/number-formatting-utils.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.js +180 -0
- package/lib/utils/number-formatting/number-formatting-utils.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.d.ts +2 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.js +235 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting.d.ts +5 -0
- package/lib/utils/number-formatting/number-formatting.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting.js +131 -0
- package/lib/utils/number-formatting/number-formatting.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting.spec.d.ts +2 -0
- package/lib/utils/number-formatting/number-formatting.spec.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting.spec.js +159 -0
- package/lib/utils/number-formatting/number-formatting.spec.js.map +1 -0
- package/package.json +4 -1
- package/src/index.ts +2 -0
- package/src/main/custom-chart-context.ts +14 -10
- package/src/main/logger.spec.ts +114 -0
- package/src/main/logger.ts +97 -0
- package/src/main/util.spec.ts +54 -1
- package/src/main/util.ts +20 -0
- package/src/react/use-custom-chart-context.tsx +4 -1
- package/src/react/use-custom-chart-context.util.ts +6 -3
- package/src/types/answer-column.types.ts +3 -3
- package/src/types/common.types.ts +7 -0
- package/src/types/number-formatting.types.ts +2 -2
- package/src/types/ts-to-chart-event.types.ts +0 -1
- package/src/types/visual-prop.types.ts +129 -2
- package/src/utils/date-formatting.ts +5 -2
- package/src/utils/globalize-Initializer/globalize-utils.spec.ts +192 -0
- package/src/utils/globalize-Initializer/globalize-utils.ts +216 -0
- package/src/utils/number-formatting/number-formatting-utils.spec.ts +321 -0
- package/src/utils/number-formatting/number-formatting-utils.ts +288 -0
- package/src/utils/number-formatting/number-formatting.spec.ts +243 -0
- package/src/utils/number-formatting/number-formatting.ts +268 -0
|
@@ -52,12 +52,15 @@ import {
|
|
|
52
52
|
VisualEditorDefinitionSetter,
|
|
53
53
|
VisualPropEditorDefinition,
|
|
54
54
|
} from '../types/visual-prop.types';
|
|
55
|
+
import { setLocaleBasedStringFormats } from '../utils/number-formatting/number-formatting-utils';
|
|
56
|
+
import { create } from './logger';
|
|
55
57
|
import {
|
|
56
58
|
globalThis,
|
|
57
59
|
initMessageListener,
|
|
58
60
|
postMessageToHostApp,
|
|
59
61
|
} from './post-message-event-bridge';
|
|
60
62
|
|
|
63
|
+
const logger = create('TsChartSDKContext');
|
|
61
64
|
/**
|
|
62
65
|
* Configuration for allowing or disallowing specific TS UI features.
|
|
63
66
|
*
|
|
@@ -410,7 +413,7 @@ export class CustomChartContext {
|
|
|
410
413
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
411
414
|
*/
|
|
412
415
|
public initialize = (): Promise<void> => {
|
|
413
|
-
|
|
416
|
+
logger.log('Chart Context: initialization start');
|
|
414
417
|
return this.hasInitializedPromise;
|
|
415
418
|
};
|
|
416
419
|
|
|
@@ -442,7 +445,7 @@ export class CustomChartContext {
|
|
|
442
445
|
*/
|
|
443
446
|
public off<T extends keyof TSToChartEventsPayloadMap>(eventType: T): void {
|
|
444
447
|
if (_.isNil(this.eventListeners[eventType])) {
|
|
445
|
-
|
|
448
|
+
logger.log('No event listener found to remove');
|
|
446
449
|
this.eventListeners[eventType] = [];
|
|
447
450
|
return;
|
|
448
451
|
}
|
|
@@ -663,7 +666,7 @@ export class CustomChartContext {
|
|
|
663
666
|
...eventPayload: ChartToTSEventsPayloadMap[T]
|
|
664
667
|
): Promise<any> {
|
|
665
668
|
if (!globalThis.isInitialized) {
|
|
666
|
-
|
|
669
|
+
logger.log(
|
|
667
670
|
'Chart Context: not initialized the context, something went wrong',
|
|
668
671
|
);
|
|
669
672
|
return Promise.reject(new Error('Context not initialized'));
|
|
@@ -686,7 +689,7 @@ export class CustomChartContext {
|
|
|
686
689
|
*/
|
|
687
690
|
private registerEventProcessor = () => {
|
|
688
691
|
if (globalThis.isInitialized) {
|
|
689
|
-
|
|
692
|
+
logger.error(
|
|
690
693
|
'The context is already initialized. you cannot have multiple contexts',
|
|
691
694
|
);
|
|
692
695
|
throw new Error(ErrorType.MultipleContextsNotSupported);
|
|
@@ -702,7 +705,7 @@ export class CustomChartContext {
|
|
|
702
705
|
* @param event : Message Event Object
|
|
703
706
|
*/
|
|
704
707
|
private eventProcessor = (data: any) => {
|
|
705
|
-
|
|
708
|
+
logger.log('Chart Context: message received:', data.eventType, data);
|
|
706
709
|
|
|
707
710
|
const messageResponse = this.executeEventListenerCBs(data);
|
|
708
711
|
|
|
@@ -887,7 +890,7 @@ export class CustomChartContext {
|
|
|
887
890
|
isValid: true,
|
|
888
891
|
};
|
|
889
892
|
} catch (error: unknown) {
|
|
890
|
-
|
|
893
|
+
logger.log(
|
|
891
894
|
'ContextMenuCustomAction: payload recieved:',
|
|
892
895
|
payload,
|
|
893
896
|
'CustomActionCallbackStore:',
|
|
@@ -930,7 +933,7 @@ export class CustomChartContext {
|
|
|
930
933
|
isValid: true,
|
|
931
934
|
};
|
|
932
935
|
} catch (error: unknown) {
|
|
933
|
-
|
|
936
|
+
logger.log(
|
|
934
937
|
'AxisMenuCustomAction: payload recieved:',
|
|
935
938
|
payload,
|
|
936
939
|
'CustomActionCallbackStore:',
|
|
@@ -1018,7 +1021,9 @@ export class CustomChartContext {
|
|
|
1018
1021
|
this.containerEl = payload.containerElSelector
|
|
1019
1022
|
? document.querySelector(payload.containerElSelector)
|
|
1020
1023
|
: null;
|
|
1021
|
-
|
|
1024
|
+
setLocaleBasedStringFormats(
|
|
1025
|
+
this.appConfig.dateFormatsConfig?.tsLocaleBasedStringsFormats,
|
|
1026
|
+
);
|
|
1022
1027
|
return this.publishChartContextPropsToHost();
|
|
1023
1028
|
};
|
|
1024
1029
|
|
|
@@ -1089,7 +1094,7 @@ export class CustomChartContext {
|
|
|
1089
1094
|
};
|
|
1090
1095
|
}
|
|
1091
1096
|
|
|
1092
|
-
|
|
1097
|
+
logger.log(
|
|
1093
1098
|
'ChartContext: Response:',
|
|
1094
1099
|
data.eventType,
|
|
1095
1100
|
response,
|
|
@@ -1112,6 +1117,5 @@ export const getChartContext = async (
|
|
|
1112
1117
|
// wait for initialization here as the host app
|
|
1113
1118
|
// needs to first handshake with the client app.
|
|
1114
1119
|
await ctx.initialize();
|
|
1115
|
-
|
|
1116
1120
|
return ctx;
|
|
1117
1121
|
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { create, LogLevel, logMethods } from './logger';
|
|
2
|
+
|
|
3
|
+
jest.mock('./util', () => ({
|
|
4
|
+
getQueryParam: jest.fn().mockReturnValue('true'),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
describe('Logger', () => {
|
|
8
|
+
let originalConsole: Record<string, any>;
|
|
9
|
+
let logger: any;
|
|
10
|
+
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
// Save original console methods
|
|
13
|
+
originalConsole = {
|
|
14
|
+
error: console.error,
|
|
15
|
+
warn: console.warn,
|
|
16
|
+
info: console.info,
|
|
17
|
+
log: console.log,
|
|
18
|
+
trace: console.trace,
|
|
19
|
+
};
|
|
20
|
+
// Mock console methods
|
|
21
|
+
const error = jest.fn();
|
|
22
|
+
const warn = jest.fn();
|
|
23
|
+
const info = jest.fn();
|
|
24
|
+
const log = jest.fn();
|
|
25
|
+
const trace = jest.fn();
|
|
26
|
+
logMethods[LogLevel.ERROR] = error;
|
|
27
|
+
logMethods[LogLevel.WARN] = warn;
|
|
28
|
+
logMethods[LogLevel.INFO] = info;
|
|
29
|
+
logMethods[LogLevel.DEBUG] = log;
|
|
30
|
+
logMethods[LogLevel.TRACE] = trace;
|
|
31
|
+
console.error = error;
|
|
32
|
+
console.warn = warn;
|
|
33
|
+
console.info = info;
|
|
34
|
+
console.log = log;
|
|
35
|
+
console.trace = trace;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterAll(() => {
|
|
39
|
+
// Restore original console methods
|
|
40
|
+
logMethods[LogLevel.ERROR] = originalConsole.error;
|
|
41
|
+
logMethods[LogLevel.WARN] = originalConsole.warn;
|
|
42
|
+
logMethods[LogLevel.INFO] = originalConsole.info;
|
|
43
|
+
logMethods[LogLevel.DEBUG] = originalConsole.log;
|
|
44
|
+
logMethods[LogLevel.TRACE] = originalConsole.trace;
|
|
45
|
+
console.error = originalConsole.error;
|
|
46
|
+
console.warn = originalConsole.warn;
|
|
47
|
+
console.info = originalConsole.info;
|
|
48
|
+
console.log = originalConsole.log;
|
|
49
|
+
console.trace = originalConsole.trace;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
// Set debug to 'true' to enable logging
|
|
54
|
+
(global as any).window = {
|
|
55
|
+
location: { href: 'https://example.com/?debug=true' },
|
|
56
|
+
};
|
|
57
|
+
logger = create('TestLogger');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
jest.clearAllMocks();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('logMessages', () => {
|
|
65
|
+
it('should log messages with appropriate prefixes for DEBUG level', async () => {
|
|
66
|
+
await logger.debug('Debug message');
|
|
67
|
+
expect(console.log).toHaveBeenCalledWith(
|
|
68
|
+
'DEBUG (TestLogger)(] Debug message)',
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should log messages with appropriate prefixes for INFO level', async () => {
|
|
73
|
+
await logger.info('Info message');
|
|
74
|
+
expect(console.info).toHaveBeenCalledWith(
|
|
75
|
+
'INFO (TestLogger)(] Info message)',
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should log messages with appropriate prefixes for WARN level', async () => {
|
|
80
|
+
await logger.warn('Warn message');
|
|
81
|
+
expect(console.warn).toHaveBeenCalledWith(
|
|
82
|
+
'WARN (TestLogger)(] Warn message)',
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should log messages with appropriate prefixes for ERROR level', async () => {
|
|
87
|
+
await logger.error('Error message');
|
|
88
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
89
|
+
'ERROR (TestLogger)(] Error message)',
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should log messages with appropriate prefixes for TRACE level', async () => {
|
|
94
|
+
await logger.trace('Trace message');
|
|
95
|
+
expect(console.trace).toHaveBeenCalledWith(
|
|
96
|
+
'TRACE (TestLogger)(] Trace message)',
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('create function', () => {
|
|
102
|
+
it('should create a new logger instance if one does not exist', () => {
|
|
103
|
+
const newLogger = create('NewLogger');
|
|
104
|
+
expect(newLogger).not.toBe(undefined);
|
|
105
|
+
expect(newLogger).toBeInstanceOf(Object);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should return the same logger instance if it already exists', () => {
|
|
109
|
+
const logger1 = create('SharedLogger');
|
|
110
|
+
const logger2 = create('SharedLogger');
|
|
111
|
+
expect(logger1).toBe(logger2);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { getQueryParam } from './util';
|
|
2
|
+
|
|
3
|
+
const loggers: Record<string, any> = {};
|
|
4
|
+
const url = window.location.href;
|
|
5
|
+
|
|
6
|
+
export enum LogLevel {
|
|
7
|
+
SILENT = -1 as number,
|
|
8
|
+
ERROR = 0 as number,
|
|
9
|
+
WARN = 1 as number,
|
|
10
|
+
INFO = 2 as number,
|
|
11
|
+
DEBUG = 3 as number,
|
|
12
|
+
TRACE = 4 as number,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const logMethods: { [key: number]: any } = {
|
|
16
|
+
[LogLevel.ERROR]: console.error,
|
|
17
|
+
[LogLevel.WARN]: console.warn,
|
|
18
|
+
[LogLevel.INFO]: console.info,
|
|
19
|
+
[LogLevel.DEBUG]: console.log,
|
|
20
|
+
[LogLevel.TRACE]: console.trace,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
class Logger {
|
|
24
|
+
private msgPrefix: string;
|
|
25
|
+
|
|
26
|
+
constructor(name: string) {
|
|
27
|
+
this.msgPrefix = name ? `(${name})` : '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private getFormattedMessage(msg: string, logLevel: LogLevel) {
|
|
31
|
+
return (
|
|
32
|
+
`${LogLevel[logLevel]} ${this.msgPrefix}` +
|
|
33
|
+
`(${msg ? `] ${msg}` : ''})`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public async logMessages(args: any, logLevel: LogLevel) {
|
|
38
|
+
const newArgs = args;
|
|
39
|
+
if (getQueryParam(url, 'debug') !== 'true') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const logFn = logMethods[logLevel];
|
|
43
|
+
newArgs[0] = this.getFormattedMessage(newArgs[0], logLevel);
|
|
44
|
+
if (logFn) {
|
|
45
|
+
logFn(...newArgs);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public async trace(...args: any) {
|
|
50
|
+
this.logMessages(args, LogLevel.TRACE);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Wrapper for log.log() with debug level
|
|
55
|
+
* @param msg
|
|
56
|
+
*/
|
|
57
|
+
public async debug(...args: any) {
|
|
58
|
+
this.logMessages(args, LogLevel.DEBUG);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public async log(...args: any) {
|
|
62
|
+
this.debug(...args);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Wrapper for log.info() with info level
|
|
67
|
+
* @param msg
|
|
68
|
+
*/
|
|
69
|
+
public async info(...args: any) {
|
|
70
|
+
this.logMessages(args, LogLevel.INFO);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Wrapper for log.warn() with warn level
|
|
75
|
+
*
|
|
76
|
+
* @param {string} msg The log message
|
|
77
|
+
*/
|
|
78
|
+
public async warn(...args: any) {
|
|
79
|
+
this.logMessages(args, LogLevel.WARN);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Wrapper for log.error() with error level
|
|
84
|
+
* Error is propagated via callback
|
|
85
|
+
* @param {string} msg The log message
|
|
86
|
+
*/
|
|
87
|
+
public async error(...args: any) {
|
|
88
|
+
const stackTrace = this.logMessages(args, LogLevel.ERROR);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function create(name: string): any {
|
|
93
|
+
if (!loggers[name]) {
|
|
94
|
+
loggers[name] = new Logger(name);
|
|
95
|
+
}
|
|
96
|
+
return loggers[name];
|
|
97
|
+
}
|
package/src/main/util.spec.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { timeout } from './util';
|
|
1
|
+
import { getQueryParam, handleMissingValue, timeout } from './util';
|
|
2
2
|
|
|
3
3
|
describe('timeout function', () => {
|
|
4
4
|
jest.useFakeTimers();
|
|
@@ -39,3 +39,56 @@ describe('timeout function', () => {
|
|
|
39
39
|
await expect(result).rejects.toThrow('Original error');
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
|
+
|
|
43
|
+
describe('getQueryParam', () => {
|
|
44
|
+
it('should return the value of a query parameter if it exists', () => {
|
|
45
|
+
const url = 'https://example.com/?key=value';
|
|
46
|
+
expect(getQueryParam(url, 'key')).toBe('value');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should return an empty string if the query parameter does not exist', () => {
|
|
50
|
+
const url = 'https://example.com/';
|
|
51
|
+
expect(getQueryParam(url, 'missingKey')).toBe('');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should return "false" if the query parameter is "debug" and it is not present', () => {
|
|
55
|
+
const url = 'https://example.com/';
|
|
56
|
+
expect(getQueryParam(url, 'debug')).toBe('false');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should return the default value "false" if the query parameter is "debug" and is set to an empty value', () => {
|
|
60
|
+
const url = 'https://example.com/?debug=';
|
|
61
|
+
expect(getQueryParam(url, 'debug')).toBe('');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should handle complex URLs with multiple parameters correctly', () => {
|
|
65
|
+
const url = 'https://example.com/?key1=value1&key2=value2';
|
|
66
|
+
expect(getQueryParam(url, 'key2')).toBe('value2');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('handleMissingValue', () => {
|
|
71
|
+
it('should return "false" if paramKey is "debug" and paramValue is undefined', () => {
|
|
72
|
+
expect(handleMissingValue('debug', undefined)).toBe('false');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should return "false" if paramKey is "debug" and paramValue is null', () => {
|
|
76
|
+
expect(handleMissingValue('debug', null)).toBe('false');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should return an empty string if paramValue is undefined and paramKey is not "debug"', () => {
|
|
80
|
+
expect(handleMissingValue('param', undefined)).toBe('');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should return an empty string if paramValue is null and paramKey is not "debug"', () => {
|
|
84
|
+
expect(handleMissingValue('param', null)).toBe('');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should return the paramValue if paramValue is defined and not null', () => {
|
|
88
|
+
expect(handleMissingValue('param', 'value')).toBe('value');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should return the paramValue even if paramKey is "debug" and paramValue is defined', () => {
|
|
92
|
+
expect(handleMissingValue('debug', 'true')).toBe('true');
|
|
93
|
+
});
|
|
94
|
+
});
|
package/src/main/util.ts
CHANGED
|
@@ -9,3 +9,23 @@ export function timeout(promise: Promise<any>, ms: number, message?: string) {
|
|
|
9
9
|
}),
|
|
10
10
|
]);
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
export function handleMissingValue(
|
|
14
|
+
paramKey: string,
|
|
15
|
+
paramValue?: string | null,
|
|
16
|
+
): string {
|
|
17
|
+
if (paramKey === 'debug') {
|
|
18
|
+
return paramValue ?? 'false';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return paramValue ?? '';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getQueryParam(url: string, paramName: string): string {
|
|
25
|
+
const urlObj = new URL(url);
|
|
26
|
+
const paramValue = handleMissingValue(
|
|
27
|
+
paramName,
|
|
28
|
+
urlObj.searchParams.get(paramName),
|
|
29
|
+
);
|
|
30
|
+
return paramValue;
|
|
31
|
+
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
CustomChartContext,
|
|
13
13
|
CustomChartContextProps,
|
|
14
14
|
} from '../main/custom-chart-context';
|
|
15
|
+
import { create } from '../main/logger';
|
|
15
16
|
import { ChartModel } from '../types/common.types';
|
|
16
17
|
import {
|
|
17
18
|
ChartModelUpdateEventPayload,
|
|
@@ -28,6 +29,8 @@ import {
|
|
|
28
29
|
TSChartContextProps,
|
|
29
30
|
} from './use-custom-chart-types';
|
|
30
31
|
|
|
32
|
+
const logger = create('CustomChartContextHookSdk');
|
|
33
|
+
|
|
31
34
|
/**
|
|
32
35
|
* A custom hook to manage the Chart Context state and provide necessary
|
|
33
36
|
* chart-related functionality.
|
|
@@ -143,7 +146,7 @@ export const useChartContext = (
|
|
|
143
146
|
return true;
|
|
144
147
|
})
|
|
145
148
|
.catch((e) => {
|
|
146
|
-
|
|
149
|
+
logger.log('Error in context initialization', e);
|
|
147
150
|
});
|
|
148
151
|
};
|
|
149
152
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { CustomChartContext } from '../main/custom-chart-context';
|
|
3
|
+
import { create } from '../main/logger';
|
|
3
4
|
import {
|
|
4
5
|
ChartToTSEvent,
|
|
5
6
|
ChartToTSEventsPayloadMap,
|
|
@@ -14,6 +15,8 @@ import {
|
|
|
14
15
|
TSToChartEventOffListener,
|
|
15
16
|
} from './use-custom-chart-types';
|
|
16
17
|
|
|
18
|
+
const logger = create('CustomChartContextUtilSdk');
|
|
19
|
+
|
|
17
20
|
/**
|
|
18
21
|
*
|
|
19
22
|
* @param ctx Custom Chart Context
|
|
@@ -31,7 +34,7 @@ export const emitter = (ctx: CustomChartContext): ChartToTSEventEmitters => {
|
|
|
31
34
|
...args: ChartToTSEventsPayloadMap[keyof ChartToTSEventsPayloadMap]
|
|
32
35
|
): Promise<void> => {
|
|
33
36
|
if (!ctx || _.isEmpty(ctx)) {
|
|
34
|
-
|
|
37
|
+
logger.log('Context is not initialized');
|
|
35
38
|
return Promise.reject(new Error('Context not initialized'));
|
|
36
39
|
}
|
|
37
40
|
return ctx.emitEvent(eventName, ...args);
|
|
@@ -60,7 +63,7 @@ export const eventListener = (
|
|
|
60
63
|
callbackFn: TSToChartEventsPayloadMap[keyof TSToChartEventsPayloadMap],
|
|
61
64
|
): Promise<void> => {
|
|
62
65
|
if (!ctx || _.isEmpty(ctx)) {
|
|
63
|
-
|
|
66
|
+
logger.log('Context is not initialized');
|
|
64
67
|
return Promise.reject(new Error('Context not initialized'));
|
|
65
68
|
}
|
|
66
69
|
ctx.on(eventName, callbackFn);
|
|
@@ -89,7 +92,7 @@ export const eventOffListener = (
|
|
|
89
92
|
|
|
90
93
|
acc[emitterKey] = (): Promise<void> => {
|
|
91
94
|
if (!ctx || _.isEmpty(ctx)) {
|
|
92
|
-
|
|
95
|
+
logger.log('Context is not initialized');
|
|
93
96
|
return Promise.reject(new Error('Context not initialized'));
|
|
94
97
|
}
|
|
95
98
|
ctx.off(eventName);
|
|
@@ -188,10 +188,17 @@ export type SuccessValidationResponse = {
|
|
|
188
188
|
visualPropEditorDefinition: VisualPropEditorDefinition;
|
|
189
189
|
};
|
|
190
190
|
|
|
191
|
+
export type VisualPropError = {
|
|
192
|
+
propElementKey: string;
|
|
193
|
+
propElementType: string;
|
|
194
|
+
value: unknown;
|
|
195
|
+
};
|
|
196
|
+
|
|
191
197
|
// Generic Validation Response
|
|
192
198
|
export type ValidationResponse = {
|
|
193
199
|
isValid: boolean;
|
|
194
200
|
validationErrorMessage?: string[];
|
|
201
|
+
visualPropError?: VisualPropError;
|
|
195
202
|
};
|
|
196
203
|
|
|
197
204
|
/**
|
|
@@ -58,7 +58,7 @@ export type NumberFormatConfig = {
|
|
|
58
58
|
/** default to true */
|
|
59
59
|
toSeparateThousands?: Maybe<Scalars['Boolean']>;
|
|
60
60
|
/** default is Auto */
|
|
61
|
-
unit?: Maybe<Unit
|
|
61
|
+
unit?: Maybe<Unit> | number;
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
export type PercentageFormatConfig = {
|
|
@@ -71,7 +71,7 @@ export type PercentageFormatConfig = {
|
|
|
71
71
|
|
|
72
72
|
export type FormatConfig = {
|
|
73
73
|
__typename?: 'FormatConfig';
|
|
74
|
-
category?: Maybe<CategoryType
|
|
74
|
+
category?: Maybe<CategoryType> | number;
|
|
75
75
|
currencyFormatConfig?: Maybe<CurrencyFormatConfig>;
|
|
76
76
|
customFormatConfig?: Maybe<CustomFormatConfig>;
|
|
77
77
|
isCategoryEditable?: Maybe<Scalars['Boolean']>;
|