Skip to content

Commit 8eecddf

Browse files
authored
Add (manual) refresh plots command to tree and palette (#1868)
* add refresh all plots to plots tree and command palette * add integration test
1 parent 4db76ed commit 8eecddf

File tree

8 files changed

+73
-0
lines changed

8 files changed

+73
-0
lines changed

extension/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,12 @@
471471
"command": "dvc.views.plotsPathsTree.selectPlots",
472472
"category": "DVC",
473473
"icon": "$(list-filter)"
474+
},
475+
{
476+
"title": "%command.views.plotsPathsTree.refreshPlots%",
477+
"command": "dvc.views.plotsPathsTree.refreshPlots",
478+
"category": "DVC",
479+
"icon": "$(refresh)"
474480
}
475481
],
476482
"configuration": {
@@ -778,6 +784,10 @@
778784
{
779785
"command": "dvc.views.plotsPathsTree.selectPlots",
780786
"when": "dvc.commands.available && dvc.project.available"
787+
},
788+
{
789+
"command": "dvc.views.plotsPathsTree.refreshPlots",
790+
"when": "dvc.commands.available && dvc.project.available"
781791
}
782792
],
783793
"scm/title": [
@@ -1058,6 +1068,11 @@
10581068
"command": "dvc.views.plotsPathsTree.selectPlots",
10591069
"group": "inline",
10601070
"when": "view == dvc.views.plotsPathsTree && dvc.commands.available && viewItem == dvcRoot"
1071+
},
1072+
{
1073+
"command": "dvc.views.plotsPathsTree.refreshPlots",
1074+
"group": "inline",
1075+
"when": "view == dvc.views.plotsPathsTree && dvc.commands.available && viewItem == dvcRoot"
10611076
}
10621077
],
10631078
"view/title": [
@@ -1210,6 +1225,11 @@
12101225
"command": "dvc.views.plotsPathsTree.selectPlots",
12111226
"when": "view == dvc.views.plotsPathsTree",
12121227
"group": "navigation@2"
1228+
},
1229+
{
1230+
"command": "dvc.views.plotsPathsTree.refreshPlots",
1231+
"when": "view == dvc.views.plotsPathsTree",
1232+
"group": "navigation@3"
12131233
}
12141234
]
12151235
},

extension/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"command.views.experimentsTree.resetAndRunCheckpointExperiment": "Modify Param(s), Reset and Run",
6868
"command.views.experimentsTree.selectExperiments": "Select Experiments to Display in Plots",
6969
"command.views.plotsPathsTree.selectPlots": "Select Plots to Display",
70+
"command.views.plotsPathsTree.refreshPlots": "Refresh Plots for Selected Experiments",
7071
"config.doNotRecommendRedHatExtension.description": "Do not prompt to install the Red Hat YAML extension to assist with DVC YAML schema validation.",
7172
"config.doNotRecommendRedHatExtension.title": "Do not prompt to install the Red Hat YAML extension.",
7273
"config.doNotShowCliUnavailable.description": "Do not warn when the workspace contains a DVC project but the CLI is inaccessible.",

extension/src/commands/external.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export enum RegisteredCommands {
5757
PLOTS_PATH_TOGGLE = 'dvc.views.plotsPathsTree.toggleStatus',
5858
PLOTS_SHOW = 'dvc.showPlots',
5959
PLOTS_SELECT = 'dvc.views.plotsPathsTree.selectPlots',
60+
PLOTS_REFRESH = 'dvc.views.plotsPathsTree.refreshPlots',
6061

6162
EXTENSION_CHECK_CLI_COMPATIBLE = 'dvc.checkCLICompatible',
6263
EXTENSION_GET_STARTED = 'dvc.getStarted',

extension/src/plots/commands/register.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ export const registerPlotsCommands = (
1717
RegisteredCommands.PLOTS_SELECT,
1818
(dvcRoot?: string) => plots.selectPlots(dvcRoot)
1919
)
20+
21+
internalCommands.registerExternalCommand(
22+
RegisteredCommands.PLOTS_REFRESH,
23+
(dvcRoot?: string) => plots.refresh(dvcRoot)
24+
)
2025
}

extension/src/plots/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ export class Plots extends BaseRepository<TPlotsData> {
125125
return this.notifyChanged()
126126
}
127127

128+
public refreshPlots() {
129+
Toast.infoWithOptions(
130+
'Attempting to refresh plots for selected experiments.'
131+
)
132+
for (const { revision } of this.plots?.getSelectedRevisionDetails() || []) {
133+
this.plots?.setupManualRefresh(revision)
134+
}
135+
this.data.managedUpdate()
136+
}
137+
128138
public getChildPaths(path: string) {
129139
return this.paths?.getChildren(path) || []
130140
}

extension/src/plots/workspace.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ export class WorkspacePlots extends BaseWorkspaceWebviews<Plots, PlotsData> {
3939
return plots
4040
}
4141

42+
public async refresh(overrideRoot?: string) {
43+
const dvcRoot = await this.getDvcRoot(overrideRoot)
44+
if (!dvcRoot) {
45+
return
46+
}
47+
return this.getRepository(dvcRoot).refreshPlots()
48+
}
49+
4250
public async selectPlots(overrideRoot?: string) {
4351
const dvcRoot = await this.getDvcRoot(overrideRoot)
4452
if (!dvcRoot) {

extension/src/telemetry/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export interface IEventNamePropertyMapping {
142142
[EventName.PLOTS_PATH_TOGGLE]: undefined
143143
[EventName.PLOTS_SHOW]: undefined
144144
[EventName.PLOTS_SELECT]: undefined
145+
[EventName.PLOTS_REFRESH]: undefined
145146

146147
[EventName.ADD_TARGET]: undefined
147148
[EventName.CHECKOUT_TARGET]: undefined

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,32 @@ suite('Plots Paths Tree Test Suite', () => {
128128
template: templatePlotsFixture
129129
})
130130
}).timeout(WEBVIEW_TEST_TIMEOUT)
131+
132+
it('should be able to refresh revision data for all plots using dvc.views.plotsPathsTree.refreshPlots', async () => {
133+
const { data, mockPlotsDiff, plots } = await buildPlots(
134+
disposable,
135+
plotsDiffFixture
136+
)
137+
138+
await plots.showWebview()
139+
140+
const dataUpdated = new Promise(resolve =>
141+
disposable.track(data.onDidUpdate(() => resolve(undefined)))
142+
)
143+
mockPlotsDiff.resetHistory()
144+
145+
await commands.executeCommand(RegisteredCommands.PLOTS_REFRESH)
146+
await dataUpdated
147+
148+
expect(mockPlotsDiff).to.be.calledOnce
149+
expect(mockPlotsDiff).to.be.calledWithExactly(
150+
dvcDemoPath,
151+
'1ba7bcd',
152+
'42b8736',
153+
'4fb124a',
154+
'main',
155+
'workspace'
156+
)
157+
}).timeout(WEBVIEW_TEST_TIMEOUT)
131158
})
132159
})

0 commit comments

Comments
 (0)