From 0c7a78a4424f7017a5123e92b34698c0eaa80760 Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Thu, 30 Nov 2023 11:28:39 +1100 Subject: [PATCH] Handle project having experiments with no data --- extension/src/experiments/index.ts | 5 +-- extension/src/experiments/model/index.test.ts | 34 +++++++++++++++++++ extension/src/experiments/model/index.ts | 10 ++++++ extension/src/experiments/webview/messages.ts | 7 ++-- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/extension/src/experiments/index.ts b/extension/src/experiments/index.ts index 2261582476..83f8d7644d 100644 --- a/extension/src/experiments/index.ts +++ b/extension/src/experiments/index.ts @@ -481,10 +481,7 @@ export class Experiments extends BaseRepository { } public getWorkspaceAndCommits() { - if ( - !this.experiments.getCliError() && - !this.columns.hasNonDefaultColumns() - ) { + if (this.experiments.hasNoData(this.columns.hasNonDefaultColumns())) { return [] } diff --git a/extension/src/experiments/model/index.test.ts b/extension/src/experiments/model/index.test.ts index cc71c4dd15..b8f3b79e15 100644 --- a/extension/src/experiments/model/index.test.ts +++ b/extension/src/experiments/model/index.test.ts @@ -611,4 +611,38 @@ describe('ExperimentsModel', () => { expect(model.getCliError()).toBe(undefined) }) + + it('should return the correct values for hasNoData', () => { + const model = new ExperimentsModel('', buildMockMemento()) + + expect(model.hasNoData(false)).toBe(true) + expect(model.hasNoData(true)).toBe(false) + + model.transformAndSetLocal( + outputFixture, + gitLogFixture, + { running: false }, + rowOrderFixture, + { main: 6 } + ) + + expect(model.hasNoData(false)).toBe(false) + expect(model.hasNoData(true)).toBe(false) + + model.transformAndSetLocal( + [ + { + error: { msg: 'CLI is broken', type: 'CLI ERROR' }, + rev: EXPERIMENT_WORKSPACE_ID + } + ], + gitLogFixture, + { running: false }, + rowOrderFixture, + { main: 6 } + ) + + expect(model.hasNoData(false)).toBe(false) + expect(model.hasNoData(true)).toBe(false) + }) }) diff --git a/extension/src/experiments/model/index.ts b/extension/src/experiments/model/index.ts index e25b411539..aa15d14d44 100644 --- a/extension/src/experiments/model/index.ts +++ b/extension/src/experiments/model/index.ts @@ -524,6 +524,16 @@ export class ExperimentsModel extends ModelWithPersistence { })) } + public hasNoData(hasNonDefaultColumns: boolean) { + if (this.getCliError()) { + return false + } + + const hasNoRows = this.getWorkspaceAndCommits().length === 0 + const hasNoExperiments = this.getExperimentsAndQueued().length === 0 + return (!hasNonDefaultColumns && hasNoExperiments) || hasNoRows + } + public setNbfCommitsToShow(numberOfCommitsToShow: number, branch: string) { this.numberOfCommitsToShow[branch] = numberOfCommitsToShow this.persistNbOfCommitsToShow() diff --git a/extension/src/experiments/webview/messages.ts b/extension/src/experiments/webview/messages.ts index 86b2a4cad5..8aa7059e0c 100644 --- a/extension/src/experiments/webview/messages.ts +++ b/extension/src/experiments/webview/messages.ts @@ -84,10 +84,11 @@ export class WebviewMessages { } const data = await this.getWebviewData() - const hasNoRows = data.rows.length === 0 - const hasNoData = !this.columns.hasNonDefaultColumns() || hasNoRows + const hasNoData = this.experiments.hasNoData( + this.columns.hasNonDefaultColumns() + ) - if (hasNoData && !data.cliError) { + if (hasNoData) { await commands.executeCommand(RegisteredCommands.SETUP_SHOW_EXPERIMENTS) return webview.dispose() }