-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelfService.jsx
73 lines (66 loc) · 2.1 KB
/
SelfService.jsx
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
62
63
64
65
66
67
68
69
70
71
72
73
import Tile from '../Tile/Tile'
import { LookerEmbedSDK } from '@looker/embed-sdk'
import { useCallback, useState } from 'react'
import { lookerConfig } from '../../lookerConfig'
function App() {
const [exploreStatus, setExploreStatus] = useState('Loading...')
const setupExplore = useCallback(
(div) => {
if (!div) {
return
}
LookerEmbedSDK.createExploreWithId(lookerConfig.exploreId)
.withAllowAttr('fullscreen')
.appendTo(div)
.withParams({
_theme: JSON.stringify({
background_color: "rgba(18,18,18,1)",
key_color: "rgba(139,108,67,1)",
primary_button_color: "rgba(139,108,67,1)",
font_color: "rgba(139,108,67,1)"
})
})
// Listen to messages to display progress
.on('explore:ready', () => setExploreStatus('Loaded'))
.on('explore:run:start', () => setExploreStatus('Running'))
.on('explore:run:complete', () => setExploreStatus('Done'))
// Listen to session status
.on('session:status', (event) => {
if (event.expired) {
setExploreStatus('Session expired')
} else if (event.interrupted) {
setExploreStatus('Session interrupted')
}
})
// Give the embedded content a class for styling purposes
.withClassName('looker-embed')
.withParams({
// TODO replace with fields present in your explore
// fields: [
// 'stock_prices.count',
// 'stock_prices.stock',
// 'stock_prices.total_volume'
// ],
// sorts: 'stock_prices.count asc',
// limit: 500
})
.build()
.connect()
.catch((error) => {
setExploreStatus('Connection error')
console.error('Connection error', error)
})
},
[setExploreStatus]
)
return (
<>
<Tile loading={exploreStatus === 'Loading...'}>
<div className="overflow-auto pb-8">
<div id="explore" ref={setupExplore}></div>
</div>
</Tile>
</>
)
}
export default App