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 | 4x 4x 19x 18x 18x 18x 18x 18x 2x 18x 4x 4x 4x | import { EmbedConfig } from './types';
/**
* Copyright (c) 2020
*
* Utilities related to reading configuration objects
*
* @summary Config-related utils
* @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
*/
const urlRegex = new RegExp(
[
'(^(https?:)//)?', // protocol
'(([^:/?#]*)(?::([0-9]+))?)', // host (hostname and port)
'(/{0,1}[^?#]*)', // pathname
'(\\?[^#]*|)', // search
'(#.*|)$', // hash
].join(''),
);
/**
* Parse and construct the ThoughtSpot host name or IP address
* from the embed configuration object
* @param config
*/
export const getThoughtSpotHost = (config: EmbedConfig): string => {
const urlParts = config.thoughtSpotHost.match(urlRegex);
Iif (!urlParts) {
throw new Error(
`Error parsing ThoughtSpot host: ${config.thoughtSpotHost}. Please provide a valid URL`,
);
}
const protocol = urlParts[2] || window.location.protocol;
const host = urlParts[3];
let path = urlParts[6];
// Lose the trailing / if any
if (path.charAt(path.length - 1) === '/') {
path = path.substring(0, path.length - 1);
}
// const urlParams = urlParts[7];
// const hash = urlParts[8];
return `${protocol}//${host}${path}`;
};
/**
* It is a good idea to keep URLs under 2000 chars.
* If this is ever breached, since we pass view configuration through
* URL params, we would like to log an warning.
* Reference: https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
*/
export const URL_MAX_LENGTH = 2000;
/**
* The default dimensions of the embedded app
*/
export const DEFAULT_EMBED_WIDTH = 1280;
export const DEFAULT_EMBED_HEIGHT = 720;
|