@thoughtspot/ts-chart-sdk 1.1.1 → 1.2.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/dist/ts-chart-sdk.d.ts +142 -1
- 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 +8 -0
- package/lib/main/custom-chart-context.js.map +1 -1
- package/lib/main/custom-chart-context.spec.js +100 -0
- package/lib/main/custom-chart-context.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 +9 -0
- package/lib/react/use-custom-chart-context.js.map +1 -1
- package/lib/react/use-custom-chart-context.spec.js +49 -0
- package/lib/react/use-custom-chart-context.spec.js.map +1 -1
- package/lib/types/actions.types.d.ts +123 -0
- package/lib/types/actions.types.d.ts.map +1 -0
- package/lib/types/actions.types.js +124 -0
- package/lib/types/actions.types.js.map +1 -0
- package/lib/types/common.types.d.ts +7 -0
- package/lib/types/common.types.d.ts.map +1 -1
- package/lib/types/common.types.js.map +1 -1
- package/lib/types/ts-to-chart-event.types.d.ts +13 -2
- 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 +136 -0
- package/src/main/custom-chart-context.ts +26 -0
- package/src/react/use-custom-chart-context.spec.tsx +68 -0
- package/src/react/use-custom-chart-context.tsx +15 -1
- package/src/types/actions.types.ts +1015 -0
- package/src/types/common.types.ts +36 -0
- package/src/types/ts-to-chart-event.types.ts +27 -0
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
ChartModel,
|
|
24
24
|
SuccessValidationResponse,
|
|
25
25
|
ValidationResponse,
|
|
26
|
+
VisualConfig,
|
|
26
27
|
VisualProps,
|
|
27
28
|
} from '../types/common.types';
|
|
28
29
|
import {
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
ChartModelUpdateEventPayload,
|
|
36
37
|
ContextMenuCustomActionPayload,
|
|
37
38
|
DataUpdateEventPayload,
|
|
39
|
+
DownloadExcelTriggerPayload,
|
|
38
40
|
GetColumnDataPayload,
|
|
39
41
|
GetColumnDataResponsePayload,
|
|
40
42
|
GetDataQueryPayload,
|
|
@@ -173,6 +175,13 @@ export type ChartConfigParameters = {
|
|
|
173
175
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
174
176
|
*/
|
|
175
177
|
batchSizeLimit?: number;
|
|
178
|
+
/**
|
|
179
|
+
* @description
|
|
180
|
+
* Optional parameter to control certain visual elements on the chart For example visibleAction
|
|
181
|
+
* array if Passed will only show those actions in context menu/Action menu of the chart on answer page
|
|
182
|
+
* @type {VisualConfig}
|
|
183
|
+
*/
|
|
184
|
+
customChartVisualConfig?: VisualConfig;
|
|
176
185
|
};
|
|
177
186
|
|
|
178
187
|
export type CustomChartContextProps = {
|
|
@@ -1024,6 +1033,23 @@ export class CustomChartContext {
|
|
|
1024
1033
|
};
|
|
1025
1034
|
},
|
|
1026
1035
|
);
|
|
1036
|
+
/**
|
|
1037
|
+
* This event is triggered when the TS app sends the download excel trigger.
|
|
1038
|
+
*/
|
|
1039
|
+
this.on(
|
|
1040
|
+
TSToChartEvent.DownloadExcelTrigger,
|
|
1041
|
+
(payload: DownloadExcelTriggerPayload) => {
|
|
1042
|
+
logger.log(
|
|
1043
|
+
'DownloadExcelTrigger event triggered from TS with payload:',
|
|
1044
|
+
payload,
|
|
1045
|
+
);
|
|
1046
|
+
return {
|
|
1047
|
+
fileName: '',
|
|
1048
|
+
error: '',
|
|
1049
|
+
message: 'Download Excel not implemented.',
|
|
1050
|
+
};
|
|
1051
|
+
},
|
|
1052
|
+
);
|
|
1027
1053
|
};
|
|
1028
1054
|
|
|
1029
1055
|
/**
|
|
@@ -488,3 +488,71 @@ describe('useChartContext on React Wrapper component', () => {
|
|
|
488
488
|
});
|
|
489
489
|
});
|
|
490
490
|
});
|
|
491
|
+
// ... existing code ...
|
|
492
|
+
|
|
493
|
+
describe('useChartContext DownloadExcelTrigger event handler', () => {
|
|
494
|
+
let eventProcessor: any;
|
|
495
|
+
let mockInitMessage;
|
|
496
|
+
let mockPostMessageToHost;
|
|
497
|
+
const mockedChartModel = { columns: [], config: {} };
|
|
498
|
+
|
|
499
|
+
beforeEach(() => {
|
|
500
|
+
mockInitMessage = jest.spyOn(
|
|
501
|
+
PostMessageEventBridge,
|
|
502
|
+
'initMessageListener',
|
|
503
|
+
);
|
|
504
|
+
mockPostMessageToHost = jest.spyOn(
|
|
505
|
+
PostMessageEventBridge,
|
|
506
|
+
'postMessageToHostApp',
|
|
507
|
+
);
|
|
508
|
+
mockInitMessage.mockImplementation((fn: any) => {
|
|
509
|
+
eventProcessor = fn;
|
|
510
|
+
return () => null;
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
mockPostMessageToHost.mockImplementation(() => {
|
|
514
|
+
return global.Promise.resolve();
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
afterEach(() => {
|
|
519
|
+
jest.clearAllMocks();
|
|
520
|
+
PostMessageEventBridge.globalThis.isInitialized = false;
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
test('should handle download Excel trigger correctly', async () => {
|
|
524
|
+
const { result, waitFor } = renderHook(() =>
|
|
525
|
+
useChartContext(contextChartProps),
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
// Initialize context
|
|
529
|
+
await eventProcessor({
|
|
530
|
+
payload: {
|
|
531
|
+
componentId: 'COMPONENT_ID',
|
|
532
|
+
hostUrl: 'https://some.chart.app',
|
|
533
|
+
chartModel: mockedChartModel,
|
|
534
|
+
},
|
|
535
|
+
eventType: TSToChartEvent.Initialize,
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
await eventProcessor({
|
|
539
|
+
payload: {},
|
|
540
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
541
|
+
source: 'ts-host-app',
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
const response = await eventProcessor({
|
|
545
|
+
payload: {},
|
|
546
|
+
eventType: TSToChartEvent.DownloadExcelTrigger,
|
|
547
|
+
source: 'ts-host-app',
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
await waitFor(() => {
|
|
551
|
+
expect(response).toEqual({
|
|
552
|
+
fileName: '',
|
|
553
|
+
error: '',
|
|
554
|
+
message: 'Download Excel not implemented.',
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
});
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* Copyright: ThoughtSpot Inc. 2023
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { error } from 'console';
|
|
9
10
|
import _ from 'lodash';
|
|
10
11
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
11
12
|
import {
|
|
@@ -17,6 +18,7 @@ import { ChartModel } from '../types/common.types';
|
|
|
17
18
|
import {
|
|
18
19
|
ChartModelUpdateEventPayload,
|
|
19
20
|
DataUpdateEventPayload,
|
|
21
|
+
DownloadExcelTriggerPayload,
|
|
20
22
|
VisualPropsUpdateEventPayload,
|
|
21
23
|
} from '../types/ts-to-chart-event.types';
|
|
22
24
|
import {
|
|
@@ -106,7 +108,16 @@ export const useChartContext = (
|
|
|
106
108
|
triggerRenderChart: true,
|
|
107
109
|
};
|
|
108
110
|
};
|
|
109
|
-
|
|
111
|
+
const defaultDownloadUpdateHandler = (
|
|
112
|
+
payload: DownloadExcelTriggerPayload,
|
|
113
|
+
) => {
|
|
114
|
+
setChartModel(context.getChartModel());
|
|
115
|
+
return {
|
|
116
|
+
fileName: '',
|
|
117
|
+
error: '',
|
|
118
|
+
message: 'Download Excel not implemented.',
|
|
119
|
+
};
|
|
120
|
+
};
|
|
110
121
|
// Register all external event listeners here
|
|
111
122
|
getChartContextValues(context).setOnChartModelUpdate(
|
|
112
123
|
commonUpdateHandler,
|
|
@@ -115,6 +126,9 @@ export const useChartContext = (
|
|
|
115
126
|
commonUpdateHandler,
|
|
116
127
|
);
|
|
117
128
|
getChartContextValues(context).setOnDataUpdate(commonUpdateHandler);
|
|
129
|
+
getChartContextValues(context).setOnDownloadExcelTrigger(
|
|
130
|
+
defaultDownloadUpdateHandler,
|
|
131
|
+
);
|
|
118
132
|
}, []);
|
|
119
133
|
|
|
120
134
|
/**
|