Skip to content
Merged
11 changes: 8 additions & 3 deletions src/embed/bodyless-conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export class ConversationMessage extends TsEmbed {
super(container, viewConfig);
}

protected getEmbedParamsObject() {
const queryParams = this.getBaseQueryParams();
queryParams[Param.HideActions] = [...(queryParams[Param.HideActions] ?? [])];
queryParams[Param.isSpotterAgentEmbed] = true;
return queryParams;
}

public getIframeSrc() {
const {
sessionId,
Expand All @@ -49,10 +56,8 @@ export class ConversationMessage extends TsEmbed {
messageId,
} = this.viewConfig;
const path = 'conv-assist-answer';
const queryParams = this.getBaseQueryParams();
const queryParams = this.getEmbedParamsObject();

queryParams[Param.HideActions] = [...(queryParams[Param.HideActions] ?? [])];
queryParams[Param.isSpotterAgentEmbed] = true;
let query = '';
const queryParamsString = getQueryParamString(queryParams, true);
if (queryParamsString) {
Expand Down
19 changes: 17 additions & 2 deletions src/embed/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class SpotterEmbed extends TsEmbed {
super(container, viewConfig);
}

public getIframeSrc(): string {
protected getEmbedParamsObject() {
const {
worksheetId,
searchOptions,
Expand All @@ -210,7 +210,7 @@ export class SpotterEmbed extends TsEmbed {
runtimeParameters,
excludeRuntimeParametersfromURL,
} = this.viewConfig;
const path = 'insights/conv-assist';

if (!worksheetId) {
this.handleError(ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND);
}
Expand All @@ -235,6 +235,21 @@ export class SpotterEmbed extends TsEmbed {
queryParams[Param.HideSampleQuestions] = !!hideSampleQuestions;
}

return queryParams;
}

public getIframeSrc(): string {
const {
worksheetId,
searchOptions,
runtimeFilters,
excludeRuntimeFiltersfromURL,
runtimeParameters,
excludeRuntimeParametersfromURL,
} = this.viewConfig;
const path = 'insights/conv-assist';
const queryParams = this.getEmbedParamsObject();

let query = '';
const queryParamsString = getQueryParamString(queryParams, true);
if (queryParamsString) {
Expand Down
14 changes: 14 additions & 0 deletions src/embed/liveboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ describe('Liveboard/viz embed tests', () => {
test('navigateToLiveboard should trigger the navigate event with the correct path', async (done) => {
mockMessageChannel();
// mock getSessionInfo

mockGetSessionInfo();
const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
...defaultViewConfig,
Expand Down Expand Up @@ -684,6 +685,13 @@ describe('Liveboard/viz embed tests', () => {
mockMessageChannel();

// mock getSessionInfo
jest.spyOn(SessionInfoService, 'getSessionInfo').mockResolvedValue({
releaseVersion: '1.0.0',
userGUID: '1234567890',
currentOrgId: 1,
privileges: [],
mixpanelToken: '1234567890',
});
mockGetSessionInfo();

const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
Expand Down Expand Up @@ -764,6 +772,12 @@ describe('Liveboard/viz embed tests', () => {
});

describe('PreRender flow for liveboard embed', () => {
beforeAll(() => {
init({
thoughtSpotHost: "http://tshost",
authType: AuthType.None,
});
});
test('it should preRender generic with liveboard id is not passed', async (done) => {
const consoleSpy = jest.spyOn(console, 'error');
const libEmbed = new LiveboardEmbed(getRootEl(), {
Expand Down
8 changes: 7 additions & 1 deletion src/embed/liveboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
*/
isLiveboardStylingAndGroupingEnabled?: boolean;
/**
* This flag is used to enable/disable the png embedding of liveboard in scheduled mails

Check warning on line 328 in src/embed/liveboard.ts

View workflow job for this annotation

GitHub Actions / build

Comments may not exceed 90 characters
*
* Supported embed types: `AppEmbed`, `LiveboardEmbed`
* @type {boolean}
Expand Down Expand Up @@ -424,6 +424,12 @@
* embedded Liveboard or visualization.
*/
protected getEmbedParams() {
const params = this.getEmbedParamsObject();
const queryParams = getQueryParamString(params, true);
return queryParams;
}

protected getEmbedParamsObject() {
let params: any = {};
params = this.getBaseQueryParams(params);
const {
Expand Down Expand Up @@ -536,7 +542,7 @@
params[Param.LiveboardXLSXCSVDownload] = !!liveboardXLSXCSVDownload;
const queryParams = getQueryParamString(params, true);

return queryParams;
return params;
}

private getIframeSuffixSrc(liveboardId: string, vizId: string, activeTabId: string) {
Expand Down
19 changes: 12 additions & 7 deletions src/embed/sage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,7 @@ export class SageEmbed extends V1Embed {
super(domSelector, viewConfig);
}

/**
* Constructs a map of parameters to be passed on to the
* embedded Eureka or Sage search page.
* @returns {string} query string
*/
protected getEmbedParams(): string {
protected getEmbedParamsObject() {
const {
disableWorksheetChange,
hideWorksheetSelector,
Expand All @@ -184,6 +179,16 @@ export class SageEmbed extends V1Embed {
params[Param.IsProductTour] = !!isProductTour;
params[Param.HideSageAnswerHeader] = !!hideSageAnswerHeader;

return params;
}

/**
* Constructs a map of parameters to be passed on to the
* embedded Eureka or Sage search page.
* @returns {string} query string
*/
protected getEmbedParams(): string {
const params = this.getEmbedParamsObject();
return getQueryParamString(params, true);
}

Expand All @@ -194,7 +199,7 @@ export class SageEmbed extends V1Embed {
*/
public getIFrameSrc(): string {
const path = 'eureka';
const postHashObj = {};
const postHashObj: Record<string, any> = {};
const tsPostHashParams = this.getThoughtSpotPostUrlParams();
const {
dataSource, searchOptions,
Expand Down
21 changes: 14 additions & 7 deletions src/embed/search-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,14 @@ export class SearchBarEmbed extends TsEmbed {
this.viewConfig = viewConfig;
}

/**
* Construct the URL of the embedded ThoughtSpot search to be
* loaded in the iframe
* @param dataSources A list of data source GUIDs
*/
private getIFrameSrc() {
protected getEmbedParamsObject() {
const {
searchOptions,
dataSource,
dataSources,
useLastSelectedSources = false,
excludeSearchTokenStringFromURL,
} = this.viewConfig;
const path = 'search-bar-embed';
const queryParams = this.getBaseQueryParams();

queryParams[Param.HideActions] = [...(queryParams[Param.HideActions] ?? [])];
Expand Down Expand Up @@ -159,6 +153,19 @@ export class SearchBarEmbed extends TsEmbed {
queryParams[Param.UseLastSelectedDataSource] = false;
}
queryParams[Param.searchEmbed] = true;

return queryParams;
}

/**
* Construct the URL of the embedded ThoughtSpot search to be
* loaded in the iframe
* @param dataSources A list of data source GUIDs
*/
private getIFrameSrc() {
const queryParams = this.getEmbedParamsObject();
const path = 'search-bar-embed';

let query = '';
const queryParamsString = getQueryParamString(queryParams, true);
if (queryParamsString) {
Expand Down
25 changes: 18 additions & 7 deletions src/embed/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export const HiddenActionItemByDefaultForSearchEmbed = [
];

export interface SearchAppInitData extends DefaultAppInitData {
searchOptions?: SearchOptions;
searchOptions?: SearchOptions;
}

/**
Expand Down Expand Up @@ -381,7 +381,7 @@ export class SearchEmbed extends TsEmbed {
return { ...defaultAppInitData, ...this.getSearchInitData() };
}

protected getEmbedParams(): string {
protected getEmbedParamsObject() {
const {
hideResults,
enableSearchAssist,
Expand All @@ -398,7 +398,7 @@ export class SearchEmbed extends TsEmbed {
collapseSearchBarInitially = false,
enableCustomColumnGroups = false,
isOnBeforeGetVizDataInterceptEnabled = false,
/* eslint-disable-next-line max-len */

dataPanelCustomGroupsAccordionInitialState = DataPanelCustomColumnGroupsAccordionState.EXPAND_ALL,
focusSearchBarOnRender = true,
excludeRuntimeParametersfromURL,
Expand Down Expand Up @@ -443,7 +443,7 @@ export class SearchEmbed extends TsEmbed {
}

if (isOnBeforeGetVizDataInterceptEnabled) {
/* eslint-disable-next-line max-len */

queryParams[Param.IsOnBeforeGetVizDataInterceptEnabled] = isOnBeforeGetVizDataInterceptEnabled;
}

Expand All @@ -460,20 +460,31 @@ export class SearchEmbed extends TsEmbed {
}

queryParams[Param.searchEmbed] = true;
/* eslint-disable-next-line max-len */

queryParams[Param.CollapseSearchBarInitially] = collapseSearchBarInitially || collapseSearchBar;
queryParams[Param.EnableCustomColumnGroups] = enableCustomColumnGroups;
if (dataPanelCustomGroupsAccordionInitialState
=== DataPanelCustomColumnGroupsAccordionState.COLLAPSE_ALL
|| dataPanelCustomGroupsAccordionInitialState
=== DataPanelCustomColumnGroupsAccordionState.EXPAND_FIRST
) {
/* eslint-disable-next-line max-len */

queryParams[Param.DataPanelCustomGroupsAccordionInitialState] = dataPanelCustomGroupsAccordionInitialState;
} else {
/* eslint-disable-next-line max-len */

queryParams[Param.DataPanelCustomGroupsAccordionInitialState] = DataPanelCustomColumnGroupsAccordionState.EXPAND_ALL;
}
return queryParams;
}

protected getEmbedParams() {
const {
runtimeParameters,
runtimeFilters,
excludeRuntimeParametersfromURL,
excludeRuntimeFiltersfromURL,
} = this.viewConfig;
const queryParams = this.getEmbedParamsObject();
let query = '';
const queryParamsString = getQueryParamString(queryParams, true);
if (queryParamsString) {
Expand Down
2 changes: 1 addition & 1 deletion src/embed/ts-embed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2488,7 +2488,7 @@ describe('Unit test case for ts embed', () => {
});

afterAll((): void => {
window.location = location;
window.location = location as any;
});

it('get url params for TS', () => {
Expand Down
40 changes: 28 additions & 12 deletions src/embed/ts-embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ export class TsEmbed {
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_EMBED_CREATE, {
...viewConfig,
});
const embedConfig = getEmbedConfig();
this.embedConfig = embedConfig;

this.hostEventClient = new HostEventClient(this.iFrame);

this.isReadyForRenderPromise = getInitPromise().then(async () => {
const embedConfig = getEmbedConfig();
this.embedConfig = embedConfig;
if (!embedConfig.authTriggerContainer && !embedConfig.useEventForSAMLPopup) {
this.embedConfig.authTriggerContainer = domSelector;
}
Expand Down Expand Up @@ -494,10 +494,10 @@ export class TsEmbed {
this.on(EmbedEvent.APP_INIT, this.appInitCb, { start: false }, true);
this.on(EmbedEvent.AuthExpire, this.updateAuthToken, { start: false }, true);
this.on(EmbedEvent.IdleSessionTimeout, this.idleSessionTimeout, { start: false }, true);
const embedListenerReadyHandler = this.createEmbedContainerHandler(EmbedEvent.EmbedListenerReady);

const embedListenerReadyHandler = this.createEmbedContainerHandler(EmbedEvent.EmbedListenerReady);
this.on(EmbedEvent.EmbedListenerReady, embedListenerReadyHandler, { start: false }, true);

const authInitHandler = this.createEmbedContainerHandler(EmbedEvent.AuthInit);
this.on(EmbedEvent.AuthInit, authInitHandler, { start: false }, true);
};
Expand All @@ -520,6 +520,12 @@ export class TsEmbed {
return `${basePath}#`;
}

protected getUpdateEmbedParamsObject() {
let queryParams = this.getEmbedParamsObject();
queryParams = { ...this.viewConfig, ...queryParams };
return queryParams;
}

/**
* Common query params set for all the embed modes.
* @param queryParams
Expand Down Expand Up @@ -702,10 +708,15 @@ export class TsEmbed {
}

protected getEmbedParams() {
const queryParams = this.getBaseQueryParams();
const queryParams = this.getEmbedParamsObject();
return getQueryParamString(queryParams);
}

protected getEmbedParamsObject() {
const params = this.getBaseQueryParams();
return params;
}

protected getRootIframeSrc() {
const query = this.getEmbedParams();
return this.getEmbedBasePath(query);
Expand Down Expand Up @@ -1140,12 +1151,12 @@ export class TsEmbed {
}
}

/**
/**
* @hidden
* Internal state to track if the embed container is loaded.
* This is used to trigger events after the embed container is loaded.
*/
public isEmbedContainerLoaded = false;
public isEmbedContainerLoaded = false;

/**
* @hidden
Expand Down Expand Up @@ -1191,7 +1202,7 @@ export class TsEmbed {
} else {
logger.debug('pushing callback to embedContainerReadyCallbacks', callback);
this.embedContainerReadyCallbacks.push(callback);
}
}
}

protected createEmbedContainerHandler = (source: EmbedEvent.AuthInit | EmbedEvent.EmbedListenerReady) => () => {
Expand Down Expand Up @@ -1279,6 +1290,7 @@ export class TsEmbed {
* Creates the preRender shell
* @param showPreRenderByDefault - Show the preRender after render, hidden by default
*/

public async preRender(showPreRenderByDefault = false, replaceExistingPreRender = false): Promise<TsEmbed> {
if (!this.viewConfig.preRenderId) {
logger.error(ERROR_MESSAGE.PRERENDER_ID_MISSING);
Expand Down Expand Up @@ -1413,8 +1425,14 @@ export class TsEmbed {
return this.preRender(true);
}
this.validatePreRenderViewConfig(this.viewConfig);
logger.debug('triggering UpdateEmbedParams', this.viewConfig);
this.executeAfterEmbedContainerLoaded(() => {
this.trigger(HostEvent.UpdateEmbedParams, this.getUpdateEmbedParamsObject());
});
}

this.beforePrerenderVisible();

if (this.el) {
this.syncPreRenderStyle();
if (!this.viewConfig.doNotTrackPreRenderSize) {
Expand All @@ -1432,8 +1450,6 @@ export class TsEmbed {
}
}

this.beforePrerenderVisible();

removeStyleProperties(this.preRenderWrapper, ['z-index', 'opacity', 'pointer-events']);

this.subscribeToEvents();
Expand Down
Loading
Loading