All files / src/embed app.ts

80% Statements 16/20
37.5% Branches 3/8
100% Functions 4/4
80% Lines 16/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73                    3x     3x 3x 3x 3x 3x 3x                   3x           1x               1x   1x                                     1x   1x 1x 1x   1x      
/**
 * Copyright (c) 2021
 *
 * Full application embedding
 * https://docs.thoughtspot.com/5.2/app-integrate/embedding-viz/about-full-embed.html
 *
 * @summary Full app embed
 * @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
 */
 
import { V1Embed } from './base';
 
// eslint-disable-next-line no-shadow
export enum Page {
    Home = 'home',
    Search = 'search',
    Answers = 'answers',
    Pinboards = 'pinboards',
    Data = 'data',
}
 
export interface AppRenderOptions {
    pageId: Page;
}
 
/**
 * Embed a page within the ThoughtSpot app
 */
export class AppEmbed extends V1Embed {
    /**
     * Construct the URL of the ThoughtSpot app page to be rendered
     * @param pageId The id of the page to be embedded
     */
    private getIFrameSrc(pageId: string) {
        return `${this.getV1EmbedBasePath(null, true)}/${pageId}`;
    }
 
    /**
     * Get the ThoughtSpot route of the page for a particular page id
     * @param pageId The identifier for a page in the ThoughtSpot app
     */
    private getPageRoute(pageId: Page) {
        switch (pageId) {
            case Page.Search:
                return 'answer';
            case Page.Answers:
                return 'answers';
            case Page.Pinboards:
                return 'pinboards';
            case Page.Data:
                return 'data/tables';
            case Page.Home:
            default:
                return 'home';
        }
    }
 
    /**
     * Render an embedded app in the ThoughtSpot app
     * @param renderOptions An object containing the page id
     * to be embedded
     */
    public render({ pageId }: AppRenderOptions): AppEmbed {
        super.render();
 
        const pageRoute = this.getPageRoute(pageId);
        const src = this.getIFrameSrc(pageRoute);
        this.renderV1Embed(src);
 
        return this;
    }
}