From effd0151dd056d94b0bde06b78fc602fc315b628 Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Wed, 10 Aug 2022 13:46:09 +1000 Subject: [PATCH 1/2] add shortcut to sort experiments by starred --- extension/package.json | 20 +++++++++++++++++ extension/package.nls.json | 1 + extension/src/commands/external.ts | 1 + .../src/experiments/commands/register.ts | 5 +++++ extension/src/experiments/index.ts | 6 +++++ .../src/experiments/model/sortBy/constants.ts | 1 + extension/src/experiments/workspace.ts | 8 +++++++ extension/src/telemetry/constants.ts | 1 + .../experiments/model/sortBy/tree.test.ts | 22 +++++++++++++++++++ 9 files changed, 65 insertions(+) create mode 100644 extension/src/experiments/model/sortBy/constants.ts diff --git a/extension/package.json b/extension/package.json index aff6b1fbcc..b0cce175cb 100644 --- a/extension/package.json +++ b/extension/package.json @@ -106,6 +106,12 @@ "category": "DVC", "icon": "$(star-full)" }, + { + "title": "%command.addStarredExperimentsTableSort%", + "command": "dvc.addStarredExperimentsTableSort", + "category": "DVC", + "icon": "$(star-full)" + }, { "title": "%command.addTarget%", "command": "dvc.addTarget", @@ -557,6 +563,10 @@ "command": "dvc.addStarredExperimentsTableFilter", "when": "dvc.commands.available && dvc.project.available" }, + { + "command": "dvc.addStarredExperimentsTableSort", + "when": "dvc.commands.available && dvc.project.available" + }, { "command": "dvc.addTarget", "when": "false" @@ -1009,6 +1019,11 @@ "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", @@ -1226,6 +1241,11 @@ "when": "view == dvc.views.experimentsSortByTree", "group": "navigation@1" }, + { + "command": "dvc.addStarredExperimentsTableSort", + "when": "view == dvc.views.experimentsSortByTree", + "group": "navigation@2" + }, { "command": "dvc.views.experimentsSortByTree.removeAllSorts", "when": "view == dvc.views.experimentsSortByTree && dvc.experiments.sorted", diff --git a/extension/package.nls.json b/extension/package.nls.json index 0702927b0a..846872c0b6 100644 --- a/extension/package.nls.json +++ b/extension/package.nls.json @@ -4,6 +4,7 @@ "command.addExperimentsTableFilter": "Add Filter To Experiments Table", "command.addExperimentsTableSort": "Add Or Update Sort On Experiments Table", "command.addStarredExperimentsTableFilter": "Filter Experiments Table to Starred", + "command.addStarredExperimentsTableSort": "Sort Experiments Table by Starred", "command.addTarget": "Add Target", "command.applyExperiment": "Apply Experiment To Workspace", "command.branchExperiment": "Create New Branch From Experiment", diff --git a/extension/src/commands/external.ts b/extension/src/commands/external.ts index 842eca2707..b11ff4acad 100644 --- a/extension/src/commands/external.ts +++ b/extension/src/commands/external.ts @@ -52,6 +52,7 @@ export enum RegisteredCommands { EXPERIMENT_SELECT = 'dvc.views.experimentsTree.selectExperiments', EXPERIMENT_SHOW = 'dvc.showExperiments', EXPERIMENT_SORT_ADD = 'dvc.addExperimentsTableSort', + EXPERIMENT_SORT_ADD_STARRED = 'dvc.addStarredExperimentsTableSort', EXPERIMENT_SORT_REMOVE = 'dvc.views.experimentsSortByTree.removeSort', EXPERIMENT_SORTS_REMOVE = 'dvc.removeExperimentsTableSorts', EXPERIMENT_SORTS_REMOVE_ALL = 'dvc.views.experimentsSortByTree.removeAllSorts', diff --git a/extension/src/experiments/commands/register.ts b/extension/src/experiments/commands/register.ts index 165e2be7d7..1367883ccd 100644 --- a/extension/src/experiments/commands/register.ts +++ b/extension/src/experiments/commands/register.ts @@ -203,6 +203,11 @@ const registerExperimentQuickPickCommands = ( (dvcRoot?: string) => experiments.addSort(dvcRoot) ) + internalCommands.registerExternalCommand( + RegisteredCommands.EXPERIMENT_SORT_ADD_STARRED, + (dvcRoot?: string) => experiments.addStarredSort(dvcRoot) + ) + internalCommands.registerExternalCommand( RegisteredCommands.EXPERIMENT_SORTS_REMOVE, () => experiments.removeSorts() diff --git a/extension/src/experiments/index.ts b/extension/src/experiments/index.ts index da0e816211..172715e3c3 100644 --- a/extension/src/experiments/index.ts +++ b/extension/src/experiments/index.ts @@ -10,6 +10,7 @@ import { pickFiltersToRemove } from './model/filterBy/quickPick' import { tooManySelected } from './model/status' +import { starredSort } from './model/sortBy/constants' import { pickSortsToRemove, pickSortToAdd } from './model/sortBy/quickPick' import { ColumnsModel } from './columns/model' import { CheckpointsModel } from './checkpoints/model' @@ -202,6 +203,11 @@ export class Experiments extends BaseRepository { return this.notifyChanged() } + public addStarredSort() { + this.experiments.addSort(starredSort) + return this.notifyChanged() + } + public removeSort(pathToRemove: string) { this.experiments.removeSort(pathToRemove) return this.notifyChanged() diff --git a/extension/src/experiments/model/sortBy/constants.ts b/extension/src/experiments/model/sortBy/constants.ts new file mode 100644 index 0000000000..e219c53ea8 --- /dev/null +++ b/extension/src/experiments/model/sortBy/constants.ts @@ -0,0 +1 @@ +export const starredSort = { descending: true, path: 'starred' } diff --git a/extension/src/experiments/workspace.ts b/extension/src/experiments/workspace.ts index 1879fa2763..0b27f66c3b 100644 --- a/extension/src/experiments/workspace.ts +++ b/extension/src/experiments/workspace.ts @@ -96,6 +96,14 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews< return this.getRepository(dvcRoot).addSort() } + public async addStarredSort(overrideRoot?: string) { + const dvcRoot = await this.getDvcRoot(overrideRoot) + if (!dvcRoot) { + return + } + return this.getRepository(dvcRoot).addStarredSort() + } + public async removeSorts() { const dvcRoot = await this.getFocusedOrOnlyOrPickProject() if (!dvcRoot) { diff --git a/extension/src/telemetry/constants.ts b/extension/src/telemetry/constants.ts index 69cb411932..d1c12b37b8 100644 --- a/extension/src/telemetry/constants.ts +++ b/extension/src/telemetry/constants.ts @@ -128,6 +128,7 @@ export interface IEventNamePropertyMapping { [EventName.EXPERIMENT_SELECT]: undefined [EventName.EXPERIMENT_SHOW]: undefined [EventName.EXPERIMENT_SORT_ADD]: undefined + [EventName.EXPERIMENT_SORT_ADD_STARRED]: undefined [EventName.EXPERIMENT_SORT_REMOVE]: undefined [EventName.EXPERIMENT_SORTS_REMOVE]: undefined [EventName.EXPERIMENT_SORTS_REMOVE_ALL]: undefined diff --git a/extension/src/test/suite/experiments/model/sortBy/tree.test.ts b/extension/src/test/suite/experiments/model/sortBy/tree.test.ts index 812e143ee4..55ba5d49c5 100644 --- a/extension/src/test/suite/experiments/model/sortBy/tree.test.ts +++ b/extension/src/test/suite/experiments/model/sortBy/tree.test.ts @@ -18,6 +18,7 @@ import { buildMetricOrParamPath } from '../../../../../experiments/columns/paths import { RegisteredCommands } from '../../../../../commands/external' import { ExperimentsOutput } from '../../../../../cli/reader' import { WEBVIEW_TEST_TIMEOUT } from '../../../timeouts' +import { starredSort } from '../../../../../experiments/model/sortBy/constants' suite('Experiments Sort By Tree Test Suite', () => { const testData = { @@ -287,5 +288,26 @@ suite('Experiments Sort By Tree Test Suite', () => { 'should not call get repository in removeSorts without a root' ).not.to.be.called }).timeout(WEBVIEW_TEST_TIMEOUT) + + it('should provide a shortcut to sort by starred experiments', async () => { + const { experiments, experimentsModel } = buildExperiments(disposable) + + await experiments.isReady() + + stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments) + stub( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (WorkspaceExperiments as any).prototype, + 'getFocusedOrOnlyOrPickProject' + ).returns(dvcDemoPath) + + const mockAddFilter = stub(experimentsModel, 'addSort') + + await commands.executeCommand( + RegisteredCommands.EXPERIMENT_SORT_ADD_STARRED + ) + + expect(mockAddFilter).to.be.calledWith(starredSort) + }) }) }) From f7b3a18db5e210eccf7241ef336bb4cb058f903a Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Wed, 10 Aug 2022 14:09:28 +1000 Subject: [PATCH 2/2] self review --- extension/package.json | 2 +- .../src/test/suite/experiments/model/sortBy/tree.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extension/package.json b/extension/package.json index b0cce175cb..2afdb864ae 100644 --- a/extension/package.json +++ b/extension/package.json @@ -1249,7 +1249,7 @@ { "command": "dvc.views.experimentsSortByTree.removeAllSorts", "when": "view == dvc.views.experimentsSortByTree && dvc.experiments.sorted", - "group": "navigation@2" + "group": "navigation@3" }, { "command": "dvc.addExperimentsTableFilter", diff --git a/extension/src/test/suite/experiments/model/sortBy/tree.test.ts b/extension/src/test/suite/experiments/model/sortBy/tree.test.ts index 55ba5d49c5..09ecb36e29 100644 --- a/extension/src/test/suite/experiments/model/sortBy/tree.test.ts +++ b/extension/src/test/suite/experiments/model/sortBy/tree.test.ts @@ -301,13 +301,13 @@ suite('Experiments Sort By Tree Test Suite', () => { 'getFocusedOrOnlyOrPickProject' ).returns(dvcDemoPath) - const mockAddFilter = stub(experimentsModel, 'addSort') + const mockAddSort = stub(experimentsModel, 'addSort') await commands.executeCommand( RegisteredCommands.EXPERIMENT_SORT_ADD_STARRED ) - expect(mockAddFilter).to.be.calledWith(starredSort) + expect(mockAddSort).to.be.calledWith(starredSort) }) }) })