Skip to content

Commit dd6a955

Browse files
Merge branch 'main' into upgrade-kotlin-and-linter
2 parents 7c8686e + 28f1218 commit dd6a955

29 files changed

+1612
-27
lines changed

packages/embed-components/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
SOFTWARE.
2424
2525
*/
26+
export default {}

packages/embed-playground/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Looker Data Sciences, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "@looker/embed-playground",
3+
"version": "0.0.1-alpha",
4+
"description": "Looker Embed Playground",
5+
"main": "lib/index.js",
6+
"module": "lib/esm/index.js",
7+
"sideEffects": false,
8+
"typings": "lib/index.d.ts",
9+
"private": true,
10+
"publishConfig": {
11+
"access": "restricted"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/looker-open-source/sdk-codegen.git",
16+
"directory": "packages/embed-playground"
17+
},
18+
"author": "Looker",
19+
"license": "MIT",
20+
"scripts": {
21+
"play": "webpack-dev-server --https --config webpack.dev.config.js",
22+
"watch": "yarn lerna exec --scope @looker/embed-playground --stream 'BABEL_ENV=build babel src --root-mode upward --out-dir lib/esm --source-maps --extensions .ts,.tsx --no-comments --watch'",
23+
"watch:cjs": "yarn lerna exec --scope @looker/embed-playground --stream 'BABEL_ENV=build_cjs babel src --root-mode upward --out-dir lib --source-maps --extensions .ts,.tsx --no-comments --watch'"
24+
},
25+
"bugs": {
26+
"url": "https://github.com/looker-open-source/sdk-codegen/issues"
27+
},
28+
"engines": {
29+
"node": ">=12",
30+
"npm": ">=5.5.1"
31+
},
32+
"homepage": "https://github.com/looker-open-source/sdk-codegen/tree/master/packages/embed-playground",
33+
"devDependencies": {
34+
"@types/react-redux": "^7.1.25",
35+
"@types/react-router": "^5.1.20",
36+
"webpack-cli": "^5.0.1",
37+
"webpack-dev-server": "^4.11.1"
38+
},
39+
"dependencies": {
40+
"@looker/components": "^4.1.1",
41+
"@looker/extension-utils": "^0.1.21",
42+
"@looker/redux": "0.0.0",
43+
"@looker/sdk": "^23.2.0",
44+
"@looker/sdk-rtl": "^21.6.0",
45+
"@styled-icons/material": "^10.47.0",
46+
"react": "16.14.0",
47+
"react-dom": "16.14.0",
48+
"react-redux": "^8.0.5",
49+
"react-router": "^5.3.4",
50+
"react-router-dom": "^5.3.4",
51+
"styled-components": "^5.3.1"
52+
},
53+
"keywords": [
54+
"Looker",
55+
"Embed",
56+
"Playground"
57+
]
58+
}

packages/embed-playground/src/App.tsx

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2023 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
import React from 'react'
27+
import { render } from 'react-dom'
28+
import { BrowserRouter } from 'react-router-dom'
29+
import { StandaloneEmbedPlayground } from './StandaloneEmbedPlayground'
30+
31+
render(
32+
<BrowserRouter>
33+
<StandaloneEmbedPlayground />
34+
</BrowserRouter>,
35+
document.getElementById('container')
36+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2023 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
import React, { useState, useEffect } from 'react'
27+
import { ComponentsProvider } from '@looker/components'
28+
import type { IEnvironmentAdaptor } from '@looker/extension-utils'
29+
import { me } from '@looker/sdk'
30+
31+
interface EmbedPlaygroundProps {
32+
adaptor: IEnvironmentAdaptor
33+
headless?: boolean
34+
}
35+
36+
export const EmbedPlayground = ({ adaptor }: EmbedPlaygroundProps) => {
37+
const [greeting, setGreeting] = useState('Hello World!')
38+
const sdk = adaptor.sdk
39+
useEffect(() => {
40+
const getCurrentUser = async () => {
41+
const currentUser = await sdk.ok(me(sdk))
42+
if (currentUser) {
43+
const { first_name, last_name } = currentUser
44+
45+
setGreeting(`Hello ${first_name} ${last_name}!`)
46+
}
47+
return currentUser
48+
}
49+
getCurrentUser()
50+
})
51+
52+
return <ComponentsProvider>{greeting}</ComponentsProvider>
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2023 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
import React, { useState, useEffect } from 'react'
27+
import { ComponentsProvider } from '@looker/components'
28+
import {
29+
OAuthConfigForm,
30+
BrowserAdaptor,
31+
registerEnvAdaptor,
32+
OAuthScene,
33+
OAuthConfigProvider,
34+
} from '@looker/extension-utils'
35+
import { Provider } from 'react-redux'
36+
import { useLocation } from 'react-router'
37+
import type { IApiSettings } from '@looker/sdk-rtl'
38+
import {
39+
BrowserSession,
40+
BrowserTransport,
41+
DefaultSettings,
42+
} from '@looker/sdk-rtl'
43+
import { functionalSdk40 } from '@looker/sdk'
44+
import { store } from './state'
45+
import { Loader } from './components'
46+
import { EmbedPlayground } from '.'
47+
48+
const ConfigKey = 'EPConfig'
49+
50+
const OAuthClientId = 'looker.embed-playground'
51+
52+
export const initSdk = () => {
53+
const settings = {
54+
...DefaultSettings(),
55+
base_url: 'https://self-signed.looker.com:19999',
56+
agentTag: 'EmbedPlayground 0.1',
57+
} as IApiSettings
58+
59+
const options = new OAuthConfigProvider(settings, OAuthClientId, ConfigKey)
60+
const transport = new BrowserTransport(options)
61+
const session = new BrowserSession(options, transport)
62+
const sdk = functionalSdk40(session)
63+
return sdk
64+
}
65+
66+
export const StandaloneEmbedPlayground = () => {
67+
const location = useLocation()
68+
const oauthReturn = location.pathname === '/oauth'
69+
const [adaptor] = useState(new BrowserAdaptor(initSdk()))
70+
const sdk = adaptor.sdk
71+
const authIsConfigured = (
72+
sdk.authSession.settings as OAuthConfigProvider
73+
).authIsConfigured()
74+
const canLogin =
75+
!authIsConfigured && !sdk.authSession.isAuthenticated() && !oauthReturn
76+
77+
useEffect(() => {
78+
const login = async () => await adaptor.login()
79+
if (canLogin) {
80+
login()
81+
}
82+
}, [])
83+
84+
const { looker_url } = (
85+
sdk.authSession.settings as OAuthConfigProvider
86+
).getStoredConfig()
87+
registerEnvAdaptor(adaptor)
88+
89+
const themeOverrides = adaptor.themeOverrides()
90+
91+
if (!authIsConfigured) {
92+
return (
93+
<Provider store={store}>
94+
<ComponentsProvider
95+
loadGoogleFonts={themeOverrides.loadGoogleFonts}
96+
themeCustomizations={themeOverrides.themeCustomizations}
97+
>
98+
<OAuthConfigForm
99+
configKey="EPConfig"
100+
clientId={OAuthClientId}
101+
clientLabel="Embed Playground"
102+
/>
103+
</ComponentsProvider>
104+
</Provider>
105+
)
106+
}
107+
108+
if (canLogin) {
109+
return (
110+
<Provider store={store}>
111+
<Loader
112+
themeOverrides={adaptor.themeOverrides()}
113+
message={`Configuration found. Logging into ${looker_url}`}
114+
/>
115+
</Provider>
116+
)
117+
}
118+
119+
return (
120+
<>
121+
{oauthReturn ? (
122+
<OAuthScene adaptor={adaptor} />
123+
) : (
124+
<EmbedPlayground adaptor={adaptor} />
125+
)}
126+
</>
127+
)
128+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2023 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
import React from 'react'
27+
import {
28+
ComponentsProvider,
29+
Flex,
30+
FlexItem,
31+
Heading,
32+
ProgressCircular,
33+
} from '@looker/components'
34+
import type { ThemeOverrides } from '@looker/extension-utils'
35+
36+
export interface LoaderProps {
37+
themeOverrides: ThemeOverrides
38+
message: string
39+
}
40+
41+
export const Loader = ({ themeOverrides, message }: LoaderProps) => (
42+
<ComponentsProvider {...themeOverrides}>
43+
<Flex flexDirection="column" justifyContent="center" mt="25%">
44+
<FlexItem alignSelf="center">
45+
<ProgressCircular size="large" />
46+
</FlexItem>
47+
<FlexItem mt="large" alignSelf="center">
48+
<Heading color="key" as="h2">
49+
{message}
50+
</Heading>
51+
</FlexItem>
52+
</Flex>
53+
</ComponentsProvider>
54+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2023 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
export * from './Loader'

0 commit comments

Comments
 (0)