@thoughtspot/visual-embed-sdk 1.9.1 → 1.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -20
- package/dist/src/embed/base.d.ts +1 -1
- package/dist/src/embed/liveboard.d.ts +7 -0
- package/dist/src/react/index.d.ts +7 -5
- package/dist/src/react/util.d.ts +1 -1
- package/dist/src/types.d.ts +18 -2
- package/dist/tsembed.es.js +18 -3
- package/dist/tsembed.js +18 -3
- package/lib/package.json +1 -1
- package/lib/src/embed/base.d.ts +1 -1
- package/lib/src/embed/base.js +1 -1
- package/lib/src/embed/liveboard.d.ts +7 -0
- package/lib/src/embed/liveboard.js +4 -1
- package/lib/src/embed/liveboard.js.map +1 -1
- package/lib/src/embed/liveboard.spec.js +11 -0
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.js +3 -0
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/react/index.d.ts +7 -5
- package/lib/src/react/index.js +10 -3
- package/lib/src/react/index.js.map +1 -1
- package/lib/src/react/index.spec.js +36 -6
- package/lib/src/react/index.spec.js.map +1 -1
- package/lib/src/react/util.d.ts +1 -1
- package/lib/src/react/util.js.map +1 -1
- package/lib/src/types.d.ts +18 -2
- package/lib/src/types.js +9 -0
- package/lib/src/types.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +26 -3
- package/package.json +1 -1
- package/src/embed/base.ts +1 -1
- package/src/embed/liveboard.spec.ts +13 -0
- package/src/embed/liveboard.ts +11 -0
- package/src/embed/ts-embed.ts +5 -1
- package/src/react/index.spec.tsx +52 -5
- package/src/react/index.tsx +39 -22
- package/src/react/util.ts +2 -1
- package/src/types.ts +17 -0
package/lib/src/react/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { SearchViewConfig } from '../embed/search';
|
|
3
3
|
import { AppViewConfig } from '../embed/app';
|
|
4
4
|
import { LiveboardViewConfig } from '../embed/liveboard';
|
|
5
|
+
import { TsEmbed } from '../embed/ts-embed';
|
|
5
6
|
import { EmbedProps } from './util';
|
|
6
7
|
interface SearchProps extends EmbedProps, SearchViewConfig {
|
|
7
8
|
}
|
|
8
|
-
export declare const SearchEmbed:
|
|
9
|
+
export declare const SearchEmbed: React.ForwardRefExoticComponent<SearchProps & React.RefAttributes<TsEmbed>>;
|
|
9
10
|
interface AppProps extends EmbedProps, AppViewConfig {
|
|
10
11
|
}
|
|
11
|
-
export declare const AppEmbed:
|
|
12
|
+
export declare const AppEmbed: React.ForwardRefExoticComponent<AppProps & React.RefAttributes<TsEmbed>>;
|
|
12
13
|
interface LiveboardProps extends EmbedProps, LiveboardViewConfig {
|
|
13
14
|
}
|
|
14
|
-
export declare const LiveboardEmbed:
|
|
15
|
-
export declare const PinboardEmbed:
|
|
15
|
+
export declare const LiveboardEmbed: React.ForwardRefExoticComponent<LiveboardProps & React.RefAttributes<TsEmbed>>;
|
|
16
|
+
export declare const PinboardEmbed: React.ForwardRefExoticComponent<LiveboardProps & React.RefAttributes<TsEmbed>>;
|
|
17
|
+
export declare const useEmbedRef: () => React.MutableRefObject<TsEmbed>;
|
|
16
18
|
export {};
|
package/lib/src/react/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { SearchEmbed as _SearchEmbed } from '../embed/search';
|
|
|
3
3
|
import { AppEmbed as _AppEmbed } from '../embed/app';
|
|
4
4
|
import { LiveboardEmbed as _LiveboardEmbed, } from '../embed/liveboard';
|
|
5
5
|
import { getViewPropsAndListeners } from './util';
|
|
6
|
-
const componentFactory = (EmbedConstructor) => (props) => {
|
|
6
|
+
const componentFactory = (EmbedConstructor) => React.forwardRef((props, forwardedRef) => {
|
|
7
7
|
const ref = React.useRef(null);
|
|
8
8
|
const { className, ...embedProps } = props;
|
|
9
9
|
const { viewConfig, listeners } = getViewPropsAndListeners(embedProps);
|
|
@@ -15,11 +15,18 @@ const componentFactory = (EmbedConstructor) => (props) => {
|
|
|
15
15
|
tsEmbed.on(eventName, listeners[eventName]);
|
|
16
16
|
});
|
|
17
17
|
tsEmbed.render();
|
|
18
|
+
if (forwardedRef) {
|
|
19
|
+
// eslint-disable-next-line no-param-reassign
|
|
20
|
+
forwardedRef.current = tsEmbed;
|
|
21
|
+
}
|
|
18
22
|
}, [embedProps]);
|
|
19
|
-
return React.createElement("div", { "data-testid": "tsEmbed",
|
|
20
|
-
};
|
|
23
|
+
return (React.createElement("div", { "data-testid": "tsEmbed", ref: ref, className: className }));
|
|
24
|
+
});
|
|
21
25
|
export const SearchEmbed = componentFactory(_SearchEmbed);
|
|
22
26
|
export const AppEmbed = componentFactory(_AppEmbed);
|
|
23
27
|
export const LiveboardEmbed = componentFactory(_LiveboardEmbed);
|
|
24
28
|
export const PinboardEmbed = componentFactory(_LiveboardEmbed);
|
|
29
|
+
export const useEmbedRef = () => {
|
|
30
|
+
return React.useRef(null);
|
|
31
|
+
};
|
|
25
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,IAAI,YAAY,EAAoB,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAiB,MAAM,cAAc,CAAC;AACpE,OAAO,EACH,cAAc,IAAI,eAAe,GAEpC,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAc,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAE9D,MAAM,gBAAgB,GAAG,CAKrB,gBAAmB,EACrB,EAAE,CAAC,CAAC,KAAQ,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EA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AIzC,YAAY,CAAC,CAAC;AAIhB,MAAM,CAAC,MAAM,QAAQ,GAAG,gBAAgB,CAItC,SAAS,CAAC,CAAC;AAIb,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAI5C,eAAe,CAAC,CAAC;AAEnB,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAI3C,eAAe,CAAC,CAAC;AAEnB,MAAM,CAAC,MAAM,WAAW,GAAG,GAAoC,EAAE;IAC7D,OAAO,KAAK,CAAC,MAAM,CAAU,IAAI,CAAC,CAAC;AACvC,CAAC,CAAC"}
|
|
@@ -2,10 +2,10 @@ import React from 'react';
|
|
|
2
2
|
import '@testing-library/jest-dom';
|
|
3
3
|
import '@testing-library/jest-dom/extend-expect';
|
|
4
4
|
import { render, waitFor } from '@testing-library/react';
|
|
5
|
-
import { getIFrameEl, getIFrameSrc, postMessageToParent, } from '../test/test-utils';
|
|
6
|
-
import { SearchEmbed } from './index';
|
|
5
|
+
import { executeAfterWait, getIFrameEl, getIFrameSrc, postMessageToParent, } from '../test/test-utils';
|
|
6
|
+
import { SearchEmbed, LiveboardEmbed, useEmbedRef } from './index';
|
|
7
7
|
import { AuthType, init } from '../index';
|
|
8
|
-
import { EmbedEvent } from '../types';
|
|
8
|
+
import { EmbedEvent, HostEvent } from '../types';
|
|
9
9
|
import { version } from '../../package.json';
|
|
10
10
|
const thoughtSpotHost = 'localhost';
|
|
11
11
|
beforeAll(() => {
|
|
@@ -17,16 +17,18 @@ beforeAll(() => {
|
|
|
17
17
|
describe('React Components', () => {
|
|
18
18
|
describe('SearchEmbed', () => {
|
|
19
19
|
it('Should Render the Iframe with props', async () => {
|
|
20
|
-
const { container } = render(React.createElement(SearchEmbed, { hideDataSources: true }));
|
|
20
|
+
const { container } = render(React.createElement(SearchEmbed, { hideDataSources: true, className: "embedClass" }));
|
|
21
21
|
await waitFor(() => getIFrameEl(container));
|
|
22
|
+
expect(getIFrameEl(container).parentElement.classList.contains('embedClass')).toBe(true);
|
|
22
23
|
expect(getIFrameSrc(container)).toBe(`http://${thoughtSpotHost}/?hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}&hideAction=[%22editACopy%22,%22saveAsView%22,%22updateTSL%22,%22editTSL%22,%22onDeleteAnswer%22]&dataSourceMode=hide&useLastSelectedSources=false&isSearchEmbed=true#/embed/answer`);
|
|
23
24
|
});
|
|
24
|
-
it('Should attach event listeners', async () => {
|
|
25
|
+
it('Should attach event listeners', async (done) => {
|
|
25
26
|
const userGUID = 'absfdfgd';
|
|
26
27
|
const { container } = render(React.createElement(SearchEmbed, { onInit: (e) => {
|
|
27
28
|
expect(e.data).toHaveProperty('timestamp');
|
|
28
29
|
}, onAuthInit: (e) => {
|
|
29
30
|
expect(e.data.userGUID).toEqual(userGUID);
|
|
31
|
+
done();
|
|
30
32
|
} }));
|
|
31
33
|
await waitFor(() => getIFrameEl(container));
|
|
32
34
|
const iframe = getIFrameEl(container);
|
|
@@ -41,8 +43,36 @@ describe('React Components', () => {
|
|
|
41
43
|
describe('AppEmbed', () => {
|
|
42
44
|
//
|
|
43
45
|
});
|
|
44
|
-
describe('
|
|
46
|
+
describe('LiveboardEmbed', () => {
|
|
45
47
|
//
|
|
48
|
+
it('Should be able to trigger events on the embed using refs', async () => {
|
|
49
|
+
const TestComponent = () => {
|
|
50
|
+
const embedRef = useEmbedRef();
|
|
51
|
+
const onLiveboardRendered = () => {
|
|
52
|
+
embedRef.current.trigger(HostEvent.SetVisibleVizs, [
|
|
53
|
+
'viz1',
|
|
54
|
+
'viz2',
|
|
55
|
+
]);
|
|
56
|
+
};
|
|
57
|
+
return (React.createElement(LiveboardEmbed, { ref: embedRef, liveboardId: "abcd", onLiveboardRendered: onLiveboardRendered }));
|
|
58
|
+
};
|
|
59
|
+
const { container } = render(React.createElement(TestComponent, null));
|
|
60
|
+
await waitFor(() => getIFrameEl(container));
|
|
61
|
+
const iframe = getIFrameEl(container);
|
|
62
|
+
jest.spyOn(iframe.contentWindow, 'postMessage');
|
|
63
|
+
postMessageToParent(iframe.contentWindow, {
|
|
64
|
+
type: EmbedEvent.LiveboardRendered,
|
|
65
|
+
data: {
|
|
66
|
+
userGUID: 'abcd',
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
await executeAfterWait(() => {
|
|
70
|
+
expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith({
|
|
71
|
+
type: HostEvent.SetVisibleVizs,
|
|
72
|
+
data: ['viz1', 'viz2'],
|
|
73
|
+
}, `http://${thoughtSpotHost}`);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
46
76
|
});
|
|
47
77
|
});
|
|
48
78
|
//# sourceMappingURL=index.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../../src/react/index.spec.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,2BAA2B,CAAC;AACnC,OAAO,yCAAyC,CAAC;AACjD,OAAO,EAAsB,MAAM,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EACH,WAAW,EACX,YAAY,EACZ,mBAAmB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../../src/react/index.spec.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,2BAA2B,CAAC;AACnC,OAAO,yCAAyC,CAAC;AACjD,OAAO,EAAsB,MAAM,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EACH,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,mBAAmB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAY,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,IAAI,EAA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C,CAAC;YAC5C,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;YACtC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;YAChD,mBAAmB,CAAC,MAAM,CAAC,aAAa,EAAE;gBACtC,IAAI,EAAE,UAAU,CAAC,iBAAiB;gBAClC,IAAI,EAAE;oBACF,QAAQ,EAAE,MAAM;iBACnB;aACJ,CAAC,CAAC;YACH,MAAM,gBAAgB,CAAC,GAAG,EAAE;gBACxB,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,oBAAoB,CACzD;oBACI,IAAI,EAAE,SAAS,CAAC,cAAc;oBAC9B,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;iBACzB,EACD,UAAU,eAAe,EAAE,CAC9B,CAAC;YACN,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/lib/src/react/util.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmbedEvent, MessageCallback } from '../types';
|
|
2
2
|
import { ViewConfig } from '../embed/ts-embed';
|
|
3
3
|
export declare type EmbedEventHandlers = {
|
|
4
|
-
[key in EmbedEvent as `on${Capitalize<key>}`]?: MessageCallback;
|
|
4
|
+
[key in keyof typeof EmbedEvent as `on${Capitalize<key>}`]?: MessageCallback;
|
|
5
5
|
};
|
|
6
6
|
export interface EmbedProps extends ViewConfig, EmbedEventHandlers {
|
|
7
7
|
className?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/react/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/react/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,UAAU,CAAC;AAgBvD,MAAM,UAAU,wBAAwB,CAA6C,KAAQ;IACzF,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAC5B,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QACV,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACtB,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;SACtD;aAAM;YACH,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC,EACD;QACI,UAAU,EAAE,EAAO;QACnB,SAAS,EAAE,EAAE;KAChB,CACJ,CAAC;AACN,CAAC"}
|
package/lib/src/types.d.ts
CHANGED
|
@@ -112,6 +112,13 @@ export interface EmbedConfig {
|
|
|
112
112
|
* @default false
|
|
113
113
|
*/
|
|
114
114
|
autoLogin?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Disable redirection to the login page when the embedded session expires
|
|
117
|
+
* This flag is typically used alongside the combination of auth modes such as {@link AuthType.AuthServer} and auto login behavior {@link EmbedConfig.autoLogin}
|
|
118
|
+
* @version SDK: 1.9.3 | ThoughtSpot: 8.1.0.cl
|
|
119
|
+
* @default false
|
|
120
|
+
*/
|
|
121
|
+
disableLoginRedirect?: boolean;
|
|
115
122
|
/**
|
|
116
123
|
* Calls the prefetch method internally when set to true
|
|
117
124
|
* @default false
|
|
@@ -342,7 +349,14 @@ export declare enum EmbedEvent {
|
|
|
342
349
|
* Emitted when any modal is closed in the app
|
|
343
350
|
* @version 1.6.0 or later
|
|
344
351
|
*/
|
|
345
|
-
DialogClose = "dialog-close"
|
|
352
|
+
DialogClose = "dialog-close",
|
|
353
|
+
/**
|
|
354
|
+
* Emitted when a liveboard has completed rendering,
|
|
355
|
+
* this event can be used as a hook to trigger events on the
|
|
356
|
+
* rendered liveboard
|
|
357
|
+
* @version 1.9.1 or later
|
|
358
|
+
*/
|
|
359
|
+
LiveboardRendered = "PinboardRendered"
|
|
346
360
|
}
|
|
347
361
|
/**
|
|
348
362
|
* Event types that can be triggered by the host application
|
|
@@ -440,7 +454,9 @@ export declare enum Param {
|
|
|
440
454
|
ViewPortHeight = "viewPortHeight",
|
|
441
455
|
ViewPortWidth = "viewPortWidth",
|
|
442
456
|
VisibleActions = "visibleAction",
|
|
443
|
-
CustomCSSUrl = "customCssUrl"
|
|
457
|
+
CustomCSSUrl = "customCssUrl",
|
|
458
|
+
visibleVizs = "pinboardVisibleVizs",
|
|
459
|
+
DisableLoginRedirect = "disableLoginRedirect"
|
|
444
460
|
}
|
|
445
461
|
/**
|
|
446
462
|
* The list of actions that can be performed on visual ThoughtSpot
|
package/lib/src/types.js
CHANGED
|
@@ -223,6 +223,13 @@ export var EmbedEvent;
|
|
|
223
223
|
* @version 1.6.0 or later
|
|
224
224
|
*/
|
|
225
225
|
EmbedEvent["DialogClose"] = "dialog-close";
|
|
226
|
+
/**
|
|
227
|
+
* Emitted when a liveboard has completed rendering,
|
|
228
|
+
* this event can be used as a hook to trigger events on the
|
|
229
|
+
* rendered liveboard
|
|
230
|
+
* @version 1.9.1 or later
|
|
231
|
+
*/
|
|
232
|
+
EmbedEvent["LiveboardRendered"] = "PinboardRendered";
|
|
226
233
|
})(EmbedEvent || (EmbedEvent = {}));
|
|
227
234
|
/**
|
|
228
235
|
* Event types that can be triggered by the host application
|
|
@@ -327,6 +334,8 @@ export var Param;
|
|
|
327
334
|
Param["ViewPortWidth"] = "viewPortWidth";
|
|
328
335
|
Param["VisibleActions"] = "visibleAction";
|
|
329
336
|
Param["CustomCSSUrl"] = "customCssUrl";
|
|
337
|
+
Param["visibleVizs"] = "pinboardVisibleVizs";
|
|
338
|
+
Param["DisableLoginRedirect"] = "disableLoginRedirect";
|
|
330
339
|
})(Param || (Param = {}));
|
|
331
340
|
/**
|
|
332
341
|
* The list of actions that can be performed on visual ThoughtSpot
|
package/lib/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,qCAAqC;AACrC,MAAM,CAAN,IAAY,QAwBX;AAxBD,WAAY,QAAQ;IAChB;;OAEG;IACH,yBAAa,CAAA;IACb;;OAEG;IACH,4BAAgB,CAAA;IAChB;;OAEG;IACH,6BAAiB,CAAA;IACjB;;OAEG;IACH,qCAAyB,CAAA;IACzB;;;;;OAKG;IACH,2BAAe,CAAA;AACnB,CAAC,EAxBW,QAAQ,KAAR,QAAQ,QAwBnB;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,qCAAqC;AACrC,MAAM,CAAN,IAAY,QAwBX;AAxBD,WAAY,QAAQ;IAChB;;OAEG;IACH,yBAAa,CAAA;IACb;;OAEG;IACH,4BAAgB,CAAA;IAChB;;OAEG;IACH,6BAAiB,CAAA;IACjB;;OAEG;IACH,qCAAyB,CAAA;IACzB;;;;;OAKG;IACH,2BAAe,CAAA;AACnB,CAAC,EAxBW,QAAQ,KAAR,QAAQ,QAwBnB;AAmID;;GAEG;AACH,qCAAqC;AACrC,MAAM,CAAN,IAAY,eAyDX;AAzDD,WAAY,eAAe;IACvB;;OAEG;IACH,4BAAS,CAAA;IACT;;OAEG;IACH,4BAAS,CAAA;IACT;;OAEG;IACH,4BAAS,CAAA;IACT;;OAEG;IACH,4BAAS,CAAA;IACT;;OAEG;IACH,4BAAS,CAAA;IACT;;OAEG;IACH,4BAAS,CAAA;IACT;;OAEG;IACH,wCAAqB,CAAA;IACrB;;OAEG;IACH,8CAA2B,CAAA;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IACH,mCAAyB,CAAA;IACzB;;OAEG;IACH,yCAA+B,CAAA;IAC/B;;OAEG;IACH,qDAA2C,CAAA;IAC3C;;OAEG;IACH,2CAAiC,CAAA;IACjC;;OAEG;IACH,qCAA2B,CAAA;AAC/B,CAAC,EAjFW,MAAM,KAAN,MAAM,QAiFjB;AAQD,qCAAqC;AACrC,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACrB,sDAAqC,CAAA;IACrC,sEAAqD,CAAA;AACzD,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB"}
|
|
@@ -134,7 +134,7 @@ declare module '@thoughtspot/visual-embed-sdk/embed/base' {
|
|
|
134
134
|
*/
|
|
135
135
|
export const prefetch: (url?: string) => void;
|
|
136
136
|
/**
|
|
137
|
-
* Initialize the ThoughtSpot embed
|
|
137
|
+
* Initialize the ThoughtSpot embed SDK globally and perform
|
|
138
138
|
* authentication if applicable.
|
|
139
139
|
* @param embedConfig The configuration object containing ThoughtSpot host,
|
|
140
140
|
* authentication mechanism and so on.
|
|
@@ -203,6 +203,13 @@ declare module '@thoughtspot/visual-embed-sdk/embed/liveboard' {
|
|
|
203
203
|
* Liveboard page will be read-only (no X buttons)
|
|
204
204
|
*/
|
|
205
205
|
preventLiveboardFilterRemoval?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Array of viz ids which should be visible when the liveboard
|
|
208
|
+
* first renders. This can be changed by triggering the "SetVisibleVizs"
|
|
209
|
+
* event.
|
|
210
|
+
* @version 1.9.1 or later
|
|
211
|
+
*/
|
|
212
|
+
visibleVizs?: string[];
|
|
206
213
|
/**
|
|
207
214
|
* To support backward compatibilty
|
|
208
215
|
* @hidden
|
|
@@ -435,6 +442,13 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
|
435
442
|
* @default false
|
|
436
443
|
*/
|
|
437
444
|
autoLogin?: boolean;
|
|
445
|
+
/**
|
|
446
|
+
* Disable redirection to the login page when the embedded session expires
|
|
447
|
+
* This flag is typically used alongside the combination of auth modes such as {@link AuthType.AuthServer} and auto login behavior {@link EmbedConfig.autoLogin}
|
|
448
|
+
* @version SDK: 1.9.3 | ThoughtSpot: 8.1.0.cl
|
|
449
|
+
* @default false
|
|
450
|
+
*/
|
|
451
|
+
disableLoginRedirect?: boolean;
|
|
438
452
|
/**
|
|
439
453
|
* Calls the prefetch method internally when set to true
|
|
440
454
|
* @default false
|
|
@@ -665,7 +679,14 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
|
665
679
|
* Emitted when any modal is closed in the app
|
|
666
680
|
* @version 1.6.0 or later
|
|
667
681
|
*/
|
|
668
|
-
DialogClose = "dialog-close"
|
|
682
|
+
DialogClose = "dialog-close",
|
|
683
|
+
/**
|
|
684
|
+
* Emitted when a liveboard has completed rendering,
|
|
685
|
+
* this event can be used as a hook to trigger events on the
|
|
686
|
+
* rendered liveboard
|
|
687
|
+
* @version 1.9.1 or later
|
|
688
|
+
*/
|
|
689
|
+
LiveboardRendered = "PinboardRendered"
|
|
669
690
|
}
|
|
670
691
|
/**
|
|
671
692
|
* Event types that can be triggered by the host application
|
|
@@ -763,7 +784,9 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
|
763
784
|
ViewPortHeight = "viewPortHeight",
|
|
764
785
|
ViewPortWidth = "viewPortWidth",
|
|
765
786
|
VisibleActions = "visibleAction",
|
|
766
|
-
CustomCSSUrl = "customCssUrl"
|
|
787
|
+
CustomCSSUrl = "customCssUrl",
|
|
788
|
+
visibleVizs = "pinboardVisibleVizs",
|
|
789
|
+
DisableLoginRedirect = "disableLoginRedirect"
|
|
767
790
|
}
|
|
768
791
|
/**
|
|
769
792
|
* The list of actions that can be performed on visual ThoughtSpot
|
package/package.json
CHANGED
package/src/embed/base.ts
CHANGED
|
@@ -52,7 +52,7 @@ export const prefetch = (url?: string): void => {
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* Initialize the ThoughtSpot embed
|
|
55
|
+
* Initialize the ThoughtSpot embed SDK globally and perform
|
|
56
56
|
* authentication if applicable.
|
|
57
57
|
* @param embedConfig The configuration object containing ThoughtSpot host,
|
|
58
58
|
* authentication mechanism and so on.
|
|
@@ -196,4 +196,17 @@ describe('Liveboard/viz embed tests', () => {
|
|
|
196
196
|
);
|
|
197
197
|
});
|
|
198
198
|
});
|
|
199
|
+
test('Should set the visible vizs', async () => {
|
|
200
|
+
const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
|
|
201
|
+
...defaultViewConfig,
|
|
202
|
+
liveboardId,
|
|
203
|
+
visibleVizs: ['abcd', 'pqrs'],
|
|
204
|
+
} as LiveboardViewConfig);
|
|
205
|
+
liveboardEmbed.render();
|
|
206
|
+
await executeAfterWait(() => {
|
|
207
|
+
expect(getIFrameSrc()).toBe(
|
|
208
|
+
`http://${thoughtSpotHost}/?embedApp=true${defaultParams}&pinboardVisibleVizs=[%22abcd%22,%22pqrs%22]${prefixParams}#/embed/viz/${liveboardId}`,
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
199
212
|
});
|
package/src/embed/liveboard.ts
CHANGED
|
@@ -62,6 +62,13 @@ export interface LiveboardViewConfig extends ViewConfig {
|
|
|
62
62
|
* Liveboard page will be read-only (no X buttons)
|
|
63
63
|
*/
|
|
64
64
|
preventLiveboardFilterRemoval?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Array of viz ids which should be visible when the liveboard
|
|
67
|
+
* first renders. This can be changed by triggering the "SetVisibleVizs"
|
|
68
|
+
* event.
|
|
69
|
+
* @version 1.9.1 or later
|
|
70
|
+
*/
|
|
71
|
+
visibleVizs?: string[];
|
|
65
72
|
/**
|
|
66
73
|
* To support backward compatibilty
|
|
67
74
|
* @hidden
|
|
@@ -93,6 +100,7 @@ export class LiveboardEmbed extends V1Embed {
|
|
|
93
100
|
enableVizTransformations,
|
|
94
101
|
fullHeight,
|
|
95
102
|
defaultHeight,
|
|
103
|
+
visibleVizs,
|
|
96
104
|
} = this.viewConfig;
|
|
97
105
|
|
|
98
106
|
const preventLiveboardFilterRemoval =
|
|
@@ -113,6 +121,9 @@ export class LiveboardEmbed extends V1Embed {
|
|
|
113
121
|
if (preventLiveboardFilterRemoval) {
|
|
114
122
|
params[Param.preventLiveboardFilterRemoval] = true;
|
|
115
123
|
}
|
|
124
|
+
if (visibleVizs) {
|
|
125
|
+
params[Param.visibleVizs] = visibleVizs;
|
|
126
|
+
}
|
|
116
127
|
params[Param.livedBoardEmbed] = true;
|
|
117
128
|
const queryParams = getQueryParamString(params, true);
|
|
118
129
|
|
package/src/embed/ts-embed.ts
CHANGED
|
@@ -324,7 +324,11 @@ export class TsEmbed {
|
|
|
324
324
|
queryParams[Param.ViewPortHeight] = window.innerHeight;
|
|
325
325
|
queryParams[Param.ViewPortWidth] = window.innerWidth;
|
|
326
326
|
queryParams[Param.Version] = version;
|
|
327
|
-
|
|
327
|
+
if (this.embedConfig.disableLoginRedirect === true) {
|
|
328
|
+
queryParams[
|
|
329
|
+
Param.DisableLoginRedirect
|
|
330
|
+
] = this.embedConfig.disableLoginRedirect;
|
|
331
|
+
}
|
|
328
332
|
if (this.embedConfig.customCssUrl) {
|
|
329
333
|
queryParams[Param.CustomCSSUrl] = this.embedConfig.customCssUrl;
|
|
330
334
|
}
|
package/src/react/index.spec.tsx
CHANGED
|
@@ -3,13 +3,14 @@ import '@testing-library/jest-dom';
|
|
|
3
3
|
import '@testing-library/jest-dom/extend-expect';
|
|
4
4
|
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react';
|
|
5
5
|
import {
|
|
6
|
+
executeAfterWait,
|
|
6
7
|
getIFrameEl,
|
|
7
8
|
getIFrameSrc,
|
|
8
9
|
postMessageToParent,
|
|
9
10
|
} from '../test/test-utils';
|
|
10
|
-
import { SearchEmbed, AppEmbed,
|
|
11
|
+
import { SearchEmbed, AppEmbed, LiveboardEmbed, useEmbedRef } from './index';
|
|
11
12
|
import { AuthType, init } from '../index';
|
|
12
|
-
import { EmbedEvent } from '../types';
|
|
13
|
+
import { EmbedEvent, HostEvent } from '../types';
|
|
13
14
|
import { version } from '../../package.json';
|
|
14
15
|
|
|
15
16
|
const thoughtSpotHost = 'localhost';
|
|
@@ -25,17 +26,22 @@ describe('React Components', () => {
|
|
|
25
26
|
describe('SearchEmbed', () => {
|
|
26
27
|
it('Should Render the Iframe with props', async () => {
|
|
27
28
|
const { container } = render(
|
|
28
|
-
<SearchEmbed hideDataSources={true} />,
|
|
29
|
+
<SearchEmbed hideDataSources={true} className="embedClass" />,
|
|
29
30
|
);
|
|
30
31
|
|
|
31
32
|
await waitFor(() => getIFrameEl(container));
|
|
32
33
|
|
|
34
|
+
expect(
|
|
35
|
+
getIFrameEl(container).parentElement.classList.contains(
|
|
36
|
+
'embedClass',
|
|
37
|
+
),
|
|
38
|
+
).toBe(true);
|
|
33
39
|
expect(getIFrameSrc(container)).toBe(
|
|
34
40
|
`http://${thoughtSpotHost}/?hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}&hideAction=[%22editACopy%22,%22saveAsView%22,%22updateTSL%22,%22editTSL%22,%22onDeleteAnswer%22]&dataSourceMode=hide&useLastSelectedSources=false&isSearchEmbed=true#/embed/answer`,
|
|
35
41
|
);
|
|
36
42
|
});
|
|
37
43
|
|
|
38
|
-
it('Should attach event listeners', async () => {
|
|
44
|
+
it('Should attach event listeners', async (done) => {
|
|
39
45
|
const userGUID = 'absfdfgd';
|
|
40
46
|
const { container } = render(
|
|
41
47
|
<SearchEmbed
|
|
@@ -44,6 +50,7 @@ describe('React Components', () => {
|
|
|
44
50
|
}}
|
|
45
51
|
onAuthInit={(e) => {
|
|
46
52
|
expect(e.data.userGUID).toEqual(userGUID);
|
|
53
|
+
done();
|
|
47
54
|
}}
|
|
48
55
|
/>,
|
|
49
56
|
);
|
|
@@ -63,7 +70,47 @@ describe('React Components', () => {
|
|
|
63
70
|
//
|
|
64
71
|
});
|
|
65
72
|
|
|
66
|
-
describe('
|
|
73
|
+
describe('LiveboardEmbed', () => {
|
|
67
74
|
//
|
|
75
|
+
it('Should be able to trigger events on the embed using refs', async () => {
|
|
76
|
+
const TestComponent = () => {
|
|
77
|
+
const embedRef = useEmbedRef();
|
|
78
|
+
const onLiveboardRendered = () => {
|
|
79
|
+
embedRef.current.trigger(HostEvent.SetVisibleVizs, [
|
|
80
|
+
'viz1',
|
|
81
|
+
'viz2',
|
|
82
|
+
]);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<LiveboardEmbed
|
|
87
|
+
ref={embedRef}
|
|
88
|
+
liveboardId="abcd"
|
|
89
|
+
onLiveboardRendered={onLiveboardRendered}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const { container } = render(<TestComponent />);
|
|
95
|
+
|
|
96
|
+
await waitFor(() => getIFrameEl(container));
|
|
97
|
+
const iframe = getIFrameEl(container);
|
|
98
|
+
jest.spyOn(iframe.contentWindow, 'postMessage');
|
|
99
|
+
postMessageToParent(iframe.contentWindow, {
|
|
100
|
+
type: EmbedEvent.LiveboardRendered,
|
|
101
|
+
data: {
|
|
102
|
+
userGUID: 'abcd',
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
await executeAfterWait(() => {
|
|
106
|
+
expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
|
|
107
|
+
{
|
|
108
|
+
type: HostEvent.SetVisibleVizs,
|
|
109
|
+
data: ['viz1', 'viz2'],
|
|
110
|
+
},
|
|
111
|
+
`http://${thoughtSpotHost}`,
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
68
115
|
});
|
|
69
116
|
});
|
package/src/react/index.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '../embed/liveboard';
|
|
8
8
|
import { TsEmbed, ViewConfig } from '../embed/ts-embed';
|
|
9
9
|
|
|
10
|
-
import { EmbedEvent
|
|
10
|
+
import { EmbedEvent } from '../types';
|
|
11
11
|
import { EmbedProps, getViewPropsAndListeners } from './util';
|
|
12
12
|
|
|
13
13
|
const componentFactory = <
|
|
@@ -16,28 +16,41 @@ const componentFactory = <
|
|
|
16
16
|
V extends ViewConfig
|
|
17
17
|
>(
|
|
18
18
|
EmbedConstructor: T,
|
|
19
|
-
) =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
eventName
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
19
|
+
) =>
|
|
20
|
+
React.forwardRef<TsEmbed, U>(
|
|
21
|
+
(props: U, forwardedRef: React.MutableRefObject<TsEmbed>) => {
|
|
22
|
+
const ref = React.useRef<HTMLDivElement>(null);
|
|
23
|
+
const { className, ...embedProps } = props;
|
|
24
|
+
const { viewConfig, listeners } = getViewPropsAndListeners<
|
|
25
|
+
Omit<U, 'className'>,
|
|
26
|
+
V
|
|
27
|
+
>(embedProps);
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
const tsEmbed = new EmbedConstructor(ref!.current, {
|
|
30
|
+
...viewConfig,
|
|
31
|
+
});
|
|
32
|
+
Object.keys(listeners).forEach((eventName) => {
|
|
33
|
+
tsEmbed.on(
|
|
34
|
+
eventName as EmbedEvent,
|
|
35
|
+
listeners[eventName as EmbedEvent],
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
tsEmbed.render();
|
|
39
|
+
if (forwardedRef) {
|
|
40
|
+
// eslint-disable-next-line no-param-reassign
|
|
41
|
+
forwardedRef.current = tsEmbed;
|
|
42
|
+
}
|
|
43
|
+
}, [embedProps]);
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
return (
|
|
46
|
+
<div
|
|
47
|
+
data-testid="tsEmbed"
|
|
48
|
+
ref={ref}
|
|
49
|
+
className={className}
|
|
50
|
+
></div>
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
);
|
|
41
54
|
|
|
42
55
|
interface SearchProps extends EmbedProps, SearchViewConfig {}
|
|
43
56
|
|
|
@@ -68,3 +81,7 @@ export const PinboardEmbed = componentFactory<
|
|
|
68
81
|
LiveboardProps,
|
|
69
82
|
LiveboardViewConfig
|
|
70
83
|
>(_LiveboardEmbed);
|
|
84
|
+
|
|
85
|
+
export const useEmbedRef = (): React.MutableRefObject<TsEmbed> => {
|
|
86
|
+
return React.useRef<TsEmbed>(null);
|
|
87
|
+
};
|
package/src/react/util.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { EmbedEvent, MessageCallback } from '../types';
|
|
|
2
2
|
import { ViewConfig } from '../embed/ts-embed';
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line prettier/prettier
|
|
5
|
-
export type EmbedEventHandlers = { [key in EmbedEvent as `on${Capitalize<key>}`]?: MessageCallback };
|
|
5
|
+
export type EmbedEventHandlers = { [key in keyof typeof EmbedEvent as `on${Capitalize<key>}`]?: MessageCallback };
|
|
6
|
+
|
|
6
7
|
|
|
7
8
|
export interface EmbedProps extends ViewConfig, EmbedEventHandlers {
|
|
8
9
|
className?: string;
|
package/src/types.ts
CHANGED
|
@@ -123,6 +123,14 @@ export interface EmbedConfig {
|
|
|
123
123
|
*/
|
|
124
124
|
autoLogin?: boolean;
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Disable redirection to the login page when the embedded session expires
|
|
128
|
+
* This flag is typically used alongside the combination of auth modes such as {@link AuthType.AuthServer} and auto login behavior {@link EmbedConfig.autoLogin}
|
|
129
|
+
* @version SDK: 1.9.3 | ThoughtSpot: 8.1.0.cl
|
|
130
|
+
* @default false
|
|
131
|
+
*/
|
|
132
|
+
disableLoginRedirect?: boolean;
|
|
133
|
+
|
|
126
134
|
/**
|
|
127
135
|
* Calls the prefetch method internally when set to true
|
|
128
136
|
* @default false
|
|
@@ -364,6 +372,13 @@ export enum EmbedEvent {
|
|
|
364
372
|
* @version 1.6.0 or later
|
|
365
373
|
*/
|
|
366
374
|
DialogClose = 'dialog-close',
|
|
375
|
+
/**
|
|
376
|
+
* Emitted when a liveboard has completed rendering,
|
|
377
|
+
* this event can be used as a hook to trigger events on the
|
|
378
|
+
* rendered liveboard
|
|
379
|
+
* @version 1.9.1 or later
|
|
380
|
+
*/
|
|
381
|
+
LiveboardRendered = 'PinboardRendered',
|
|
367
382
|
}
|
|
368
383
|
|
|
369
384
|
/**
|
|
@@ -468,6 +483,8 @@ export enum Param {
|
|
|
468
483
|
ViewPortWidth = 'viewPortWidth',
|
|
469
484
|
VisibleActions = 'visibleAction',
|
|
470
485
|
CustomCSSUrl = 'customCssUrl',
|
|
486
|
+
visibleVizs = 'pinboardVisibleVizs',
|
|
487
|
+
DisableLoginRedirect = 'disableLoginRedirect',
|
|
471
488
|
}
|
|
472
489
|
|
|
473
490
|
/**
|