Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge create plot commands #4680

Merged
merged 10 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@
},
{
"title": "Add Plot",
"command": "dvc.addTopLevelPlot",
"command": "dvc.addPlot",
"category": "DVC",
"icon": "$(add)"
},
Expand Down Expand Up @@ -601,11 +601,6 @@
"category": "DVC",
"icon": "$(refresh)"
},
{
"title": "Add Custom Plot",
"command": "dvc.views.plots.addCustomPlot",
"category": "DVC"
},
{
"title": "Remove Custom Plot(s)",
"command": "dvc.views.plots.removeCustomPlots",
Expand Down Expand Up @@ -910,7 +905,7 @@
"when": "dvc.commands.available && dvc.project.available"
},
{
"command": "dvc.addTopLevelPlot",
"command": "dvc.addPlot",
"when": "dvc.commands.available && dvc.project.available"
},
{
Expand Down Expand Up @@ -1029,10 +1024,6 @@
"command": "dvc.views.plots.refreshPlots",
"when": "dvc.commands.available && dvc.project.available"
},
{
"command": "dvc.views.plots.addCustomPlot",
"when": "dvc.commands.available && dvc.project.available"
},
{
"command": "dvc.views.plots.removeCustomPlots",
"when": "dvc.commands.available && dvc.project.available"
Expand Down Expand Up @@ -1425,7 +1416,7 @@
"group": "navigation@3"
},
{
"command": "dvc.addTopLevelPlot",
"command": "dvc.addPlot",
"when": "view == dvc.views.plotsPathsTree",
"group": "navigation@0"
},
Expand Down
2 changes: 2 additions & 0 deletions extension/src/commands/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export enum RegisteredCommands {
PLOTS_CUSTOM_ADD = 'dvc.views.plots.addCustomPlot',
PLOTS_CUSTOM_REMOVE = 'dvc.views.plots.removeCustomPlots',

ADD_PLOT = 'dvc.addPlot',

EXPERIMENT_AND_PLOTS_SHOW = 'dvc.showExperimentsAndPlots',

EXTENSION_CHECK_CLI_COMPATIBLE = 'dvc.checkCLICompatible',
Expand Down
66 changes: 66 additions & 0 deletions extension/src/commands/util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { commands } from 'vscode'
import { RegisteredCommands } from './external'
import { addPlotCommand } from './util'
import { quickPickValue } from '../vscode/quickPick'
import { Title } from '../vscode/title'

jest.mock('../vscode/quickPick')

const mockedQuickPickValue = jest.mocked(quickPickValue)
const mockedCommands = jest.mocked(commands)
const mockedExecuteCommand = jest.fn()
mockedCommands.executeCommand = mockedExecuteCommand

beforeEach(() => {
jest.resetAllMocks()
})

describe('addPlotCommand', () => {
it('should call no add commands if no plots types are selected', async () => {
mockedQuickPickValue.mockResolvedValueOnce(undefined)

await addPlotCommand(undefined)

expect(mockedQuickPickValue).toHaveBeenCalledWith(
[
{
description: 'Create a dvc.yaml plot based off a chosen data file',
label: 'Top-Level',
value: 'top-level'
},
{
description:
'Create an extension-only plot based off a chosen metric and param',
label: 'Custom',
value: 'custom'
}
],
{
title: Title.SELECT_PLOT_TYPE
}
)
expect(mockedExecuteCommand).not.toHaveBeenCalled()
})

it('should call the add top-level plot command if the top-level type is selected', async () => {
mockedQuickPickValue.mockResolvedValueOnce('top-level')

await addPlotCommand(undefined)

expect(mockedExecuteCommand).toHaveBeenCalledWith(
RegisteredCommands.PIPELINE_ADD_PLOT,
undefined
)
})

it('should call the add custom plot command if the custom type is selected', async () => {
mockedQuickPickValue.mockResolvedValueOnce('custom')

await addPlotCommand('cwd')

expect(mockedExecuteCommand).toHaveBeenCalledWith(
RegisteredCommands.PLOTS_CUSTOM_ADD,
'cwd'
)
})
})
39 changes: 39 additions & 0 deletions extension/src/commands/util.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better place for these two commands that are registered in extension.ts? I couldn't think of a place that didn't feel confusing 🤔

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { commands } from 'vscode'
import { RegisteredCommands } from './external'
import { Setup } from '../setup'
import { Context } from '../vscode/context'
import { quickPickValue } from '../vscode/quickPick'
import { Title } from '../vscode/title'

export const showSetupOrExecuteCommand =
<T>(setup: Setup, callback: (context: Context) => Promise<T | undefined>) =>
Expand All @@ -18,3 +20,40 @@ export const showSetupOrExecuteCommand =

return callback(context)
}

const enum PLOT_TYPE {
CUSTOM = 'custom',
TOP_LEVEL = 'top-level'
}

export const addPlotCommand = async (context: Context) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[I] These should go in a new plots/quickPick file. Can you also please check to see if we will get two analytics events each time this is called (I don't think we want that).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also please check to see if we will get two analytics events each time this is called (I don't think we want that).

Oh, I think we would get two since addPlot fires one and then "add custom"/"add pipeline" would fire another. We could remove the "add custom" and "add pipeline" commands and add a type argument to the "add plot" command 🤔

const result: PLOT_TYPE | undefined = await quickPickValue(
julieg18 marked this conversation as resolved.
Show resolved Hide resolved
[
{
description: 'Create a dvc.yaml plot based off a chosen data file',
julieg18 marked this conversation as resolved.
Show resolved Hide resolved
label: 'Top-Level',
value: PLOT_TYPE.TOP_LEVEL
},
{
description:
'Create an extension-only plot based off a chosen metric and param',
julieg18 marked this conversation as resolved.
Show resolved Hide resolved
label: 'Custom',
value: PLOT_TYPE.CUSTOM
}
],
{
title: Title.SELECT_PLOT_TYPE
}
)

if (result === PLOT_TYPE.CUSTOM) {
return commands.executeCommand(RegisteredCommands.PLOTS_CUSTOM_ADD, context)
}

if (result === PLOT_TYPE.TOP_LEVEL) {
return commands.executeCommand(
RegisteredCommands.PIPELINE_ADD_PLOT,
context
)
}
}
6 changes: 5 additions & 1 deletion extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { DvcViewer } from './cli/dvc/viewer'
import { registerSetupCommands } from './setup/commands/register'
import { Status } from './status'
import { registerPersistenceCommands } from './persistence/register'
import { showSetupOrExecuteCommand } from './commands/util'
import { addPlotCommand, showSetupOrExecuteCommand } from './commands/util'
import { WorkspacePipeline } from './pipeline/workspace'
import { registerPipelineCommands } from './pipeline/register'

Expand Down Expand Up @@ -193,6 +193,10 @@ class Extension extends Disposable {
)
registerPipelineCommands(this.pipelines, this.internalCommands)
registerPlotsCommands(this.plots, this.internalCommands, this.setup)
this.internalCommands.registerExternalCommand(
julieg18 marked this conversation as resolved.
Show resolved Hide resolved
RegisteredCommands.ADD_PLOT,
addPlotCommand
)
registerSetupCommands(this.setup, this.internalCommands)
this.internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_AND_PLOTS_SHOW,
Expand Down
8 changes: 4 additions & 4 deletions extension/src/plots/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ export class WebviewMessages {

public handleMessageFromWebview(message: MessageFromWebview) {
switch (message.type) {
case MessageFromWebviewType.ADD_CUSTOM_PLOT:
case MessageFromWebviewType.ADD_PLOT:
return commands.executeCommand(
RegisteredCommands.PLOTS_CUSTOM_ADD,
RegisteredCommands.ADD_PLOT,
this.dvcRoot
)
case MessageFromWebviewType.ADD_PIPELINE_PLOT:
case MessageFromWebviewType.ADD_CUSTOM_PLOT:
return commands.executeCommand(
RegisteredCommands.PIPELINE_ADD_PLOT,
RegisteredCommands.PLOTS_CUSTOM_ADD,
this.dvcRoot
)
case MessageFromWebviewType.EXPORT_PLOT_DATA_AS_CSV:
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 @@ -204,6 +204,8 @@ export interface IEventNamePropertyMapping {
[EventName.PLOTS_CUSTOM_ADD]: undefined
[EventName.PLOTS_CUSTOM_REMOVE]: undefined

[EventName.ADD_PLOT]: undefined

[EventName.ADD_TARGET]: undefined
[EventName.CHECKOUT_TARGET]: undefined
[EventName.CHECKOUT]: undefined
Expand Down
4 changes: 3 additions & 1 deletion extension/src/test/e2e/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ export const closeAllEditors = async (): Promise<void> => {

export const createCustomPlot = async (): Promise<void> => {
const workbench = await browser.getWorkbench()
const addCustomPlot = await workbench.executeCommand('DVC: Add Custom Plot')
const addCustomPlot = await workbench.executeCommand('DVC: Add Plot')
await browser.waitUntil(() => addCustomPlot.elem.isDisplayed())
await browser.keys(['ArrowDown', 'Enter'])
await browser.waitUntil(() => addCustomPlot.elem.isDisplayed())
await browser.keys('Enter')
await browser.waitUntil(() => addCustomPlot.elem.isDisplayed())
Expand Down
6 changes: 3 additions & 3 deletions extension/src/test/suite/plots/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ suite('Plots Test Suite', () => {
)
})

it('should handle an add pipeline plot message from the webview', async () => {
it('should handle an add plot message from the webview', async () => {
const { mockMessageReceived } = await buildPlotsWebview({
disposer: disposable,
plotsDiff: plotsDiffFixture
Expand All @@ -1218,11 +1218,11 @@ suite('Plots Test Suite', () => {
const executeCommandSpy = spy(commands, 'executeCommand')

mockMessageReceived.fire({
type: MessageFromWebviewType.ADD_PIPELINE_PLOT
type: MessageFromWebviewType.ADD_PLOT
})

expect(executeCommandSpy).to.be.calledWithExactly(
RegisteredCommands.PIPELINE_ADD_PLOT,
RegisteredCommands.ADD_PLOT,
dvcDemoPath
)
})
Expand Down
1 change: 1 addition & 0 deletions extension/src/vscode/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export enum Title {
SELECT_SORTS_TO_REMOVE = 'Select Sort(s) to Remove',
SELECT_TRAINING_SCRIPT = 'Select your Training Script',
SELECT_PLOT_DATA = 'Select Data to Plot',
SELECT_PLOT_TYPE = 'Select Plot Type',
SETUP_WORKSPACE = 'Setup the Workspace',
SET_EXPERIMENTS_HEADER_HEIGHT = 'Set the Maximum Experiment Table Header Height',
SET_REMOTE_AS_DEFAULT = 'Set Default Remote',
Expand Down
4 changes: 2 additions & 2 deletions extension/src/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export enum MessageFromWebviewType {
ADD_CONFIGURATION = 'add-configuration',
APPLY_EXPERIMENT_TO_WORKSPACE = 'apply-experiment-to-workspace',
ADD_STARRED_EXPERIMENT_FILTER = 'add-starred-experiment-filter',
ADD_PLOT = 'add-plot',
ADD_CUSTOM_PLOT = 'add-custom-plot',
ADD_PIPELINE_PLOT = 'add-pipeline-plot',
CREATE_BRANCH_FROM_EXPERIMENT = 'create-branch-from-experiment',
COPY_TO_CLIPBOARD = 'copy-to-clipboard',
COPY_STUDIO_LINK = 'copy-studio-link',
Expand Down Expand Up @@ -112,7 +112,7 @@ export type MessageFromWebview =
type: MessageFromWebviewType.ADD_CUSTOM_PLOT
}
| {
type: MessageFromWebviewType.ADD_PIPELINE_PLOT
type: MessageFromWebviewType.ADD_PLOT
}
| {
type: MessageFromWebviewType.COPY_TO_CLIPBOARD
Expand Down
Loading