@thoughtspot/ts-chart-sdk 0.0.1-alpha.0 → 0.0.1-alpha.1
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/README.md +782 -0
- package/cjs/index.d.ts +8 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +24 -0
- package/cjs/index.js.map +1 -0
- package/cjs/main/custom-chart-context.d.ts +39 -0
- package/cjs/main/custom-chart-context.d.ts.map +1 -0
- package/cjs/main/custom-chart-context.js +211 -0
- package/cjs/main/custom-chart-context.js.map +1 -0
- package/cjs/main/custom-chart-context.spec.d.ts +2 -0
- package/cjs/main/custom-chart-context.spec.d.ts.map +1 -0
- package/cjs/main/custom-chart-context.spec.js +379 -0
- package/cjs/main/custom-chart-context.spec.js.map +1 -0
- package/cjs/main/post-message-event-bridge.d.ts +6 -0
- package/cjs/main/post-message-event-bridge.d.ts.map +1 -0
- package/cjs/main/post-message-event-bridge.js +46 -0
- package/cjs/main/post-message-event-bridge.js.map +1 -0
- package/cjs/main/post-message-event-bridge.spec.d.ts +2 -0
- package/cjs/main/post-message-event-bridge.spec.d.ts.map +1 -0
- package/cjs/main/post-message-event-bridge.spec.js +122 -0
- package/cjs/main/post-message-event-bridge.spec.js.map +1 -0
- package/cjs/test/test-utils.d.ts +7 -0
- package/cjs/test/test-utils.d.ts.map +1 -0
- package/cjs/test/test-utils.js +14 -0
- package/cjs/test/test-utils.js.map +1 -0
- package/cjs/types/answer-column.types.d.ts +69 -0
- package/cjs/types/answer-column.types.d.ts.map +1 -0
- package/cjs/types/answer-column.types.js +59 -0
- package/cjs/types/answer-column.types.js.map +1 -0
- package/cjs/types/chart-to-ts-event.types.d.ts +48 -0
- package/cjs/types/chart-to-ts-event.types.d.ts.map +1 -0
- package/cjs/types/chart-to-ts-event.types.js +19 -0
- package/cjs/types/chart-to-ts-event.types.js.map +1 -0
- package/cjs/types/common.types.d.ts +50 -0
- package/cjs/types/common.types.d.ts.map +1 -0
- package/cjs/types/common.types.js +3 -0
- package/cjs/types/common.types.js.map +1 -0
- package/cjs/types/configurator.types.d.ts +15 -0
- package/cjs/types/configurator.types.d.ts.map +1 -0
- package/cjs/types/configurator.types.js +3 -0
- package/cjs/types/configurator.types.js.map +1 -0
- package/cjs/types/ts-to-chart-event.types.d.ts +69 -0
- package/cjs/types/ts-to-chart-event.types.d.ts.map +1 -0
- package/cjs/types/ts-to-chart-event.types.js +16 -0
- package/cjs/types/ts-to-chart-event.types.js.map +1 -0
- package/cjs/types/visual-prop.types.d.ts +47 -0
- package/cjs/types/visual-prop.types.d.ts.map +1 -0
- package/cjs/types/visual-prop.types.js +3 -0
- package/cjs/types/visual-prop.types.js.map +1 -0
- package/lib/main/custom-chart-context.d.ts +2 -1
- package/lib/main/custom-chart-context.d.ts.map +1 -1
- package/lib/main/custom-chart-context.js +11 -7
- package/lib/main/custom-chart-context.js.map +1 -1
- package/lib/main/custom-chart-context.spec.js +64 -25
- package/lib/main/custom-chart-context.spec.js.map +1 -1
- package/lib/types/chart-to-ts-event.types.d.ts +8 -8
- package/lib/types/chart-to-ts-event.types.d.ts.map +1 -1
- package/lib/types/chart-to-ts-event.types.js.map +1 -1
- package/lib/types/common.types.d.ts +7 -8
- package/lib/types/common.types.d.ts.map +1 -1
- package/lib/types/ts-to-chart-event.types.d.ts +2 -0
- package/lib/types/ts-to-chart-event.types.d.ts.map +1 -1
- package/lib/types/ts-to-chart-event.types.js +1 -0
- package/lib/types/ts-to-chart-event.types.js.map +1 -1
- package/package.json +2 -2
- package/src/main/custom-chart-context.spec.ts +87 -26
- package/src/main/custom-chart-context.ts +26 -16
- package/src/main/post-message-event-bridge.ts +2 -2
- package/src/types/answer-column.types.ts +5 -5
- package/src/types/chart-to-ts-event.types.ts +18 -28
- package/src/types/common.types.ts +22 -25
- package/src/types/configurator.types.ts +8 -8
- package/src/types/ts-to-chart-event.types.ts +10 -4
- package/src/types/visual-prop.types.ts +11 -11
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { mockInitializeContextPayload } from '../test/test-utils';
|
|
8
|
-
import { ErrorType } from '../types/chart-to-ts-event.types';
|
|
8
|
+
import { ChartToTSEvent, ErrorType } from '../types/chart-to-ts-event.types';
|
|
9
9
|
import { TSToChartEvent } from '../types/ts-to-chart-event.types';
|
|
10
10
|
import { CustomChartContext, getChartContext } from './custom-chart-context';
|
|
11
11
|
import * as PostMessageEventBridge from './post-message-event-bridge';
|
|
@@ -17,7 +17,7 @@ jest.spyOn(console, 'log').mockImplementation(() => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
describe('CustomChartContext', () => {
|
|
20
|
-
let
|
|
20
|
+
let eventProcessor: any;
|
|
21
21
|
|
|
22
22
|
let getDefaultChartConfig = jest.fn();
|
|
23
23
|
let getQueriesFromChartConfig = jest.fn();
|
|
@@ -37,7 +37,11 @@ describe('CustomChartContext', () => {
|
|
|
37
37
|
renderChart = jest.fn();
|
|
38
38
|
|
|
39
39
|
mockInitMessage.mockImplementation((fn: any) => {
|
|
40
|
-
|
|
40
|
+
eventProcessor = fn;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
mockPostMessageToHost.mockImplementation(() => {
|
|
44
|
+
return global.Promise.resolve();
|
|
41
45
|
});
|
|
42
46
|
});
|
|
43
47
|
|
|
@@ -53,9 +57,9 @@ describe('CustomChartContext', () => {
|
|
|
53
57
|
|
|
54
58
|
afterEach(() => {
|
|
55
59
|
// Destroy the chart context after each test
|
|
56
|
-
customChartContext.destroy();
|
|
57
60
|
jest.resetAllMocks();
|
|
58
|
-
|
|
61
|
+
customChartContext.destroy();
|
|
62
|
+
eventProcessor = null;
|
|
59
63
|
});
|
|
60
64
|
|
|
61
65
|
test('should wait till the parent calls initialize', async () => {
|
|
@@ -81,7 +85,7 @@ describe('CustomChartContext', () => {
|
|
|
81
85
|
|
|
82
86
|
// Check that the hasInitializedPromise has resolved
|
|
83
87
|
const mockPostMessage = jest.fn();
|
|
84
|
-
|
|
88
|
+
eventProcessor({
|
|
85
89
|
data: {
|
|
86
90
|
payload: mockInitializeContextPayload,
|
|
87
91
|
eventType: TSToChartEvent.Initialize,
|
|
@@ -90,8 +94,19 @@ describe('CustomChartContext', () => {
|
|
|
90
94
|
ports: [{ postMessage: mockPostMessage }],
|
|
91
95
|
});
|
|
92
96
|
|
|
97
|
+
eventProcessor({
|
|
98
|
+
data: {
|
|
99
|
+
payload: {},
|
|
100
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
101
|
+
source: 'ts-host-app',
|
|
102
|
+
},
|
|
103
|
+
ports: [{ postMessage: mockPostMessage }],
|
|
104
|
+
});
|
|
105
|
+
|
|
93
106
|
await expect(promise).resolves.toBeUndefined();
|
|
94
|
-
expect(mockPostMessage).
|
|
107
|
+
expect(mockPostMessage).toHaveBeenCalledTimes(2);
|
|
108
|
+
|
|
109
|
+
expect(mockPostMessage.mock.calls[0][0]).toEqual({
|
|
95
110
|
isConfigValid: false,
|
|
96
111
|
defaultChartConfig: undefined,
|
|
97
112
|
chartConfigEditorDefinition: undefined,
|
|
@@ -107,7 +122,7 @@ describe('CustomChartContext', () => {
|
|
|
107
122
|
|
|
108
123
|
// Check that the hasInitializedPromise has resolved
|
|
109
124
|
const mockPostMessage = jest.fn();
|
|
110
|
-
|
|
125
|
+
eventProcessor({
|
|
111
126
|
data: {
|
|
112
127
|
payload: mockInitializeContextPayload,
|
|
113
128
|
eventType: TSToChartEvent.Initialize,
|
|
@@ -116,6 +131,15 @@ describe('CustomChartContext', () => {
|
|
|
116
131
|
ports: [{ postMessage: mockPostMessage }],
|
|
117
132
|
});
|
|
118
133
|
|
|
134
|
+
eventProcessor({
|
|
135
|
+
data: {
|
|
136
|
+
payload: {},
|
|
137
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
138
|
+
source: 'ts-host-app',
|
|
139
|
+
},
|
|
140
|
+
ports: [{ postMessage: mockPostMessage }],
|
|
141
|
+
});
|
|
142
|
+
|
|
119
143
|
await expect(promise).resolves.toBeUndefined();
|
|
120
144
|
|
|
121
145
|
let error;
|
|
@@ -156,7 +180,7 @@ describe('CustomChartContext', () => {
|
|
|
156
180
|
// Destroy the chart context after each test
|
|
157
181
|
jest.resetAllMocks();
|
|
158
182
|
customChartContext.destroy();
|
|
159
|
-
|
|
183
|
+
eventProcessor = null;
|
|
160
184
|
});
|
|
161
185
|
|
|
162
186
|
test('should not trigger post message if host is not accurate', () => {
|
|
@@ -164,7 +188,7 @@ describe('CustomChartContext', () => {
|
|
|
164
188
|
|
|
165
189
|
// mock the event trigger for ChartConfigValidate
|
|
166
190
|
const mockPostMessage = jest.fn();
|
|
167
|
-
|
|
191
|
+
eventProcessor({
|
|
168
192
|
data: {
|
|
169
193
|
payload: mockInitializeContextPayload,
|
|
170
194
|
eventType: TSToChartEvent.ChartConfigValidate,
|
|
@@ -182,7 +206,7 @@ describe('CustomChartContext', () => {
|
|
|
182
206
|
|
|
183
207
|
// mock the event trigger for ChartConfigValidate
|
|
184
208
|
const mockPostMessage = jest.fn();
|
|
185
|
-
|
|
209
|
+
eventProcessor({
|
|
186
210
|
data: {
|
|
187
211
|
payload: mockInitializeContextPayload,
|
|
188
212
|
eventType: TSToChartEvent.ChartConfigValidate,
|
|
@@ -197,7 +221,7 @@ describe('CustomChartContext', () => {
|
|
|
197
221
|
mockPostMessage.mockReset();
|
|
198
222
|
|
|
199
223
|
// mock the event trigger for VisualPropsValidate
|
|
200
|
-
|
|
224
|
+
eventProcessor({
|
|
201
225
|
data: {
|
|
202
226
|
payload: mockInitializeContextPayload,
|
|
203
227
|
eventType: TSToChartEvent.VisualPropsValidate,
|
|
@@ -213,7 +237,7 @@ describe('CustomChartContext', () => {
|
|
|
213
237
|
mockPostMessage.mockReset();
|
|
214
238
|
|
|
215
239
|
// mock the event trigger for TriggerRenderChart
|
|
216
|
-
|
|
240
|
+
eventProcessor({
|
|
217
241
|
data: {
|
|
218
242
|
payload: mockInitializeContextPayload,
|
|
219
243
|
eventType: TSToChartEvent.TriggerRenderChart,
|
|
@@ -228,7 +252,7 @@ describe('CustomChartContext', () => {
|
|
|
228
252
|
mockPostMessage.mockReset();
|
|
229
253
|
|
|
230
254
|
// mock the event trigger for getQueriesFromChartConfig
|
|
231
|
-
|
|
255
|
+
eventProcessor({
|
|
232
256
|
data: {
|
|
233
257
|
payload: mockInitializeContextPayload,
|
|
234
258
|
eventType: TSToChartEvent.GetDataQuery,
|
|
@@ -246,7 +270,7 @@ describe('CustomChartContext', () => {
|
|
|
246
270
|
|
|
247
271
|
// mock the event trigger for DataUpdate
|
|
248
272
|
const mockPostMessage = jest.fn();
|
|
249
|
-
|
|
273
|
+
eventProcessor({
|
|
250
274
|
data: {
|
|
251
275
|
payload: {
|
|
252
276
|
data: 'random data',
|
|
@@ -264,7 +288,7 @@ describe('CustomChartContext', () => {
|
|
|
264
288
|
mockPostMessage.mockReset();
|
|
265
289
|
|
|
266
290
|
// mock the event trigger for VisualPropsValidate
|
|
267
|
-
|
|
291
|
+
eventProcessor({
|
|
268
292
|
data: {
|
|
269
293
|
payload: {
|
|
270
294
|
chartModel: {
|
|
@@ -288,8 +312,8 @@ describe('CustomChartContext', () => {
|
|
|
288
312
|
|
|
289
313
|
mockPostMessage.mockReset();
|
|
290
314
|
|
|
291
|
-
// mock the event trigger for
|
|
292
|
-
|
|
315
|
+
// mock the event trigger for VisualPropsUpdate
|
|
316
|
+
eventProcessor({
|
|
293
317
|
data: {
|
|
294
318
|
payload: {
|
|
295
319
|
visualProps: 'random data',
|
|
@@ -319,7 +343,7 @@ describe('CustomChartContext', () => {
|
|
|
319
343
|
|
|
320
344
|
// mock the event trigger
|
|
321
345
|
const mockPostMessage = jest.fn();
|
|
322
|
-
|
|
346
|
+
eventProcessor({
|
|
323
347
|
data: {
|
|
324
348
|
payload: mockInitializeContextPayload,
|
|
325
349
|
eventType: TEST_EVENT_TYPE,
|
|
@@ -339,7 +363,7 @@ describe('CustomChartContext', () => {
|
|
|
339
363
|
|
|
340
364
|
// mock the event trigger
|
|
341
365
|
const mockPostMessage = jest.fn();
|
|
342
|
-
|
|
366
|
+
eventProcessor({
|
|
343
367
|
data: {
|
|
344
368
|
payload: mockInitializeContextPayload,
|
|
345
369
|
eventType: TEST_EVENT_TYPE,
|
|
@@ -358,6 +382,7 @@ describe('CustomChartContext', () => {
|
|
|
358
382
|
|
|
359
383
|
describe('emitEvent', () => {
|
|
360
384
|
let customChartContext: CustomChartContext;
|
|
385
|
+
|
|
361
386
|
beforeEach(() => {
|
|
362
387
|
customChartContext = new CustomChartContext({
|
|
363
388
|
getDefaultChartConfig,
|
|
@@ -367,9 +392,9 @@ describe('CustomChartContext', () => {
|
|
|
367
392
|
});
|
|
368
393
|
afterEach(() => {
|
|
369
394
|
// Destroy the chart context after each test
|
|
370
|
-
jest.resetAllMocks();
|
|
371
395
|
customChartContext.destroy();
|
|
372
|
-
|
|
396
|
+
eventProcessor = null;
|
|
397
|
+
jest.resetAllMocks();
|
|
373
398
|
});
|
|
374
399
|
|
|
375
400
|
test('should reject the promise if the chart context is not initialized', async () => {
|
|
@@ -384,13 +409,13 @@ describe('CustomChartContext', () => {
|
|
|
384
409
|
|
|
385
410
|
// Check that the result is defined
|
|
386
411
|
expect(mockPostMessageToHost).not.toHaveBeenCalled();
|
|
387
|
-
await expect(result).rejects.
|
|
412
|
+
await expect(result).rejects.toBeDefined();
|
|
388
413
|
});
|
|
389
414
|
|
|
390
415
|
test('should resolve the promise if the chart context is initialized', async () => {
|
|
391
416
|
// Check that the hasInitializedPromise has resolved
|
|
392
417
|
const mockPostMessage = jest.fn();
|
|
393
|
-
|
|
418
|
+
eventProcessor({
|
|
394
419
|
data: {
|
|
395
420
|
payload: mockInitializeContextPayload,
|
|
396
421
|
eventType: TSToChartEvent.Initialize,
|
|
@@ -399,6 +424,19 @@ describe('CustomChartContext', () => {
|
|
|
399
424
|
ports: [{ postMessage: mockPostMessage }],
|
|
400
425
|
});
|
|
401
426
|
|
|
427
|
+
eventProcessor({
|
|
428
|
+
data: {
|
|
429
|
+
payload: {},
|
|
430
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
431
|
+
source: 'ts-host-app',
|
|
432
|
+
},
|
|
433
|
+
ports: [{ postMessage: mockPostMessage }],
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
const promise = customChartContext.initialize();
|
|
437
|
+
await expect(promise).resolves.toBeUndefined();
|
|
438
|
+
expect(mockPostMessage).toHaveBeenCalledTimes(2);
|
|
439
|
+
|
|
402
440
|
// define mock response for the postMessage response promise
|
|
403
441
|
let resolve: any;
|
|
404
442
|
mockPostMessageToHost.mockImplementation(
|
|
@@ -417,8 +455,9 @@ describe('CustomChartContext', () => {
|
|
|
417
455
|
TEST_EVENT_TYPE,
|
|
418
456
|
testPayload,
|
|
419
457
|
);
|
|
420
|
-
global.setTimeout(() => resolve('helloworld'),
|
|
458
|
+
global.setTimeout(() => resolve('helloworld'), 1000);
|
|
421
459
|
|
|
460
|
+
await expect(result).resolves.toEqual('helloworld');
|
|
422
461
|
// Check that the result is defined
|
|
423
462
|
expect(mockPostMessageToHost).toHaveBeenCalledWith(
|
|
424
463
|
mockInitializeContextPayload.componentId,
|
|
@@ -426,7 +465,29 @@ describe('CustomChartContext', () => {
|
|
|
426
465
|
testPayload,
|
|
427
466
|
TEST_EVENT_TYPE,
|
|
428
467
|
);
|
|
429
|
-
|
|
468
|
+
|
|
469
|
+
// test for null payload
|
|
470
|
+
// Call the emitEvent function and wait for it to resolve
|
|
471
|
+
mockPostMessageToHost.mockReset();
|
|
472
|
+
mockPostMessageToHost.mockImplementation(
|
|
473
|
+
() =>
|
|
474
|
+
new global.Promise<any>((res) => {
|
|
475
|
+
resolve = res;
|
|
476
|
+
}),
|
|
477
|
+
);
|
|
478
|
+
const result2 = customChartContext.emitEvent(
|
|
479
|
+
ChartToTSEvent.RenderStart,
|
|
480
|
+
);
|
|
481
|
+
global.setTimeout(() => resolve('helloworld'), 1000);
|
|
482
|
+
|
|
483
|
+
await expect(result2).resolves.toEqual('helloworld');
|
|
484
|
+
// Check that the result is defined
|
|
485
|
+
expect(mockPostMessageToHost).toHaveBeenCalledWith(
|
|
486
|
+
mockInitializeContextPayload.componentId,
|
|
487
|
+
mockInitializeContextPayload.hostUrl,
|
|
488
|
+
null,
|
|
489
|
+
ChartToTSEvent.RenderStart,
|
|
490
|
+
);
|
|
430
491
|
});
|
|
431
492
|
});
|
|
432
493
|
});
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import _ from 'lodash';
|
|
9
9
|
import {
|
|
10
|
+
ChartToTSEvent,
|
|
10
11
|
ChartToTSEventsPayloadMap,
|
|
11
12
|
ErrorType,
|
|
12
13
|
} from '../types/chart-to-ts-event.types';
|
|
@@ -63,7 +64,7 @@ export type CustomChartContextProps = {
|
|
|
63
64
|
*/
|
|
64
65
|
renderChart: (ctx: CustomChartContext) => Promise<void>;
|
|
65
66
|
/**
|
|
66
|
-
*
|
|
67
|
+
* Required to validate the current chart configuration
|
|
67
68
|
* that chart user has updated on the chart config editor
|
|
68
69
|
*
|
|
69
70
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
@@ -77,7 +78,7 @@ export type CustomChartContextProps = {
|
|
|
77
78
|
) => ValidationResponse;
|
|
78
79
|
|
|
79
80
|
/**
|
|
80
|
-
*
|
|
81
|
+
* Required to validate the custom visual props that
|
|
81
82
|
* the chart user has updated on the chart settings editor.
|
|
82
83
|
*
|
|
83
84
|
* @param updatedVisualProps
|
|
@@ -120,8 +121,8 @@ const DEFAULT_CHART_CONTEXT_PROPS: Partial<CustomChartContextProps> = {
|
|
|
120
121
|
|
|
121
122
|
export class CustomChartContext {
|
|
122
123
|
/**
|
|
123
|
-
*
|
|
124
|
-
* This is used to differentiate between multiple chart
|
|
124
|
+
* ID to map to the parent chart component.
|
|
125
|
+
* This is used to differentiate between multiple chart components rendered on the
|
|
125
126
|
* parent app Example: liveboards with multiple charts
|
|
126
127
|
*
|
|
127
128
|
* @hidden
|
|
@@ -194,7 +195,7 @@ export class CustomChartContext {
|
|
|
194
195
|
...chartContextProps,
|
|
195
196
|
};
|
|
196
197
|
this.registerEventProcessor();
|
|
197
|
-
this.hasInitializedPromise = new Promise((resolve) => {
|
|
198
|
+
this.hasInitializedPromise = new Promise((resolve, reject) => {
|
|
198
199
|
this.triggerInitResolve = resolve;
|
|
199
200
|
});
|
|
200
201
|
}
|
|
@@ -277,18 +278,18 @@ export class CustomChartContext {
|
|
|
277
278
|
*/
|
|
278
279
|
public emitEvent<T extends keyof ChartToTSEventsPayloadMap>(
|
|
279
280
|
eventType: T,
|
|
280
|
-
eventPayload: ChartToTSEventsPayloadMap[T]
|
|
281
|
+
...eventPayload: ChartToTSEventsPayloadMap[T]
|
|
281
282
|
): Promise<any> {
|
|
282
283
|
if (!isInitialized) {
|
|
283
284
|
console.log(
|
|
284
285
|
'Chart Context: not initialized the context, something went wrong',
|
|
285
286
|
);
|
|
286
|
-
return Promise.reject();
|
|
287
|
+
return Promise.reject(new Error('Context not initialized'));
|
|
287
288
|
}
|
|
288
289
|
return PostMessageEventBridge.postMessageToHostApp(
|
|
289
290
|
this.componentId,
|
|
290
291
|
this.hostUrl,
|
|
291
|
-
eventPayload,
|
|
292
|
+
eventPayload?.[0] ?? null,
|
|
292
293
|
eventType,
|
|
293
294
|
);
|
|
294
295
|
}
|
|
@@ -357,6 +358,13 @@ export class CustomChartContext {
|
|
|
357
358
|
this.initializeContext(payload),
|
|
358
359
|
);
|
|
359
360
|
|
|
361
|
+
/**
|
|
362
|
+
* This event is triggered when the TS app initialization is complete.
|
|
363
|
+
*/
|
|
364
|
+
this.onInternal(TSToChartEvent.InitializeComplete, () =>
|
|
365
|
+
this.initializationComplete(),
|
|
366
|
+
);
|
|
367
|
+
|
|
360
368
|
/**
|
|
361
369
|
* This event is triggered when the TS app asks for validating the updated visual
|
|
362
370
|
* props If {validateVisualProps} is not defined, default is always returned as
|
|
@@ -419,8 +427,8 @@ export class CustomChartContext {
|
|
|
419
427
|
/**
|
|
420
428
|
* This event is triggered when the TS app re-renders the chart
|
|
421
429
|
*/
|
|
422
|
-
this.onInternal(TSToChartEvent.TriggerRenderChart,
|
|
423
|
-
|
|
430
|
+
this.onInternal(TSToChartEvent.TriggerRenderChart, () => {
|
|
431
|
+
this.chartContextProps.renderChart(this);
|
|
424
432
|
});
|
|
425
433
|
|
|
426
434
|
// Register External Events
|
|
@@ -481,8 +489,8 @@ export class CustomChartContext {
|
|
|
481
489
|
};
|
|
482
490
|
|
|
483
491
|
/**
|
|
484
|
-
*
|
|
485
|
-
* the
|
|
492
|
+
* Private function is going to initialize the flow from TS app and send back
|
|
493
|
+
* the configuration back to ts app to complete the handshake.
|
|
486
494
|
*
|
|
487
495
|
* @param {InitializeEventPayload} payload
|
|
488
496
|
* @returns InitializeEventResponsePayload
|
|
@@ -494,13 +502,15 @@ export class CustomChartContext {
|
|
|
494
502
|
this.hostUrl = payload.hostUrl;
|
|
495
503
|
this.chartModel = payload.chartModel;
|
|
496
504
|
|
|
505
|
+
return this.publishChartContextPropsToHost();
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
private initializationComplete = (): void => {
|
|
497
509
|
// context is now initialized
|
|
498
510
|
isInitialized = true;
|
|
499
511
|
|
|
500
512
|
// TODO: following can be done behind a promise
|
|
501
513
|
this.triggerInitResolve();
|
|
502
|
-
|
|
503
|
-
return this.publishChartContextPropsToHost();
|
|
504
514
|
};
|
|
505
515
|
|
|
506
516
|
private publishChartContextPropsToHost =
|
|
@@ -547,8 +557,8 @@ export class CustomChartContext {
|
|
|
547
557
|
let response;
|
|
548
558
|
if (_.isArray(this.eventListeners[event.data.eventType])) {
|
|
549
559
|
this.eventListeners[event.data.eventType].forEach((callback) => {
|
|
550
|
-
// this is a problem today if we have
|
|
551
|
-
// registered. only the last
|
|
560
|
+
// this is a problem today if we have multiple callbacks
|
|
561
|
+
// registered. only the last response will be sent back to the
|
|
552
562
|
// server
|
|
553
563
|
response = callback(payload);
|
|
554
564
|
});
|
|
@@ -3,7 +3,7 @@ import { ChartToTSEvent } from '../types/chart-to-ts-event.types';
|
|
|
3
3
|
const TIMEOUT_THRESHOLD = 30000; // 30sec
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* method to listen to messages using postMessage from parent.
|
|
6
|
+
* method to listen to messages using postMessage from the parent.
|
|
7
7
|
*
|
|
8
8
|
* @param {any} handleMessageEvent
|
|
9
9
|
*/
|
|
@@ -23,7 +23,7 @@ const destroy = (handleMessageEvent: any) => {
|
|
|
23
23
|
/**
|
|
24
24
|
* @param {string} componentId This is required to send the event to the
|
|
25
25
|
* right chart component in case of multiple components
|
|
26
|
-
* @param {string} hostUrl The host application
|
|
26
|
+
* @param {string} hostUrl The host application URL
|
|
27
27
|
* @param {any} eventPayload payload for the event
|
|
28
28
|
* @param {ChartToTSEvent} eventType type of the event
|
|
29
29
|
* @returns Promise
|
|
@@ -72,14 +72,14 @@ export enum CurrencyFormatType {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
* Currency
|
|
75
|
+
* Currency format for the column defined in the worksheet
|
|
76
76
|
*
|
|
77
77
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
78
78
|
*/
|
|
79
79
|
export interface CurrencyFormat {
|
|
80
80
|
type: CurrencyFormatType;
|
|
81
81
|
/**
|
|
82
|
-
* column
|
|
82
|
+
* column ID of the column in case of currency formatted by a column
|
|
83
83
|
*
|
|
84
84
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
85
85
|
*/
|
|
@@ -118,13 +118,13 @@ export interface ColumnFormat {
|
|
|
118
118
|
|
|
119
119
|
export interface ChartColumn {
|
|
120
120
|
/**
|
|
121
|
-
* Column
|
|
121
|
+
* Column ID
|
|
122
122
|
*
|
|
123
123
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
124
124
|
*/
|
|
125
125
|
id: string;
|
|
126
126
|
/**
|
|
127
|
-
* Column
|
|
127
|
+
* Column name
|
|
128
128
|
*
|
|
129
129
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
130
130
|
*/
|
|
@@ -137,7 +137,7 @@ export interface ChartColumn {
|
|
|
137
137
|
type: ColumnType;
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
|
-
* Type of the time
|
|
140
|
+
* Type of the time-based aggregation
|
|
141
141
|
* when the column data is of type Date, Datetime, Time
|
|
142
142
|
*
|
|
143
143
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
@@ -31,7 +31,7 @@ export enum ChartToTSEvent {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* This map defines the event type and its corresponding payload needed by event
|
|
34
|
+
* This map defines the event type and its corresponding payload needed by the event
|
|
35
35
|
*
|
|
36
36
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
37
37
|
* @group Chart to ThoughtSpot Events
|
|
@@ -42,38 +42,38 @@ export interface ChartToTSEventsPayloadMap {
|
|
|
42
42
|
*
|
|
43
43
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
44
44
|
*/
|
|
45
|
-
[ChartToTSEvent.OpenContextMenu]: OpenContextMenuEventPayload;
|
|
45
|
+
[ChartToTSEvent.OpenContextMenu]: [OpenContextMenuEventPayload];
|
|
46
46
|
/**
|
|
47
47
|
* Trigger to close Context Menu
|
|
48
48
|
*
|
|
49
49
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
50
50
|
*/
|
|
51
|
-
[ChartToTSEvent.CloseContextMenu]:
|
|
51
|
+
[ChartToTSEvent.CloseContextMenu]: [];
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Trigger to notify the render start
|
|
55
55
|
*
|
|
56
56
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
57
57
|
*/
|
|
58
|
-
[ChartToTSEvent.RenderStart]:
|
|
58
|
+
[ChartToTSEvent.RenderStart]: [];
|
|
59
59
|
/**
|
|
60
60
|
* Trigger to notify the render completion
|
|
61
61
|
*
|
|
62
62
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
63
63
|
*/
|
|
64
|
-
[ChartToTSEvent.RenderComplete]:
|
|
64
|
+
[ChartToTSEvent.RenderComplete]: [];
|
|
65
65
|
/**
|
|
66
66
|
* Trigger to notify the render error
|
|
67
67
|
*
|
|
68
68
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
69
69
|
*/
|
|
70
|
-
[ChartToTSEvent.RenderError]: RenderErrorEventPayload;
|
|
70
|
+
[ChartToTSEvent.RenderError]: [RenderErrorEventPayload];
|
|
71
71
|
/**
|
|
72
72
|
* Trigger to update the visual props
|
|
73
73
|
*
|
|
74
74
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
75
75
|
*/
|
|
76
|
-
[ChartToTSEvent.UpdateVisualProps]: UpdateVisualPropsEventPayload;
|
|
76
|
+
[ChartToTSEvent.UpdateVisualProps]: [UpdateVisualPropsEventPayload];
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
@@ -87,10 +87,10 @@ type UpdateVisualPropsEventPayload = VisualProps;
|
|
|
87
87
|
*/
|
|
88
88
|
// start - open context menu payload
|
|
89
89
|
export interface PointVal {
|
|
90
|
-
//
|
|
90
|
+
// Column ID of the column associated with the value
|
|
91
91
|
columnId: string;
|
|
92
|
-
//
|
|
93
|
-
//
|
|
92
|
+
// Value of the point clicked on, mostly makes sense for attributes.
|
|
93
|
+
// This can be an array of values as well.
|
|
94
94
|
value: any;
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
@@ -106,16 +106,16 @@ export interface Point {
|
|
|
106
106
|
* @group Chart to ThoughtSpot Events / Context Menu
|
|
107
107
|
*/
|
|
108
108
|
export interface CustomAction {
|
|
109
|
-
id: string; //
|
|
110
|
-
label: string; //
|
|
111
|
-
icon
|
|
109
|
+
id: string; // ID of the user-defined action
|
|
110
|
+
label: string; // Developer should i18n this
|
|
111
|
+
icon?: string; // Icon string to show on the context/axis menu
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
* This function will need to have a defined set of
|
|
115
|
-
* For
|
|
116
|
-
* For
|
|
114
|
+
* This function will need to have a defined set of arguments.
|
|
115
|
+
* For example, pointClick Event, point details and chart model in case of context menu
|
|
116
|
+
* For Axis menu, it would be different.
|
|
117
117
|
*
|
|
118
|
-
* Callback will be triggered via postMessage
|
|
118
|
+
* Callback will be triggered via postMessage API contract.
|
|
119
119
|
*/
|
|
120
120
|
onClick: (...args: any[]) => void;
|
|
121
121
|
}
|
|
@@ -125,17 +125,7 @@ export interface CustomAction {
|
|
|
125
125
|
* @group Chart to ThoughtSpot Events
|
|
126
126
|
*/
|
|
127
127
|
export interface OpenContextMenuEventPayload {
|
|
128
|
-
event: Pick<
|
|
129
|
-
PointerEvent,
|
|
130
|
-
| 'x'
|
|
131
|
-
| 'y'
|
|
132
|
-
| 'clientX'
|
|
133
|
-
| 'clientY'
|
|
134
|
-
| 'pageX'
|
|
135
|
-
| 'pageY'
|
|
136
|
-
| 'screenX'
|
|
137
|
-
| 'screenY'
|
|
138
|
-
>;
|
|
128
|
+
event: Pick<PointerEvent, 'clientX' | 'clientY'>;
|
|
139
129
|
clickedPoint: Point;
|
|
140
130
|
selectedPoints?: Point[];
|
|
141
131
|
customActions?: CustomAction[];
|