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 createTreeView wrapper #703

Merged
merged 8 commits into from
Aug 3, 2021
Merged
4 changes: 0 additions & 4 deletions extension/src/experiments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ export class Experiments {
return Object.keys(this.experiments)
}

public getParamOrMetric(dvcRoot: string, path: string) {
return this.getRepository(dvcRoot).getParamOrMetric(path)
}

public getChildParamsOrMetrics(dvcRoot: string, path: string) {
return this.getRepository(dvcRoot).getChildParamsOrMetrics(path)
}
Expand Down
13 changes: 3 additions & 10 deletions extension/src/experiments/model/filterBy/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
TreeDataProvider,
TreeItem,
TreeItemCollapsibleState,
Uri,
window
Uri
} from 'vscode'
import { getFilterId } from '.'
import { Experiments } from '../..'
import { definedAndNonEmpty, flatten } from '../../../util/array'
import { createTreeView } from '../../../vscode/tree'

type FilterItem = {
description: string
Expand All @@ -33,14 +33,7 @@ export class ExperimentsFilterByTree
this.onDidChangeTreeData = experiments.experimentsChanged.event

this.dispose.track(
window.createTreeView<string | FilterItem>(
'dvc.views.experimentsFilterByTree',
{
canSelectMany: true,
showCollapseAll: true,
treeDataProvider: this
}
)
createTreeView<FilterItem>('dvc.views.experimentsFilterByTree', this)
)

this.experiments = experiments
Expand Down
35 changes: 17 additions & 18 deletions extension/src/experiments/paramsAndMetrics/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,20 @@ export class ParamsAndMetricsModel {
return this.data.filter(paramOrMetric => !paramOrMetric.hasChildren)
}

public getParamOrMetric(path: string) {
const paramOrMetric = this.data?.find(
paramOrMetric => paramOrMetric.path === path
)
if (paramOrMetric) {
return {
...paramOrMetric,
descendantStatuses: this.getDescendantsStatuses(paramOrMetric.path),
status: this.status[paramOrMetric.path]
}
}
}

public getChildren(path: string) {
return this.data?.filter(paramOrMetric =>
path
? paramOrMetric.parentPath === path
: ['metrics', 'params'].includes(paramOrMetric.parentPath)
)
return this.data
?.filter(paramOrMetric =>
path
? paramOrMetric.parentPath === path
: ['metrics', 'params'].includes(paramOrMetric.parentPath)
)
.map(paramOrMetric => {
return {
...paramOrMetric,
descendantStatuses: this.getDescendantsStatuses(paramOrMetric.path),
status: this.status[paramOrMetric.path]
}
})
}

public toggleStatus(path: string) {
Expand All @@ -90,6 +85,10 @@ export class ParamsAndMetricsModel {
})
}

private getParamOrMetric(path: string) {
return this.data?.find(paramOrMetric => paramOrMetric.path === path)
}

private setAreParentsSelected(path: string) {
const changed = this.getParamOrMetric(path)
if (!changed) {
Expand Down
Loading