@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.
Files changed (105) hide show
  1. package/cjs/package.json +1 -1
  2. package/cjs/src/embed/app.d.ts +1 -1
  3. package/cjs/src/embed/base.d.ts +1 -1
  4. package/cjs/src/embed/base.js +1 -1
  5. package/cjs/src/embed/hostEventClient/contracts.d.ts +26 -30
  6. package/cjs/src/embed/hostEventClient/contracts.d.ts.map +1 -1
  7. package/cjs/src/embed/hostEventClient/contracts.js +10 -10
  8. package/cjs/src/embed/hostEventClient/contracts.js.map +1 -1
  9. package/cjs/src/embed/hostEventClient/host-event-client.d.ts +21 -7
  10. package/cjs/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  11. package/cjs/src/embed/hostEventClient/host-event-client.js +62 -28
  12. package/cjs/src/embed/hostEventClient/host-event-client.js.map +1 -1
  13. package/cjs/src/embed/hostEventClient/host-event-client.spec.js +43 -39
  14. package/cjs/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
  15. package/cjs/src/embed/liveboard.d.ts +8 -7
  16. package/cjs/src/embed/liveboard.d.ts.map +1 -1
  17. package/cjs/src/embed/liveboard.js +2 -2
  18. package/cjs/src/embed/liveboard.js.map +1 -1
  19. package/cjs/src/embed/liveboard.spec.js +4 -2
  20. package/cjs/src/embed/liveboard.spec.js.map +1 -1
  21. package/cjs/src/embed/ts-embed.d.ts +14 -9
  22. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  23. package/cjs/src/embed/ts-embed.js +23 -15
  24. package/cjs/src/embed/ts-embed.js.map +1 -1
  25. package/cjs/src/embed/ts-embed.spec.js +4 -4
  26. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  27. package/cjs/src/index.d.ts +2 -2
  28. package/cjs/src/index.js +2 -2
  29. package/cjs/src/react/all-types-export.d.ts +1 -1
  30. package/cjs/src/react/all-types-export.js +2 -2
  31. package/cjs/src/types.d.ts +26 -21
  32. package/cjs/src/types.d.ts.map +1 -1
  33. package/cjs/src/types.js +20 -19
  34. package/cjs/src/types.js.map +1 -1
  35. package/dist/index-DaLHJaLd.js +7370 -0
  36. package/dist/index-nWevLycs.js +7370 -0
  37. package/dist/src/embed/app.d.ts +1 -1
  38. package/dist/src/embed/base.d.ts +1 -1
  39. package/dist/src/embed/hostEventClient/contracts.d.ts +26 -30
  40. package/dist/src/embed/hostEventClient/contracts.d.ts.map +1 -1
  41. package/dist/src/embed/hostEventClient/host-event-client.d.ts +21 -7
  42. package/dist/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  43. package/dist/src/embed/liveboard.d.ts +8 -7
  44. package/dist/src/embed/liveboard.d.ts.map +1 -1
  45. package/dist/src/embed/ts-embed.d.ts +14 -9
  46. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  47. package/dist/src/index.d.ts +2 -2
  48. package/dist/src/react/all-types-export.d.ts +1 -1
  49. package/dist/src/types.d.ts +26 -21
  50. package/dist/src/types.d.ts.map +1 -1
  51. package/dist/tsembed-react.es.js +118 -76
  52. package/dist/tsembed-react.js +117 -75
  53. package/dist/tsembed.es.js +120 -78
  54. package/dist/tsembed.js +118 -76
  55. package/dist/visual-embed-sdk-react-full.d.ts +96 -75
  56. package/dist/visual-embed-sdk-react.d.ts +96 -75
  57. package/dist/visual-embed-sdk.d.ts +96 -75
  58. package/lib/package.json +1 -1
  59. package/lib/src/embed/app.d.ts +1 -1
  60. package/lib/src/embed/base.d.ts +1 -1
  61. package/lib/src/embed/base.js +1 -1
  62. package/lib/src/embed/hostEventClient/contracts.d.ts +26 -30
  63. package/lib/src/embed/hostEventClient/contracts.d.ts.map +1 -1
  64. package/lib/src/embed/hostEventClient/contracts.js +9 -9
  65. package/lib/src/embed/hostEventClient/contracts.js.map +1 -1
  66. package/lib/src/embed/hostEventClient/host-event-client.d.ts +21 -7
  67. package/lib/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  68. package/lib/src/embed/hostEventClient/host-event-client.js +64 -30
  69. package/lib/src/embed/hostEventClient/host-event-client.js.map +1 -1
  70. package/lib/src/embed/hostEventClient/host-event-client.spec.js +43 -40
  71. package/lib/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
  72. package/lib/src/embed/liveboard.d.ts +8 -7
  73. package/lib/src/embed/liveboard.d.ts.map +1 -1
  74. package/lib/src/embed/liveboard.js +2 -2
  75. package/lib/src/embed/liveboard.js.map +1 -1
  76. package/lib/src/embed/liveboard.spec.js +4 -2
  77. package/lib/src/embed/liveboard.spec.js.map +1 -1
  78. package/lib/src/embed/ts-embed.d.ts +14 -9
  79. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  80. package/lib/src/embed/ts-embed.js +23 -15
  81. package/lib/src/embed/ts-embed.js.map +1 -1
  82. package/lib/src/embed/ts-embed.spec.js +5 -5
  83. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  84. package/lib/src/index.d.ts +2 -2
  85. package/lib/src/index.js +2 -2
  86. package/lib/src/react/all-types-export.d.ts +1 -1
  87. package/lib/src/react/all-types-export.js +1 -1
  88. package/lib/src/types.d.ts +26 -21
  89. package/lib/src/types.d.ts.map +1 -1
  90. package/lib/src/types.js +20 -19
  91. package/lib/src/types.js.map +1 -1
  92. package/lib/src/visual-embed-sdk.d.ts +99 -78
  93. package/package.json +1 -1
  94. package/src/embed/app.ts +1 -1
  95. package/src/embed/base.ts +1 -1
  96. package/src/embed/hostEventClient/contracts.ts +43 -32
  97. package/src/embed/hostEventClient/host-event-client.spec.ts +58 -54
  98. package/src/embed/hostEventClient/host-event-client.ts +105 -48
  99. package/src/embed/liveboard.spec.ts +4 -2
  100. package/src/embed/liveboard.ts +8 -7
  101. package/src/embed/ts-embed.spec.ts +6 -6
  102. package/src/embed/ts-embed.ts +39 -28
  103. package/src/index.ts +2 -2
  104. package/src/react/all-types-export.ts +1 -1
  105. 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
- UiPassthroughEvent,
6
- UiPassthroughRequest,
7
- UiPassthroughArrayResponse,
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 = getIFrameEl();
18
- const mockThoughtSpotHost = 'http://localhost';
19
- const client = new HostEventClient(mockThoughtSpotHost);
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('executeUiPassthroughApi', () => {
33
+ describe('executeUIPassthroughApi', () => {
29
34
  it('should call processTrigger with correct parameters and return response', async () => {
30
- const { client, mockIframe, mockThoughtSpotHost } = createHostEventClient();
35
+ const { client, mockIframe } = createHostEventClient();
31
36
 
32
- const apiName = UiPassthroughEvent.addVizToPinboard;
33
- const parameters: UiPassthroughRequest<typeof apiName> = {
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.executeUiPassthroughApi(getIFrameEl(), apiName, parameters);
47
+ const result = await client.triggerUIPassthroughApi(apiName, parameters);
43
48
 
44
49
  expect(mockProcessTrigger).toHaveBeenCalledWith(
45
50
  mockIframe,
46
- HostEvent.UiPassthrough,
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('handleUiPassthroughForHostEvent', () => {
62
+ describe('handleUIPassthroughForHostEvent', () => {
58
63
  it('should return the value from the first valid response', async () => {
59
64
  const { client } = createHostEventClient();
60
- const apiName = UiPassthroughEvent.addVizToPinboard;
61
- const parameters: UiPassthroughRequest<typeof apiName> = {
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.handleUiPassthroughForHostEvent(getIFrameEl(),
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 = UiPassthroughEvent.addVizToPinboard;
82
- const parameters: UiPassthroughRequest<typeof apiName> = {
85
+ const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
86
+ const parameters: UIPassthroughRequest<typeof apiName> = {
83
87
  newVizName: 'testViz',
84
88
  };
85
- const triggerResponse: UiPassthroughArrayResponse<typeof apiName> = Promise.resolve([]);
89
+ const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [];
86
90
  mockProcessTrigger.mockResolvedValue(triggerResponse);
87
91
 
88
- await expect(client.handleUiPassthroughForHostEvent(getIFrameEl(), apiName, parameters))
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 = UiPassthroughEvent.addVizToPinboard;
95
- const parameters: UiPassthroughRequest<typeof apiName> = {
98
+ const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
99
+ const parameters: UIPassthroughRequest<typeof apiName> = {
96
100
  newVizName: 'testViz',
97
101
  vizId: 'testVizId',
98
102
  };
99
- const triggerResponse: UiPassthroughArrayResponse<typeof apiName> = Promise.resolve([]);
103
+ const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [];
100
104
  mockProcessTrigger.mockResolvedValue(triggerResponse);
101
105
 
102
- await expect(client.handleUiPassthroughForHostEvent(getIFrameEl(), apiName, parameters))
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 = UiPassthroughEvent.addVizToPinboard;
109
- const parameters: UiPassthroughRequest<typeof apiName> = {
112
+ const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
113
+ const parameters: UIPassthroughRequest<typeof apiName> = {
110
114
  newVizName: 'testViz',
111
115
  };
112
- const triggerResponse: UiPassthroughArrayResponse<typeof apiName> = Promise.resolve([
116
+ const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [
113
117
  { error: 'Some error' },
114
- ]);
118
+ ];
115
119
  mockProcessTrigger.mockResolvedValue(triggerResponse);
116
120
 
117
- await expect(client.handleUiPassthroughForHostEvent(getIFrameEl(), apiName, parameters))
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 handleUiPassthroughForHostEvent for Pin event', async () => {
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.executeHostEvent(getIFrameEl(), hostEvent, payload);
143
+ const result = await client.triggerHostEvent(hostEvent, payload);
140
144
 
141
145
  expect(mockProcessTrigger).toHaveBeenCalledWith(
142
- getIFrameEl(),
143
- HostEvent.UiPassthrough,
146
+ mockIframe,
147
+ HostEvent.UIPassthrough,
144
148
  'http://localhost',
145
- { parameters: payload, type: UiPassthroughEvent.addVizToPinboard },
149
+ { parameters: payload, type: UIPassthroughEvent.PinAnswerToLiveboard },
146
150
  );
147
151
  expect(result).toEqual(mockResponse.value);
148
152
  });
149
153
 
150
- it('should call handleUiPassthroughForHostEvent for SaveAnswer event', async () => {
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.executeHostEvent(getIFrameEl(), hostEvent, payload);
177
+ const result = await client.triggerHostEvent(hostEvent, payload);
174
178
 
175
179
  expect(mockProcessTrigger).toHaveBeenCalledWith(
176
- null,
177
- 'UiPassthrough',
178
- 'http://localhost',
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.executeHostEvent(getIFrameEl(), hostEvent, payload);
198
+ const result = await client.triggerHostEvent(hostEvent, payload);
195
199
 
196
- expect(client.hostEventFallback).toHaveBeenCalledWith(null, hostEvent, payload);
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.executeHostEvent(getIFrameEl(), hostEvent, payload);
218
+ const result = await client.triggerHostEvent(hostEvent, payload);
215
219
 
216
220
  expect(mockProcessTrigger).toHaveBeenCalledWith(
217
- getIFrameEl(),
221
+ mockIframe,
218
222
  HostEvent.Pin,
219
- 'http://localhost',
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.executeHostEvent(getIFrameEl(), hostEvent, payload);
243
+ const result = await client.triggerHostEvent(hostEvent, payload);
240
244
 
241
245
  expect(mockProcessTrigger).toHaveBeenCalledWith(
242
- getIFrameEl(),
246
+ mockIframe,
243
247
  HostEvent.Save,
244
- 'http://localhost',
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
- UiPassthroughArrayResponse,
5
- UiPassthroughEvent, HostEventRequest, HostEventResponse,
6
- UiPassthroughRequest,
7
- UiPassthroughResponse,
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
- thoughtSpotHost: string;
14
+ iFrame: HTMLIFrameElement;
12
15
 
13
- constructor(thoughtSpotHost: string) {
14
- this.thoughtSpotHost = thoughtSpotHost;
16
+ constructor(iFrame?: HTMLIFrameElement) {
17
+ this.iFrame = iFrame;
15
18
  }
16
19
 
17
- public async executeUiPassthroughApi<UiPassthroughEventT extends UiPassthroughEvent>(
18
- iFrame: HTMLIFrameElement,
19
- apiName: UiPassthroughEventT,
20
- parameters: UiPassthroughRequest<UiPassthroughEventT>,
21
- ): UiPassthroughArrayResponse<UiPassthroughEventT> {
22
- const res = await processTrigger(iFrame, HostEvent.UiPassthrough, this.thoughtSpotHost, {
23
- type: apiName,
24
- parameters,
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
- return res;
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 handleUiPassthroughForHostEvent<UiPassthroughEventT extends UiPassthroughEvent>(
31
- iFrame: HTMLIFrameElement,
32
- apiName: UiPassthroughEventT,
33
- parameters: UiPassthroughRequest<UiPassthroughEventT>,
34
- ): Promise<UiPassthroughResponse<UiPassthroughEventT>> {
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 || (response.value as any)?.errors;
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: response.error };
59
+ throw { error: errors };
48
60
  }
49
61
 
50
62
  return { ...response.value };
51
63
  }
52
64
 
53
65
  public async hostEventFallback(
54
- iFrame: HTMLIFrameElement, hostEvent: HostEvent, data: any,
66
+ hostEvent: HostEvent,
67
+ data: any,
55
68
  ): Promise<any> {
56
- return processTrigger(iFrame, hostEvent, this.thoughtSpotHost, data);
69
+ return this.processTrigger(hostEvent, data);
57
70
  }
58
71
 
59
- public async executeHostEvent<T extends HostEvent>(
60
- iFrame: HTMLIFrameElement,
61
- hostEvent: HostEvent,
62
- payload?: HostEventRequest<T>,
63
- ): Promise<HostEventResponse<HostEvent>> {
64
- if (hostEvent === HostEvent.Pin && payload?.newVizName) {
65
- return this.handleUiPassthroughForHostEvent(
66
- iFrame, UiPassthroughEvent.addVizToPinboard, payload,
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
- if (hostEvent === HostEvent.SaveAnswer && payload?.name) {
70
- const data = await this.handleUiPassthroughForHostEvent(
71
- iFrame, UiPassthroughEvent.saveAnswer, payload,
72
- );
73
- return {
74
- ...data,
75
- answerId: data?.saveResponse?.data?.Answer__save?.answer?.id,
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
- const result = await liveboardEmbed.trigger(HostEvent.Pin);
488
- expect(mockProcessTrigger).toBeCalled();
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 () => {
@@ -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 in liveboard
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 in liveboard
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 Icon in liveboard compact header
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 in liveboard compact header
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 liveboard tab
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 liveboard/viz which can be used to open
686
- * this liveboard inside the full Thoughtspot application in a new tab.
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 { UiPassthroughEvent } from './hostEventClient/contracts';
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('triggerUiPassThrough with params', async () => {
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.triggerUiPassThrough(
153
- UiPassthroughEvent.addVizToPinboard,
152
+ await searchEmbed.triggerUIPassThrough(
153
+ UIPassthroughEvent.PinAnswerToLiveboard,
154
154
  payload,
155
155
  ),
156
156
  );
157
157
  expect(mockProcessTrigger).toHaveBeenCalledWith(
158
158
  getIFrameEl(),
159
- HostEvent.UiPassthrough,
159
+ HostEvent.UIPassthrough,
160
160
  'http://tshost',
161
161
  {
162
162
  parameters: payload,
163
- type: UiPassthroughEvent.addVizToPinboard,
163
+ type: UIPassthroughEvent.PinAnswerToLiveboard,
164
164
  },
165
165
  );
166
166
  });