Skip to content

Commit

Permalink
Handle project having experiments with no data
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Nov 30, 2023
1 parent 37e8668 commit 0c7a78a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
5 changes: 1 addition & 4 deletions extension/src/experiments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,7 @@ export class Experiments extends BaseRepository<TableData> {
}

public getWorkspaceAndCommits() {
if (
!this.experiments.getCliError() &&
!this.columns.hasNonDefaultColumns()
) {
if (this.experiments.hasNoData(this.columns.hasNonDefaultColumns())) {
return []
}

Expand Down
34 changes: 34 additions & 0 deletions extension/src/experiments/model/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
10 changes: 10 additions & 0 deletions extension/src/experiments/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions extension/src/experiments/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 0c7a78a

Please sign in to comment.