Skip to content

Commit 96167f3

Browse files
authored
Only show plots which are available for selected revisions (#2915)
* only show plots which are available for selected revisions * use cli id to label mapping in path collection * filter missing plots from orders (will move to end) * rework base class * expose get selected revisions * test comparison plot ordering with unstable paths * refactor collection for complexity * recollect workspace path if mutable revision refetched * self review * fix plots welcome screen
1 parent 475574e commit 96167f3

File tree

13 files changed

+476
-105
lines changed

13 files changed

+476
-105
lines changed

extension/src/experiments/columns/model.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { EXPERIMENT_COLUMN_ID, timestampColumn } from './constants'
44
import { Column, ColumnType } from '../webview/contract'
55
import { ExperimentsOutput } from '../../cli/dvc/contract'
66
import { PersistenceKey } from '../../persistence/constants'
7-
import { PathSelectionModel } from '../../path/selection/model'
7+
import { PathSelectionModel, Status } from '../../path/selection/model'
88

99
export class ColumnsModel extends PathSelectionModel<Column> {
1010
private columnOrderState: string[] = []
@@ -91,6 +91,20 @@ export class ColumnsModel extends PathSelectionModel<Column> {
9191
})
9292
}
9393

94+
public getTerminalNodes(): (Column & { selected: boolean })[] {
95+
return this.data
96+
.filter(element => !element.hasChildren)
97+
.map(element => ({ ...element, selected: !!this.status[element.path] }))
98+
}
99+
100+
public getSelected() {
101+
return (
102+
this.data.filter(
103+
element => this.status[element.path] !== Status.UNSELECTED
104+
) || []
105+
)
106+
}
107+
94108
public hasNonDefaultColumns() {
95109
return this.data.length > 1
96110
}

extension/src/path/selection/model.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,6 @@ export abstract class PathSelectionModel<
3535
}
3636
}
3737

38-
public getSelected() {
39-
return (
40-
this.data.filter(
41-
element => this.status[element.path] !== Status.UNSELECTED
42-
) || []
43-
)
44-
}
45-
46-
public getTerminalNodes(): (T & { selected: boolean })[] {
47-
return this.data
48-
.filter(element => !element.hasChildren)
49-
.map(element => ({ ...element, selected: !!this.status[element.path] }))
50-
}
51-
5238
public toggleStatus(path: string) {
5339
const status = this.getNextStatus(path)
5440
return this.setStatus(path, status)
@@ -159,4 +145,6 @@ export abstract class PathSelectionModel<
159145
abstract getChildren(
160146
...args: unknown[]
161147
): (T & { descendantStatuses: Status[]; label: string; status: Status })[]
148+
149+
abstract getTerminalNodes(): (T & { selected: boolean })[]
162150
}

extension/src/path/selection/quickPick.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { quickPickManyValues } from '../../vscode/quickPick'
44
import { Toast } from '../../vscode/toast'
55
import { Title } from '../../vscode/title'
66
import { PathType } from '../../plots/paths/collect'
7+
import { EXPERIMENT_WORKSPACE_ID } from '../../cli/dvc/contract'
78

89
jest.mock('../../vscode/quickPick')
910
jest.mock('../../vscode/toast')
@@ -36,13 +37,15 @@ describe('pickPaths', () => {
3637

3738
it('should call the quickPick with the correct items', async () => {
3839
mockedQuickPickManyValues.mockResolvedValueOnce([])
40+
const revisions = new Set([EXPERIMENT_WORKSPACE_ID])
3941

4042
const plotPaths = [
4143
{
4244
hasChildren: false,
4345
label: 'loss.tsv',
4446
parentPath: 'logs',
4547
path: join('logs', 'loss.tsv'),
48+
revisions,
4649
selected: true,
4750
type: new Set([PathType.TEMPLATE_SINGLE])
4851
},
@@ -51,6 +54,7 @@ describe('pickPaths', () => {
5154
label: 'acc.tsv',
5255
parentPath: 'logs',
5356
path: join('logs', 'acc.tsv'),
57+
revisions,
5458
selected: true,
5559
type: new Set([PathType.TEMPLATE_SINGLE])
5660
},
@@ -59,6 +63,7 @@ describe('pickPaths', () => {
5963
label: 'fun.tsv',
6064
parentPath: 'logs',
6165
path: join('logs', 'fun.tsv'),
66+
revisions,
6267
selected: false,
6368
type: new Set([PathType.TEMPLATE_SINGLE])
6469
}

extension/src/plots/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,15 @@ export class Plots extends BaseRepository<TPlotsData> {
121121
}
122122

123123
public getPathStatuses() {
124-
return this.paths.getTerminalNodeStatuses()
124+
return this.paths.getTerminalNodeStatuses(undefined)
125125
}
126126

127127
public getScale() {
128128
return collectScale(this.paths.getTerminalNodes())
129129
}
130130

131131
private notifyChanged() {
132+
this.paths.setSelectedRevisions(this.plots.getSelectedRevisions())
132133
this.pathsChanged.fire()
133134
this.fetchMissingOrSendPlots()
134135
}
@@ -187,9 +188,7 @@ export class Plots extends BaseRepository<TPlotsData> {
187188
await this.plots.transformAndSetExperiments(data)
188189
}
189190

190-
this.plots.setComparisonOrder()
191-
192-
this.fetchMissingOrSendPlots()
191+
this.notifyChanged()
193192
})
194193
)
195194
}
@@ -210,7 +209,7 @@ export class Plots extends BaseRepository<TPlotsData> {
210209
this.data.onDidUpdate(async ({ data, revs }) => {
211210
await Promise.all([
212211
this.plots.transformAndSetPlots(data, revs),
213-
this.paths.transformAndSet(data)
212+
this.paths.transformAndSet(data, revs, this.plots.getCLIIdToLabel())
214213
])
215214
this.notifyChanged()
216215
})

extension/src/plots/model/index.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ export class PlotsModel extends ModelWithPersistence {
291291
this.persist(PersistenceKey.PLOT_COMPARISON_ORDER, this.comparisonOrder)
292292
}
293293

294+
public getSelectedRevisions() {
295+
return this.experiments.getSelectedRevisions().map(({ label }) => label)
296+
}
297+
294298
public setSelectedMetrics(selectedMetrics: string[]) {
295299
this.selectedMetrics = selectedMetrics
296300
this.setMetricOrder()
@@ -349,6 +353,16 @@ export class PlotsModel extends ModelWithPersistence {
349353
return this.multiSourceEncoding
350354
}
351355

356+
public getCLIIdToLabel() {
357+
const mapping: { [shortSha: string]: string } = {}
358+
359+
for (const rev of this.experiments.getRevisions()) {
360+
mapping[this.getCLIId(rev)] = rev
361+
}
362+
363+
return mapping
364+
}
365+
352366
private removeStaleData() {
353367
return Promise.all([
354368
this.removeStaleBranches(),
@@ -397,24 +411,10 @@ export class PlotsModel extends ModelWithPersistence {
397411
this.fetchedRevs.delete(id)
398412
}
399413

400-
private getCLIIdToLabel() {
401-
const mapping: { [shortSha: string]: string } = {}
402-
403-
for (const rev of this.experiments.getRevisions()) {
404-
mapping[this.getCLIId(rev)] = rev
405-
}
406-
407-
return mapping
408-
}
409-
410414
private getCLIId(label: string) {
411415
return this.branchRevisions[label] || label
412416
}
413417

414-
private getSelectedRevisions() {
415-
return this.experiments.getSelectedRevisions().map(({ label }) => label)
416-
}
417-
418418
private getPlots(
419419
checkpointPlots: CheckpointPlot[],
420420
selectedExperiments: string[]

0 commit comments

Comments
 (0)