Skip to content

Commit f6654fd

Browse files
authored
Merge create plot commands (#4680)
1 parent b7e0ce5 commit f6654fd

File tree

26 files changed

+268
-127
lines changed

26 files changed

+268
-127
lines changed

extension/package.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@
425425
},
426426
{
427427
"title": "Add Plot",
428-
"command": "dvc.addTopLevelPlot",
428+
"command": "dvc.addPlot",
429429
"category": "DVC",
430430
"icon": "$(add)"
431431
},
@@ -601,11 +601,6 @@
601601
"category": "DVC",
602602
"icon": "$(refresh)"
603603
},
604-
{
605-
"title": "Add Custom Plot",
606-
"command": "dvc.views.plots.addCustomPlot",
607-
"category": "DVC"
608-
},
609604
{
610605
"title": "Remove Custom Plot(s)",
611606
"command": "dvc.views.plots.removeCustomPlots",
@@ -910,7 +905,7 @@
910905
"when": "dvc.commands.available && dvc.project.available"
911906
},
912907
{
913-
"command": "dvc.addTopLevelPlot",
908+
"command": "dvc.addPlot",
914909
"when": "dvc.commands.available && dvc.project.available"
915910
},
916911
{
@@ -1029,10 +1024,6 @@
10291024
"command": "dvc.views.plots.refreshPlots",
10301025
"when": "dvc.commands.available && dvc.project.available"
10311026
},
1032-
{
1033-
"command": "dvc.views.plots.addCustomPlot",
1034-
"when": "dvc.commands.available && dvc.project.available"
1035-
},
10361027
{
10371028
"command": "dvc.views.plots.removeCustomPlots",
10381029
"when": "dvc.commands.available && dvc.project.available"
@@ -1425,7 +1416,7 @@
14251416
"group": "navigation@3"
14261417
},
14271418
{
1428-
"command": "dvc.addTopLevelPlot",
1419+
"command": "dvc.addPlot",
14291420
"when": "view == dvc.views.plotsPathsTree",
14301421
"group": "navigation@0"
14311422
},

extension/src/commands/external.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ export enum RegisteredCommands {
7272
STOP_EXPERIMENTS = 'dvc.stopAllRunningExperiments',
7373

7474
PIPELINE_SHOW_DAG = 'dvc.showPipelineDAG',
75-
PIPELINE_ADD_PLOT = 'dvc.addTopLevelPlot',
7675

7776
PLOTS_PATH_TOGGLE = 'dvc.views.plotsPathsTree.toggleStatus',
7877
PLOTS_SHOW = 'dvc.showPlots',
7978
PLOTS_SELECT = 'dvc.views.plotsPathsTree.selectPlots',
8079
PLOTS_REFRESH = 'dvc.views.plots.refreshPlots',
81-
PLOTS_CUSTOM_ADD = 'dvc.views.plots.addCustomPlot',
8280
PLOTS_CUSTOM_REMOVE = 'dvc.views.plots.removeCustomPlots',
8381

82+
ADD_PLOT = 'dvc.addPlot',
83+
8484
EXPERIMENT_AND_PLOTS_SHOW = 'dvc.showExperimentsAndPlots',
8585

8686
EXTENSION_CHECK_CLI_COMPATIBLE = 'dvc.checkCLICompatible',

extension/src/extension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,12 @@ class Extension extends Disposable {
192192
this.setup
193193
)
194194
registerPipelineCommands(this.pipelines, this.internalCommands)
195-
registerPlotsCommands(this.plots, this.internalCommands, this.setup)
195+
registerPlotsCommands(
196+
this.plots,
197+
this.internalCommands,
198+
this.setup,
199+
this.pipelines
200+
)
196201
registerSetupCommands(this.setup, this.internalCommands)
197202
this.internalCommands.registerExternalCommand(
198203
RegisteredCommands.EXPERIMENT_AND_PLOTS_SHOW,

extension/src/pipeline/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class Pipeline extends DeferredDisposable {
112112
return this.addPipeline()
113113
}
114114

115-
public async addTopLevelPlot() {
115+
public async addDataSeriesPlot() {
116116
const cwd = await this.getCwd()
117117

118118
if (!cwd) {

extension/src/pipeline/register.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { WorkspacePipeline } from './workspace'
22
import { RegisteredCommands } from '../commands/external'
33
import { InternalCommands } from '../commands/internal'
4-
import { Context, getDvcRootFromContext } from '../vscode/context'
54

65
export const registerPipelineCommands = (
76
pipelines: WorkspacePipeline,
@@ -11,10 +10,4 @@ export const registerPipelineCommands = (
1110
RegisteredCommands.PIPELINE_SHOW_DAG,
1211
() => pipelines.showDag()
1312
)
14-
15-
internalCommands.registerExternalCommand(
16-
RegisteredCommands.PIPELINE_ADD_PLOT,
17-
(context: Context) =>
18-
pipelines.addTopLevelPlot(getDvcRootFromContext(context))
19-
)
2013
}

extension/src/pipeline/workspace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ export class WorkspacePipeline extends BaseWorkspace<Pipeline> {
6363
)
6464
}
6565

66-
public async addTopLevelPlot(overrideRoot?: string) {
66+
public async addDataSeriesPlot(overrideRoot?: string) {
6767
const cwd = overrideRoot || (await this.getCwd())
6868

6969
if (!cwd) {
7070
return
7171
}
7272

73-
void this.getRepository(cwd).addTopLevelPlot()
73+
void this.getRepository(cwd).addDataSeriesPlot()
7474
}
7575

7676
private getCwd() {

extension/src/plots/commands/register.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1+
import { commands } from 'vscode'
12
import { RegisteredCommands } from '../../commands/external'
23
import { InternalCommands } from '../../commands/internal'
34
import { showSetupOrExecuteCommand } from '../../commands/util'
45
import { Setup } from '../../setup'
56
import { Context, getDvcRootFromContext } from '../../vscode/context'
67
import { WorkspacePlots } from '../workspace'
8+
import { WorkspacePipeline } from '../../pipeline/workspace'
79

810
export const registerPlotsCommands = (
911
plots: WorkspacePlots,
1012
internalCommands: InternalCommands,
11-
setup: Setup
13+
setup: Setup,
14+
pipelines: WorkspacePipeline
1215
) => {
16+
commands.registerCommand(RegisteredCommands.ADD_PLOT, (context: Context) =>
17+
plots.addPlot(pipelines, getDvcRootFromContext(context))
18+
)
19+
1320
internalCommands.registerExternalCommand(
1421
RegisteredCommands.PLOTS_SHOW,
1522
showSetupOrExecuteCommand(setup, context =>
@@ -27,11 +34,6 @@ export const registerPlotsCommands = (
2734
(context: Context) => plots.refresh(getDvcRootFromContext(context))
2835
)
2936

30-
internalCommands.registerExternalCommand(
31-
RegisteredCommands.PLOTS_CUSTOM_ADD,
32-
(context: Context) => plots.addCustomPlot(getDvcRootFromContext(context))
33-
)
34-
3537
internalCommands.registerExternalCommand(
3638
RegisteredCommands.PLOTS_CUSTOM_REMOVE,
3739
(context: Context) =>

extension/src/plots/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ export class Plots extends BaseRepository<TPlotsData> {
223223
errors,
224224
experiments,
225225
() => this.getWebview(),
226-
() => this.selectPlots()
226+
() => this.selectPlots(),
227+
() => this.addCustomPlot()
227228
)
228229
this.dispose.track(
229230
this.onDidReceivedWebviewMessage(message =>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { pickPlotType } from './quickPick'
2+
import { quickPickValue } from '../vscode/quickPick'
3+
import { Title } from '../vscode/title'
4+
5+
jest.mock('../vscode/quickPick')
6+
7+
const mockedQuickPickValue = jest.mocked(quickPickValue)
8+
9+
beforeEach(() => {
10+
jest.resetAllMocks()
11+
})
12+
13+
describe('pickPlotType', () => {
14+
it('should call a quick pick with possible plot types', async () => {
15+
mockedQuickPickValue.mockResolvedValueOnce(undefined)
16+
17+
await pickPlotType()
18+
19+
expect(mockedQuickPickValue).toHaveBeenCalledWith(
20+
[
21+
{
22+
description:
23+
'Create a data series plot definition by selecting data from a file',
24+
label: 'Data Series',
25+
value: 'data-series'
26+
},
27+
{
28+
description:
29+
'Create an extension-only plot by selecting one metric and one param from the experiments table',
30+
label: 'Custom',
31+
value: 'custom'
32+
}
33+
],
34+
{
35+
title: Title.SELECT_PLOT_TYPE
36+
}
37+
)
38+
})
39+
})

extension/src/plots/quickPick.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { quickPickValue } from '../vscode/quickPick'
2+
import { Title } from '../vscode/title'
3+
4+
export const enum PLOT_TYPE {
5+
CUSTOM = 'custom',
6+
DATA_SERIES = 'data-series'
7+
}
8+
9+
export const pickPlotType = () =>
10+
quickPickValue(
11+
[
12+
{
13+
description:
14+
'Create a data series plot definition by selecting data from a file',
15+
label: 'Data Series',
16+
value: PLOT_TYPE.DATA_SERIES
17+
},
18+
{
19+
description:
20+
'Create an extension-only plot by selecting one metric and one param from the experiments table',
21+
label: 'Custom',
22+
value: PLOT_TYPE.CUSTOM
23+
}
24+
],
25+
{
26+
title: Title.SELECT_PLOT_TYPE
27+
}
28+
)

0 commit comments

Comments
 (0)