Skip to content

Commit

Permalink
feat: add render callback to tile extensions
Browse files Browse the repository at this point in the history
Also removes animation from tile visualization when rendering.
  • Loading branch information
bryans99 committed Oct 23, 2023
1 parent 512ac8d commit 8255d2b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@
SOFTWARE.
*/
import React from 'react'
import React, { useCallback, useEffect, useContext } from 'react'
import { SpaceVertical, Box } from '@looker/components'
import { ExtensionContext40 } from '@looker/extension-sdk-react'
import { EventTester } from './components/EventTester/EventTester'
import { TileHostData } from './components/TileHostData/TileHostData'
import { VisualizationData } from './components/VisualizationData/VisualizationData'

export const Inspector = () => {
const { extensionSDK } = useContext(ExtensionContext40)

useEffect(() => {
extensionSDK.rendered()
}, [extensionSDK])

return (
<SpaceVertical gap="small">
<Box width="100%">
Expand Down
31 changes: 23 additions & 8 deletions react/javascript/tile-visualization/src/TileExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,51 @@
SOFTWARE.
*/
import React, { useContext } from 'react'
import React, { useContext, useMemo } from 'react'
import styled from 'styled-components'
import { ComponentsProvider } from '@looker/components'
import { ExtensionContext40 } from '@looker/extension-sdk-react'
import { MountPoint } from '@looker/extension-sdk'
import { VisualizationTile } from './components/VisualizationTile/VisualizationTile'
import { DashboardTile } from './components/DashboardTile/DashboardTile'

const getDefaultRouteComponent = (mountPoint) => {
const getDefaultRouteComponent = (mountPoint, isRendering) => {
const config = isRendering
? {
valueCountUp: false,
waveAnimateTime: 0,
waveRiseTime: 0,
waveAnimate: false,
waveRise: false,
}
: {}

if (mountPoint === MountPoint.dashboardVisualization) {
return <VisualizationTile />
return <VisualizationTile config={config} />
}

if (mountPoint === MountPoint.dashboardTile) {
return <DashboardTile />
return <DashboardTile config={config} />
}
// Standalone extensions do not get the additional CSS
// that ensures the html and body tags occupy 100% of the
// IFRAME content window. In standalone mode Dashboard tile
// uses vh to calculate its height.
return <DashboardTile standalone={true} />
return <DashboardTile standalone={true} config={config} />
}

export const TileExtension = () => {
const { lookerHostData } = useContext(ExtensionContext40)
const mountPoint = lookerHostData?.mountPoint
const isRendering = lookerHostData?.isRendering
const component = useMemo(
() => getDefaultRouteComponent(mountPoint, isRendering),
[mountPoint, isRendering]
)

return (
<ComponentsProviderWrapper>
<ComponentsProvider>
{getDefaultRouteComponent(lookerHostData?.mountPoint)}
</ComponentsProvider>
<ComponentsProvider>{component}</ComponentsProvider>
</ComponentsProviderWrapper>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { LiquidFillGaugeViz } from '../LiquidFillGaugeViz/LiquidFillGaugeViz'
* then the user has clicked the dashboard run button (or the dashboard
* has been setup to auto refresh).
*/
export const DashboardTile = ({ standalone }) => {
export const DashboardTile = ({ standalone, config }) => {
const { extensionSDK, coreSDK, tileHostData } = useContext(ExtensionContext40)
const { lastRunStartTime, dashboardRunState } = tileHostData || -1
const [saveLastRunStartTime, setSaveLastRunStartTime] = useState()
Expand Down Expand Up @@ -117,6 +117,7 @@ export const DashboardTile = ({ standalone }) => {
value={value}
renderComplete={renderComplete}
valueFormat={null}
config={config}
/>
)}
</SpaceVertical>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
getValueAndFormat,
} from '../LiquidFillGaugeViz/liquid_fill'

export const VisualizationTile = () => {
export const VisualizationTile = ({ config }) => {
const { visualizationData, visualizationSDK, extensionSDK } =
useContext(ExtensionContext40)

Expand Down Expand Up @@ -69,6 +69,7 @@ export const VisualizationTile = () => {
value={value}
renderComplete={renderComplete}
valueFormat={valueFormat}
config={config}
/>
)}
{!value && (
Expand Down

0 comments on commit 8255d2b

Please sign in to comment.