UNPKG

@thoughtspot/visual-embed-sdk

Version:
116 lines 4.75 kB
import isUndefined from 'lodash/isUndefined'; import { ERROR_MESSAGE } from '../errors'; import { Param, ErrorDetailsTypes, EmbedErrorCodes } from '../types'; import { TsEmbed } from './ts-embed'; import { getQueryParamString, getFilterQuery, getRuntimeParameters } from '../utils'; /** * Embed ThoughtSpot AI Conversation. * @group Embed components * @example * ```js * const conversation = new SpotterEmbed('#tsEmbed', { * worksheetId: 'worksheetId', * searchOptions: { * searchQuery: 'searchQuery', * }, * }); * conversation.render(); * ``` * @version SDK: 1.37.0 | ThoughtSpot: 10.9.0.cl */ export class SpotterEmbed extends TsEmbed { constructor(container, viewConfig) { viewConfig.embedComponentType = 'conversation'; super(container, viewConfig); this.viewConfig = viewConfig; } getEmbedParamsObject() { const { worksheetId, searchOptions, disableSourceSelection, hideSourceSelection, dataPanelV2, showSpotterLimitations, hideSampleQuestions, enablePastConversationsSidebar, runtimeFilters, excludeRuntimeFiltersfromURL, runtimeParameters, excludeRuntimeParametersfromURL, updatedSpotterChatPrompt, } = this.viewConfig; if (!worksheetId) { this.handleError({ errorType: ErrorDetailsTypes.VALIDATION_ERROR, message: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, code: EmbedErrorCodes.WORKSHEET_ID_NOT_FOUND, error: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, }); } const queryParams = this.getBaseQueryParams(); queryParams[Param.SpotterEnabled] = true; if (!isUndefined(disableSourceSelection)) { queryParams[Param.DisableSourceSelection] = !!disableSourceSelection; } if (!isUndefined(hideSourceSelection)) { queryParams[Param.HideSourceSelection] = !!hideSourceSelection; } if (!isUndefined(dataPanelV2)) { queryParams[Param.DataPanelV2Enabled] = !!dataPanelV2; } if (!isUndefined(showSpotterLimitations)) { queryParams[Param.ShowSpotterLimitations] = !!showSpotterLimitations; } if (!isUndefined(hideSampleQuestions)) { queryParams[Param.HideSampleQuestions] = !!hideSampleQuestions; } if (!isUndefined(updatedSpotterChatPrompt)) { queryParams[Param.UpdatedSpotterChatPrompt] = !!updatedSpotterChatPrompt; } return queryParams; } getIframeSrc() { const { worksheetId, searchOptions, runtimeFilters, excludeRuntimeFiltersfromURL, runtimeParameters, excludeRuntimeParametersfromURL, enablePastConversationsSidebar, } = this.viewConfig; const path = 'insights/conv-assist'; const queryParams = this.getEmbedParamsObject(); if (!isUndefined(enablePastConversationsSidebar)) { queryParams[Param.EnablePastConversationsSidebar] = !!enablePastConversationsSidebar; } let query = ''; const queryParamsString = getQueryParamString(queryParams, true); if (queryParamsString) { query = `?${queryParamsString}`; } const filterQuery = getFilterQuery(runtimeFilters || []); if (filterQuery && !excludeRuntimeFiltersfromURL) { query += `&${filterQuery}`; } const parameterQuery = getRuntimeParameters(runtimeParameters || []); if (parameterQuery && !excludeRuntimeParametersfromURL) { query += `&${parameterQuery}`; } const tsPostHashParams = this.getThoughtSpotPostUrlParams({ worksheet: worksheetId, query: (searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.searchQuery) || '', }); return `${this.getEmbedBasePath(query)}/embed/${path}${tsPostHashParams}`; } async render() { await super.render(); const src = this.getIframeSrc(); await this.renderIFrame(src); return this; } } /** * Embed ThoughtSpot AI Conversation. * @deprecated from SDK: 1.39.0 | ThoughtSpot: 10.10.0.cl * Use {@link SpotterEmbed} instead * @group Embed components * @example * ```js * const conversation = new SpotterEmbed('#tsEmbed', { * worksheetId: 'worksheetId', * searchOptions: { * searchQuery: 'searchQuery', * }, * }); * conversation.render(); * ``` * @version SDK: 1.37.0 | ThoughtSpot: 10.9.0.cl */ export class ConversationEmbed extends SpotterEmbed { constructor(container, viewConfig) { viewConfig.embedComponentType = 'conversation'; super(container, viewConfig); this.viewConfig = viewConfig; } } //# sourceMappingURL=conversation.js.map