Skip to content

Commit

Permalink
feat: extension framework identifies looker host type (#634)
Browse files Browse the repository at this point in the history
The Looker host type is sent in the lookerHostData parameter of the initialization message.

Looker host type can be
1. standard - standard chromed Looker UI.
2. embed - embedded extension.
3. spartan - spartan extension.

Requires Looker 21.8.

In addition:
1. hostUrl has been deprecated in favor of hostOrigin (hostOrigin reflects more accurately what the contents of the parameter contains)
2. mountType - extension mount type. Currently fullscreen. In preparation for alternative mount points in the future.
  • Loading branch information
bryans99 authored Apr 27, 2021
1 parent 77b0a98 commit c6c6f64
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/extension-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ The following create methods are also available

Looker host data is made available once the host connection has been established

- `extensionId` - id of the extension.
- `lookerVersion` - host Looker version. Test this value if the extension depends on a particular version of Looker.
- `route` - if routes are tracked, route is the last active route tracked by the host. On initialization the extension may set its route to this value.
- `routeState`- if routes are tracked, [push state](https://developer.mozilla.org/en-US/docs/Web/API/History/state) associated with the route
- `hostOrigin` - [origin](https://developer.mozilla.org/en-US/docs/Web/API/Location/origin) of the Looker host. **Looker >=21.8**.
- `hostType` - Looker host type. `standard`|`embed`|`spartan`. **Looker >=21.8**.
- `mountType` - Extension mount type. `fullscreen`. **Looker >=21.8**.

#### Context data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@

import { connectExtensionHost } from './connect_extension_host'
import * as globalListener from './global_listener'
import { ExtensionNotification, ExtensionNotificationType } from './types'
import {
ExtensionNotification,
ExtensionNotificationType,
HostType,
MountType,
} from './types'

let channel: any
class MockMessageChannel {
Expand Down Expand Up @@ -96,6 +101,9 @@ describe('connect_extension_host tests', () => {
payload: {
lookerVersion: '7.14.0',
hostUrl: 'https://self-signed.looker.com:9999',
hostOrigin: 'https://self-signed.looker.com:9999',
hostType: HostType.STANDARD,
mountType: MountType.FULLSCREEN,
extensionId: 'a::b',
},
})
Expand Down Expand Up @@ -125,6 +133,9 @@ describe('connect_extension_host tests', () => {
routeState: { hello: 'world' },
lookerVersion: '7.14.0',
hostUrl: 'https://self-signed.looker.com:9999',
hostOrigin: 'https://self-signed.looker.com:9999',
hostType: HostType.STANDARD,
mountType: MountType.FULLSCREEN,
extensionId: 'a::b',
},
})
Expand All @@ -151,6 +162,9 @@ describe('connect_extension_host tests', () => {
routeState: { hello: 'world' },
lookerVersion: '7.14.0',
hostUrl: 'https://self-signed.looker.com:9999',
hostOrigin: 'https://self-signed.looker.com:9999',
hostType: HostType.STANDARD,
mountType: MountType.FULLSCREEN,
extensionId: 'a::b',
},
})
Expand Down
32 changes: 31 additions & 1 deletion packages/extension-sdk/src/connect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ export interface RouteChangeData {
routeState?: any
}

/**
* Looker host type.
* standard - Standard Looker host with the navigation bar.
* embed - Embedded Looker host.
* spartan - Spartan Looker host.
*/
export type HostType = 'standard' | 'embed' | 'spartan'

/**
* Extension mount type.
* Fullscreen mount.
*/
export type MountType = 'fullscreen'

/**
* Initialization data. Looker host data.
*/
Expand All @@ -272,9 +286,25 @@ export interface LookerHostData {
*/
routeState?: any
/**
* hostUrl url of Looker host
* Origin of Looker host
* @deprecated
*/
hostUrl?: string
/**
* Origin of Looker host
* <code>Looker >=21.8</code>
*/
hostOrigin?: string
/**
* Looker host type (standard, embed, spartan)
* <code>Looker >=21.8</code>
*/
hostType?: HostType
/**
* Extension mount type.
* <code>Looker >=21.8</code>
*/
mountType?: MountType
/**
* Extension context data
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ describe('ShowResponse', () => {
})

test('it renders html responses', () => {
render(<ShowResponse response={testHtmlResponse} />)
renderWithTheme(<ShowResponse response={testHtmlResponse} />)
expect(screen.getByText('200: text/html;charset=utf-8')).toBeInTheDocument()
expect(screen.getByRole('textbox', { name: '' })).toBeInTheDocument()
expect(screen.getByText('Orders Created Date')).toBeInTheDocument()
})

test('it renders png responses', () => {
Expand All @@ -79,8 +79,8 @@ describe('ShowResponse', () => {
expect(screen.getByRole('img')).toBeInTheDocument()
})

test.skip('it renders a message for unknown response types', () => {
render(<ShowResponse response={testUnknownResponse} />)
test('it renders a message for unknown response types', () => {
renderWithTheme(<ShowResponse response={testUnknownResponse} />)
expect(
screen.getByText(
`Received ${testUnknownResponse.body.length} bytes of ${testUnknownResponse.contentType} data.`
Expand Down

0 comments on commit c6c6f64

Please sign in to comment.