@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
85 lines • 3.65 kB
JavaScript
/**
* Copyright (c) 2023
*
* Embed ThoughtSpot Sage
* @summary TS Sage embed
* @author Mourya Balabhadra <mourya.balabhadra@thoughtspot.com>
*/
import { Param } from '../types';
import { getQueryParamString } from '../utils';
import { V1Embed } from './ts-embed';
/**
* Embed ThoughtSpot LLM and GPT-based Natural Language Search component.
* @version: SDK: 1.23.0 | ThoughtSpot: 9.4.0.cl, 9.5.1-sw
*
* Note: This embed will be deprecated from SDK: 1.40.0 | ThoughtSpot: 10.13.0.cl
* @group Embed components
*/
export class SageEmbed extends V1Embed {
// eslint-disable-next-line no-useless-constructor
constructor(domSelector, viewConfig) {
viewConfig.embedComponentType = 'SageEmbed';
super(domSelector, viewConfig);
}
getEmbedParamsObject() {
const { disableWorksheetChange, hideWorksheetSelector, showObjectSuggestions, dataPanelV2, hideSampleQuestions, isProductTour, hideSageAnswerHeader, hideAutocompleteSuggestions, } = this.viewConfig;
const params = this.getBaseQueryParams();
params[Param.DataPanelV2Enabled] = !!dataPanelV2;
params[Param.IsSageEmbed] = true;
params[Param.DisableWorksheetChange] = !!disableWorksheetChange;
params[Param.HideWorksheetSelector] = !!hideWorksheetSelector;
params[Param.HideEurekaSuggestions] = !!hideAutocompleteSuggestions;
if (showObjectSuggestions) {
params[Param.HideEurekaSuggestions] = !showObjectSuggestions;
// support backwards compatibility
}
params[Param.HideSampleQuestions] = !!hideSampleQuestions;
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
*/
getEmbedParams() {
const params = this.getEmbedParamsObject();
return getQueryParamString(params, true);
}
/**
* Construct the URL of the embedded ThoughtSpot sage to be
* loaded in the iframe
* @returns {string} iframe url
*/
getIFrameSrc() {
const path = 'eureka';
const postHashObj = {};
const tsPostHashParams = this.getThoughtSpotPostUrlParams();
const { dataSource, searchOptions, } = this.viewConfig;
if (dataSource)
postHashObj[Param.WorksheetId] = dataSource;
if ((searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.searchQuery) && searchOptions.executeSearch) {
postHashObj[Param.executeSearch] = true;
}
let sagePostHashParams = new URLSearchParams(postHashObj).toString();
if (sagePostHashParams)
sagePostHashParams = `${tsPostHashParams ? '&' : '?'}${sagePostHashParams}`;
if (searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.searchQuery)
sagePostHashParams += `${sagePostHashParams ? '&' : '?'}${[Param.Query]}=${encodeURIComponent(searchOptions.searchQuery)}`;
// use encodeURIComponent for query instead of URLSearchParams
// as it adds + instead of %20 for spaces
return `${this.getRootIframeSrc()}/embed/${path}${tsPostHashParams}${sagePostHashParams}`;
}
/**
* Render the embedded ThoughtSpot Sage
* @returns {SageEmbed} Eureka/Sage embed
*/
async render() {
await super.render();
const src = this.getIFrameSrc();
await this.renderV1Embed(src);
return this;
}
}
//# sourceMappingURL=sage.js.map