diff --git a/src/helpers.ts b/src/helpers.ts index fef157a..5444de6 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -13,7 +13,7 @@ export function genID() { } export function openUrl(route: Route, options?: OpenOptions) { - return `${getOrigin(options)}${getOrg(options)}${route}${buildParams(options)}`; + return `${getOrigin(options)}${route}${buildParams(options)}`; } export function embedUrl(route: Route, options?: EmbedOptions) { @@ -23,7 +23,7 @@ export function embedUrl(route: Route, options?: EmbedOptions) { if (options && typeof options === 'object') { Object.assign(config, options); } - return `${getOrigin(config)}${getOrg(options)}${route}${buildParams(config)}`; + return `${getOrigin(config)}${route}${buildParams(config)}`; } function getOrigin(options: OpenOptions & EmbedOptions = {}) { @@ -31,10 +31,6 @@ function getOrigin(options: OpenOptions & EmbedOptions = {}) { return origin.replace(/\/$/, ''); } -function getOrg(options: OpenOptions & EmbedOptions = {}){ - return options?.organization ? `/orgs/${options.organization}` : ''; -} - export function replaceAndEmbed( target: HTMLElement, frame: HTMLIFrameElement, diff --git a/src/interfaces.ts b/src/interfaces.ts index 977b015..5df6c65 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -114,7 +114,10 @@ export interface ProjectOptions { * * Defaults to no organization. */ - organization?: string; + organization?: { + provider: 'github'; + name: string; + } /** * Show the sidebar as open or closed on page load. * diff --git a/src/params.ts b/src/params.ts index 904f70c..e146e95 100644 --- a/src/params.ts +++ b/src/params.ts @@ -4,7 +4,7 @@ import { UI_SIDEBAR_VIEWS, UI_THEMES, UI_VIEWS } from './constants'; export type ParamOptions = Omit< OpenOptions & EmbedOptions, - 'origin' | 'newWindow' | 'height' | 'width' | 'organization' + 'origin' | 'newWindow' | 'height' | 'width' >; /** @@ -36,7 +36,9 @@ type ParamName = | 'terminalHeight' | 'theme' | 'view' - | 'zenMode'; + | 'zenMode' + | 'orgName' + | 'orgProvider'; export const generators: Record string> = { clickToLoad: (value: ParamOptions['clickToLoad']) => trueParam('ctl', value), @@ -54,6 +56,7 @@ export const generators: Record string> = { theme: (value: ParamOptions['theme']) => enumParam('theme', value, UI_THEMES), view: (value: ParamOptions['view']) => enumParam('view', value, UI_VIEWS), zenMode: (value: ParamOptions['zenMode']) => trueParam('zenMode', value), + organization: (value: ParamOptions['organization']) => `${stringParams('orgName', value?.name)}&${stringParams('orgProvider', value?.provider)}`, }; export function buildParams(options: ParamOptions = {}): string { diff --git a/test/unit/params.spec.ts b/test/unit/params.spec.ts index a1a8cdd..434ee05 100644 --- a/test/unit/params.spec.ts +++ b/test/unit/params.spec.ts @@ -84,6 +84,7 @@ describe('buildParams', () => { hideExplorer: false, hideNavigation: false, openFile: '', + organization: undefined, showSidebar: undefined, sidebarView: 'default', startScript: undefined, @@ -107,6 +108,7 @@ describe('buildParams', () => { hideExplorer: true, hideNavigation: true, openFile: ['src/index.js,src/styles.css', 'package.json'], + organization: {name: 'stackblitz', provider: 'github'}, showSidebar: true, sidebarView: 'search', startScript: 'dev:serve', @@ -129,6 +131,8 @@ describe('buildParams', () => { 'hideNavigation=1', 'file=src%2Findex.js%2Csrc%2Fstyles.css', 'file=package.json', + 'orgName=stackblitz', + 'orgProvider=github', 'showSidebar=1', 'sidebarView=search', 'startScript=dev%3Aserve',