Skip to content

Commit

Permalink
Add zoom plot telemetry event (#3433)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon authored Mar 8, 2023
1 parent 267d0bc commit 83d27bc
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 2 deletions.
6 changes: 6 additions & 0 deletions extension/src/plots/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export class WebviewMessages {
return this.attemptToRefreshSelectedData(message.payload)
case MessageFromWebviewType.TOGGLE_EXPERIMENT:
return this.setExperimentStatus(message.payload)
case MessageFromWebviewType.ZOOM_PLOT:
return sendTelemetryEvent(
EventName.VIEWS_PLOTS_ZOOM_PLOT,
undefined,
undefined
)
default:
Logger.error(`Unexpected message: ${JSON.stringify(message)}`)
}
Expand Down
2 changes: 2 additions & 0 deletions extension/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const EventName = Object.assign(
VIEWS_PLOTS_SECTION_TOGGLE: 'views.plots.toggleSection',
VIEWS_PLOTS_SELECT_EXPERIMENTS: 'view.plots.selectExperiments',
VIEWS_PLOTS_SELECT_PLOTS: 'view.plots.selectPlots',
VIEWS_PLOTS_ZOOM_PLOT: 'views.plots.zoomPlot',
VIEWS_REORDER_PLOTS_CUSTOM: 'views.plots.customReordered',
VIEWS_REORDER_PLOTS_METRICS: 'views.plots.metricsReordered',
VIEWS_REORDER_PLOTS_TEMPLATES: 'views.plots.templatesReordered',
Expand Down Expand Up @@ -261,6 +262,7 @@ export interface IEventNamePropertyMapping {
[EventName.VIEWS_PLOTS_SELECT_EXPERIMENTS]: undefined
[EventName.VIEWS_PLOTS_SELECT_PLOTS]: undefined
[EventName.VIEWS_PLOTS_EXPERIMENT_TOGGLE]: undefined
[EventName.VIEWS_PLOTS_ZOOM_PLOT]: undefined
[EventName.VIEWS_REORDER_PLOTS_METRICS]: undefined
[EventName.VIEWS_REORDER_PLOTS_CUSTOM]: undefined
[EventName.VIEWS_REORDER_PLOTS_TEMPLATES]: undefined
Expand Down
20 changes: 20 additions & 0 deletions extension/src/test/suite/plots/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,26 @@ suite('Plots Test Suite', () => {
)
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should handle a plot zoomed message from the webview', async () => {
const { plots } = await buildPlots(disposable, plotsDiffFixture)

const webview = await plots.showWebview()

const mockSendTelemetryEvent = stub(Telemetry, 'sendTelemetryEvent')
const mockMessageReceived = getMessageReceivedEmitter(webview)

mockMessageReceived.fire({
type: MessageFromWebviewType.ZOOM_PLOT
})

expect(mockSendTelemetryEvent).to.be.calledOnce
expect(mockSendTelemetryEvent).to.be.calledWithExactly(
EventName.VIEWS_PLOTS_ZOOM_PLOT,
undefined,
undefined
)
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should handle a custom plots reordered message from the webview', async () => {
const { plots, plotsModel, messageSpy } = await buildPlots(
disposable,
Expand Down
4 changes: 3 additions & 1 deletion extension/src/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export enum MessageFromWebviewType {
INITIALIZE_GIT = 'initialize-git',
SHOW_SCM_PANEL = 'show-scm-panel',
INSTALL_DVC = 'install-dvc',
SETUP_WORKSPACE = 'setup-workspace'
SETUP_WORKSPACE = 'setup-workspace',
ZOOM_PLOT = 'zoom-plot'
}

export type ColumnResizePayload = {
Expand Down Expand Up @@ -236,6 +237,7 @@ export type MessageFromWebview =
| { type: MessageFromWebviewType.OPEN_STUDIO_PROFILE }
| { type: MessageFromWebviewType.SAVE_STUDIO_TOKEN }
| { type: MessageFromWebviewType.ADD_CONFIGURATION }
| { type: MessageFromWebviewType.ZOOM_PLOT }

export type MessageToWebview<T extends WebviewData> = {
type: MessageToWebviewType.SET_DATA
Expand Down
16 changes: 16 additions & 0 deletions webview/src/plots/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,22 @@ describe('App', () => {
expect(screen.getByTestId('modal')).toBeInTheDocument()
})

it('should send a message to the extension when a plot is opened in a modal', () => {
renderAppWithOptionalData({
template: complexTemplatePlotsFixture
})

expect(screen.queryByTestId('modal')).not.toBeInTheDocument()

const plot = within(screen.getAllByTestId(/^plot_/)[0]).getByRole('button')

fireEvent.click(plot)

expect(mockPostMessage).toHaveBeenCalledWith({
type: MessageFromWebviewType.ZOOM_PLOT
})
})

it('should open a modal with the plot zoomed in when clicking a checkpoint plot', () => {
renderAppWithOptionalData({
checkpoint: checkpointPlotsFixture
Expand Down
6 changes: 5 additions & 1 deletion webview/src/plots/components/ZoomablePlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import VegaLite, { VegaLiteProps } from 'react-vega/lib/VegaLite'
import { setZoomedInPlot } from './webviewSlice'
import styles from './styles.module.scss'
import { config } from './constants'
import { zoomPlot } from './messages'
import { useGetPlot } from '../hooks/useGetPlot'
import { GripIcon } from '../../shared/components/dragDrop/GripIcon'

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

const handleOnClick = () => dispatch(setZoomedInPlot({ id, plot: plotProps }))
const handleOnClick = () => {
zoomPlot()
return dispatch(setZoomedInPlot({ id, plot: plotProps }))
}

if (!data && !spec) {
return null
Expand Down
5 changes: 5 additions & 0 deletions webview/src/plots/components/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
import { sendMessage } from '../../shared/vscode'

export const zoomPlot = () =>
sendMessage({ type: MessageFromWebviewType.ZOOM_PLOT })

0 comments on commit 83d27bc

Please sign in to comment.