Skip to content

Commit 0697b88

Browse files
authored
Add update row limit in extension (#1409)
feat: Add updating row limit and remove trigger from extension SDK With the addition of being able to update the row limit with a separate event here, there is no longer a need to have the trigger functionality copied from Custom Visualizations as all trigger types are covered by the existing SDK methods. Also some minor updates to the example extension just for testing purposes for the reviewer of this PR.
2 parents 6ddfe7d + e25c7a6 commit 0697b88

File tree

9 files changed

+34
-66
lines changed

9 files changed

+34
-66
lines changed

packages/extension-sdk/src/connect/tile/tile_sdk.spec.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,6 @@ describe('TileSDK', () => {
147147
expect(api.send).toBeCalledWith('TILE_CLEAR_ERRORS', { group: 'abc' })
148148
})
149149

150-
it('sends trigger message ', () => {
151-
const tileSdk = makeTileSdk()
152-
const config = [{ hello: 'world' }]
153-
const message = 'message1'
154-
tileSdk.trigger(message, config, makeEvent(config))
155-
expect(api.send).toBeCalledWith('TILE_TRIGGER', {
156-
message,
157-
config,
158-
event: makeEvent(),
159-
})
160-
})
161-
162150
it('sends open drill menu message ', () => {
163151
const tileSdk = makeTileSdk()
164152
const options = { hello: 'world' }
@@ -211,7 +199,6 @@ describe('TileSDK', () => {
211199
method
212200
${'addErrors'}
213201
${'clearErrors'}
214-
${'trigger'}
215202
${'openDrillMenu'}
216203
${'toggleCrossFilter'}
217204
${'runDashboard'}

packages/extension-sdk/src/connect/tile/tile_sdk.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import type {
3232
TileSDK,
3333
TileError,
3434
DrillMenuOptions,
35-
TriggerConfig,
3635
CrossFilterOptions,
3736
Filters,
3837
TileHostData,
@@ -77,18 +76,6 @@ export class TileSDKImpl implements TileSDK {
7776
}
7877
}
7978

80-
trigger(message: string, config: TriggerConfig[], event?: MouseEvent) {
81-
if (this.hostApi.isDashboardMountSupported) {
82-
this.hostApi.send(ExtensionRequestType.TILE_TRIGGER, {
83-
message,
84-
config,
85-
event: this.sanitizeEvent(event),
86-
})
87-
} else {
88-
throw NOT_DASHBOARD_MOUNT_NOT_SUPPORTED_ERROR
89-
}
90-
}
91-
9279
openDrillMenu(options: DrillMenuOptions, event?: MouseEvent) {
9380
if (this.hostApi.isDashboardMountSupported) {
9481
this.hostApi.send(ExtensionRequestType.TILE_OPEN_DRILL_MENU, {

packages/extension-sdk/src/connect/tile/types.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ export interface CrossFilterOptions {
198198
row: Row
199199
}
200200

201-
// TODO build out type
202-
export type TriggerConfig = any
203-
204-
// TODO build out type
205201
export type DrillMenuOptions = any
206202

207203
export interface Filters {
@@ -216,11 +212,6 @@ export interface TileSDK {
216212
tileHostDataChanged: (hostData: Partial<TileHostData>) => void
217213
addErrors: (...errors: TileError[]) => void
218214
clearErrors: (group?: string) => void
219-
trigger: (
220-
message: string,
221-
config: TriggerConfig[],
222-
event?: MouseEvent
223-
) => void
224215
openDrillMenu: (options: DrillMenuOptions, event?: MouseEvent) => void
225216
toggleCrossFilter: (options: CrossFilterOptions, event?: MouseEvent) => void
226217
runDashboard: () => void

packages/extension-sdk/src/connect/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ export enum ExtensionRequestType {
139139
* Tile clear error messages
140140
*/
141141
TILE_CLEAR_ERRORS = 'TILE_CLEAR_ERRORS',
142-
/**
143-
* Tile trigger
144-
*/
145-
TILE_TRIGGER = 'TILE_TRIGGER',
146142
/**
147143
* Tile open drill menu
148144
*/
@@ -151,6 +147,10 @@ export enum ExtensionRequestType {
151147
* Tile toggle cross filter
152148
*/
153149
TILE_TOGGLE_CROSS_FILTER = 'TILE_TOGGLE_CROSS_FILTER',
150+
/**
151+
* Tile update row limit
152+
*/
153+
TILE_ROW_LIMIT_UPDATE = 'TILE_ROW_LIMIT_UPDATE',
154154
/**
155155
* Tile run dashboard. Indicates that the dashboard queries should be run.
156156
*/

packages/extension-sdk/src/connect/visualization/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface VisualizationSDK {
121121
updateVisData: (rawVisData: RawVisualizationData) => void
122122
configureVisualization: (options: VisOptions) => void
123123
setVisConfig: (config: RawVisConfig) => void
124+
updateRowLimit: (rowLimit: number) => void
124125
}
125126

126127
export interface VisOptionValue {

packages/extension-sdk/src/connect/visualization/visualization_sdk.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ export class VisualizationSDKImpl implements VisualizationSDK {
165165
return this._visConfig
166166
}
167167

168+
updateRowLimit(rowLimit: number) {
169+
if (this.hostApi.isDashboardMountSupported) {
170+
this.hostApi.send(ExtensionRequestType.TILE_ROW_LIMIT_UPDATE, {
171+
rowLimit,
172+
})
173+
} else {
174+
throw NOT_DASHBOARD_MOUNT_NOT_SUPPORTED_ERROR
175+
}
176+
}
177+
168178
get queryResponse(): QueryResponse {
169179
if (!this._queryResponse) {
170180
this._queryResponse = new QueryResponseImpl(

packages/extension-tile-playground/src/components/Inspector/components/EventTester/EventTester.tsx

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const EventTester: React.FC = () => {
4040
const {
4141
extensionSDK,
4242
tileSDK,
43+
visualizationSDK,
4344
tileHostData: { dashboardFilters },
4445
} = useContext(ExtensionContext40)
4546
const [runDashboard, setRunDashboard] = useState(false)
@@ -67,28 +68,6 @@ export const EventTester: React.FC = () => {
6768
tileSDK.clearErrors()
6869
}, [tileSDK])
6970

70-
const triggerClick = useCallback(
71-
(event: MouseEvent) => {
72-
// Taken from custom visualizations 2
73-
const defaultColors = {
74-
red: '#F36254',
75-
green: '#4FBC89',
76-
yellow: '#FCF758',
77-
white: '#FFFFFF',
78-
}
79-
tileSDK.trigger(
80-
'updateConfig',
81-
[
82-
{ lowColor: defaultColors.red },
83-
{ midColor: defaultColors.white },
84-
{ highColor: defaultColors.green },
85-
],
86-
event
87-
)
88-
},
89-
[tileSDK]
90-
)
91-
9271
const toggleCrossFilterClick = useCallback(
9372
(event: MouseEvent) => {
9473
// TODO pivot and row data needs to be populated
@@ -135,6 +114,10 @@ export const EventTester: React.FC = () => {
135114
extensionSDK.updateTitle(`Update tile title ${new Date().getSeconds()}`)
136115
}, [extensionSDK])
137116

117+
const updateRowLimit = useCallback(() => {
118+
visualizationSDK.updateRowLimit(100)
119+
}, [visualizationSDK])
120+
138121
return (
139122
<Card>
140123
<CardContent>
@@ -149,8 +132,8 @@ export const EventTester: React.FC = () => {
149132
<ButtonOutline onClick={clearAllErrorsClick} width="100%">
150133
Test clear all errors
151134
</ButtonOutline>
152-
<ButtonOutline onClick={triggerClick} width="100%">
153-
Test trigger
135+
<ButtonOutline onClick={updateRowLimit} width="100%">
136+
Test Update Row Limit
154137
</ButtonOutline>
155138
<ButtonOutline onClick={openDrillMenuClick} width="100%">
156139
Test open drill menu

packages/extension-tile-playground/src/components/Inspector/components/TileHostData/TileHostData.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const TileHostData: React.FC = () => {
6767
: 'Dashboard is NOT printing'
6868

6969
const exploringMessage =
70-
isExploring && 'Extension visualization is being configured in exlore'
70+
isExploring && 'Extension visualization is being configured in an explore'
7171

7272
const dashboardEditingMessage = isDashboardEditing
7373
? 'Dashboard is editing'

packages/extension-tile-playground/src/components/VisualizationTile/VisualizationTile.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
SOFTWARE.
2424
2525
*/
26-
import React, { useContext, useEffect, useCallback, useMemo } from 'react'
26+
import React, {
27+
useContext,
28+
useEffect,
29+
useCallback,
30+
useMemo,
31+
useState,
32+
} from 'react'
2733
import { SpaceVertical, Text, Button } from '@looker/components'
2834
import { More } from '@looker/icons'
2935
import { ExtensionContext40 } from '@looker/extension-sdk-react'
@@ -39,6 +45,8 @@ export const VisualizationTile: React.FC = () => {
3945
const { visualizationData, visualizationSDK, extensionSDK } =
4046
useContext(ExtensionContext40)
4147

48+
const [visConfigured, setVisConfigured] = useState<boolean>(true)
49+
4250
const { value, valueFormat } = useMemo(() => {
4351
if (visualizationData) {
4452
return getValueAndFormat(visualizationSDK)
@@ -47,8 +55,9 @@ export const VisualizationTile: React.FC = () => {
4755
}, [visualizationData, visualizationSDK])
4856

4957
useEffect(() => {
50-
if (visualizationSDK) {
58+
if (visualizationSDK && !visConfigured) {
5159
visualizationSDK.configureVisualization(liquidFillVisOptions)
60+
setVisConfigured(true)
5261
}
5362
}, [visualizationSDK])
5463

0 commit comments

Comments
 (0)