Skip to content

Commit

Permalink
1. Add new method to original SDK to return instance of new
Browse files Browse the repository at this point in the history
   SDK.
2. Rename original demo to multi frame demo
3. Rename new demo to single frame demo
4. Change title of message example tp Embed Message API Demo
  • Loading branch information
bryans99 committed Jan 9, 2025
1 parent 6483368 commit e7c4c1e
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 32 deletions.
10 changes: 5 additions & 5 deletions demo/demo_v1.html → demo/demo_multi_frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Looker Embed SDK Demo (V1)</title>
<title>Looker Embed SDK Multi Frame Demo</title>
<link href="components.css" rel="stylesheet" />
<link href="demo.css" rel="stylesheet" type="text/css" />
<script src="demo_v1.js"></script>
<script src="demo_multi_frame.js"></script>
</head>
<body class="pt-5">
<h1 class="main-heading">Looker Embed SDK Demo Page (V1)</h1>
<h1 class="main-heading">Looker Embed SDK Multi Frame Demo</h1>
<div id="controls" class="flex pt-5 gap-5 px-5">
<div class="flex-auto flex gap-2">
<div class="flex flex-col text-left">
Expand Down Expand Up @@ -71,8 +71,8 @@ <h1 class="main-heading">Looker Embed SDK Demo Page (V1)</h1>
</div>
</div>
<div class="flex-auto text-right flex flex-col">
<a href="index.html" class="link">Embed SDK Demo (V2)</a>
<a href="message_example.html" class="link">Window Message Example</a>
<a href="index.html" class="link">Single Frame Demo</a>
<a href="message_example.html" class="link">Embed Message API Demo</a>
</div>
</div>
<div class="embed-container">
Expand Down
40 changes: 24 additions & 16 deletions demo/demo_v1.ts → demo/demo_multi_frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
// IDs for content to demonstrate are configured in demo_config.ts

import type {
LookerEmbedLook,
LookerEmbedDashboard,
LookerEmbedExplore,
SessionStatus,
ILookerConnection,
ILookerEmbedDashboard,
ILookerEmbedExplore,
ILookerEmbedLook,
} from '../src/index'
import { LookerEmbedSDK } from '../src/index'
import type { RuntimeConfig } from './demo_config'
Expand All @@ -41,9 +42,9 @@ import {
resetConfiguration,
} from './demo_config'

let currentDashboard: LookerEmbedDashboard | undefined
let currentLook: LookerEmbedLook | undefined
let currentExplore: LookerEmbedExplore | undefined
let currentDashboard: ILookerEmbedDashboard | undefined
let currentLook: ILookerEmbedLook | undefined
let currentExplore: ILookerEmbedExplore | undefined

const initializeRunAllButton = () => {
// Add a listener to the "Run All" button and send 'xxxx:run' messages when clicked
Expand All @@ -66,7 +67,8 @@ const initializeRunAllButton = () => {
/**
* Set up the dashboard after the SDK connects
*/
const setupDashboard = (dashboard: LookerEmbedDashboard) => {
const setupDashboard = (connection: ILookerConnection) => {
const dashboard = connection.asDashboardConnection()
currentDashboard = dashboard

// Add a listener to the dashboard's "Run" button and send a 'dashboard:run' message when clicked
Expand Down Expand Up @@ -101,7 +103,8 @@ const setupDashboard = (dashboard: LookerEmbedDashboard) => {
/**
* Set up the look after the SDK connects.
*/
const setupLook = (look: LookerEmbedLook) => {
const setupLook = (connection: ILookerConnection) => {
const look = connection.asLookConnection()
currentLook = look

// Add a listener to the look's "Run" button and send a 'look:run' message when clicked
Expand All @@ -124,7 +127,8 @@ const setupLook = (look: LookerEmbedLook) => {
/**
* Set up the explore after the SDK connects.
*/
const setupExplore = (explore: LookerEmbedExplore) => {
const setupExplore = (connection: ILookerConnection) => {
const explore = connection.asExploreConnection()
currentExplore = explore

// Add a listener to the explore's "Run" button and send a 'explore:run' message when clicked
Expand Down Expand Up @@ -354,7 +358,8 @@ const renderDashboard = (runtimeConfig: RuntimeConfig) => {
if (runtimeConfig.showDashboard) {
document.querySelector<HTMLDivElement>('#demo-dashboard')!.style.display =
''
LookerEmbedSDK.createDashboardWithId(runtimeConfig.dashboardId)
LookerEmbedSDK.getSDK()
.createDashboardWithId(runtimeConfig.dashboardId)
// When true scrolls the top of the IFRAME into view
.withDialogScroll(runtimeConfig.useDynamicHeights)
// When true updates the IFRAME height to reflect the height of the
Expand Down Expand Up @@ -427,7 +432,8 @@ const renderLook = (runtimeConfig: RuntimeConfig) => {
// Create an embedded Look
if (runtimeConfig.showLook) {
document.querySelector<HTMLDivElement>('#demo-look')!.style.display = ''
LookerEmbedSDK.createLookWithId(parseInt(runtimeConfig.lookId, 10))
LookerEmbedSDK.getSDK()
.createLookWithId(parseInt(runtimeConfig.lookId, 10))
// Append to the #look element
.appendTo('#look')
// Listen to messages to display progress
Expand Down Expand Up @@ -469,7 +475,8 @@ const renderExplore = (runtimeConfig: RuntimeConfig) => {
// Create an embedded Explore
if (runtimeConfig.showExplore) {
document.querySelector<HTMLDivElement>('#demo-explore')!.style.display = ''
LookerEmbedSDK.createExploreWithId(runtimeConfig.exploreId)
LookerEmbedSDK.getSDK()
.createExploreWithId(runtimeConfig.exploreId)
// Append to the #explore element
.appendTo('#explore')
// Listen to messages to display progress
Expand Down Expand Up @@ -510,7 +517,8 @@ const renderExtension = (runtimeConfig: RuntimeConfig) => {
if (runtimeConfig.showExtension) {
document.querySelector<HTMLDivElement>('#demo-extension')!.style.display =
''
LookerEmbedSDK.createExtensionWithId(runtimeConfig.extensionId)
LookerEmbedSDK.getSDK()
.createExtensionWithId(runtimeConfig.extensionId)
// Append to the #extension element
.appendTo('#extension')
.on('session:status', (event: SessionStatus) => {
Expand Down Expand Up @@ -542,14 +550,14 @@ const renderExtension = (runtimeConfig: RuntimeConfig) => {
const initializeEmbedSdk = (runtimeConfig: RuntimeConfig) => {
if (runtimeConfig.useCookieless) {
// Use cookieless embed
LookerEmbedSDK.initCookieless(
runtimeConfig.lookerHost,
LookerEmbedSDK.getSDK().initCookieless(
runtimeConfig.getSDK().lookerHost,
'/acquire-embed-session',
'/generate-embed-tokens'
)
} else {
// Use SSO embed
LookerEmbedSDK.init(runtimeConfig.lookerHost, '/auth')
LookerEmbedSDK.getSDK().init(runtimeConfig.lookerHost, '/auth')
}
}

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Looker Embed SDK Demo (V2)</title>
<title>Looker Embed SDK Single Frame Demo</title>
<link href="components.css" rel="stylesheet" />
<style>
#embed-container {
Expand All @@ -13,10 +13,10 @@
}
}
</style>
<script src="demo.js"></script>
<script src="demo_single_frame.js"></script>
</head>
<body class="p-5 h-dvh flex flex-col">
<h1 class="main-heading">Looker Embed SDK Demo Page (V2)</h1>
<h1 class="main-heading">Looker Embed SDK Single Frame Demo</h1>
<div id="controls" class="flex pt-5">
<div class="flex-auto flex space-x-5">
<div class="pt-1">
Expand All @@ -39,8 +39,8 @@ <h1 class="main-heading">Looker Embed SDK Demo Page (V2)</h1>
</div>
</div>
<div class="flex-auto flex flex-col text-right">
<a href="demo_v1.html" class="link">Embed SDK Demo (V1)</a>
<a href="message_example.html" class="link">Window Message Example</a>
<a href="demo_multi_frame.html" class="link">Multi Frame Demo</a>
<a href="message_example.html" class="link">Embed Message API Demo</a>
</div>
</div>
<div class="tabs-container">
Expand Down
8 changes: 4 additions & 4 deletions demo/message_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Looker Embed Window Message Example</title>
<title>Looker Embed Message API Demo</title>
<link href="components.css" rel="stylesheet" />
<link href="demo.css" rel="stylesheet" type="text/css" />
<script src="message_example.js"></script>
</head>
<body class="pt-5">
<h1 class="main-heading">Looker Embed Window Message Example</h1>
<h1 class="main-heading">Looker Embed Message API Demo</h1>
<div id="controls" class="flex pt-5 gap-5 px-5">
<div class="flex-auto flex flex-col text-left">
<div class="pt-2">
Expand Down Expand Up @@ -47,8 +47,8 @@ <h1 class="main-heading">Looker Embed Window Message Example</h1>
</div>
</div>
<div class="flex-auto text-right flex flex-col">
<a href="demo_v1.html" class="link">Embed SDK Demo (V1)</a>
<a href="index.html" class="link">Embed SDK Demo (V2)</a>
<a href="index.html" class="link">Single Frame Demo</a>
<a href="demo_multi_frame.html" class="link">Multi Frame Demo</a>
</div>
</div>
<div class="embed-container">
Expand Down
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
CookielessCallback,
CookielessRequestInit,
} from './types'
import { getSDKFactory } from './v2/LookerEmbedSDKFactory'

export type { LookerEmbedDashboard } from './dashboard_client'
export type { LookerEmbedExplore } from './explore_client'
Expand Down Expand Up @@ -210,6 +211,20 @@ export class LookerEmbedSDK {
).withId(id)
}

/**
* Create an instance of the new combined connection Embed SDK. The combined
* connection Embed SDK allows a developer to create a single connection for
* all Looker object types (dashboard, explores, looks, extensions). The
* developer can use the connection to navigate to different object types
* within Looker without having to recreate the IFRAME.
*
* Requires Looker version 25.0 or above.
*/

static getSDK() {
return getSDKFactory().getSDK()
}

/**
* @hidden
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/v2/LookerEmbedSDKFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

import { LookerEmbedSDK } from '../../src'
import {
getSDKFactory,
LookerEmbedSDKFactory,
Expand All @@ -41,4 +42,10 @@ describe('LookerEmbedSDKFactory', () => {
const factory = new LookerEmbedSDKFactory(sdk)
expect(sdk === factory.getSDK()).toBeTruthy()
})

it('returns an instance of the new SDK from the original SDK', () => {
const sdk = LookerEmbedSDK.getSDK()
expect(sdk).toBeDefined()
expect(LookerEmbedSDK.getSDK()).toBe(sdk)
})
})
4 changes: 2 additions & 2 deletions webpack-devserver.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var webpackConfig = {
mode: 'development',
devtool: 'source-map',
entry: {
demo: './demo/demo.ts',
demo_v1: './demo/demo_v1.ts',
demo_single_frame: './demo/demo_single_frame.ts',
demo_multi_frame: './demo/demo_multi_frame.ts',
message_example: './demo/message_example.ts',
},
output: {
Expand Down

0 comments on commit e7c4c1e

Please sign in to comment.