Skip to content

Commit e7dcdc6

Browse files
authored
Handle project having experiments with no data (#5045)
1 parent c674f9d commit e7dcdc6

File tree

9 files changed

+57
-23
lines changed

9 files changed

+57
-23
lines changed

extension/src/experiments/columns/collect/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ describe('collectColumns', () => {
7373
expect(metrics).toBeDefined()
7474
})
7575

76-
it('should return an empty array if no params and metrics are provided', async () => {
76+
it('should return the timestamp column if no params, metrics or deps are provided', async () => {
7777
const columns = await collectColumns(generateTestExpShowOutput({}))
78-
expect(columns).toStrictEqual([])
78+
expect(columns).toStrictEqual([timestampColumn])
7979
})
8080

8181
it('should aggregate multiple different field names', async () => {

extension/src/experiments/columns/collect/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ export const collectColumns = async (
7171
}
7272
await Promise.all(promises)
7373

74-
const columns = Object.values(acc.columns)
75-
const hasNoData = isEqual(columns, [timestampColumn])
76-
77-
return hasNoData ? [] : columns
74+
return Object.values(acc.columns)
7875
}
7976

8077
export const getExpData = (expState: ExpState): ExpData | undefined => {

extension/src/experiments/columns/model.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ describe('ColumnsModel', () => {
4646
const exampleDvcRoot = 'test'
4747
const mockedColumnsOrderOrStatusChanged = buildMockedEventEmitter<void>()
4848

49-
it('should return no columns when given an output with no data', async () => {
49+
it('should return the timestamp column when given output with no params, metrics or deps', async () => {
5050
const model = new ColumnsModel(
5151
'',
5252
buildMockMemento(),
5353
mockedColumnsOrderOrStatusChanged
5454
)
5555
await model.transformAndSet(generateTestExpShowOutput({}))
5656

57-
expect(model.getSelected()).toStrictEqual([])
57+
expect(model.getSelected()).toStrictEqual([timestampColumn])
5858
})
5959

6060
it('should return the expected columns when given the default output fixture', async () => {

extension/src/experiments/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,7 @@ export class Experiments extends BaseRepository<TableData> {
481481
}
482482

483483
public getWorkspaceAndCommits() {
484-
if (
485-
!this.experiments.getCliError() &&
486-
!this.columns.hasNonDefaultColumns()
487-
) {
484+
if (!this.experiments.hasData(this.columns.hasNonDefaultColumns())) {
488485
return []
489486
}
490487

@@ -496,7 +493,7 @@ export class Experiments extends BaseRepository<TableData> {
496493
}
497494

498495
public getSelectedRevisions() {
499-
if (!this.columns.hasNonDefaultColumns()) {
496+
if (!this.experiments.hasData(this.columns.hasNonDefaultColumns())) {
500497
return []
501498
}
502499

@@ -603,7 +600,7 @@ export class Experiments extends BaseRepository<TableData> {
603600
if (this.deferred.state === 'none') {
604601
return
605602
}
606-
return this.columns.hasNonDefaultColumns()
603+
return this.experiments.hasData(this.columns.hasNonDefaultColumns())
607604
}
608605

609606
public getRelativeMetricsFiles() {

extension/src/experiments/model/index.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,4 +611,38 @@ describe('ExperimentsModel', () => {
611611

612612
expect(model.getCliError()).toBe(undefined)
613613
})
614+
615+
it('should return the correct values for hasData', () => {
616+
const model = new ExperimentsModel('', buildMockMemento())
617+
618+
expect(model.hasData(false)).toBe(false)
619+
expect(model.hasData(true)).toBe(true)
620+
621+
model.transformAndSetLocal(
622+
outputFixture,
623+
gitLogFixture,
624+
{ running: false },
625+
rowOrderFixture,
626+
{ main: 6 }
627+
)
628+
629+
expect(model.hasData(false)).toBe(true)
630+
expect(model.hasData(true)).toBe(true)
631+
632+
model.transformAndSetLocal(
633+
[
634+
{
635+
error: { msg: 'CLI is broken', type: 'CLI ERROR' },
636+
rev: EXPERIMENT_WORKSPACE_ID
637+
}
638+
],
639+
gitLogFixture,
640+
{ running: false },
641+
rowOrderFixture,
642+
{ main: 6 }
643+
)
644+
645+
expect(model.hasData(false)).toBe(true)
646+
expect(model.hasData(true)).toBe(true)
647+
})
614648
})

extension/src/experiments/model/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,16 @@ export class ExperimentsModel extends ModelWithPersistence {
524524
}))
525525
}
526526

527+
public hasData(hasNonDefaultColumns: boolean) {
528+
if (this.getCliError()) {
529+
return true
530+
}
531+
532+
const hasRows = this.getWorkspaceAndCommits().length > 0
533+
const hasExperiments = this.getExperimentsAndQueued().length > 0
534+
return (hasNonDefaultColumns || hasExperiments) && hasRows
535+
}
536+
527537
public setNbfCommitsToShow(numberOfCommitsToShow: number, branch: string) {
528538
this.numberOfCommitsToShow[branch] = numberOfCommitsToShow
529539
this.persistNbOfCommitsToShow()

extension/src/experiments/webview/messages.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ export class WebviewMessages {
8484
}
8585
const data = await this.getWebviewData()
8686

87-
const hasNoRows = data.rows.length === 0
88-
const hasNoData = !this.columns.hasNonDefaultColumns() || hasNoRows
87+
const hasNoData = !this.experiments.hasData(
88+
this.columns.hasNonDefaultColumns()
89+
)
8990

90-
if (hasNoData && !data.cliError) {
91+
if (hasNoData) {
9192
await commands.executeCommand(RegisteredCommands.SETUP_SHOW_EXPERIMENTS)
9293
return webview.dispose()
9394
}

extension/src/setup/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export class Setup
8585

8686
private readonly webviewMessages: WebviewMessages
8787
private readonly getHasData: () => boolean | undefined
88-
private readonly getExpShowError: () => string | undefined
8988
private readonly collectWorkspaceScale: () => Promise<WorkspaceScale>
9089

9190
private readonly setupRun: EventEmitter<void> = this.dispose.track(
@@ -153,7 +152,6 @@ export class Setup
153152
void this.sendDataToWebview()
154153

155154
this.getHasData = () => experiments.getHasData()
156-
this.getExpShowError = () => experiments.getCliError()
157155
const onDidChangeHasData = experiments.columnsChanged.event
158156
this.dispose.track(onDidChangeHasData(() => this.updateProjectHasData()))
159157

@@ -254,7 +252,7 @@ export class Setup
254252
public shouldBeShown(): { dvc: boolean; experiments: boolean } {
255253
return {
256254
dvc: !!this.getCliCompatible() && this.hasRoots(),
257-
experiments: !!(this.getExpShowError() || this.getHasData())
255+
experiments: !!this.getHasData()
258256
}
259257
}
260258

extension/src/test/suite/setup/util.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ export const TEMP_DIR = join(dvcDemoPath, 'temp-empty-watcher-dir')
2626

2727
export const buildSetup = ({
2828
disposer,
29-
cliError = undefined,
3029
gitVersion,
3130
hasData = false,
3231
noDvcRoot = true,
3332
noGitCommits = true,
3433
noGitRoot = true
3534
}: {
36-
cliError?: undefined
3735
disposer: Disposer
3836
gitVersion?: string | null
3937
hasData?: boolean
@@ -107,7 +105,6 @@ export const buildSetup = ({
107105
internalCommands,
108106
{
109107
columnsChanged: mockEmitter,
110-
getCliError: () => cliError,
111108
getHasData: () => hasData,
112109
isReady: () => Promise.resolve(),
113110
showWebview: mockShowWebview

0 commit comments

Comments
 (0)