@thoughtspot/visual-embed-sdk 1.20.0-alpha.2 → 1.20.0-prerender.0

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 (184) hide show
  1. package/dist/src/auth.d.ts +75 -5
  2. package/dist/src/auth.d.ts.map +1 -1
  3. package/dist/src/config.d.ts +1 -0
  4. package/dist/src/config.d.ts.map +1 -1
  5. package/dist/src/embed/app.d.ts +19 -7
  6. package/dist/src/embed/app.d.ts.map +1 -1
  7. package/dist/src/embed/base.d.ts +39 -19
  8. package/dist/src/embed/base.d.ts.map +1 -1
  9. package/dist/src/embed/liveboard.d.ts +19 -7
  10. package/dist/src/embed/liveboard.d.ts.map +1 -1
  11. package/dist/src/embed/search-bar.d.ts +7 -1
  12. package/dist/src/embed/search-bar.d.ts.map +1 -1
  13. package/dist/src/embed/search.d.ts +11 -3
  14. package/dist/src/embed/search.d.ts.map +1 -1
  15. package/dist/src/embed/ts-embed.d.ts +76 -5
  16. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  17. package/dist/src/errors.d.ts.map +1 -1
  18. package/dist/src/index.d.ts +3 -3
  19. package/dist/src/index.d.ts.map +1 -1
  20. package/dist/src/mixpanel-service.d.ts +8 -0
  21. package/dist/src/mixpanel-service.d.ts.map +1 -1
  22. package/dist/src/react/index.d.ts.map +1 -1
  23. package/dist/src/react/util.d.ts +4 -0
  24. package/dist/src/react/util.d.ts.map +1 -1
  25. package/dist/src/test/test-utils.d.ts +11 -2
  26. package/dist/src/test/test-utils.d.ts.map +1 -1
  27. package/dist/src/types.d.ts +429 -97
  28. package/dist/src/types.d.ts.map +1 -1
  29. package/dist/src/utils/answerService.d.ts +7 -0
  30. package/dist/src/utils/answerService.d.ts.map +1 -1
  31. package/dist/src/utils/authService.d.ts +30 -0
  32. package/dist/src/utils/authService.d.ts.map +1 -1
  33. package/dist/src/utils/processData.d.ts +12 -0
  34. package/dist/src/utils/processData.d.ts.map +1 -1
  35. package/dist/src/utils/processTrigger.d.ts +7 -0
  36. package/dist/src/utils/processTrigger.d.ts.map +1 -1
  37. package/dist/src/utils.d.ts +12 -0
  38. package/dist/src/utils.d.ts.map +1 -1
  39. package/dist/tsembed.es.js +818 -285
  40. package/dist/tsembed.js +791 -284
  41. package/lib/package.json +4 -3
  42. package/lib/src/auth.d.ts +75 -5
  43. package/lib/src/auth.d.ts.map +1 -1
  44. package/lib/src/auth.js +86 -26
  45. package/lib/src/auth.js.map +1 -1
  46. package/lib/src/auth.spec.js +14 -5
  47. package/lib/src/auth.spec.js.map +1 -1
  48. package/lib/src/config.d.ts +1 -0
  49. package/lib/src/config.d.ts.map +1 -1
  50. package/lib/src/config.js +5 -3
  51. package/lib/src/config.js.map +1 -1
  52. package/lib/src/config.spec.js.map +1 -1
  53. package/lib/src/embed/app.d.ts +19 -7
  54. package/lib/src/embed/app.d.ts.map +1 -1
  55. package/lib/src/embed/app.js +26 -16
  56. package/lib/src/embed/app.js.map +1 -1
  57. package/lib/src/embed/app.spec.js +12 -12
  58. package/lib/src/embed/app.spec.js.map +1 -1
  59. package/lib/src/embed/base.d.ts +39 -19
  60. package/lib/src/embed/base.d.ts.map +1 -1
  61. package/lib/src/embed/base.js +49 -15
  62. package/lib/src/embed/base.js.map +1 -1
  63. package/lib/src/embed/base.spec.js +2 -2
  64. package/lib/src/embed/base.spec.js.map +1 -1
  65. package/lib/src/embed/embed.spec.js +1 -1
  66. package/lib/src/embed/embed.spec.js.map +1 -1
  67. package/lib/src/embed/liveboard.d.ts +19 -7
  68. package/lib/src/embed/liveboard.d.ts.map +1 -1
  69. package/lib/src/embed/liveboard.js +50 -38
  70. package/lib/src/embed/liveboard.js.map +1 -1
  71. package/lib/src/embed/liveboard.spec.js +37 -30
  72. package/lib/src/embed/liveboard.spec.js.map +1 -1
  73. package/lib/src/embed/pinboard.spec.js +14 -26
  74. package/lib/src/embed/pinboard.spec.js.map +1 -1
  75. package/lib/src/embed/search-bar.d.ts +7 -1
  76. package/lib/src/embed/search-bar.d.ts.map +1 -1
  77. package/lib/src/embed/search-bar.js +6 -7
  78. package/lib/src/embed/search-bar.js.map +1 -1
  79. package/lib/src/embed/search.d.ts +11 -3
  80. package/lib/src/embed/search.d.ts.map +1 -1
  81. package/lib/src/embed/search.js +19 -15
  82. package/lib/src/embed/search.js.map +1 -1
  83. package/lib/src/embed/search.spec.js +16 -19
  84. package/lib/src/embed/search.spec.js.map +1 -1
  85. package/lib/src/embed/searchEmbed-basic-auth.spec.js +4 -0
  86. package/lib/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
  87. package/lib/src/embed/ts-embed.d.ts +76 -5
  88. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  89. package/lib/src/embed/ts-embed.js +150 -72
  90. package/lib/src/embed/ts-embed.js.map +1 -1
  91. package/lib/src/embed/ts-embed.spec.js +23 -24
  92. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  93. package/lib/src/errors.d.ts.map +1 -1
  94. package/lib/src/errors.js.map +1 -1
  95. package/lib/src/index.d.ts +3 -3
  96. package/lib/src/index.d.ts.map +1 -1
  97. package/lib/src/index.js +3 -3
  98. package/lib/src/index.js.map +1 -1
  99. package/lib/src/mixpanel-service.d.ts +8 -0
  100. package/lib/src/mixpanel-service.d.ts.map +1 -1
  101. package/lib/src/mixpanel-service.js +13 -1
  102. package/lib/src/mixpanel-service.js.map +1 -1
  103. package/lib/src/mixpanel-service.spec.js.map +1 -1
  104. package/lib/src/react/index.d.ts.map +1 -1
  105. package/lib/src/react/index.js +4 -6
  106. package/lib/src/react/index.js.map +1 -1
  107. package/lib/src/react/index.spec.js +3 -6
  108. package/lib/src/react/index.spec.js.map +1 -1
  109. package/lib/src/react/util.d.ts +4 -0
  110. package/lib/src/react/util.d.ts.map +1 -1
  111. package/lib/src/react/util.js +4 -0
  112. package/lib/src/react/util.js.map +1 -1
  113. package/lib/src/test/test-utils.d.ts +11 -2
  114. package/lib/src/test/test-utils.d.ts.map +1 -1
  115. package/lib/src/test/test-utils.js +36 -25
  116. package/lib/src/test/test-utils.js.map +1 -1
  117. package/lib/src/types.d.ts +429 -97
  118. package/lib/src/types.d.ts.map +1 -1
  119. package/lib/src/types.js +310 -72
  120. package/lib/src/types.js.map +1 -1
  121. package/lib/src/utils/answerService.d.ts +7 -0
  122. package/lib/src/utils/answerService.d.ts.map +1 -1
  123. package/lib/src/utils/answerService.js +7 -0
  124. package/lib/src/utils/answerService.js.map +1 -1
  125. package/lib/src/utils/answerService.spec.js.map +1 -1
  126. package/lib/src/utils/authService.d.ts +30 -0
  127. package/lib/src/utils/authService.d.ts.map +1 -1
  128. package/lib/src/utils/authService.js +39 -2
  129. package/lib/src/utils/authService.js.map +1 -1
  130. package/lib/src/utils/authService.spec.js.map +1 -1
  131. package/lib/src/utils/processData.d.ts +12 -0
  132. package/lib/src/utils/processData.d.ts.map +1 -1
  133. package/lib/src/utils/processData.js +33 -5
  134. package/lib/src/utils/processData.js.map +1 -1
  135. package/lib/src/utils/processData.spec.js.map +1 -1
  136. package/lib/src/utils/processTrigger.d.ts +7 -0
  137. package/lib/src/utils/processTrigger.d.ts.map +1 -1
  138. package/lib/src/utils/processTrigger.js +17 -3
  139. package/lib/src/utils/processTrigger.js.map +1 -1
  140. package/lib/src/utils/processTrigger.spec.js.map +1 -1
  141. package/lib/src/utils.d.ts +12 -0
  142. package/lib/src/utils.d.ts.map +1 -1
  143. package/lib/src/utils.js +24 -19
  144. package/lib/src/utils.js.map +1 -1
  145. package/lib/src/utils.spec.js.map +1 -1
  146. package/lib/src/visual-embed-sdk.d.ts +664 -141
  147. package/package.json +4 -3
  148. package/src/auth.spec.ts +68 -150
  149. package/src/auth.ts +141 -101
  150. package/src/config.spec.ts +2 -4
  151. package/src/config.ts +5 -3
  152. package/src/embed/app.spec.ts +25 -14
  153. package/src/embed/app.ts +49 -37
  154. package/src/embed/base.spec.ts +6 -12
  155. package/src/embed/base.ts +74 -57
  156. package/src/embed/embed.spec.ts +5 -6
  157. package/src/embed/liveboard.spec.ts +56 -37
  158. package/src/embed/liveboard.ts +67 -65
  159. package/src/embed/pinboard.spec.ts +26 -29
  160. package/src/embed/search-bar.tsx +14 -9
  161. package/src/embed/search.spec.ts +31 -21
  162. package/src/embed/search.ts +28 -22
  163. package/src/embed/searchEmbed-basic-auth.spec.ts +22 -28
  164. package/src/embed/ts-embed.spec.ts +70 -148
  165. package/src/embed/ts-embed.ts +180 -157
  166. package/src/errors.ts +3 -6
  167. package/src/index.ts +23 -7
  168. package/src/mixpanel-service.spec.ts +1 -3
  169. package/src/mixpanel-service.ts +13 -1
  170. package/src/react/index.spec.tsx +11 -20
  171. package/src/react/index.tsx +40 -71
  172. package/src/react/util.ts +8 -4
  173. package/src/test/test-utils.ts +43 -39
  174. package/src/types.ts +427 -97
  175. package/src/utils/answerService.spec.ts +3 -5
  176. package/src/utils/answerService.ts +21 -17
  177. package/src/utils/authService.spec.ts +26 -41
  178. package/src/utils/authService.ts +47 -21
  179. package/src/utils/processData.spec.ts +26 -59
  180. package/src/utils/processData.ts +36 -14
  181. package/src/utils/processTrigger.spec.ts +1 -6
  182. package/src/utils/processTrigger.ts +18 -9
  183. package/src/utils.spec.ts +8 -12
  184. package/src/utils.ts +25 -26
@@ -15,6 +15,10 @@ import {
15
15
  getRootEl,
16
16
  defaultParams,
17
17
  defaultParamsWithoutHiddenActions,
18
+ expectUrlMatchesWithParams,
19
+ postMessageToParent,
20
+ getIFrameEl,
21
+ mockMessageChannel,
18
22
  } from '../test/test-utils';
19
23
  import { version } from '../../package.json';
20
24
  import * as processTriggerInstance from '../utils/processTrigger';
@@ -51,7 +55,8 @@ describe('Liveboard/viz embed tests', () => {
51
55
  } as LiveboardViewConfig);
52
56
  liveboardEmbed.render();
53
57
  await executeAfterWait(() => {
54
- expect(getIFrameSrc()).toBe(
58
+ expectUrlMatchesWithParams(
59
+ getIFrameSrc(),
55
60
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}${prefixParams}#/embed/viz/${liveboardId}`,
56
61
  );
57
62
  });
@@ -59,18 +64,15 @@ describe('Liveboard/viz embed tests', () => {
59
64
 
60
65
  test('should set disabled actions', async () => {
61
66
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
62
- disabledActions: [
63
- Action.DownloadAsCsv,
64
- Action.DownloadAsPdf,
65
- Action.DownloadAsXlsx,
66
- ],
67
+ disabledActions: [Action.DownloadAsCsv, Action.DownloadAsPdf, Action.DownloadAsXlsx],
67
68
  disabledActionReason: 'Action denied',
68
69
  ...defaultViewConfig,
69
70
  liveboardId,
70
71
  } as LiveboardViewConfig);
71
72
  liveboardEmbed.render();
72
73
  await executeAfterWait(() => {
73
- expect(getIFrameSrc()).toBe(
74
+ expectUrlMatchesWithParams(
75
+ getIFrameSrc(),
74
76
  `http://${thoughtSpotHost}/?embedApp=true&${defaultParamsWithoutHiddenActions}&disableAction=[%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]&disableHint=Action%20denied&hideAction=[%22${Action.ReportError}%22]${prefixParams}#/embed/viz/${liveboardId}`,
75
77
  );
76
78
  });
@@ -78,17 +80,14 @@ describe('Liveboard/viz embed tests', () => {
78
80
 
79
81
  test('should set hidden actions', async () => {
80
82
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
81
- hiddenActions: [
82
- Action.DownloadAsCsv,
83
- Action.DownloadAsPdf,
84
- Action.DownloadAsXlsx,
85
- ],
83
+ hiddenActions: [Action.DownloadAsCsv, Action.DownloadAsPdf, Action.DownloadAsXlsx],
86
84
  ...defaultViewConfig,
87
85
  liveboardId,
88
86
  } as LiveboardViewConfig);
89
87
  liveboardEmbed.render();
90
88
  await executeAfterWait(() => {
91
- expect(getIFrameSrc()).toBe(
89
+ expectUrlMatchesWithParams(
90
+ getIFrameSrc(),
92
91
  `http://${thoughtSpotHost}/?embedApp=true&${defaultParamsWithoutHiddenActions}&hideAction=[%22${Action.ReportError}%22,%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]${prefixParams}#/embed/viz/${liveboardId}`,
93
92
  );
94
93
  });
@@ -96,17 +95,14 @@ describe('Liveboard/viz embed tests', () => {
96
95
 
97
96
  test('should set visible actions', async () => {
98
97
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
99
- visibleActions: [
100
- Action.DownloadAsCsv,
101
- Action.DownloadAsPdf,
102
- Action.DownloadAsXlsx,
103
- ],
98
+ visibleActions: [Action.DownloadAsCsv, Action.DownloadAsPdf, Action.DownloadAsXlsx],
104
99
  ...defaultViewConfig,
105
100
  liveboardId,
106
101
  } as LiveboardViewConfig);
107
102
  liveboardEmbed.render();
108
103
  await executeAfterWait(() => {
109
- expect(getIFrameSrc()).toBe(
104
+ expectUrlMatchesWithParams(
105
+ getIFrameSrc(),
110
106
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&visibleAction=[%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]${prefixParams}#/embed/viz/${liveboardId}`,
111
107
  );
112
108
  });
@@ -120,7 +116,8 @@ describe('Liveboard/viz embed tests', () => {
120
116
  } as LiveboardViewConfig);
121
117
  liveboardEmbed.render();
122
118
  await executeAfterWait(() => {
123
- expect(getIFrameSrc()).toBe(
119
+ expectUrlMatchesWithParams(
120
+ getIFrameSrc(),
124
121
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&visibleAction=[]${prefixParams}#/embed/viz/${liveboardId}`,
125
122
  );
126
123
  });
@@ -134,7 +131,8 @@ describe('Liveboard/viz embed tests', () => {
134
131
  } as LiveboardViewConfig);
135
132
  liveboardEmbed.render();
136
133
  await executeAfterWait(() => {
137
- expect(getIFrameSrc()).toBe(
134
+ expectUrlMatchesWithParams(
135
+ getIFrameSrc(),
138
136
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&enableVizTransform=true${prefixParams}#/embed/viz/${liveboardId}`,
139
137
  );
140
138
  });
@@ -148,7 +146,8 @@ describe('Liveboard/viz embed tests', () => {
148
146
  } as LiveboardViewConfig);
149
147
  liveboardEmbed.render();
150
148
  await executeAfterWait(() => {
151
- expect(getIFrameSrc()).toBe(
149
+ expectUrlMatchesWithParams(
150
+ getIFrameSrc(),
152
151
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&enableVizTransform=false${prefixParams}#/embed/viz/${liveboardId}`,
153
152
  );
154
153
  });
@@ -162,7 +161,8 @@ describe('Liveboard/viz embed tests', () => {
162
161
  } as LiveboardViewConfig);
163
162
  liveboardEmbed.render();
164
163
  await executeAfterWait(() => {
165
- expect(getIFrameSrc()).toBe(
164
+ expectUrlMatchesWithParams(
165
+ getIFrameSrc(),
166
166
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}${prefixParamsVizEmbed}#/embed/viz/${liveboardId}/${vizId}`,
167
167
  );
168
168
  });
@@ -183,13 +183,15 @@ describe('Liveboard/viz embed tests', () => {
183
183
  } as LiveboardViewConfig);
184
184
  liveboardEmbed.render();
185
185
  await executeAfterWait(() => {
186
- expect(getIFrameSrc()).toBe(
186
+ expectUrlMatchesWithParams(
187
+ getIFrameSrc(),
187
188
  `http://${thoughtSpotHost}/?embedApp=true&col1=sales&op1=EQ&val1=1000${defaultParams}${prefixParamsVizEmbed}#/embed/viz/${liveboardId}/${vizId}`,
188
189
  );
189
190
  });
190
191
  });
191
192
 
192
193
  test('should register event handler to adjust iframe height', async () => {
194
+ const onSpy = jest.spyOn(LiveboardEmbed.prototype, 'on');
193
195
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
194
196
  ...defaultViewConfig,
195
197
  fullHeight: true,
@@ -197,14 +199,10 @@ describe('Liveboard/viz embed tests', () => {
197
199
  vizId,
198
200
  } as LiveboardViewConfig);
199
201
 
200
- const onSpy = jest.spyOn(liveboardEmbed, 'on');
201
202
  liveboardEmbed.render();
202
203
 
203
204
  executeAfterWait(() => {
204
- expect(onSpy).toHaveBeenCalledWith(
205
- EmbedEvent.EmbedHeight,
206
- expect.anything(),
207
- );
205
+ expect(onSpy).toHaveBeenCalledWith(EmbedEvent.EmbedHeight, expect.anything());
208
206
  });
209
207
  });
210
208
  test('Should set the visible vizs', async () => {
@@ -215,16 +213,14 @@ describe('Liveboard/viz embed tests', () => {
215
213
  } as LiveboardViewConfig);
216
214
  liveboardEmbed.render();
217
215
  await executeAfterWait(() => {
218
- expect(getIFrameSrc()).toBe(
216
+ expectUrlMatchesWithParams(
217
+ getIFrameSrc(),
219
218
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&pinboardVisibleVizs=[%22abcd%22,%22pqrs%22]${prefixParams}#/embed/viz/${liveboardId}`,
220
219
  );
221
220
  });
222
221
  });
223
222
  test('should process the trigger, for vizEmbed', async () => {
224
- const mockProcessTrigger = spyOn(
225
- processTriggerInstance,
226
- 'processTrigger',
227
- );
223
+ const mockProcessTrigger = spyOn(processTriggerInstance, 'processTrigger');
228
224
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
229
225
  enableVizTransformations: true,
230
226
  ...defaultViewConfig,
@@ -244,7 +240,8 @@ describe('Liveboard/viz embed tests', () => {
244
240
  } as LiveboardViewConfig);
245
241
  liveboardEmbed.render();
246
242
  await executeAfterWait(() => {
247
- expect(getIFrameSrc()).toBe(
243
+ expectUrlMatchesWithParams(
244
+ getIFrameSrc(),
248
245
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&isLiveboardEmbed=true&isPinboardV2Enabled=true#/embed/viz/${liveboardId}/tab/${activeTabId}`,
249
246
  );
250
247
  });
@@ -259,7 +256,8 @@ describe('Liveboard/viz embed tests', () => {
259
256
  } as LiveboardViewConfig);
260
257
  liveboardEmbed.render();
261
258
  await executeAfterWait(() => {
262
- expect(getIFrameSrc()).toBe(
259
+ expectUrlMatchesWithParams(
260
+ getIFrameSrc(),
263
261
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&preventPinboardFilterRemoval=true&isLiveboardEmbed=true&isPinboardV2Enabled=true#/embed/viz/${liveboardId}/tab/${activeTabId}`,
264
262
  );
265
263
  });
@@ -273,9 +271,30 @@ describe('Liveboard/viz embed tests', () => {
273
271
  } as LiveboardViewConfig);
274
272
  liveboardEmbed.render();
275
273
  await executeAfterWait(() => {
276
- expect(getIFrameSrc()).toBe(
274
+ expectUrlMatchesWithParams(
275
+ getIFrameSrc(),
277
276
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&isContextMenuEnabledOnLeftClick=true&isLiveboardEmbed=true&isPinboardV2Enabled=true#/embed/viz/${liveboardId}/tab/${activeTabId}`,
278
277
  );
279
278
  });
280
279
  });
280
+
281
+ test('navigateToLiveboard should trigger the navigate event with the correct path', (done) => {
282
+ mockMessageChannel();
283
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
284
+ ...defaultViewConfig,
285
+ } as LiveboardViewConfig);
286
+ const onSpy = jest.spyOn(liveboardEmbed, 'trigger');
287
+ liveboardEmbed.prerenderGeneric();
288
+ executeAfterWait(() => {
289
+ const iframe = getIFrameEl();
290
+ postMessageToParent(iframe.contentWindow, {
291
+ type: EmbedEvent.APP_INIT,
292
+ });
293
+ });
294
+ executeAfterWait(() => {
295
+ liveboardEmbed.navigateToLiveboard('lb1', 'viz1');
296
+ expect(onSpy).toHaveBeenCalledWith(HostEvent.Navigate, '/embed/viz/lb1/viz1');
297
+ done();
298
+ });
299
+ });
281
300
  });
@@ -19,17 +19,20 @@ import {
19
19
  HostEvent,
20
20
  ViewConfig,
21
21
  } from '../types';
22
- import { getFilterQuery, getQueryParamString } from '../utils';
22
+ import { getQueryParamString } from '../utils';
23
+ import { getAuthPromise } from './base';
23
24
  import { V1Embed } from './ts-embed';
24
25
 
25
26
  /**
26
27
  * The configuration for the embedded Liveboard or visualization page view.
27
- * @Category Liveboards and Charts
28
+ *
29
+ * @group Embed components
28
30
  */
29
31
  export interface LiveboardViewConfig extends ViewConfig {
30
32
  /**
31
33
  * If set to true, the embedded object container dynamically resizes
32
34
  * according to the height of the Liveboard.
35
+ *
33
36
  * @version SDK: 1.1.0 | ThoughtSpot: ts7.may.cl, 7.2.1
34
37
  */
35
38
  fullHeight?: boolean;
@@ -37,6 +40,7 @@ export interface LiveboardViewConfig extends ViewConfig {
37
40
  * This is the minimum height(in pixels) for a full height Liveboard.
38
41
  * Setting this height helps resolves issues with empty Liveboards and
39
42
  * other screens navigable from a Liveboard.
43
+ *
40
44
  * @version SDK: 1.5.0 | ThoughtSpot: ts7.oct.cl, 7.2.1
41
45
  * @default 500
42
46
  */
@@ -48,11 +52,13 @@ export interface LiveboardViewConfig extends ViewConfig {
48
52
  /**
49
53
  * The Liveboard to display in the embedded view.
50
54
  * Use either of liveboardId or pinboardId to reference the Liveboard to embed.
55
+ *
51
56
  * @version SDK: 1.3.0 | ThoughtSpot ts7.aug.cl, 7.2.1
52
57
  */
53
58
  liveboardId?: string;
54
59
  /**
55
60
  * To support backward compatibility
61
+ *
56
62
  * @hidden
57
63
  */
58
64
  pinboardId?: string;
@@ -63,6 +69,7 @@ export interface LiveboardViewConfig extends ViewConfig {
63
69
  /**
64
70
  * If set to true, all filter chips from a
65
71
  * Liveboard page will be read-only (no X buttons)
72
+ *
66
73
  * @version SDK: 1.3.0 | ThoughtSpot ts7.aug.cl, 7.2.1
67
74
  */
68
75
  preventLiveboardFilterRemoval?: boolean;
@@ -70,21 +77,25 @@ export interface LiveboardViewConfig extends ViewConfig {
70
77
  * Array of viz ids which should be visible when the liveboard
71
78
  * first renders. This can be changed by triggering the "SetVisibleVizs"
72
79
  * event.
80
+ *
73
81
  * @version SDK: 1.9.1 | ThoughtSpot: 8.1.0.cl, 8.4.1-sw
74
82
  */
75
83
  visibleVizs?: string[];
76
84
  /**
77
85
  * To support backward compatibilty
86
+ *
78
87
  * @hidden
79
88
  */
80
89
  preventPinboardFilterRemoval?: boolean;
81
90
  /**
82
91
  * Render embedded Liveboards and visualizations in the new Liveboard experience mode
92
+ *
83
93
  * @version SDK: 1.14.0 | ThoughtSpot: 8.6.0.cl, 8.8.1-sw
84
94
  */
85
95
  liveboardV2?: boolean;
86
96
  /**
87
97
  * Tab Id of the Liveboard that is supposed to be active
98
+ *
88
99
  * @version SDK: 1.15.0 | ThoughtSpot: 8.7.0.cl, 8.8.1-sw
89
100
  */
90
101
  activeTabId?: string;
@@ -92,7 +103,8 @@ export interface LiveboardViewConfig extends ViewConfig {
92
103
 
93
104
  /**
94
105
  * Embed a ThoughtSpot Liveboard or visualization
95
- * @Category Liveboards and Charts
106
+ *
107
+ * @group Embed components
96
108
  */
97
109
  export class LiveboardEmbed extends V1Embed {
98
110
  protected viewConfig: LiveboardViewConfig;
@@ -102,14 +114,21 @@ export class LiveboardEmbed extends V1Embed {
102
114
  // eslint-disable-next-line no-useless-constructor
103
115
  constructor(domSelector: DOMSelector, viewConfig: LiveboardViewConfig) {
104
116
  super(domSelector, viewConfig);
117
+ if (this.viewConfig.fullHeight === true) {
118
+ this.on(EmbedEvent.RouteChange, this.setIframeHeightForNonEmbedLiveboard);
119
+ this.on(EmbedEvent.EmbedHeight, this.updateIFrameHeight);
120
+ this.on(EmbedEvent.EmbedIframeCenter, this.embedIframeCenter);
121
+ }
105
122
  }
106
123
 
107
124
  /**
108
125
  * Construct a map of params to be passed on to the
109
126
  * embedded Liveboard or visualization.
110
127
  */
111
- private getEmbedParams() {
112
- const params = this.getBaseQueryParams();
128
+ protected getEmbedParams() {
129
+ let params = {};
130
+ params[Param.EmbedApp] = true;
131
+ params = this.getBaseQueryParams(params);
113
132
  const {
114
133
  enableVizTransformations,
115
134
  fullHeight,
@@ -120,9 +139,8 @@ export class LiveboardEmbed extends V1Embed {
120
139
  activeTabId,
121
140
  } = this.viewConfig;
122
141
 
123
- const preventLiveboardFilterRemoval =
124
- this.viewConfig.preventLiveboardFilterRemoval ||
125
- this.viewConfig.preventPinboardFilterRemoval;
142
+ const preventLiveboardFilterRemoval = this.viewConfig.preventLiveboardFilterRemoval
143
+ || this.viewConfig.preventPinboardFilterRemoval;
126
144
 
127
145
  if (fullHeight === true) {
128
146
  params[Param.fullHeight] = true;
@@ -131,9 +149,7 @@ export class LiveboardEmbed extends V1Embed {
131
149
  this.defaultHeight = defaultHeight;
132
150
  }
133
151
  if (enableVizTransformations !== undefined) {
134
- params[
135
- Param.EnableVizTransformations
136
- ] = enableVizTransformations.toString();
152
+ params[Param.EnableVizTransformations] = enableVizTransformations.toString();
137
153
  }
138
154
  if (preventLiveboardFilterRemoval) {
139
155
  params[Param.preventLiveboardFilterRemoval] = true;
@@ -153,47 +169,41 @@ export class LiveboardEmbed extends V1Embed {
153
169
  return queryParams;
154
170
  }
155
171
 
156
- /**
157
- * Construct the URL of the embedded ThoughtSpot Liveboard or visualization
158
- * to be loaded within the iframe.
159
- * @param liveboardId The GUID of the Liveboard.
160
- * @param vizId The optional GUID of a visualization within the Liveboard.
161
- * @param runtimeFilters A list of runtime filters to be applied to
162
- * the Liveboard or visualization on load.
163
- */
164
- private getIFrameSrc(
165
- liveboardId: string,
166
- vizId?: string,
167
- runtimeFilters?: RuntimeFilter[],
168
- activeTabId?: string,
169
- ) {
170
- const filterQuery = getFilterQuery(runtimeFilters || []);
171
- const queryParams = this.getEmbedParams();
172
- const queryString = [filterQuery, queryParams]
173
- .filter(Boolean)
174
- .join('&');
175
- let url = `${this.getV1EmbedBasePath(
176
- queryString,
177
- true,
178
- false,
179
- false,
180
- )}/viz/${liveboardId}`;
172
+ private getIframeSuffixSrc(liveboardId: string, vizId: string, activeTabId: string) {
173
+ let suffix = `/embed/viz/${liveboardId}`;
181
174
  if (activeTabId) {
182
- url = `${url}/tab/${activeTabId}`;
175
+ suffix = `${suffix}/tab/${activeTabId} `;
183
176
  }
184
177
  if (vizId) {
185
- url = `${url}/${vizId}`;
178
+ suffix = `${suffix}/${vizId}`;
186
179
  }
187
-
188
180
  const tsPostHashParams = this.getThoughtSpotPostUrlParams();
189
- url = `${url}${tsPostHashParams}`;
181
+ suffix = `${suffix}${tsPostHashParams}`;
182
+ return suffix;
183
+ }
184
+
185
+ /**
186
+ * Construct the URL of the embedded ThoughtSpot Liveboard or visualization
187
+ * to be loaded within the iframe.
188
+ */
189
+ private getIFrameSrc() {
190
+ const { vizId, activeTabId } = this.viewConfig;
191
+ const liveboardId = this.viewConfig.liveboardId ?? this.viewConfig.pinboardId;
190
192
 
191
- return url;
193
+ if (!liveboardId) {
194
+ this.handleError(ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION);
195
+ }
196
+ return `${this.getRootIframeSrc()}${this.getIframeSuffixSrc(
197
+ liveboardId,
198
+ vizId,
199
+ activeTabId,
200
+ )}`;
192
201
  }
193
202
 
194
203
  /**
195
204
  * Set the iframe height as per the computed height received
196
205
  * from the ThoughtSpot app.
206
+ *
197
207
  * @param data The event payload
198
208
  */
199
209
  private updateIFrameHeight = (data: MessagePayload) => {
@@ -213,12 +223,13 @@ export class LiveboardEmbed extends V1Embed {
213
223
 
214
224
  /**
215
225
  * Triggers an event to the embedded app
226
+ *
216
227
  * @param messageType The event type
217
228
  * @param data The payload to send with the message
218
229
  */
219
230
  public trigger(messageType: HostEvent, data: any = {}): Promise<any> {
220
231
  const dataWithVizId = data;
221
- if (this.viewConfig.vizId) {
232
+ if (typeof dataWithVizId === 'object' && this.viewConfig.vizId) {
222
233
  dataWithVizId.vizId = this.viewConfig.vizId;
223
234
  }
224
235
  return super.trigger(messageType, dataWithVizId);
@@ -226,39 +237,30 @@ export class LiveboardEmbed extends V1Embed {
226
237
 
227
238
  /**
228
239
  * Render an embedded ThoughtSpot Liveboard or visualization
240
+ *
229
241
  * @param renderOptions An object specifying the Liveboard ID,
230
242
  * visualization ID and the runtime filters.
231
243
  */
232
244
  public render(): LiveboardEmbed {
233
- const { vizId, activeTabId, runtimeFilters } = this.viewConfig;
234
- const liveboardId =
235
- this.viewConfig.liveboardId ?? this.viewConfig.pinboardId;
236
-
237
- if (!liveboardId) {
238
- this.handleError(ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION);
239
- }
240
-
241
- if (this.viewConfig.fullHeight === true) {
242
- this.on(
243
- EmbedEvent.RouteChange,
244
- this.setIframeHeightForNonEmbedLiveboard,
245
- );
246
- this.on(EmbedEvent.EmbedHeight, this.updateIFrameHeight);
247
- this.on(EmbedEvent.EmbedIframeCenter, this.embedIframeCenter);
248
- }
249
-
250
245
  super.render();
251
246
 
252
- const src = this.getIFrameSrc(
253
- liveboardId,
254
- vizId,
255
- runtimeFilters,
256
- activeTabId,
257
- );
247
+ const src = this.getIFrameSrc();
258
248
  this.renderV1Embed(src);
259
249
 
260
250
  return this;
261
251
  }
252
+
253
+ public navigateToLiveboard(liveboardId: string, vizId?: string, activeTabId?: string) {
254
+ const path = this.getIframeSuffixSrc(liveboardId, vizId, activeTabId);
255
+ this.viewConfig.liveboardId = liveboardId;
256
+ this.viewConfig.activeTabId = activeTabId;
257
+ this.viewConfig.vizId = vizId;
258
+ if (this.isAppInitialized) {
259
+ this.trigger(HostEvent.Navigate, path);
260
+ } else {
261
+ this.render();
262
+ }
263
+ }
262
264
  }
263
265
 
264
266
  /**
@@ -1,6 +1,8 @@
1
1
  import { PinboardEmbed, LiveboardViewConfig } from './liveboard';
2
2
  import { init } from '../index';
3
- import { Action, AuthType, EmbedEvent, RuntimeFilterOp } from '../types';
3
+ import {
4
+ Action, AuthType, EmbedEvent, RuntimeFilterOp,
5
+ } from '../types';
4
6
  import {
5
7
  executeAfterWait,
6
8
  getDocumentBody,
@@ -8,6 +10,7 @@ import {
8
10
  getRootEl,
9
11
  defaultParams,
10
12
  defaultParamsWithoutHiddenActions,
13
+ expectUrlMatchesWithParams,
11
14
  } from '../test/test-utils';
12
15
  import { version } from '../../package.json';
13
16
 
@@ -41,7 +44,8 @@ describe('Pinboard/viz embed tests', () => {
41
44
  } as LiveboardViewConfig);
42
45
  pinboardEmbed.render();
43
46
  await executeAfterWait(() => {
44
- expect(getIFrameSrc()).toBe(
47
+ expectUrlMatchesWithParams(
48
+ getIFrameSrc(),
45
49
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}${prefixParams}#/embed/viz/${pinboardId}`,
46
50
  );
47
51
  });
@@ -49,18 +53,15 @@ describe('Pinboard/viz embed tests', () => {
49
53
 
50
54
  test('should set disabled actions', async () => {
51
55
  const pinboardEmbed = new PinboardEmbed(getRootEl(), {
52
- disabledActions: [
53
- Action.DownloadAsCsv,
54
- Action.DownloadAsPdf,
55
- Action.DownloadAsXlsx,
56
- ],
56
+ disabledActions: [Action.DownloadAsCsv, Action.DownloadAsPdf, Action.DownloadAsXlsx],
57
57
  disabledActionReason: 'Action denied',
58
58
  ...defaultViewConfig,
59
59
  pinboardId,
60
60
  } as LiveboardViewConfig);
61
61
  pinboardEmbed.render();
62
62
  await executeAfterWait(() => {
63
- expect(getIFrameSrc()).toBe(
63
+ expectUrlMatchesWithParams(
64
+ getIFrameSrc(),
64
65
  `http://${thoughtSpotHost}/?embedApp=true&${defaultParamsWithoutHiddenActions}&disableAction=[%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]&disableHint=Action%20denied&hideAction=[%22${Action.ReportError}%22]${prefixParams}#/embed/viz/${pinboardId}`,
65
66
  );
66
67
  });
@@ -68,17 +69,14 @@ describe('Pinboard/viz embed tests', () => {
68
69
 
69
70
  test('should set hidden actions', async () => {
70
71
  const pinboardEmbed = new PinboardEmbed(getRootEl(), {
71
- hiddenActions: [
72
- Action.DownloadAsCsv,
73
- Action.DownloadAsPdf,
74
- Action.DownloadAsXlsx,
75
- ],
72
+ hiddenActions: [Action.DownloadAsCsv, Action.DownloadAsPdf, Action.DownloadAsXlsx],
76
73
  ...defaultViewConfig,
77
74
  pinboardId,
78
75
  } as LiveboardViewConfig);
79
76
  pinboardEmbed.render();
80
77
  await executeAfterWait(() => {
81
- expect(getIFrameSrc()).toBe(
78
+ expectUrlMatchesWithParams(
79
+ getIFrameSrc(),
82
80
  `http://${thoughtSpotHost}/?embedApp=true&${defaultParamsWithoutHiddenActions}&hideAction=[%22${Action.ReportError}%22,%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]${prefixParams}#/embed/viz/${pinboardId}`,
83
81
  );
84
82
  });
@@ -86,17 +84,14 @@ describe('Pinboard/viz embed tests', () => {
86
84
 
87
85
  test('should set visible actions', async () => {
88
86
  const pinboardEmbed = new PinboardEmbed(getRootEl(), {
89
- visibleActions: [
90
- Action.DownloadAsCsv,
91
- Action.DownloadAsPdf,
92
- Action.DownloadAsXlsx,
93
- ],
87
+ visibleActions: [Action.DownloadAsCsv, Action.DownloadAsPdf, Action.DownloadAsXlsx],
94
88
  ...defaultViewConfig,
95
89
  pinboardId,
96
90
  } as LiveboardViewConfig);
97
91
  pinboardEmbed.render();
98
92
  await executeAfterWait(() => {
99
- expect(getIFrameSrc()).toBe(
93
+ expectUrlMatchesWithParams(
94
+ getIFrameSrc(),
100
95
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&visibleAction=[%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]${prefixParams}#/embed/viz/${pinboardId}`,
101
96
  );
102
97
  });
@@ -110,7 +105,8 @@ describe('Pinboard/viz embed tests', () => {
110
105
  } as LiveboardViewConfig);
111
106
  pinboardEmbed.render();
112
107
  await executeAfterWait(() => {
113
- expect(getIFrameSrc()).toBe(
108
+ expectUrlMatchesWithParams(
109
+ getIFrameSrc(),
114
110
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&visibleAction=[]${prefixParams}#/embed/viz/${pinboardId}`,
115
111
  );
116
112
  });
@@ -124,7 +120,8 @@ describe('Pinboard/viz embed tests', () => {
124
120
  } as LiveboardViewConfig);
125
121
  pinboardEmbed.render();
126
122
  await executeAfterWait(() => {
127
- expect(getIFrameSrc()).toBe(
123
+ expectUrlMatchesWithParams(
124
+ getIFrameSrc(),
128
125
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&enableVizTransform=true${prefixParams}#/embed/viz/${pinboardId}`,
129
126
  );
130
127
  });
@@ -138,7 +135,8 @@ describe('Pinboard/viz embed tests', () => {
138
135
  } as LiveboardViewConfig);
139
136
  pinboardEmbed.render();
140
137
  await executeAfterWait(() => {
141
- expect(getIFrameSrc()).toBe(
138
+ expectUrlMatchesWithParams(
139
+ getIFrameSrc(),
142
140
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&enableVizTransform=false${prefixParams}#/embed/viz/${pinboardId}`,
143
141
  );
144
142
  });
@@ -152,7 +150,8 @@ describe('Pinboard/viz embed tests', () => {
152
150
  } as LiveboardViewConfig);
153
151
  pinboardEmbed.render();
154
152
  await executeAfterWait(() => {
155
- expect(getIFrameSrc()).toBe(
153
+ expectUrlMatchesWithParams(
154
+ getIFrameSrc(),
156
155
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}${prefixParamsVizEmbed}#/embed/viz/${pinboardId}/${vizId}`,
157
156
  );
158
157
  });
@@ -173,7 +172,8 @@ describe('Pinboard/viz embed tests', () => {
173
172
  } as LiveboardViewConfig);
174
173
  pinboardEmbed.render();
175
174
  await executeAfterWait(() => {
176
- expect(getIFrameSrc()).toBe(
175
+ expectUrlMatchesWithParams(
176
+ getIFrameSrc(),
177
177
  `http://${thoughtSpotHost}/?embedApp=true&col1=sales&op1=EQ&val1=1000${defaultParams}${prefixParamsVizEmbed}#/embed/viz/${pinboardId}/${vizId}`,
178
178
  );
179
179
  });
@@ -191,10 +191,7 @@ describe('Pinboard/viz embed tests', () => {
191
191
  pinboardEmbed.render();
192
192
 
193
193
  executeAfterWait(() => {
194
- expect(onSpy).toHaveBeenCalledWith(
195
- EmbedEvent.EmbedHeight,
196
- expect.anything(),
197
- );
194
+ expect(onSpy).toHaveBeenCalledWith(EmbedEvent.EmbedHeight, expect.anything());
198
195
  });
199
196
  });
200
197
  });