@thoughtspot/visual-embed-sdk 1.6.0-alpha.2 → 1.7.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/src/embed/app.d.ts +9 -2
  2. package/dist/src/embed/liveboard.d.ts +19 -19
  3. package/dist/src/embed/liveboard.spec.d.ts +1 -0
  4. package/dist/src/embed/search.d.ts +2 -1
  5. package/dist/src/embed/ts-embed.d.ts +2 -11
  6. package/dist/src/test/test-utils.d.ts +1 -0
  7. package/dist/src/types.d.ts +21 -25
  8. package/dist/tsembed.es.js +63 -61
  9. package/dist/tsembed.js +62 -60
  10. package/lib/package.json +4 -1
  11. package/lib/src/embed/app.d.ts +9 -2
  12. package/lib/src/embed/app.js +18 -1
  13. package/lib/src/embed/app.js.map +1 -1
  14. package/lib/src/embed/app.spec.js +31 -0
  15. package/lib/src/embed/app.spec.js.map +1 -1
  16. package/lib/src/embed/events.spec.js +55 -2
  17. package/lib/src/embed/events.spec.js.map +1 -1
  18. package/lib/src/embed/liveboard.d.ts +19 -19
  19. package/lib/src/embed/liveboard.js +12 -13
  20. package/lib/src/embed/liveboard.js.map +1 -1
  21. package/lib/src/embed/liveboard.spec.d.ts +1 -0
  22. package/lib/src/embed/liveboard.spec.js +159 -0
  23. package/lib/src/embed/liveboard.spec.js.map +1 -0
  24. package/lib/src/embed/search.d.ts +2 -1
  25. package/lib/src/embed/search.js +11 -1
  26. package/lib/src/embed/search.js.map +1 -1
  27. package/lib/src/embed/search.spec.js +32 -20
  28. package/lib/src/embed/search.spec.js.map +1 -1
  29. package/lib/src/embed/ts-embed.d.ts +2 -11
  30. package/lib/src/embed/ts-embed.js +4 -23
  31. package/lib/src/embed/ts-embed.js.map +1 -1
  32. package/lib/src/embed/ts-embed.spec.js +63 -6
  33. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  34. package/lib/src/react/index.spec.js +1 -1
  35. package/lib/src/react/index.spec.js.map +1 -1
  36. package/lib/src/test/test-utils.d.ts +1 -0
  37. package/lib/src/test/test-utils.js +3 -0
  38. package/lib/src/test/test-utils.js.map +1 -1
  39. package/lib/src/types.d.ts +21 -25
  40. package/lib/src/types.js +18 -23
  41. package/lib/src/types.js.map +1 -1
  42. package/lib/src/visual-embed-sdk.d.ts +46 -51
  43. package/package.json +4 -1
  44. package/src/embed/app.spec.ts +40 -0
  45. package/src/embed/app.ts +21 -2
  46. package/src/embed/events.spec.ts +60 -1
  47. package/src/embed/liveboard.spec.ts +199 -0
  48. package/src/embed/liveboard.ts +21 -24
  49. package/src/embed/search.spec.ts +38 -19
  50. package/src/embed/search.ts +13 -1
  51. package/src/embed/ts-embed.spec.ts +78 -5
  52. package/src/embed/ts-embed.ts +6 -25
  53. package/src/react/index.spec.tsx +1 -1
  54. package/src/test/test-utils.ts +4 -0
  55. package/src/types.ts +21 -25
  56. package/dist/src/embed/pinboard.d.ts +0 -85
  57. package/lib/src/embed/pinboard.d.ts +0 -85
  58. package/lib/src/embed/pinboard.js +0 -107
  59. package/lib/src/embed/pinboard.js.map +0 -1
  60. package/lib/src/utils/fetchAnswers.d.ts +0 -3
  61. package/lib/src/utils/fetchAnswers.js +0 -49
  62. package/lib/src/utils/fetchAnswers.js.map +0 -1
@@ -0,0 +1,199 @@
1
+ import { LiveboardEmbed, LiveboardViewConfig } from './liveboard';
2
+ import { init } from '../index';
3
+ import { Action, AuthType, EmbedEvent, RuntimeFilterOp } from '../types';
4
+ import {
5
+ executeAfterWait,
6
+ getDocumentBody,
7
+ getIFrameSrc,
8
+ getRootEl,
9
+ } from '../test/test-utils';
10
+ import { version } from '../../package.json';
11
+
12
+ const defaultViewConfig = {
13
+ frameParams: {
14
+ width: 1280,
15
+ height: 720,
16
+ },
17
+ };
18
+ const liveboardId = 'eca215d4-0d2c-4a55-90e3-d81ef6848ae0';
19
+ const vizId = '6e73f724-660e-11eb-ae93-0242ac130002';
20
+ const thoughtSpotHost = 'tshost';
21
+ const defaultParams = `&hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}`;
22
+ const prefixParams = '&isLiveboardEmbed=true';
23
+
24
+ beforeAll(() => {
25
+ init({
26
+ thoughtSpotHost,
27
+ authType: AuthType.None,
28
+ });
29
+ });
30
+
31
+ describe('Liveboard/viz embed tests', () => {
32
+ beforeEach(() => {
33
+ document.body.innerHTML = getDocumentBody();
34
+ });
35
+
36
+ test('should render liveboard', async () => {
37
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
38
+ ...defaultViewConfig,
39
+ liveboardId,
40
+ } as LiveboardViewConfig);
41
+ liveboardEmbed.render();
42
+ await executeAfterWait(() => {
43
+ expect(getIFrameSrc()).toBe(
44
+ `http://${thoughtSpotHost}/?embedApp=true${defaultParams}${prefixParams}#/embed/viz/${liveboardId}`,
45
+ );
46
+ });
47
+ });
48
+
49
+ test('should set disabled actions', async () => {
50
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
51
+ disabledActions: [
52
+ Action.DownloadAsCsv,
53
+ Action.DownloadAsPdf,
54
+ Action.DownloadAsXlsx,
55
+ ],
56
+ disabledActionReason: 'Action denied',
57
+ ...defaultViewConfig,
58
+ liveboardId,
59
+ } as LiveboardViewConfig);
60
+ liveboardEmbed.render();
61
+ await executeAfterWait(() => {
62
+ expect(getIFrameSrc()).toBe(
63
+ `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&disableAction=[%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]&disableHint=Action%20denied${prefixParams}#/embed/viz/${liveboardId}`,
64
+ );
65
+ });
66
+ });
67
+
68
+ test('should set hidden actions', async () => {
69
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
70
+ hiddenActions: [
71
+ Action.DownloadAsCsv,
72
+ Action.DownloadAsPdf,
73
+ Action.DownloadAsXlsx,
74
+ ],
75
+ ...defaultViewConfig,
76
+ liveboardId,
77
+ } as LiveboardViewConfig);
78
+ liveboardEmbed.render();
79
+ await executeAfterWait(() => {
80
+ expect(getIFrameSrc()).toBe(
81
+ `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&hideAction=[%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]${prefixParams}#/embed/viz/${liveboardId}`,
82
+ );
83
+ });
84
+ });
85
+
86
+ test('should set visible actions', async () => {
87
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
88
+ visibleActions: [
89
+ Action.DownloadAsCsv,
90
+ Action.DownloadAsPdf,
91
+ Action.DownloadAsXlsx,
92
+ ],
93
+ ...defaultViewConfig,
94
+ liveboardId,
95
+ } as LiveboardViewConfig);
96
+ liveboardEmbed.render();
97
+ await executeAfterWait(() => {
98
+ expect(getIFrameSrc()).toBe(
99
+ `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&visibleAction=[%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]${prefixParams}#/embed/viz/${liveboardId}`,
100
+ );
101
+ });
102
+ });
103
+
104
+ test('should set visible actions as empty array', async () => {
105
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
106
+ visibleActions: [],
107
+ ...defaultViewConfig,
108
+ liveboardId,
109
+ } as LiveboardViewConfig);
110
+ liveboardEmbed.render();
111
+ await executeAfterWait(() => {
112
+ expect(getIFrameSrc()).toBe(
113
+ `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&visibleAction=[]${prefixParams}#/embed/viz/${liveboardId}`,
114
+ );
115
+ });
116
+ });
117
+
118
+ test('should enable viz transformations true', async () => {
119
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
120
+ enableVizTransformations: true,
121
+ ...defaultViewConfig,
122
+ liveboardId,
123
+ } as LiveboardViewConfig);
124
+ liveboardEmbed.render();
125
+ await executeAfterWait(() => {
126
+ expect(getIFrameSrc()).toBe(
127
+ `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&enableVizTransform=true${prefixParams}#/embed/viz/${liveboardId}`,
128
+ );
129
+ });
130
+ });
131
+
132
+ test('should disable viz transformations when enableVizTransformations false', async () => {
133
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
134
+ enableVizTransformations: false,
135
+ ...defaultViewConfig,
136
+ liveboardId,
137
+ } as LiveboardViewConfig);
138
+ liveboardEmbed.render();
139
+ await executeAfterWait(() => {
140
+ expect(getIFrameSrc()).toBe(
141
+ `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&enableVizTransform=false${prefixParams}#/embed/viz/${liveboardId}`,
142
+ );
143
+ });
144
+ });
145
+
146
+ test('should render viz', async () => {
147
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
148
+ ...defaultViewConfig,
149
+ liveboardId,
150
+ vizId,
151
+ } as LiveboardViewConfig);
152
+ liveboardEmbed.render();
153
+ await executeAfterWait(() => {
154
+ expect(getIFrameSrc()).toBe(
155
+ `http://${thoughtSpotHost}/?embedApp=true${defaultParams}${prefixParams}#/embed/viz/${liveboardId}/${vizId}`,
156
+ );
157
+ });
158
+ });
159
+
160
+ test('should apply runtime filters', async () => {
161
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
162
+ ...defaultViewConfig,
163
+ liveboardId,
164
+ vizId,
165
+ runtimeFilters: [
166
+ {
167
+ columnName: 'sales',
168
+ operator: RuntimeFilterOp.EQ,
169
+ values: [1000],
170
+ },
171
+ ],
172
+ } as LiveboardViewConfig);
173
+ liveboardEmbed.render();
174
+ await executeAfterWait(() => {
175
+ expect(getIFrameSrc()).toBe(
176
+ `http://${thoughtSpotHost}/?embedApp=true&col1=sales&op1=EQ&val1=1000${defaultParams}${prefixParams}#/embed/viz/${liveboardId}/${vizId}`,
177
+ );
178
+ });
179
+ });
180
+
181
+ test('should register event handler to adjust iframe height', async () => {
182
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
183
+ ...defaultViewConfig,
184
+ fullHeight: true,
185
+ liveboardId,
186
+ vizId,
187
+ } as LiveboardViewConfig);
188
+
189
+ const onSpy = jest.spyOn(liveboardEmbed, 'on');
190
+ liveboardEmbed.render();
191
+
192
+ executeAfterWait(() => {
193
+ expect(onSpy).toHaveBeenCalledWith(
194
+ EmbedEvent.EmbedHeight,
195
+ expect.anything(),
196
+ );
197
+ });
198
+ });
199
+ });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2021
3
3
  *
4
- * Embed a ThoughtSpot liveboard or visualization
4
+ * Embed a ThoughtSpot Liveboard or visualization
5
5
  * https://developers.thoughtspot.com/docs/?pageid=embed-pinboard
6
6
  * https://developers.thoughtspot.com/docs/?pageid=embed-a-viz
7
7
  *
@@ -22,21 +22,21 @@ import { getFilterQuery, getQueryParamString } from '../utils';
22
22
  import { V1Embed, ViewConfig } from './ts-embed';
23
23
 
24
24
  /**
25
- * The configuration for the embedded liveboard or visualization page view.
25
+ * The configuration for the embedded Liveboard or visualization page view.
26
26
  * @Category Liveboards and Charts
27
27
  */
28
28
  export interface LiveboardViewConfig extends ViewConfig {
29
29
  /**
30
30
  * If set to true, the embedded object container dynamically resizes
31
- * according to the height of the liveboard.
31
+ * according to the height of the Liveboard.
32
32
  */
33
33
  fullHeight?: boolean;
34
34
  /**
35
- * This is the minimum height(in pixels) for a full height liveboard.
36
- * Setting this height helps resolves issues with empty liveboards and
37
- * other screens navigable from a liveboard.
35
+ * This is the minimum height(in pixels) for a full height Liveboard.
36
+ * Setting this height helps resolves issues with empty Liveboards and
37
+ * other screens navigable from a Liveboard.
38
+ * *_since 1.5.0_
38
39
  * @default 500
39
- * * _since 1.5.0_
40
40
  */
41
41
  defaultHeight?: number;
42
42
  /**
@@ -44,7 +44,7 @@ export interface LiveboardViewConfig extends ViewConfig {
44
44
  */
45
45
  enableVizTransformations?: boolean;
46
46
  /**
47
- * The liveboard to display in the embedded view.
47
+ * The Liveboard to display in the embedded view.
48
48
  * Use either of liveboardId or pinboardId to reference the Liveboard to embed.
49
49
  */
50
50
  liveboardId?: string;
@@ -54,12 +54,12 @@ export interface LiveboardViewConfig extends ViewConfig {
54
54
  */
55
55
  pinboardId?: string;
56
56
  /**
57
- * The visualization within the liveboard to display.
57
+ * The visualization within the Liveboard to display.
58
58
  */
59
59
  vizId?: string;
60
60
  /**
61
61
  * If set to true, all filter chips from a
62
- * liveboard page will be read-only (no X buttons)
62
+ * Liveboard page will be read-only (no X buttons)
63
63
  */
64
64
  preventLiveboardFilterRemoval?: boolean;
65
65
  /**
@@ -70,7 +70,7 @@ export interface LiveboardViewConfig extends ViewConfig {
70
70
  }
71
71
 
72
72
  /**
73
- * Embed a ThoughtSpot liveboard or visualization
73
+ * Embed a ThoughtSpot Liveboard or visualization
74
74
  * @Category Liveboards and Charts
75
75
  */
76
76
  export class LiveboardEmbed extends V1Embed {
@@ -85,7 +85,7 @@ export class LiveboardEmbed extends V1Embed {
85
85
 
86
86
  /**
87
87
  * Construct a map of params to be passed on to the
88
- * embedded liveboard or visualization.
88
+ * embedded Liveboard or visualization.
89
89
  */
90
90
  private getEmbedParams() {
91
91
  const params = this.getBaseQueryParams();
@@ -120,12 +120,12 @@ export class LiveboardEmbed extends V1Embed {
120
120
  }
121
121
 
122
122
  /**
123
- * Construct the URL of the embedded ThoughtSpot liveboard or visualization
123
+ * Construct the URL of the embedded ThoughtSpot Liveboard or visualization
124
124
  * to be loaded within the iframe.
125
- * @param liveboardId The GUID of the liveboard.
126
- * @param vizId The optional GUID of a visualization within the liveboard.
125
+ * @param liveboardId The GUID of the Liveboard.
126
+ * @param vizId The optional GUID of a visualization within the Liveboard.
127
127
  * @param runtimeFilters A list of runtime filters to be applied to
128
- * the liveboard or visualization on load.
128
+ * the Liveboard or visualization on load.
129
129
  */
130
130
  private getIFrameSrc(
131
131
  liveboardId: string,
@@ -164,18 +164,15 @@ export class LiveboardEmbed extends V1Embed {
164
164
  responder({ type: EmbedEvent.EmbedIframeCenter, data: obj });
165
165
  };
166
166
 
167
- private handleRouteChangeFullHeightLiveboard = (data: MessagePayload) => {
168
- if (
169
- data.data.canvasState !== 'EMBED' &&
170
- data.data.canvasState !== 'pinboard'
171
- ) {
167
+ private setIframeHeightForNonEmbedLiveboard = (data: MessagePayload) => {
168
+ if (!data.data.currentPath.startsWith('/embed/viz/')) {
172
169
  this.setIFrameHeight(this.defaultHeight);
173
170
  }
174
171
  };
175
172
 
176
173
  /**
177
- * Render an embedded ThoughtSpot liveboard or visualization
178
- * @param renderOptions An object specifying the liveboard ID,
174
+ * Render an embedded ThoughtSpot Liveboard or visualization
175
+ * @param renderOptions An object specifying the Liveboard ID,
179
176
  * visualization ID and the runtime filters.
180
177
  */
181
178
  public render(): LiveboardEmbed {
@@ -190,7 +187,7 @@ export class LiveboardEmbed extends V1Embed {
190
187
  if (this.viewConfig.fullHeight === true) {
191
188
  this.on(
192
189
  EmbedEvent.RouteChange,
193
- this.handleRouteChangeFullHeightLiveboard,
190
+ this.setIframeHeightForNonEmbedLiveboard,
194
191
  );
195
192
  this.on(EmbedEvent.EmbedHeight, this.updateIFrameHeight);
196
193
  this.on(EmbedEvent.EmbedIframeCenter, this.embedIframeCenter);
@@ -1,4 +1,4 @@
1
- import { SearchEmbed } from './search';
1
+ import { SearchEmbed, HiddenActionItemByDefaultForSearchEmbed } from './search';
2
2
  import { init } from '../index';
3
3
  import { Action, AuthType } from '../types';
4
4
  import {
@@ -6,6 +6,7 @@ import {
6
6
  getDocumentBody,
7
7
  getIFrameSrc,
8
8
  getRootEl,
9
+ fixedEncodeURI,
9
10
  } from '../test/test-utils';
10
11
  import { version } from '../../package.json';
11
12
 
@@ -18,6 +19,10 @@ const defaultViewConfig = {
18
19
  const answerId = 'eca215d4-0d2c-4a55-90e3-d81ef6848ae0';
19
20
  const thoughtSpotHost = 'tshost';
20
21
  const defaultParams = `hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}`;
22
+ const hideBydefault = `&hideAction=${fixedEncodeURI(
23
+ JSON.stringify(HiddenActionItemByDefaultForSearchEmbed),
24
+ )}`;
25
+ const defaultParamsWithHiddenActions = defaultParams + hideBydefault;
21
26
 
22
27
  beforeAll(() => {
23
28
  init({
@@ -36,7 +41,7 @@ describe('Search embed tests', () => {
36
41
  searchEmbed.render();
37
42
  await executeAfterWait(() => {
38
43
  expect(getIFrameSrc()).toBe(
39
- `http://${thoughtSpotHost}/v2/?${defaultParams}&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
44
+ `http://${thoughtSpotHost}/v2/?${defaultParamsWithHiddenActions}&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
40
45
  );
41
46
  });
42
47
  });
@@ -50,7 +55,7 @@ describe('Search embed tests', () => {
50
55
  searchEmbed.render();
51
56
  await executeAfterWait(() => {
52
57
  expect(getIFrameSrc()).toBe(
53
- `http://${thoughtSpotHost}/v2/?${defaultParams}&dataSources=[%22data-source-1%22]&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
58
+ `http://${thoughtSpotHost}/v2/?${defaultParamsWithHiddenActions}&dataSources=[%22data-source-1%22]&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
54
59
  );
55
60
  });
56
61
  });
@@ -68,7 +73,7 @@ describe('Search embed tests', () => {
68
73
  searchEmbed.render();
69
74
  await executeAfterWait(() => {
70
75
  expect(getIFrameSrc()).toBe(
71
- `http://${thoughtSpotHost}/v2/?${defaultParams}&dataSources=[%22data-source-1%22]&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
76
+ `http://${thoughtSpotHost}/v2/?${defaultParamsWithHiddenActions}&dataSources=[%22data-source-1%22]&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
72
77
  );
73
78
  });
74
79
  });
@@ -86,7 +91,7 @@ describe('Search embed tests', () => {
86
91
  searchEmbed.render();
87
92
  await executeAfterWait(() => {
88
93
  expect(getIFrameSrc()).toBe(
89
- `http://${thoughtSpotHost}/v2/?${defaultParams}&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
94
+ `http://${thoughtSpotHost}/v2/?${defaultParamsWithHiddenActions}&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
90
95
  );
91
96
  });
92
97
 
@@ -101,7 +106,7 @@ describe('Search embed tests', () => {
101
106
  searchEmbed.render();
102
107
  await executeAfterWait(() => {
103
108
  expect(getIFrameSrc()).toBe(
104
- `http://${thoughtSpotHost}/v2/?${defaultParams}&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&executeSearch=true&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
109
+ `http://${thoughtSpotHost}/v2/?${defaultParamsWithHiddenActions}&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&executeSearch=true&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
105
110
  );
106
111
  });
107
112
  });
@@ -120,7 +125,7 @@ describe('Search embed tests', () => {
120
125
  searchEmbed.render();
121
126
  await executeAfterWait(() => {
122
127
  expect(getIFrameSrc()).toBe(
123
- `http://${thoughtSpotHost}/v2/?${defaultParams}&dataSources=[%22data-source-1%22]&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&dataSourceMode=collapse&useLastSelectedSources=false#/embed/answer`,
128
+ `http://${thoughtSpotHost}/v2/?${defaultParamsWithHiddenActions}&dataSources=[%22data-source-1%22]&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&dataSourceMode=collapse&useLastSelectedSources=false#/embed/answer`,
124
129
  );
125
130
  });
126
131
  });
@@ -139,7 +144,7 @@ describe('Search embed tests', () => {
139
144
  searchEmbed.render();
140
145
  await executeAfterWait(() => {
141
146
  expect(getIFrameSrc()).toBe(
142
- `http://${thoughtSpotHost}/v2/?${defaultParams}&dataSources=[%22data-source-1%22]&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&dataSourceMode=hide&useLastSelectedSources=false#/embed/answer`,
147
+ `http://${thoughtSpotHost}/v2/?${defaultParamsWithHiddenActions}&dataSources=[%22data-source-1%22]&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&dataSourceMode=hide&useLastSelectedSources=false#/embed/answer`,
143
148
  );
144
149
  });
145
150
  });
@@ -159,7 +164,7 @@ describe('Search embed tests', () => {
159
164
  searchEmbed.render();
160
165
  await executeAfterWait(() => {
161
166
  expect(getIFrameSrc()).toBe(
162
- `http://${thoughtSpotHost}/v2/?${defaultParams}&disableAction=[%22download%22,%22edit%22]&disableHint=Permission%20denied&dataSources=[%22data-source-1%22]&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
167
+ `http://${thoughtSpotHost}/v2/?${defaultParams}&disableAction=[%22download%22,%22edit%22]&disableHint=Permission%20denied${hideBydefault}&dataSources=[%22data-source-1%22]&searchTokenString=%5Bcommit%20date%5D%5Brevenue%5D&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
163
168
  );
164
169
  });
165
170
  });
@@ -172,41 +177,55 @@ describe('Search embed tests', () => {
172
177
  searchEmbed.render();
173
178
  await executeAfterWait(() => {
174
179
  expect(getIFrameSrc()).toBe(
175
- `http://${thoughtSpotHost}/v2/?${defaultParams}&enableSearchAssist=true&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
180
+ `http://${thoughtSpotHost}/v2/?${defaultParamsWithHiddenActions}&enableSearchAssist=true&dataSourceMode=expand&useLastSelectedSources=false#/embed/answer`,
176
181
  );
177
182
  });
178
183
  });
179
184
 
180
185
  test('should hide actions', async () => {
186
+ const hiddenActionsForSearch = [
187
+ Action.DownloadAsCsv,
188
+ Action.DownloadAsPdf,
189
+ Action.DownloadAsXlsx,
190
+ ];
181
191
  const searchEmbed = new SearchEmbed(getRootEl(), {
182
- hiddenActions: [
183
- Action.DownloadAsCsv,
184
- Action.DownloadAsPdf,
185
- Action.DownloadAsXlsx,
186
- ],
192
+ hiddenActions: hiddenActionsForSearch,
187
193
  ...defaultViewConfig,
188
194
  answerId,
189
195
  });
190
196
  searchEmbed.render();
197
+ const hideActionUrl = fixedEncodeURI(
198
+ JSON.stringify([
199
+ ...hiddenActionsForSearch,
200
+ ...HiddenActionItemByDefaultForSearchEmbed,
201
+ ]),
202
+ );
191
203
  await executeAfterWait(() => {
192
204
  expect(getIFrameSrc()).toBe(
193
- `http://${thoughtSpotHost}/v2/?${defaultParams}&hideAction=[%22downloadAsCSV%22,%22downloadAsPdf%22,%22downloadAsXLSX%22]&dataSourceMode=expand&useLastSelectedSources=false#/embed/saved-answer/${answerId}`,
205
+ `http://${thoughtSpotHost}/v2/?${defaultParams}&hideAction=${hideActionUrl}&dataSourceMode=expand&useLastSelectedSources=false#/embed/saved-answer/${answerId}`,
194
206
  );
195
207
  });
196
208
  });
197
209
 
198
210
  test('should disable and hide actions', async () => {
211
+ const hiddenActionsForSearch = [Action.DownloadAsCsv];
199
212
  const searchEmbed = new SearchEmbed(getRootEl(), {
200
213
  disabledActions: [Action.DownloadAsXlsx],
201
- hiddenActions: [Action.DownloadAsCsv],
214
+ hiddenActions: hiddenActionsForSearch,
202
215
  disabledActionReason: 'Access denied',
203
216
  ...defaultViewConfig,
204
217
  answerId,
205
218
  });
206
219
  searchEmbed.render();
220
+ const hideActionUrl = fixedEncodeURI(
221
+ JSON.stringify([
222
+ ...hiddenActionsForSearch,
223
+ ...HiddenActionItemByDefaultForSearchEmbed,
224
+ ]),
225
+ );
207
226
  await executeAfterWait(() => {
208
227
  expect(getIFrameSrc()).toBe(
209
- `http://${thoughtSpotHost}/v2/?${defaultParams}&disableAction=[%22downloadAsXLSX%22]&disableHint=Access%20denied&hideAction=[%22downloadAsCSV%22]&dataSourceMode=expand&useLastSelectedSources=false#/embed/saved-answer/${answerId}`,
228
+ `http://${thoughtSpotHost}/v2/?${defaultParams}&disableAction=[%22downloadAsXLSX%22]&disableHint=Access%20denied&hideAction=${hideActionUrl}&dataSourceMode=expand&useLastSelectedSources=false#/embed/saved-answer/${answerId}`,
210
229
  );
211
230
  });
212
231
  });
@@ -219,7 +238,7 @@ describe('Search embed tests', () => {
219
238
  searchEmbed.render();
220
239
  await executeAfterWait(() => {
221
240
  expect(getIFrameSrc()).toBe(
222
- `http://${thoughtSpotHost}/v2/?${defaultParams}&dataSourceMode=expand&useLastSelectedSources=false#/embed/saved-answer/${answerId}`,
241
+ `http://${thoughtSpotHost}/v2/?${defaultParamsWithHiddenActions}&dataSourceMode=expand&useLastSelectedSources=false#/embed/saved-answer/${answerId}`,
223
242
  );
224
243
  });
225
244
  });
@@ -7,7 +7,7 @@
7
7
  * @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
8
8
  */
9
9
 
10
- import { DataSourceVisualMode, DOMSelector, Param } from '../types';
10
+ import { DataSourceVisualMode, DOMSelector, Param, Action } from '../types';
11
11
  import { getQueryParamString } from '../utils';
12
12
  import { ViewConfig, TsEmbed } from './ts-embed';
13
13
  import { version } from '../../package.json';
@@ -77,6 +77,12 @@ export interface SearchViewConfig extends ViewConfig {
77
77
  answerId?: string;
78
78
  }
79
79
 
80
+ export const HiddenActionItemByDefaultForSearchEmbed = [
81
+ Action.EditACopy,
82
+ Action.SpotIQAnalyze,
83
+ Action.SaveAsView,
84
+ ];
85
+
80
86
  /**
81
87
  * Embed ThoughtSpot search
82
88
  *
@@ -124,6 +130,12 @@ export class SearchEmbed extends TsEmbed {
124
130
  } = this.viewConfig;
125
131
  const answerPath = answerId ? `saved-answer/${answerId}` : 'answer';
126
132
  const queryParams = this.getBaseQueryParams();
133
+
134
+ queryParams[Param.HideActions] = [
135
+ ...(queryParams[Param.HideActions] ?? []),
136
+ ...HiddenActionItemByDefaultForSearchEmbed,
137
+ ];
138
+
127
139
  if (dataSources && dataSources.length) {
128
140
  queryParams[Param.DataSources] = JSON.stringify(dataSources);
129
141
  }
@@ -7,6 +7,7 @@ import {
7
7
  PinboardEmbed,
8
8
  LiveboardViewConfig,
9
9
  AppEmbed,
10
+ LiveboardEmbed,
10
11
  } from '../index';
11
12
  import { Action } from '../types';
12
13
  import { getDocumentBody, getIFrameSrc, getRootEl } from '../test/test-utils';
@@ -24,6 +25,7 @@ const defaultViewConfig = {
24
25
  },
25
26
  };
26
27
  const pinboardId = 'eca215d4-0d2c-4a55-90e3-d81ef6848ae0';
28
+ const liveboardId = 'eca215d4-0d2c-4a55-90e3-d81ef6848ae0';
27
29
  const thoughtSpotHost = 'tshost';
28
30
  const defaultParamsForPinboardEmbed = `hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}`;
29
31
 
@@ -119,7 +121,7 @@ describe('Unit test case for ts embed', () => {
119
121
  });
120
122
 
121
123
  describe('when visible actions are set', () => {
122
- test('should throw error when there are both visible and hidden actions', async () => {
124
+ test('should throw error when there are both visible and hidden actions - pinboard', async () => {
123
125
  spyOn(console, 'log');
124
126
  const pinboardEmbed = new PinboardEmbed(getRootEl(), {
125
127
  hiddenActions: [Action.DownloadAsCsv],
@@ -133,7 +135,7 @@ describe('Unit test case for ts embed', () => {
133
135
  'You cannot have both hidden actions and visible actions',
134
136
  );
135
137
  });
136
- test('should not throw error when there are only visible or hidden actions', async () => {
138
+ test('should not throw error when there are only visible or hidden actions - pinboard', async () => {
137
139
  const pinboardEmbed = new PinboardEmbed(getRootEl(), {
138
140
  hiddenActions: [Action.DownloadAsCsv],
139
141
  ...defaultViewConfig,
@@ -142,6 +144,55 @@ describe('Unit test case for ts embed', () => {
142
144
  pinboardEmbed.render();
143
145
  expect(pinboardEmbed['isError']).toBe(false);
144
146
  });
147
+
148
+ async function testActionsForLiveboards(
149
+ hiddenActions: Array<Action>,
150
+ visibleActions: Array<Action>,
151
+ ) {
152
+ spyOn(console, 'log');
153
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
154
+ hiddenActions,
155
+ visibleActions,
156
+ ...defaultViewConfig,
157
+ liveboardId,
158
+ } as LiveboardViewConfig);
159
+ await liveboardEmbed.render();
160
+ expect(liveboardEmbed['isError']).toBe(true);
161
+ expect(console.log).toHaveBeenCalledWith(
162
+ 'You cannot have both hidden actions and visible actions',
163
+ );
164
+ }
165
+ test('should throw error when there are both visible and hidden action arrays', async () => {
166
+ await testActionsForLiveboards(
167
+ [Action.DownloadAsCsv],
168
+ [Action.DownloadAsCsv],
169
+ );
170
+ });
171
+ test('should throw error when there are both visible and hidden actions arrays as empty', async () => {
172
+ await testActionsForLiveboards([], []);
173
+ });
174
+ test('should throw error when there are both visible and hidden actions - one of them is an empty array', async () => {
175
+ await testActionsForLiveboards([], [Action.DownloadAsCsv]);
176
+ });
177
+
178
+ test('should not throw error when there are only visible or hidden actions', async () => {
179
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
180
+ hiddenActions: [Action.DownloadAsCsv],
181
+ ...defaultViewConfig,
182
+ liveboardId,
183
+ } as LiveboardViewConfig);
184
+ liveboardEmbed.render();
185
+ expect(liveboardEmbed['isError']).toBe(false);
186
+ });
187
+ test('should not throw error when there are only visible or hidden actions', async () => {
188
+ const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
189
+ visibleActions: [Action.DownloadAsCsv],
190
+ ...defaultViewConfig,
191
+ liveboardId,
192
+ } as LiveboardViewConfig);
193
+ liveboardEmbed.render();
194
+ expect(liveboardEmbed['isError']).toBe(false);
195
+ });
145
196
  });
146
197
 
147
198
  describe('when thoughtSpotHost is empty', () => {
@@ -180,7 +231,7 @@ describe('Unit test case for ts embed', () => {
180
231
  });
181
232
 
182
233
  describe('Naviage to Page API', () => {
183
- const path = 'pinboard/e0836cad-4fdf-42d4-bd97-567a6b2a6058';
234
+ const path = 'viz/e0836cad-4fdf-42d4-bd97-567a6b2a6058';
184
235
  beforeEach(() => {
185
236
  jest.spyOn(config, 'getThoughtSpotHost').mockImplementation(
186
237
  () => 'http://tshost',
@@ -189,10 +240,10 @@ describe('Unit test case for ts embed', () => {
189
240
 
190
241
  test('when app is PinboardEmbed after navigateToPage function call, new path should be set to iframe', async () => {
191
242
  const pinboardEmbed = new PinboardEmbed(getRootEl(), {
192
- pinboardId: '123',
243
+ pinboardId: 'e0836cad-4fdf-42d4-bd97-567a6b2a6058',
193
244
  });
194
245
  await pinboardEmbed.render();
195
- pinboardEmbed.navigateToPage(path);
246
+ // pinboardEmbed.navigateToPage(path);
196
247
  expect(getIFrameSrc()).toBe(
197
248
  `http://${thoughtSpotHost}/?embedApp=true&${defaultParamsForPinboardEmbed}&isLiveboardEmbed=true#/embed/${path}`,
198
249
  );
@@ -227,4 +278,26 @@ describe('Unit test case for ts embed', () => {
227
278
  );
228
279
  });
229
280
  });
281
+ describe('Naviage to Page API - Pinboard', () => {
282
+ const path = 'pinboard/e0836cad-4fdf-42d4-bd97-567a6b2a6058';
283
+ beforeEach(() => {
284
+ jest.spyOn(config, 'getThoughtSpotHost').mockImplementation(
285
+ () => 'http://tshost',
286
+ );
287
+ });
288
+
289
+ test('when app is AppEmbed after navigateToPage function call, new path should be set to iframe', async () => {
290
+ const appEmbed = new AppEmbed(getRootEl(), {
291
+ frameParams: {
292
+ width: '100%',
293
+ height: '100%',
294
+ },
295
+ });
296
+ await appEmbed.render();
297
+ appEmbed.navigateToPage(path);
298
+ expect(getIFrameSrc()).toBe(
299
+ `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&${defaultParamsForPinboardEmbed}#/${path}`,
300
+ );
301
+ });
302
+ });
230
303
  });