Skip to content

Commit 9c9e15d

Browse files
authored
Fix issues with messages from the plots webview (#3986)
1 parent 728abbf commit 9c9e15d

File tree

7 files changed

+29
-34
lines changed

7 files changed

+29
-34
lines changed

extension/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@
577577
},
578578
{
579579
"title": "Refresh Plots for Selected Experiments",
580-
"command": "dvc.views.plotsPathsTree.refreshPlots",
580+
"command": "dvc.views.plots.refreshPlots",
581581
"category": "DVC",
582582
"icon": "$(refresh)"
583583
},
@@ -989,7 +989,7 @@
989989
"when": "dvc.commands.available && dvc.project.available"
990990
},
991991
{
992-
"command": "dvc.views.plotsPathsTree.refreshPlots",
992+
"command": "dvc.views.plots.refreshPlots",
993993
"when": "dvc.commands.available && dvc.project.available"
994994
},
995995
{
@@ -1383,7 +1383,7 @@
13831383
"group": "navigation@2"
13841384
},
13851385
{
1386-
"command": "dvc.views.plotsPathsTree.refreshPlots",
1386+
"command": "dvc.views.plots.refreshPlots",
13871387
"when": "view == dvc.views.plotsPathsTree",
13881388
"group": "navigation@3"
13891389
}

extension/src/commands/external.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export enum RegisteredCommands {
7272
PLOTS_PATH_TOGGLE = 'dvc.views.plotsPathsTree.toggleStatus',
7373
PLOTS_SHOW = 'dvc.showPlots',
7474
PLOTS_SELECT = 'dvc.views.plotsPathsTree.selectPlots',
75-
PLOTS_REFRESH = 'dvc.views.plotsPathsTree.refreshPlots',
75+
PLOTS_REFRESH = 'dvc.views.plots.refreshPlots',
7676
PLOTS_CUSTOM_ADD = 'dvc.views.plots.addCustomPlot',
7777
PLOTS_CUSTOM_REMOVE = 'dvc.views.plots.removeCustomPlots',
7878

extension/src/plots/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ export class Plots extends BaseRepository<TPlotsData> {
198198
experiments: Experiments
199199
) {
200200
const webviewMessages = new WebviewMessages(
201+
this.dvcRoot,
201202
paths,
202203
plots,
203204
errors,
204205
experiments,
205206
() => this.getWebview(),
206-
() => this.selectPlots(),
207-
() => this.data.update()
207+
() => this.selectPlots()
208208
)
209209
this.dispose.track(
210210
this.onDidReceivedWebviewMessage(message =>

extension/src/plots/webview/messages.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { Logger } from '../../common/logger'
1313
import { Experiments } from '../../experiments'
1414
import { sendTelemetryEvent } from '../../telemetry'
1515
import { EventName } from '../../telemetry/constants'
16-
import { Toast } from '../../vscode/toast'
1716
import {
1817
MessageFromWebview,
1918
MessageFromWebviewType,
@@ -30,31 +29,31 @@ import { RegisteredCommands } from '../../commands/external'
3029
import { ErrorsModel } from '../errors/model'
3130

3231
export class WebviewMessages {
32+
private readonly dvcRoot: string
3333
private readonly paths: PathsModel
3434
private readonly plots: PlotsModel
3535
private readonly errors: ErrorsModel
3636
private readonly experiments: Experiments
3737

3838
private readonly getWebview: () => BaseWebview<TPlotsData> | undefined
3939
private readonly selectPlots: () => Promise<void>
40-
private readonly updateData: () => Promise<void>
4140

4241
constructor(
42+
dvcRoot: string,
4343
paths: PathsModel,
4444
plots: PlotsModel,
4545
errors: ErrorsModel,
4646
experiments: Experiments,
4747
getWebview: () => BaseWebview<TPlotsData> | undefined,
48-
selectPlots: () => Promise<void>,
49-
updateData: () => Promise<void>
48+
selectPlots: () => Promise<void>
5049
) {
50+
this.dvcRoot = dvcRoot
5151
this.paths = paths
5252
this.plots = plots
5353
this.errors = errors
5454
this.experiments = experiments
5555
this.getWebview = getWebview
5656
this.selectPlots = selectPlots
57-
this.updateData = updateData
5857
}
5958

6059
public async sendWebviewMessage() {
@@ -79,7 +78,10 @@ export class WebviewMessages {
7978
public handleMessageFromWebview(message: MessageFromWebview) {
8079
switch (message.type) {
8180
case MessageFromWebviewType.ADD_CUSTOM_PLOT:
82-
return commands.executeCommand(RegisteredCommands.PLOTS_CUSTOM_ADD)
81+
return commands.executeCommand(
82+
RegisteredCommands.PLOTS_CUSTOM_ADD,
83+
this.dvcRoot
84+
)
8385
case MessageFromWebviewType.RESIZE_PLOTS:
8486
return this.setPlotSize(
8587
message.payload.section,
@@ -101,9 +103,15 @@ export class WebviewMessages {
101103
case MessageFromWebviewType.SELECT_EXPERIMENTS:
102104
return this.selectExperimentsFromWebview()
103105
case MessageFromWebviewType.REMOVE_CUSTOM_PLOTS:
104-
return commands.executeCommand(RegisteredCommands.PLOTS_CUSTOM_REMOVE)
106+
return commands.executeCommand(
107+
RegisteredCommands.PLOTS_CUSTOM_REMOVE,
108+
this.dvcRoot
109+
)
105110
case MessageFromWebviewType.REFRESH_REVISIONS:
106-
return this.refreshData()
111+
return commands.executeCommand(
112+
RegisteredCommands.PLOTS_REFRESH,
113+
this.dvcRoot
114+
)
107115
case MessageFromWebviewType.TOGGLE_EXPERIMENT:
108116
return this.setExperimentStatus(message.payload)
109117
case MessageFromWebviewType.ZOOM_PLOT:
@@ -237,16 +245,6 @@ export class WebviewMessages {
237245
)
238246
}
239247

240-
private refreshData() {
241-
void Toast.infoWithOptions('Attempting to refresh visible plots data.')
242-
void this.updateData()
243-
sendTelemetryEvent(
244-
EventName.VIEWS_PLOTS_MANUAL_REFRESH,
245-
undefined,
246-
undefined
247-
)
248-
}
249-
250248
private sendSectionCollapsed() {
251249
void this.getWebview()?.show({
252250
sectionCollapsed: this.plots.getSectionCollapsed()

extension/src/telemetry/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export const EventName = Object.assign(
7171
VIEWS_PLOTS_CREATED: 'views.plots.created',
7272
VIEWS_PLOTS_EXPERIMENT_TOGGLE: 'views.plots.toggleExperimentStatus',
7373
VIEWS_PLOTS_FOCUS_CHANGED: 'views.plots.focusChanged',
74-
VIEWS_PLOTS_MANUAL_REFRESH: 'views.plots.manualRefresh',
7574
VIEWS_PLOTS_REVISIONS_REORDERED: 'views.plots.revisionsReordered',
7675
VIEWS_PLOTS_SECTION_RESIZED: 'views.plots.sectionResized',
7776
VIEWS_PLOTS_SECTION_TOGGLE: 'views.plots.toggleSection',
@@ -252,7 +251,6 @@ export interface IEventNamePropertyMapping {
252251
[EventName.VIEWS_PLOTS_CLOSED]: undefined
253252
[EventName.VIEWS_PLOTS_CREATED]: undefined
254253
[EventName.VIEWS_PLOTS_FOCUS_CHANGED]: WebviewFocusChangedProperties
255-
[EventName.VIEWS_PLOTS_MANUAL_REFRESH]: undefined
256254
[EventName.VIEWS_PLOTS_REVISIONS_REORDERED]: undefined
257255
[EventName.VIEWS_PLOTS_COMPARISON_ROWS_REORDERED]: undefined
258256
[EventName.VIEWS_PLOTS_SECTION_RESIZED]: {

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ suite('Plots Test Suite', () => {
568568
const webview = await plots.showWebview()
569569
mockPlotsDiff.resetHistory()
570570
const instanceMessageSpy = spy(webview, 'show')
571+
await webview.isReady()
571572

572573
const mockSendTelemetryEvent = stub(Telemetry, 'sendTelemetryEvent')
573574
const mockMessageReceived = getMessageReceivedEmitter(webview)
@@ -583,11 +584,7 @@ suite('Plots Test Suite', () => {
583584
await dataUpdateEvent
584585

585586
expect(mockSendTelemetryEvent).to.be.calledOnce
586-
expect(mockSendTelemetryEvent).to.be.calledWithExactly(
587-
EventName.VIEWS_PLOTS_MANUAL_REFRESH,
588-
undefined,
589-
undefined
590-
)
587+
expect(mockSendTelemetryEvent).to.be.calledWith(EventName.PLOTS_REFRESH)
591588
expect(mockPlotsDiff).to.be.called
592589
expect(mockPlotsDiff).to.be.calledWithExactly(
593590
dvcDemoPath,
@@ -841,7 +838,8 @@ suite('Plots Test Suite', () => {
841838
})
842839

843840
expect(executeCommandSpy).to.be.calledWithExactly(
844-
RegisteredCommands.PLOTS_CUSTOM_ADD
841+
RegisteredCommands.PLOTS_CUSTOM_ADD,
842+
dvcDemoPath
845843
)
846844
})
847845

@@ -857,7 +855,8 @@ suite('Plots Test Suite', () => {
857855
})
858856

859857
expect(executeCommandSpy).to.be.calledWithExactly(
860-
RegisteredCommands.PLOTS_CUSTOM_REMOVE
858+
RegisteredCommands.PLOTS_CUSTOM_REMOVE,
859+
dvcDemoPath
861860
)
862861
})
863862

extension/src/test/suite/plots/paths/tree.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ suite('Plots Paths Tree Test Suite', () => {
130130
})
131131
}).timeout(WEBVIEW_TEST_TIMEOUT)
132132

133-
it('should be able to refresh revision data for all plots using dvc.views.plotsPathsTree.refreshPlots', async () => {
133+
it('should be able to refresh revision data for all plots using dvc.views.plots.refreshPlots', async () => {
134134
const { data, mockPlotsDiff, plots } = await buildPlots(
135135
disposable,
136136
plotsDiffFixture

0 commit comments

Comments
 (0)