@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
78 lines • 3.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SearchBarEmbed = void 0;
const types_1 = require("../types");
const utils_1 = require("../utils");
const ts_embed_1 = require("./ts-embed");
/**
* Embed ThoughtSpot search bar
* @version: SDK: 1.18.0 | ThoughtSpot: 8.10.0.cl, 9.0.1-sw
* @group Embed components
*/
class SearchBarEmbed extends ts_embed_1.TsEmbed {
constructor(domSelector, viewConfig) {
super(domSelector);
this.embedComponentType = 'SearchBarEmbed';
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
*/
getIFrameSrc() {
var _a;
const { searchOptions, dataSource, dataSources, useLastSelectedSources = false, excludeSearchTokenStringFromURL, } = this.viewConfig;
const path = 'search-bar-embed';
const queryParams = this.getBaseQueryParams();
queryParams[types_1.Param.HideActions] = [...((_a = queryParams[types_1.Param.HideActions]) !== null && _a !== void 0 ? _a : [])];
if (dataSources && dataSources.length) {
queryParams[types_1.Param.DataSources] = JSON.stringify(dataSources);
}
if (dataSource) {
queryParams[types_1.Param.DataSources] = `["${dataSource}"]`;
}
if (searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.searchTokenString) {
if (!excludeSearchTokenStringFromURL) {
queryParams[types_1.Param.searchTokenString] = encodeURIComponent(searchOptions.searchTokenString);
}
if (searchOptions.executeSearch) {
queryParams[types_1.Param.executeSearch] = true;
}
}
queryParams[types_1.Param.UseLastSelectedDataSource] = useLastSelectedSources;
if (dataSource || dataSources) {
queryParams[types_1.Param.UseLastSelectedDataSource] = false;
}
queryParams[types_1.Param.searchEmbed] = true;
let query = '';
const queryParamsString = (0, utils_1.getQueryParamString)(queryParams, true);
if (queryParamsString) {
query = `?${queryParamsString}`;
}
const tsPostHashParams = this.getThoughtSpotPostUrlParams();
return `${this.getEmbedBasePath(query)}/embed/${path}${tsPostHashParams}`;
}
/**
* Render the embedded ThoughtSpot search
*/
async render() {
await super.render();
const src = this.getIFrameSrc();
await this.renderIFrame(src);
return this;
}
getSearchInitData() {
return {
searchOptions: this.viewConfig.excludeSearchTokenStringFromURL
? this.viewConfig.searchOptions
: null,
};
}
async getAppInitData() {
const defaultAppInitData = await super.getAppInitData();
return { ...defaultAppInitData, ...this.getSearchInitData() };
}
}
exports.SearchBarEmbed = SearchBarEmbed;
//# sourceMappingURL=search-bar.js.map