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

Add shortcut to filter experiments to starred #2170

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 21 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
"category": "DVC",
"icon": "$(add)"
},
{
"title": "%command.addStarredExperimentsTableFilter%",
"command": "dvc.addStarredExperimentsTableFilter",
"category": "DVC",
"icon": "$(star-full)"
},
{
"title": "%command.addTarget%",
"command": "dvc.addTarget",
Expand Down Expand Up @@ -547,6 +553,10 @@
"command": "dvc.addExperimentsTableSort",
"when": "dvc.commands.available && dvc.project.available"
},
{
"command": "dvc.addStarredExperimentsTableFilter",
"when": "dvc.commands.available && dvc.project.available"
},
{
"command": "dvc.addTarget",
"when": "false"
Expand Down Expand Up @@ -1014,6 +1024,11 @@
"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",
Expand Down Expand Up @@ -1221,10 +1236,15 @@
"when": "view == dvc.views.experimentsFilterByTree",
"group": "navigation@1"
},
{
"command": "dvc.addStarredExperimentsTableFilter",
"when": "view == dvc.views.experimentsFilterByTree",
"group": "navigation@2"
},
{
"command": "dvc.views.experimentsFilterByTree.removeAllFilters",
"when": "view == dvc.views.experimentsFilterByTree && dvc.experiments.filtered",
"group": "navigation@2"
"group": "navigation@3"
},
{
"command": "dvc.showPlots",
Expand Down
1 change: 1 addition & 0 deletions extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "Machine learning experiment management with tracking, plots, and data versioning.",
"command.addExperimentsTableFilter": "Add Filter To Experiments Table",
"command.addExperimentsTableSort": "Add Or Update Sort On Experiments Table",
"command.addStarredExperimentsTableFilter": "Filter Experiments Table to Starred",
"command.addTarget": "Add Target",
"command.applyExperiment": "Apply Experiment To Workspace",
"command.branchExperiment": "Create New Branch From Experiment",
Expand Down
1 change: 1 addition & 0 deletions extension/src/commands/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export enum RegisteredCommands {
EXPERIMENT_COLUMNS_SELECT = 'dvc.views.experimentsColumnsTree.selectColumns',
EXPERIMENT_DISABLE_AUTO_APPLY_FILTERS = 'dvc.views.experimentsTree.disableAutoApplyFilters',
EXPERIMENT_FILTER_ADD = 'dvc.addExperimentsTableFilter',
EXPERIMENT_FILTER_ADD_STARRED = 'dvc.addStarredExperimentsTableFilter',
EXPERIMENT_FILTER_REMOVE = 'dvc.views.experimentsFilterByTree.removeFilter',
EXPERIMENT_FILTERS_REMOVE = 'dvc.removeExperimentsTableFilters',
EXPERIMENT_FILTERS_REMOVE_ALL = 'dvc.views.experimentsFilterByTree.removeAllFilters',
Expand Down
5 changes: 5 additions & 0 deletions extension/src/experiments/commands/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ const registerExperimentQuickPickCommands = (
(dvcRoot?: string) => experiments.addFilter(dvcRoot)
)

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

internalCommands.registerExternalCommand(
RegisteredCommands.EXPERIMENT_FILTERS_REMOVE,
() => experiments.removeFilters()
Expand Down
6 changes: 6 additions & 0 deletions extension/src/experiments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { askToDisableAutoApplyFilters } from './toast'
import { Experiment, ColumnType, TableData } from './webview/contract'
import { WebviewMessages } from './webview/messages'
import { DecorationProvider } from './model/decorationProvider'
import { starredFilter } from './model/filterBy/constants'
import { ResourceLocator } from '../resourceLocator'
import { AvailableCommands, InternalCommands } from '../commands/internal'
import { ExperimentsOutput } from '../cli/reader'
Expand Down Expand Up @@ -233,6 +234,11 @@ export class Experiments extends BaseRepository<TableData> {
return this.notifyChanged()
}

public addStarredFilter() {
this.experiments.addFilter(starredFilter)
return this.notifyChanged()
}

public async removeFilter(id: string) {
const response = await this.checkAutoApplyFilters(id)
if (response === Response.CANCEL) {
Expand Down
7 changes: 7 additions & 0 deletions extension/src/experiments/model/filterBy/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Operator } from '.'

export const starredFilter = {
operator: Operator.IS_TRUE,
path: 'starred',
value: undefined
}
8 changes: 8 additions & 0 deletions extension/src/experiments/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
return this.getRepository(dvcRoot).addFilter()
}

public async addStarredFilter(overrideRoot?: string) {
const dvcRoot = await this.getDvcRoot(overrideRoot)
if (!dvcRoot) {
return
}
return this.getRepository(dvcRoot).addStarredFilter()
}

public async removeFilters() {
const dvcRoot = await this.getFocusedOrOnlyOrPickProject()
if (!dvcRoot) {
Expand Down
1 change: 1 addition & 0 deletions extension/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface IEventNamePropertyMapping {
[EventName.EXPERIMENT_BRANCH]: undefined
[EventName.EXPERIMENT_COLUMNS_SELECT]: undefined
[EventName.EXPERIMENT_FILTER_ADD]: undefined
[EventName.EXPERIMENT_FILTER_ADD_STARRED]: undefined
[EventName.EXPERIMENT_FILTER_REMOVE]: undefined
[EventName.EXPERIMENT_FILTERS_REMOVE]: undefined
[EventName.EXPERIMENT_FILTERS_REMOVE_ALL]: undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
ExperimentsFilterByTree,
FilterItem
} from '../../../../../experiments/model/filterBy/tree'
import { starredFilter } from '../../../../../experiments/model/filterBy/constants'

suite('Experiments Filter By Tree Test Suite', () => {
const disposable = Disposable.fn()
Expand Down Expand Up @@ -479,12 +480,6 @@ suite('Experiments Filter By Tree Test Suite', () => {
'getFocusedOrOnlyOrPickProject'
).returns(dvcDemoPath)

const starredFilter = {
operator: Operator.IS_TRUE,
path: 'starred',
value: undefined
}

await addFilterViaQuickInput(experiments, starredFilter)

const [workspace, main] = rowsFixture
Expand Down Expand Up @@ -513,5 +508,26 @@ suite('Experiments Filter By Tree Test Suite', () => {

expect(messageSpy).to.be.calledWith(filteredTableData)
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should provide a shortcut to filter to 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, 'addFilter')

await commands.executeCommand(
RegisteredCommands.EXPERIMENT_FILTER_ADD_STARRED
)

expect(mockAddFilter).to.be.calledWith(starredFilter)
})
})
})