@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
55 lines • 2.56 kB
JavaScript
import { ErrorDetailsTypes, EmbedErrorCodes } from '../types';
import { validateHttpUrl } from '../utils';
import { ERROR_MESSAGE } from '../errors';
/**
* Resolves enablePastConversationsSidebar with
* spotterSidebarConfig taking precedence over the
* standalone flag.
*/
export const resolveEnablePastConversationsSidebar = (params) => (params.spotterSidebarConfigValue !== undefined
? params.spotterSidebarConfigValue
: params.standaloneValue);
export function buildSpotterSidebarAppInitData(defaultAppInitData, viewConfig, handleError) {
const { spotterSidebarConfig, enablePastConversationsSidebar, visualOverrides } = viewConfig;
const resolvedEnablePastConversations = resolveEnablePastConversationsSidebar({
spotterSidebarConfigValue: spotterSidebarConfig === null || spotterSidebarConfig === void 0 ? void 0 : spotterSidebarConfig.enablePastConversationsSidebar,
standaloneValue: enablePastConversationsSidebar,
});
const hasConfig = spotterSidebarConfig || resolvedEnablePastConversations !== undefined;
if (!hasConfig) {
if (visualOverrides === undefined) {
return defaultAppInitData;
}
return {
...defaultAppInitData,
embedParams: { visualOverridesParams: visualOverrides },
};
}
const resolvedSidebarConfig = {
...spotterSidebarConfig,
...(resolvedEnablePastConversations !== undefined && {
enablePastConversationsSidebar: resolvedEnablePastConversations,
}),
};
if (resolvedSidebarConfig.spotterDocumentationUrl !== undefined) {
const [isValid, validationError] = validateHttpUrl(resolvedSidebarConfig.spotterDocumentationUrl);
if (!isValid) {
handleError({
errorType: ErrorDetailsTypes.VALIDATION_ERROR,
message: ERROR_MESSAGE.INVALID_SPOTTER_DOCUMENTATION_URL,
code: EmbedErrorCodes.INVALID_URL,
error: (validationError === null || validationError === void 0 ? void 0 : validationError.message) || ERROR_MESSAGE.INVALID_SPOTTER_DOCUMENTATION_URL,
});
delete resolvedSidebarConfig.spotterDocumentationUrl;
}
}
return {
...defaultAppInitData,
embedParams: {
...(defaultAppInitData.embedParams || {}),
spotterSidebarConfig: resolvedSidebarConfig,
...(visualOverrides !== undefined ? { visualOverridesParams: visualOverrides } : {}),
},
};
}
//# sourceMappingURL=spotter-utils.js.map