Skip to content

Commit

Permalink
Fix view/title commands (#2439)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon authored Sep 22, 2022
1 parent 998d3f3 commit bb10bcc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 79 deletions.
60 changes: 0 additions & 60 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1054,46 +1054,16 @@
"group": "7_modification@2",
"when": "view == dvc.views.trackedExplorerTree && viewItem =~ /^.*Data$/ && !dvc.scm.command.running"
},
{
"command": "dvc.addExperimentsTableSort",
"group": "inline",
"when": "view == dvc.views.experimentsSortByTree && dvc.commands.available && viewItem == dvcRoot"
},
{
"command": "dvc.addStarredExperimentsTableSort",
"group": "inline",
"when": "view == dvc.views.experimentsSortByTree && dvc.commands.available && viewItem == dvcRoot"
},
{
"command": "dvc.views.experimentsSortByTree.removeSort",
"group": "inline",
"when": "view == dvc.views.experimentsSortByTree && dvc.commands.available && viewItem != dvcRoot"
},
{
"command": "dvc.views.experimentsSortByTree.removeAllSorts",
"group": "inline",
"when": "view == dvc.views.experimentsSortByTree && dvc.commands.available && viewItem == dvcRoot"
},
{
"command": "dvc.addExperimentsTableFilter",
"group": "inline",
"when": "view == dvc.views.experimentsFilterByTree && dvc.commands.available && viewItem == dvcRoot"
},
{
"command": "dvc.addStarredExperimentsTableFilter",
"group": "inline",
"when": "view == dvc.views.experimentsFilterByTree && dvc.commands.available && viewItem == dvcRoot"
},
{
"command": "dvc.views.experimentsFilterByTree.removeFilter",
"group": "inline",
"when": "view == dvc.views.experimentsFilterByTree && dvc.commands.available && viewItem != dvcRoot"
},
{
"command": "dvc.views.experimentsFilterByTree.removeAllFilters",
"group": "inline",
"when": "view == dvc.views.experimentsFilterByTree && dvc.commands.available && viewItem == dvcRoot"
},
{
"command": "dvc.views.experiments.applyExperiment",
"group": "inline@1",
Expand Down Expand Up @@ -1138,31 +1108,6 @@
"command": "dvc.views.experiments.queueExperiment",
"group": "2_modify@3",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(workspace|branch|experiment|queued)$/ && !dvc.experiment.running"
},
{
"command": "dvc.views.experimentsTree.selectExperiments",
"group": "inline",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem == dvcRoot"
},
{
"command": "dvc.views.experimentsTree.autoApplyFilters",
"group": "inline",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && !dvc.experiments.filter.selected && viewItem == dvcRoot"
},
{
"command": "dvc.views.experimentsTree.disableAutoApplyFilters",
"group": "inline",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && dvc.experiments.filter.selected && viewItem == dvcRoot"
},
{
"command": "dvc.views.plotsPathsTree.selectPlots",
"group": "inline",
"when": "view == dvc.views.plotsPathsTree && dvc.commands.available && viewItem == dvcRoot"
},
{
"command": "dvc.views.plotsPathsTree.refreshPlots",
"group": "inline",
"when": "view == dvc.views.plotsPathsTree && dvc.commands.available && viewItem == dvcRoot"
}
],
"view/title": [
Expand Down Expand Up @@ -1191,11 +1136,6 @@
"when": "view == dvc.views.experimentsColumnsTree",
"group": "navigation@2"
},
{
"command": "dvc.views.experimentsColumnsTree.selectColumns",
"group": "inline",
"when": "view == dvc.views.experimentsColumnsTree && dvc.commands.available && viewItem == dvcRoot"
},
{
"command": "dvc.runExperiment",
"when": "view == dvc.views.experimentsTree && !dvc.experiments.webviewActive && !dvc.experiment.running && !dvc.experiment.checkpoints",
Expand Down
27 changes: 17 additions & 10 deletions extension/src/experiments/commands/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
RegisteredCommands
} from '../../commands/external'
import { Title } from '../../vscode/title'
import { Context, getDvcRootFromContext } from '../../vscode/context'

type ExperimentDetails = { dvcRoot: string; id: string }

Expand Down Expand Up @@ -230,12 +231,13 @@ const registerExperimentQuickPickCommands = (

internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_FILTER_ADD,
(dvcRoot?: string) => experiments.addFilter(dvcRoot)
(context: Context) => experiments.addFilter(getDvcRootFromContext(context))
)

internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_FILTER_ADD_STARRED,
(dvcRoot?: string) => experiments.addStarredFilter(dvcRoot)
(context: Context) =>
experiments.addStarredFilter(getDvcRootFromContext(context))
)

internalCommands.registerExternalCommand(
Expand All @@ -245,12 +247,13 @@ const registerExperimentQuickPickCommands = (

internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_SORT_ADD,
(dvcRoot?: string) => experiments.addSort(dvcRoot)
(context: Context) => experiments.addSort(getDvcRootFromContext(context))
)

internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_SORT_ADD_STARRED,
(dvcRoot?: string) => experiments.addStarredSort(dvcRoot)
(context: Context) =>
experiments.addStarredSort(getDvcRootFromContext(context))
)

internalCommands.registerExternalCommand(
Expand All @@ -260,12 +263,14 @@ const registerExperimentQuickPickCommands = (

internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_SELECT,
(dvcRoot?: string) => experiments.selectExperiments(dvcRoot)
(context: Context) =>
experiments.selectExperiments(getDvcRootFromContext(context))
)

internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_COLUMNS_SELECT,
(dvcRoot?: string) => experiments.selectColumns(dvcRoot)
(context: Context) =>
experiments.selectColumns(getDvcRootFromContext(context))
)
}

Expand Down Expand Up @@ -295,8 +300,8 @@ const registerExperimentRunCommands = (

internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_SHOW,
(context: { dvcRoot?: string } | undefined) =>
experiments.showWebview(context?.dvcRoot)
(context: Context) =>
experiments.showWebview(getDvcRootFromContext(context))
)
}

Expand All @@ -312,12 +317,14 @@ export const registerExperimentCommands = (

internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_AUTO_APPLY_FILTERS,
(dvcRoot?: string) => experiments.autoApplyFilters(true, dvcRoot)
(context: Context) =>
experiments.autoApplyFilters(true, getDvcRootFromContext(context))
)

internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_DISABLE_AUTO_APPLY_FILTERS,
(dvcRoot?: string) => experiments.autoApplyFilters(false, dvcRoot)
(context: Context) =>
experiments.autoApplyFilters(false, getDvcRootFromContext(context))
)

internalCommands.registerExternalCommand(
Expand Down
6 changes: 5 additions & 1 deletion extension/src/experiments/model/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ export class ExperimentsTree
)
)

return `${selected} of ${total} (max ${MAX_SELECTED_EXPERIMENTS})`
return (
`${selected} of ${total} (max ${MAX_SELECTED_EXPERIMENTS}` +
(dvcRoots.length > 1 ? ' per project' : '') +
')'
)
}

private isRoot(element: string | ExperimentItem): element is string {
Expand Down
4 changes: 1 addition & 3 deletions extension/src/experiments/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ export class WebviewMessages {
}

private showPlots() {
return commands.executeCommand(RegisteredCommands.PLOTS_SHOW, {
dvcRoot: this.dvcRoot
})
return commands.executeCommand(RegisteredCommands.PLOTS_SHOW, this.dvcRoot)
}
}
8 changes: 4 additions & 4 deletions extension/src/plots/commands/register.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RegisteredCommands } from '../../commands/external'
import { InternalCommands } from '../../commands/internal'
import { Context, getDvcRootFromContext } from '../../vscode/context'
import { WorkspacePlots } from '../workspace'

export const registerPlotsCommands = (
Expand All @@ -8,17 +9,16 @@ export const registerPlotsCommands = (
) => {
internalCommands.registerExternalCommand(
RegisteredCommands.PLOTS_SHOW,
(context: { dvcRoot?: string } | undefined) =>
plots.showWebview(context?.dvcRoot)
(context: Context) => plots.showWebview(getDvcRootFromContext(context))
)

internalCommands.registerExternalCommand(
RegisteredCommands.PLOTS_SELECT,
(dvcRoot?: string) => plots.selectPlots(dvcRoot)
(context: Context) => plots.selectPlots(getDvcRootFromContext(context))
)

internalCommands.registerExternalCommand(
RegisteredCommands.PLOTS_REFRESH,
(dvcRoot?: string) => plots.refresh(dvcRoot)
(context: Context) => plots.refresh(getDvcRootFromContext(context))
)
}
5 changes: 4 additions & 1 deletion extension/src/tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export const createTreeView = <T>(
})

export const getRootItem = (path: string): TreeItem => {
const item = new TreeItem(Uri.file(path), TreeItemCollapsibleState.Expanded)
const item = new TreeItem(
Uri.file(path),
TreeItemCollapsibleState.Expanded
) as TreeItem
item.id = path
item.contextValue = 'dvcRoot'
return item
Expand Down
7 changes: 7 additions & 0 deletions extension/src/vscode/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ import { commands } from 'vscode'

export const setContextValue = (key: string, value: unknown) =>
commands.executeCommand('setContext', key, value)

export type Context = string | Record<string, unknown> | undefined

export const getDvcRootFromContext = (context: Context): string | undefined => {
const isDvcRoot = typeof context === 'string'
return isDvcRoot ? context : undefined
}

0 comments on commit bb10bcc

Please sign in to comment.