@thoughtspot/visual-embed-sdk 1.35.5-hostEvent.6 → 1.35.5-hostEvent.8
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/cjs/package.json +1 -1
- package/cjs/src/embed/app.d.ts +1 -1
- package/cjs/src/embed/base.d.ts +1 -1
- package/cjs/src/embed/base.js +1 -1
- package/cjs/src/embed/hostEventClient/contracts.d.ts +26 -30
- package/cjs/src/embed/hostEventClient/contracts.d.ts.map +1 -1
- package/cjs/src/embed/hostEventClient/contracts.js +10 -10
- package/cjs/src/embed/hostEventClient/contracts.js.map +1 -1
- package/cjs/src/embed/hostEventClient/host-event-client.d.ts +21 -7
- package/cjs/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
- package/cjs/src/embed/hostEventClient/host-event-client.js +62 -28
- package/cjs/src/embed/hostEventClient/host-event-client.js.map +1 -1
- package/cjs/src/embed/hostEventClient/host-event-client.spec.js +43 -39
- package/cjs/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
- package/cjs/src/embed/liveboard.d.ts +8 -7
- package/cjs/src/embed/liveboard.d.ts.map +1 -1
- package/cjs/src/embed/liveboard.js +2 -2
- package/cjs/src/embed/liveboard.js.map +1 -1
- package/cjs/src/embed/liveboard.spec.js +4 -2
- package/cjs/src/embed/liveboard.spec.js.map +1 -1
- package/cjs/src/embed/ts-embed.d.ts +14 -9
- package/cjs/src/embed/ts-embed.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.js +23 -15
- package/cjs/src/embed/ts-embed.js.map +1 -1
- package/cjs/src/embed/ts-embed.spec.js +4 -4
- package/cjs/src/embed/ts-embed.spec.js.map +1 -1
- package/cjs/src/index.d.ts +2 -2
- package/cjs/src/index.js +2 -2
- package/cjs/src/react/all-types-export.d.ts +1 -1
- package/cjs/src/react/all-types-export.js +2 -2
- package/cjs/src/types.d.ts +26 -21
- package/cjs/src/types.d.ts.map +1 -1
- package/cjs/src/types.js +20 -19
- package/cjs/src/types.js.map +1 -1
- package/dist/index-DaLHJaLd.js +7370 -0
- package/dist/index-nWevLycs.js +7370 -0
- package/dist/src/embed/app.d.ts +1 -1
- package/dist/src/embed/base.d.ts +1 -1
- package/dist/src/embed/hostEventClient/contracts.d.ts +26 -30
- package/dist/src/embed/hostEventClient/contracts.d.ts.map +1 -1
- package/dist/src/embed/hostEventClient/host-event-client.d.ts +21 -7
- package/dist/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
- package/dist/src/embed/liveboard.d.ts +8 -7
- package/dist/src/embed/liveboard.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts +14 -9
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/react/all-types-export.d.ts +1 -1
- package/dist/src/types.d.ts +26 -21
- package/dist/src/types.d.ts.map +1 -1
- package/dist/tsembed-react.es.js +118 -76
- package/dist/tsembed-react.js +117 -75
- package/dist/tsembed.es.js +120 -78
- package/dist/tsembed.js +118 -76
- package/dist/visual-embed-sdk-react-full.d.ts +96 -75
- package/dist/visual-embed-sdk-react.d.ts +96 -75
- package/dist/visual-embed-sdk.d.ts +96 -75
- package/lib/package.json +1 -1
- package/lib/src/embed/app.d.ts +1 -1
- package/lib/src/embed/base.d.ts +1 -1
- package/lib/src/embed/base.js +1 -1
- package/lib/src/embed/hostEventClient/contracts.d.ts +26 -30
- package/lib/src/embed/hostEventClient/contracts.d.ts.map +1 -1
- package/lib/src/embed/hostEventClient/contracts.js +9 -9
- package/lib/src/embed/hostEventClient/contracts.js.map +1 -1
- package/lib/src/embed/hostEventClient/host-event-client.d.ts +21 -7
- package/lib/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
- package/lib/src/embed/hostEventClient/host-event-client.js +64 -30
- package/lib/src/embed/hostEventClient/host-event-client.js.map +1 -1
- package/lib/src/embed/hostEventClient/host-event-client.spec.js +43 -40
- package/lib/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
- package/lib/src/embed/liveboard.d.ts +8 -7
- package/lib/src/embed/liveboard.d.ts.map +1 -1
- package/lib/src/embed/liveboard.js +2 -2
- package/lib/src/embed/liveboard.js.map +1 -1
- package/lib/src/embed/liveboard.spec.js +4 -2
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +14 -9
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +23 -15
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +5 -5
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/index.d.ts +2 -2
- package/lib/src/index.js +2 -2
- package/lib/src/react/all-types-export.d.ts +1 -1
- package/lib/src/react/all-types-export.js +1 -1
- package/lib/src/types.d.ts +26 -21
- package/lib/src/types.d.ts.map +1 -1
- package/lib/src/types.js +20 -19
- package/lib/src/types.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +99 -78
- package/package.json +1 -1
- package/src/embed/app.ts +1 -1
- package/src/embed/base.ts +1 -1
- package/src/embed/hostEventClient/contracts.ts +43 -32
- package/src/embed/hostEventClient/host-event-client.spec.ts +58 -54
- package/src/embed/hostEventClient/host-event-client.ts +105 -48
- package/src/embed/liveboard.spec.ts +4 -2
- package/src/embed/liveboard.ts +8 -7
- package/src/embed/ts-embed.spec.ts +6 -6
- package/src/embed/ts-embed.ts +39 -28
- package/src/index.ts +2 -2
- package/src/react/all-types-export.ts +1 -1
- package/src/types.ts +26 -21
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { getIFrameEl } from '../../test/test-utils';
|
|
1
|
+
import { getIFrameEl, getRootEl } from '../../test/test-utils';
|
|
2
2
|
import { HostEvent } from '../../types';
|
|
3
3
|
import { processTrigger } from '../../utils/processTrigger';
|
|
4
|
+
import * as EmbedConfigService from '../embedConfig';
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
UIPassthroughEvent,
|
|
7
|
+
UIPassthroughRequest,
|
|
8
|
+
UIPassthroughArrayResponse,
|
|
8
9
|
HostEventRequest,
|
|
9
10
|
} from './contracts';
|
|
10
11
|
import { HostEventClient } from './host-event-client';
|
|
@@ -14,23 +15,27 @@ jest.mock('../../utils/processTrigger');
|
|
|
14
15
|
const mockProcessTrigger = processTrigger as jest.Mock;
|
|
15
16
|
|
|
16
17
|
const createHostEventClient = () => {
|
|
17
|
-
const mockIframe =
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
return { client, mockIframe, mockThoughtSpotHost };
|
|
18
|
+
const mockIframe = document.createElement('iframe');
|
|
19
|
+
const client = new HostEventClient(mockIframe);
|
|
20
|
+
return { client, mockIframe };
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
describe('HostEventClient', () => {
|
|
24
|
+
const mockThoughtSpotHost = 'http://localhost';
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
jest.spyOn(EmbedConfigService, 'getEmbedConfig').mockReturnValue({ thoughtSpotHost: mockThoughtSpotHost });
|
|
27
|
+
});
|
|
28
|
+
|
|
24
29
|
afterEach(() => {
|
|
25
30
|
jest.clearAllMocks();
|
|
26
31
|
});
|
|
27
32
|
|
|
28
|
-
describe('
|
|
33
|
+
describe('executeUIPassthroughApi', () => {
|
|
29
34
|
it('should call processTrigger with correct parameters and return response', async () => {
|
|
30
|
-
const { client, mockIframe
|
|
35
|
+
const { client, mockIframe } = createHostEventClient();
|
|
31
36
|
|
|
32
|
-
const apiName =
|
|
33
|
-
const parameters:
|
|
37
|
+
const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
|
|
38
|
+
const parameters: UIPassthroughRequest<typeof apiName> = {
|
|
34
39
|
newVizName: 'testViz',
|
|
35
40
|
};
|
|
36
41
|
const triggerResponse = Promise.resolve([
|
|
@@ -39,11 +44,11 @@ describe('HostEventClient', () => {
|
|
|
39
44
|
|
|
40
45
|
mockProcessTrigger.mockResolvedValue(triggerResponse);
|
|
41
46
|
|
|
42
|
-
const result = await client.
|
|
47
|
+
const result = await client.triggerUIPassthroughApi(apiName, parameters);
|
|
43
48
|
|
|
44
49
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
45
50
|
mockIframe,
|
|
46
|
-
HostEvent.
|
|
51
|
+
HostEvent.UIPassthrough,
|
|
47
52
|
mockThoughtSpotHost,
|
|
48
53
|
{
|
|
49
54
|
type: apiName,
|
|
@@ -54,11 +59,11 @@ describe('HostEventClient', () => {
|
|
|
54
59
|
});
|
|
55
60
|
});
|
|
56
61
|
|
|
57
|
-
describe('
|
|
62
|
+
describe('handleUIPassthroughForHostEvent', () => {
|
|
58
63
|
it('should return the value from the first valid response', async () => {
|
|
59
64
|
const { client } = createHostEventClient();
|
|
60
|
-
const apiName =
|
|
61
|
-
const parameters:
|
|
65
|
+
const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
|
|
66
|
+
const parameters: UIPassthroughRequest<typeof apiName> = {
|
|
62
67
|
newVizName: 'testViz',
|
|
63
68
|
};
|
|
64
69
|
const triggerResponse = Promise.resolve([
|
|
@@ -66,8 +71,7 @@ describe('HostEventClient', () => {
|
|
|
66
71
|
]);
|
|
67
72
|
mockProcessTrigger.mockResolvedValue(triggerResponse);
|
|
68
73
|
|
|
69
|
-
const result = await client.
|
|
70
|
-
apiName, parameters);
|
|
74
|
+
const result = await client.handleHostEventWithParam(apiName, parameters);
|
|
71
75
|
|
|
72
76
|
expect(result).toEqual({
|
|
73
77
|
pinboardId: 'testPinboard',
|
|
@@ -78,50 +82,50 @@ describe('HostEventClient', () => {
|
|
|
78
82
|
|
|
79
83
|
it('should throw an error if no valid response is found', async () => {
|
|
80
84
|
const { client } = createHostEventClient();
|
|
81
|
-
const apiName =
|
|
82
|
-
const parameters:
|
|
85
|
+
const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
|
|
86
|
+
const parameters: UIPassthroughRequest<typeof apiName> = {
|
|
83
87
|
newVizName: 'testViz',
|
|
84
88
|
};
|
|
85
|
-
const triggerResponse:
|
|
89
|
+
const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [];
|
|
86
90
|
mockProcessTrigger.mockResolvedValue(triggerResponse);
|
|
87
91
|
|
|
88
|
-
await expect(client.
|
|
92
|
+
await expect(client.handleHostEventWithParam(apiName, parameters))
|
|
89
93
|
.rejects.toEqual({ error: 'No answer found.' });
|
|
90
94
|
});
|
|
91
95
|
|
|
92
96
|
it('should throw an error if no valid response is found for vizId', async () => {
|
|
93
97
|
const { client } = createHostEventClient();
|
|
94
|
-
const apiName =
|
|
95
|
-
const parameters:
|
|
98
|
+
const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
|
|
99
|
+
const parameters: UIPassthroughRequest<typeof apiName> = {
|
|
96
100
|
newVizName: 'testViz',
|
|
97
101
|
vizId: 'testVizId',
|
|
98
102
|
};
|
|
99
|
-
const triggerResponse:
|
|
103
|
+
const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [];
|
|
100
104
|
mockProcessTrigger.mockResolvedValue(triggerResponse);
|
|
101
105
|
|
|
102
|
-
await expect(client.
|
|
106
|
+
await expect(client.handleHostEventWithParam(apiName, parameters))
|
|
103
107
|
.rejects.toEqual({ error: 'No answer found for vizId: testVizId.' });
|
|
104
108
|
});
|
|
105
109
|
|
|
106
110
|
it('should throw an error if the response contains errors', async () => {
|
|
107
111
|
const { client } = createHostEventClient();
|
|
108
|
-
const apiName =
|
|
109
|
-
const parameters:
|
|
112
|
+
const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
|
|
113
|
+
const parameters: UIPassthroughRequest<typeof apiName> = {
|
|
110
114
|
newVizName: 'testViz',
|
|
111
115
|
};
|
|
112
|
-
const triggerResponse:
|
|
116
|
+
const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [
|
|
113
117
|
{ error: 'Some error' },
|
|
114
|
-
]
|
|
118
|
+
];
|
|
115
119
|
mockProcessTrigger.mockResolvedValue(triggerResponse);
|
|
116
120
|
|
|
117
|
-
await expect(client.
|
|
121
|
+
await expect(client.handleHostEventWithParam(apiName, parameters))
|
|
118
122
|
.rejects.toEqual({ error: 'Some error' });
|
|
119
123
|
});
|
|
120
124
|
});
|
|
121
125
|
|
|
122
126
|
describe('executeHostEvent', () => {
|
|
123
|
-
it('should call
|
|
124
|
-
const { client } = createHostEventClient();
|
|
127
|
+
it('should call handleUIPassthroughForHostEvent for Pin event', async () => {
|
|
128
|
+
const { client, mockIframe } = createHostEventClient();
|
|
125
129
|
const hostEvent = HostEvent.Pin;
|
|
126
130
|
const payload: HostEventRequest<typeof hostEvent> = {
|
|
127
131
|
newVizName: 'testViz',
|
|
@@ -136,19 +140,19 @@ describe('HostEventClient', () => {
|
|
|
136
140
|
|
|
137
141
|
mockProcessTrigger.mockResolvedValue([mockResponse]);
|
|
138
142
|
|
|
139
|
-
const result = await client.
|
|
143
|
+
const result = await client.triggerHostEvent(hostEvent, payload);
|
|
140
144
|
|
|
141
145
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
142
|
-
|
|
143
|
-
HostEvent.
|
|
146
|
+
mockIframe,
|
|
147
|
+
HostEvent.UIPassthrough,
|
|
144
148
|
'http://localhost',
|
|
145
|
-
{ parameters: payload, type:
|
|
149
|
+
{ parameters: payload, type: UIPassthroughEvent.PinAnswerToLiveboard },
|
|
146
150
|
);
|
|
147
151
|
expect(result).toEqual(mockResponse.value);
|
|
148
152
|
});
|
|
149
153
|
|
|
150
|
-
it('should call
|
|
151
|
-
const { client } = createHostEventClient();
|
|
154
|
+
it('should call handleUIPassthroughForHostEvent for SaveAnswer event', async () => {
|
|
155
|
+
const { client, mockIframe } = createHostEventClient();
|
|
152
156
|
const hostEvent = HostEvent.SaveAnswer;
|
|
153
157
|
const payload: HostEventRequest<typeof hostEvent> = {
|
|
154
158
|
name: 'Test Answer',
|
|
@@ -170,12 +174,12 @@ describe('HostEventClient', () => {
|
|
|
170
174
|
refId: 'testVizId',
|
|
171
175
|
}];
|
|
172
176
|
mockProcessTrigger.mockResolvedValue(mockResponse);
|
|
173
|
-
const result = await client.
|
|
177
|
+
const result = await client.triggerHostEvent(hostEvent, payload);
|
|
174
178
|
|
|
175
179
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
180
|
+
mockIframe,
|
|
181
|
+
HostEvent.UIPassthrough,
|
|
182
|
+
mockThoughtSpotHost,
|
|
179
183
|
{
|
|
180
184
|
parameters: payload,
|
|
181
185
|
type: 'saveAnswer',
|
|
@@ -191,14 +195,14 @@ describe('HostEventClient', () => {
|
|
|
191
195
|
const mockResponse = { fallbackResponse: 'data' };
|
|
192
196
|
jest.spyOn(client, 'hostEventFallback').mockResolvedValue(mockResponse);
|
|
193
197
|
|
|
194
|
-
const result = await client.
|
|
198
|
+
const result = await client.triggerHostEvent(hostEvent, payload);
|
|
195
199
|
|
|
196
|
-
expect(client.hostEventFallback).toHaveBeenCalledWith(
|
|
200
|
+
expect(client.hostEventFallback).toHaveBeenCalledWith(hostEvent, payload);
|
|
197
201
|
expect(result).toEqual(mockResponse);
|
|
198
202
|
});
|
|
199
203
|
|
|
200
204
|
it('should call fallback for Pin event', async () => {
|
|
201
|
-
const { client } = createHostEventClient();
|
|
205
|
+
const { client, mockIframe } = createHostEventClient();
|
|
202
206
|
const hostEvent = HostEvent.Pin;
|
|
203
207
|
const payload: HostEventRequest<typeof hostEvent> = {} as any;
|
|
204
208
|
const mockResponse = {
|
|
@@ -211,19 +215,19 @@ describe('HostEventClient', () => {
|
|
|
211
215
|
|
|
212
216
|
mockProcessTrigger.mockResolvedValue([mockResponse]);
|
|
213
217
|
|
|
214
|
-
const result = await client.
|
|
218
|
+
const result = await client.triggerHostEvent(hostEvent, payload);
|
|
215
219
|
|
|
216
220
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
217
|
-
|
|
221
|
+
mockIframe,
|
|
218
222
|
HostEvent.Pin,
|
|
219
|
-
|
|
223
|
+
mockThoughtSpotHost,
|
|
220
224
|
{},
|
|
221
225
|
);
|
|
222
226
|
expect(result).toEqual([mockResponse]);
|
|
223
227
|
});
|
|
224
228
|
|
|
225
229
|
it('should call fallback for SaveAnswer event', async () => {
|
|
226
|
-
const { client } = createHostEventClient();
|
|
230
|
+
const { client, mockIframe } = createHostEventClient();
|
|
227
231
|
const hostEvent = HostEvent.SaveAnswer;
|
|
228
232
|
const payload: HostEventRequest<typeof hostEvent> = {} as any;
|
|
229
233
|
const mockResponse = {
|
|
@@ -236,12 +240,12 @@ describe('HostEventClient', () => {
|
|
|
236
240
|
|
|
237
241
|
mockProcessTrigger.mockResolvedValue([mockResponse]);
|
|
238
242
|
|
|
239
|
-
const result = await client.
|
|
243
|
+
const result = await client.triggerHostEvent(hostEvent, payload);
|
|
240
244
|
|
|
241
245
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
242
|
-
|
|
246
|
+
mockIframe,
|
|
243
247
|
HostEvent.Save,
|
|
244
|
-
|
|
248
|
+
mockThoughtSpotHost,
|
|
245
249
|
{},
|
|
246
250
|
);
|
|
247
251
|
expect(result).toEqual([mockResponse]);
|
|
@@ -1,38 +1,47 @@
|
|
|
1
1
|
import { HostEvent } from '../../types';
|
|
2
|
-
import { processTrigger } from '../../utils/processTrigger';
|
|
2
|
+
import { processTrigger as processTriggerService } from '../../utils/processTrigger';
|
|
3
|
+
import { getEmbedConfig } from '../embedConfig';
|
|
3
4
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
UIPassthroughArrayResponse,
|
|
6
|
+
UIPassthroughEvent, HostEventRequest, HostEventResponse,
|
|
7
|
+
UIPassthroughRequest,
|
|
8
|
+
UIPassthroughResponse,
|
|
9
|
+
TriggerPayload,
|
|
10
|
+
TriggerResponse,
|
|
8
11
|
} from './contracts';
|
|
9
12
|
|
|
10
13
|
export class HostEventClient {
|
|
11
|
-
|
|
14
|
+
iFrame: HTMLIFrameElement;
|
|
12
15
|
|
|
13
|
-
constructor(
|
|
14
|
-
this.
|
|
16
|
+
constructor(iFrame?: HTMLIFrameElement) {
|
|
17
|
+
this.iFrame = iFrame;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
/**
|
|
21
|
+
* A wrapper over process trigger to
|
|
22
|
+
* @param {HostEvent} message Host event to send
|
|
23
|
+
* @param {any} data Data to send with the host event
|
|
24
|
+
* @returns {Promise<any>} - the response from the process trigger
|
|
25
|
+
*/
|
|
26
|
+
protected async processTrigger(message: HostEvent, data: any): Promise<any> {
|
|
27
|
+
if (!this.iFrame) {
|
|
28
|
+
throw new Error('Iframe element is not set');
|
|
29
|
+
}
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
const thoughtspotHost = getEmbedConfig().thoughtSpotHost;
|
|
32
|
+
return processTriggerService(
|
|
33
|
+
this.iFrame,
|
|
34
|
+
message,
|
|
35
|
+
thoughtspotHost,
|
|
36
|
+
data,
|
|
37
|
+
);
|
|
28
38
|
}
|
|
29
39
|
|
|
30
|
-
public async
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const response = (await this.executeUiPassthroughApi(iFrame, apiName, parameters))
|
|
40
|
+
public async handleHostEventWithParam<UIPassthroughEventT extends UIPassthroughEvent>(
|
|
41
|
+
apiName: UIPassthroughEventT,
|
|
42
|
+
parameters: UIPassthroughRequest<UIPassthroughEventT>,
|
|
43
|
+
): Promise<UIPassthroughResponse<UIPassthroughEventT>> {
|
|
44
|
+
const response = (await this.triggerUIPassthroughApi(apiName, parameters))
|
|
36
45
|
?.filter?.((r) => r.error || r.value)[0];
|
|
37
46
|
|
|
38
47
|
if (!response) {
|
|
@@ -41,42 +50,90 @@ export class HostEventClient {
|
|
|
41
50
|
throw { error };
|
|
42
51
|
}
|
|
43
52
|
|
|
44
|
-
const errors = response.error
|
|
53
|
+
const errors = response.error
|
|
54
|
+
|| (response.value as any)?.errors
|
|
55
|
+
|| (response.value as any)?.error;
|
|
56
|
+
|
|
45
57
|
if (errors) {
|
|
46
58
|
// eslint-disable-next-line no-throw-literal
|
|
47
|
-
throw { error:
|
|
59
|
+
throw { error: errors };
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
return { ...response.value };
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
public async hostEventFallback(
|
|
54
|
-
|
|
66
|
+
hostEvent: HostEvent,
|
|
67
|
+
data: any,
|
|
55
68
|
): Promise<any> {
|
|
56
|
-
return processTrigger(
|
|
69
|
+
return this.processTrigger(hostEvent, data);
|
|
57
70
|
}
|
|
58
71
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
):
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Setter for the iframe element used for host events
|
|
74
|
+
* @param {HTMLIFrameElement} iFrame - the iframe element to set
|
|
75
|
+
*/
|
|
76
|
+
public setIframeElement(iFrame: HTMLIFrameElement): void {
|
|
77
|
+
this.iFrame = iFrame;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public async triggerUIPassthroughApi<UIPassthroughEventT extends UIPassthroughEvent>(
|
|
81
|
+
apiName: UIPassthroughEventT,
|
|
82
|
+
parameters: UIPassthroughRequest<UIPassthroughEventT>,
|
|
83
|
+
): Promise<UIPassthroughArrayResponse<UIPassthroughEventT>> {
|
|
84
|
+
const res = await this.processTrigger(HostEvent.UIPassthrough, {
|
|
85
|
+
type: apiName,
|
|
86
|
+
parameters,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return res;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
protected async handlePinEvent(
|
|
93
|
+
payload: HostEventRequest<HostEvent.Pin>,
|
|
94
|
+
): Promise<HostEventResponse<HostEvent.Pin>> {
|
|
95
|
+
if (!payload || !('newVizName' in payload)) {
|
|
96
|
+
return this.hostEventFallback(HostEvent.Pin, payload);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return this.handleHostEventWithParam(
|
|
100
|
+
UIPassthroughEvent.PinAnswerToLiveboard, payload,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
protected async handleSaveAnswerEvent(
|
|
105
|
+
payload: HostEventRequest<HostEvent.SaveAnswer>,
|
|
106
|
+
): Promise<any> {
|
|
107
|
+
if (!payload || !('name' in payload) || !('description' in payload)) {
|
|
108
|
+
// Save is the fallback for SaveAnswer
|
|
109
|
+
return this.hostEventFallback(HostEvent.Save, payload);
|
|
68
110
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
111
|
+
|
|
112
|
+
const data = await this.handleHostEventWithParam(
|
|
113
|
+
UIPassthroughEvent.SaveAnswer, payload,
|
|
114
|
+
);
|
|
115
|
+
return {
|
|
116
|
+
...data,
|
|
117
|
+
answerId: data?.saveResponse?.data?.Answer__save?.answer?.id,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public async triggerHostEvent<
|
|
122
|
+
HostEventT extends HostEvent,
|
|
123
|
+
PayloadT,
|
|
124
|
+
>(
|
|
125
|
+
hostEvent: HostEventT,
|
|
126
|
+
payload?: TriggerPayload<PayloadT, HostEventT>,
|
|
127
|
+
): Promise<TriggerResponse<PayloadT, HostEventT>> {
|
|
128
|
+
switch (hostEvent) {
|
|
129
|
+
case HostEvent.Pin:
|
|
130
|
+
return this.handlePinEvent(payload as HostEventRequest<HostEvent.Pin>) as any;
|
|
131
|
+
case HostEvent.SaveAnswer:
|
|
132
|
+
return this.handleSaveAnswerEvent(
|
|
133
|
+
payload as HostEventRequest<HostEvent.SaveAnswer>,
|
|
134
|
+
) as any;
|
|
135
|
+
default:
|
|
136
|
+
return this.hostEventFallback(hostEvent, payload);
|
|
77
137
|
}
|
|
78
|
-
// fallback for save answer is Save
|
|
79
|
-
if (hostEvent === HostEvent.SaveAnswer) hostEvent = HostEvent.Save;
|
|
80
|
-
return this.hostEventFallback(iFrame, hostEvent, payload);
|
|
81
138
|
}
|
|
82
139
|
}
|
|
@@ -484,8 +484,10 @@ describe('Liveboard/viz embed tests', () => {
|
|
|
484
484
|
liveboardId,
|
|
485
485
|
} as LiveboardViewConfig);
|
|
486
486
|
liveboardEmbed.render();
|
|
487
|
-
|
|
488
|
-
|
|
487
|
+
await executeAfterWait(async () => {
|
|
488
|
+
await liveboardEmbed.trigger(HostEvent.Pin);
|
|
489
|
+
expect(mockProcessTrigger).toBeCalled();
|
|
490
|
+
});
|
|
489
491
|
});
|
|
490
492
|
|
|
491
493
|
test('should render active tab when activeTab present', async () => {
|
package/src/embed/liveboard.ts
CHANGED
|
@@ -249,7 +249,7 @@ export interface LiveboardViewConfig
|
|
|
249
249
|
*/
|
|
250
250
|
enableAskSage?: boolean;
|
|
251
251
|
/**
|
|
252
|
-
* This flag is used to enable the 2 column layout
|
|
252
|
+
* This flag is used to enable the 2 column layout on a Liveboard
|
|
253
253
|
* @type {boolean}
|
|
254
254
|
* @default false
|
|
255
255
|
* @version SDK: 1.32.0 | ThoughtSpot:10.1.0.cl
|
|
@@ -284,7 +284,7 @@ export interface LiveboardViewConfig
|
|
|
284
284
|
*/
|
|
285
285
|
showPreviewLoader?: boolean;
|
|
286
286
|
/**
|
|
287
|
-
* This flag is used to enable the compact header
|
|
287
|
+
* This flag is used to enable the compact header on a Liveboard
|
|
288
288
|
* @type {boolean}
|
|
289
289
|
* @default false
|
|
290
290
|
* @version SDK: 1.35.0 | ThoughtSpot:10.3.0.cl
|
|
@@ -298,7 +298,7 @@ export interface LiveboardViewConfig
|
|
|
298
298
|
*/
|
|
299
299
|
isLiveboardCompactHeaderEnabled?: boolean;
|
|
300
300
|
/**
|
|
301
|
-
* This flag is used to show/hide verified
|
|
301
|
+
* This flag is used to show/hide verified icon in the Liveboard compact header
|
|
302
302
|
* @type {boolean}
|
|
303
303
|
* @default true
|
|
304
304
|
* @version SDK: 1.35.0 | ThoughtSpot:10.4.0.cl
|
|
@@ -312,7 +312,8 @@ export interface LiveboardViewConfig
|
|
|
312
312
|
*/
|
|
313
313
|
showLiveboardVerifiedBadge?: boolean;
|
|
314
314
|
/**
|
|
315
|
-
* This flag is used to show/hide re-verify banner
|
|
315
|
+
* This flag is used to show/hide the re-verify banner
|
|
316
|
+
* in Liveboard compact header
|
|
316
317
|
* @type {boolean}
|
|
317
318
|
* @default true
|
|
318
319
|
* @version SDK: 1.35.0 | ThoughtSpot:10.4.0.cl
|
|
@@ -326,7 +327,7 @@ export interface LiveboardViewConfig
|
|
|
326
327
|
*/
|
|
327
328
|
showLiveboardReverifyBanner?: boolean;
|
|
328
329
|
/**
|
|
329
|
-
* This flag is used to enable/disable hide irrelevant filters in
|
|
330
|
+
* This flag is used to enable/disable hide irrelevant filters in a Liveboard tab
|
|
330
331
|
* @type {boolean}
|
|
331
332
|
* @default false
|
|
332
333
|
* @version SDK: 1.36.0 | ThoughtSpot:10.6.0.cl
|
|
@@ -682,8 +683,8 @@ export class LiveboardEmbed extends V1Embed {
|
|
|
682
683
|
}
|
|
683
684
|
|
|
684
685
|
/**
|
|
685
|
-
* Returns the full url of the
|
|
686
|
-
* this
|
|
686
|
+
* Returns the full url of the Liveboard/visualization which can be used to open
|
|
687
|
+
* this Liveboard inside the full Thoughtspot application in a new tab.
|
|
687
688
|
* @returns url string
|
|
688
689
|
*/
|
|
689
690
|
public getLiveboardUrl(): string {
|
|
@@ -50,7 +50,7 @@ import { logger } from '../utils/logger';
|
|
|
50
50
|
import { version } from '../../package.json';
|
|
51
51
|
import { HiddenActionItemByDefaultForSearchEmbed } from './search';
|
|
52
52
|
import { processTrigger } from '../utils/processTrigger';
|
|
53
|
-
import {
|
|
53
|
+
import { UIPassthroughEvent } from './hostEventClient/contracts';
|
|
54
54
|
|
|
55
55
|
jest.mock('../utils/processTrigger');
|
|
56
56
|
|
|
@@ -142,25 +142,25 @@ describe('Unit test case for ts embed', () => {
|
|
|
142
142
|
});
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
-
test('
|
|
145
|
+
test('triggerUIPassThrough with params', async () => {
|
|
146
146
|
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
147
147
|
searchEmbed.render();
|
|
148
148
|
mockProcessTrigger.mockResolvedValue({ session: 'test' });
|
|
149
149
|
await executeAfterWait(async () => {
|
|
150
150
|
const payload = { newVizName: 'test' };
|
|
151
151
|
expect(
|
|
152
|
-
await searchEmbed.
|
|
153
|
-
|
|
152
|
+
await searchEmbed.triggerUIPassThrough(
|
|
153
|
+
UIPassthroughEvent.PinAnswerToLiveboard,
|
|
154
154
|
payload,
|
|
155
155
|
),
|
|
156
156
|
);
|
|
157
157
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
158
158
|
getIFrameEl(),
|
|
159
|
-
HostEvent.
|
|
159
|
+
HostEvent.UIPassthrough,
|
|
160
160
|
'http://tshost',
|
|
161
161
|
{
|
|
162
162
|
parameters: payload,
|
|
163
|
-
type:
|
|
163
|
+
type: UIPassthroughEvent.PinAnswerToLiveboard,
|
|
164
164
|
},
|
|
165
165
|
);
|
|
166
166
|
});
|