UNPKG

@thoughtspot/visual-embed-sdk

Version:
74 lines 2.89 kB
import { Param } from '../types'; import { getQueryParamString } from '../utils'; import { TsEmbed } from './ts-embed'; /** * Embed ThoughtSpot search bar * @version: SDK: 1.18.0 | ThoughtSpot: 8.10.0.cl, 9.0.1-sw * @group Embed components */ export class SearchBarEmbed extends 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[Param.HideActions] = [...((_a = queryParams[Param.HideActions]) !== null && _a !== void 0 ? _a : [])]; if (dataSources && dataSources.length) { queryParams[Param.DataSources] = JSON.stringify(dataSources); } if (dataSource) { queryParams[Param.DataSources] = `["${dataSource}"]`; } if (searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.searchTokenString) { if (!excludeSearchTokenStringFromURL) { queryParams[Param.searchTokenString] = encodeURIComponent(searchOptions.searchTokenString); } if (searchOptions.executeSearch) { queryParams[Param.executeSearch] = true; } } queryParams[Param.UseLastSelectedDataSource] = useLastSelectedSources; if (dataSource || dataSources) { queryParams[Param.UseLastSelectedDataSource] = false; } queryParams[Param.searchEmbed] = true; let query = ''; const queryParamsString = 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() }; } } //# sourceMappingURL=search-bar.js.map