Skip to content

Commit 83d27bc

Browse files
authored
Add zoom plot telemetry event (#3433)
1 parent 267d0bc commit 83d27bc

File tree

7 files changed

+57
-2
lines changed

7 files changed

+57
-2
lines changed

extension/src/plots/webview/messages.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ export class WebviewMessages {
110110
return this.attemptToRefreshSelectedData(message.payload)
111111
case MessageFromWebviewType.TOGGLE_EXPERIMENT:
112112
return this.setExperimentStatus(message.payload)
113+
case MessageFromWebviewType.ZOOM_PLOT:
114+
return sendTelemetryEvent(
115+
EventName.VIEWS_PLOTS_ZOOM_PLOT,
116+
undefined,
117+
undefined
118+
)
113119
default:
114120
Logger.error(`Unexpected message: ${JSON.stringify(message)}`)
115121
}

extension/src/telemetry/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const EventName = Object.assign(
7474
VIEWS_PLOTS_SECTION_TOGGLE: 'views.plots.toggleSection',
7575
VIEWS_PLOTS_SELECT_EXPERIMENTS: 'view.plots.selectExperiments',
7676
VIEWS_PLOTS_SELECT_PLOTS: 'view.plots.selectPlots',
77+
VIEWS_PLOTS_ZOOM_PLOT: 'views.plots.zoomPlot',
7778
VIEWS_REORDER_PLOTS_CUSTOM: 'views.plots.customReordered',
7879
VIEWS_REORDER_PLOTS_METRICS: 'views.plots.metricsReordered',
7980
VIEWS_REORDER_PLOTS_TEMPLATES: 'views.plots.templatesReordered',
@@ -261,6 +262,7 @@ export interface IEventNamePropertyMapping {
261262
[EventName.VIEWS_PLOTS_SELECT_EXPERIMENTS]: undefined
262263
[EventName.VIEWS_PLOTS_SELECT_PLOTS]: undefined
263264
[EventName.VIEWS_PLOTS_EXPERIMENT_TOGGLE]: undefined
265+
[EventName.VIEWS_PLOTS_ZOOM_PLOT]: undefined
264266
[EventName.VIEWS_REORDER_PLOTS_METRICS]: undefined
265267
[EventName.VIEWS_REORDER_PLOTS_CUSTOM]: undefined
266268
[EventName.VIEWS_REORDER_PLOTS_TEMPLATES]: undefined

extension/src/test/suite/plots/index.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,26 @@ suite('Plots Test Suite', () => {
510510
)
511511
}).timeout(WEBVIEW_TEST_TIMEOUT)
512512

513+
it('should handle a plot zoomed message from the webview', async () => {
514+
const { plots } = await buildPlots(disposable, plotsDiffFixture)
515+
516+
const webview = await plots.showWebview()
517+
518+
const mockSendTelemetryEvent = stub(Telemetry, 'sendTelemetryEvent')
519+
const mockMessageReceived = getMessageReceivedEmitter(webview)
520+
521+
mockMessageReceived.fire({
522+
type: MessageFromWebviewType.ZOOM_PLOT
523+
})
524+
525+
expect(mockSendTelemetryEvent).to.be.calledOnce
526+
expect(mockSendTelemetryEvent).to.be.calledWithExactly(
527+
EventName.VIEWS_PLOTS_ZOOM_PLOT,
528+
undefined,
529+
undefined
530+
)
531+
}).timeout(WEBVIEW_TEST_TIMEOUT)
532+
513533
it('should handle a custom plots reordered message from the webview', async () => {
514534
const { plots, plotsModel, messageSpy } = await buildPlots(
515535
disposable,

extension/src/webview/contract.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export enum MessageFromWebviewType {
6666
INITIALIZE_GIT = 'initialize-git',
6767
SHOW_SCM_PANEL = 'show-scm-panel',
6868
INSTALL_DVC = 'install-dvc',
69-
SETUP_WORKSPACE = 'setup-workspace'
69+
SETUP_WORKSPACE = 'setup-workspace',
70+
ZOOM_PLOT = 'zoom-plot'
7071
}
7172

7273
export type ColumnResizePayload = {
@@ -236,6 +237,7 @@ export type MessageFromWebview =
236237
| { type: MessageFromWebviewType.OPEN_STUDIO_PROFILE }
237238
| { type: MessageFromWebviewType.SAVE_STUDIO_TOKEN }
238239
| { type: MessageFromWebviewType.ADD_CONFIGURATION }
240+
| { type: MessageFromWebviewType.ZOOM_PLOT }
239241

240242
export type MessageToWebview<T extends WebviewData> = {
241243
type: MessageToWebviewType.SET_DATA

webview/src/plots/components/App.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,22 @@ describe('App', () => {
14041404
expect(screen.getByTestId('modal')).toBeInTheDocument()
14051405
})
14061406

1407+
it('should send a message to the extension when a plot is opened in a modal', () => {
1408+
renderAppWithOptionalData({
1409+
template: complexTemplatePlotsFixture
1410+
})
1411+
1412+
expect(screen.queryByTestId('modal')).not.toBeInTheDocument()
1413+
1414+
const plot = within(screen.getAllByTestId(/^plot_/)[0]).getByRole('button')
1415+
1416+
fireEvent.click(plot)
1417+
1418+
expect(mockPostMessage).toHaveBeenCalledWith({
1419+
type: MessageFromWebviewType.ZOOM_PLOT
1420+
})
1421+
})
1422+
14071423
it('should open a modal with the plot zoomed in when clicking a checkpoint plot', () => {
14081424
renderAppWithOptionalData({
14091425
checkpoint: checkpointPlotsFixture

webview/src/plots/components/ZoomablePlot.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import VegaLite, { VegaLiteProps } from 'react-vega/lib/VegaLite'
77
import { setZoomedInPlot } from './webviewSlice'
88
import styles from './styles.module.scss'
99
import { config } from './constants'
10+
import { zoomPlot } from './messages'
1011
import { useGetPlot } from '../hooks/useGetPlot'
1112
import { GripIcon } from '../../shared/components/dragDrop/GripIcon'
1213

@@ -47,7 +48,10 @@ export const ZoomablePlot: React.FC<ZoomablePlotProps> = ({
4748
)
4849
}, [data, spec, dispatch, id])
4950

50-
const handleOnClick = () => dispatch(setZoomedInPlot({ id, plot: plotProps }))
51+
const handleOnClick = () => {
52+
zoomPlot()
53+
return dispatch(setZoomedInPlot({ id, plot: plotProps }))
54+
}
5155

5256
if (!data && !spec) {
5357
return null
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
2+
import { sendMessage } from '../../shared/vscode'
3+
4+
export const zoomPlot = () =>
5+
sendMessage({ type: MessageFromWebviewType.ZOOM_PLOT })

0 commit comments

Comments
 (0)