Skip to content

Commit c0f3902

Browse files
authored
Refactor experiment table branch data (#4364)
1 parent 22d3efd commit c0f3902

File tree

20 files changed

+90
-52
lines changed

20 files changed

+90
-52
lines changed

extension/src/experiments/model/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import {
2626
isQueued,
2727
isRunning,
2828
GitRemoteStatus,
29-
RunningExperiment
29+
RunningExperiment,
30+
WORKSPACE_BRANCH
3031
} from '../webview/contract'
3132
import { reorderListSubset } from '../../util/array'
3233
import {
@@ -413,7 +414,7 @@ export class ExperimentsModel extends ModelWithPersistence {
413414
const commitsBySha = this.applyFiltersToCommits()
414415

415416
const rows: Commit[] = [
416-
{ branch: undefined, ...this.addDetails(this.workspace) }
417+
{ branch: WORKSPACE_BRANCH, ...this.addDetails(this.workspace) }
417418
]
418419
for (const { branch, sha } of this.rowOrder) {
419420
const commit = commitsBySha[sha]
@@ -520,6 +521,10 @@ export class ExperimentsModel extends ModelWithPersistence {
520521
return [this.currentBranch as string, ...this.selectedBranches]
521522
}
522523

524+
public getSelectedBranches() {
525+
return this.selectedBranches
526+
}
527+
523528
public getAvailableBranchesToShow() {
524529
return this.availableBranchesToShow
525530
}

extension/src/experiments/webview/contract.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type Experiment = {
5353
starred?: boolean
5454
status?: ExperimentStatus
5555
timestamp?: string | null
56-
branch?: string | undefined
56+
branch?: string | typeof WORKSPACE_BRANCH
5757
}
5858

5959
export const isRunning = (status: ExperimentStatus | undefined): boolean =>
@@ -92,6 +92,8 @@ export type Column = {
9292
width?: number
9393
}
9494

95+
export const WORKSPACE_BRANCH = null
96+
9597
export type TableData = {
9698
changes: string[]
9799
cliError: string | null
@@ -107,6 +109,7 @@ export type TableData = {
107109
hasRunningWorkspaceExperiment: boolean
108110
isShowingMoreCommits: Record<string, boolean>
109111
rows: Commit[]
112+
selectedBranches: string[]
110113
selectedForPlotsCount: number
111114
sorts: SortDefinition[]
112115
}

extension/src/experiments/webview/messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ export class WebviewMessages {
276276
this.experiments.hasRunningWorkspaceExperiment(),
277277
isShowingMoreCommits: this.experiments.getIsShowingMoreCommits(),
278278
rows: this.experiments.getRowData(),
279+
selectedBranches: this.experiments.getSelectedBranches(),
279280
selectedForPlotsCount: this.experiments.getSelectedRevisions().length,
280281
sorts: this.experiments.getSorts()
281282
}

extension/src/test/fixtures/expShow/base/rows.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { join } from '../../../util/path'
22
import {
33
Commit,
4-
GitRemoteStatus
4+
GitRemoteStatus,
5+
WORKSPACE_BRANCH
56
} from '../../../../experiments/webview/contract'
67
import { copyOriginalColors } from '../../../../experiments/model/status/colors'
78
import { shortenForLabel } from '../../../../util/string'
@@ -20,7 +21,7 @@ const colorsList = copyOriginalColors()
2021

2122
const rowsFixture: Commit[] = [
2223
{
23-
branch: undefined,
24+
branch: WORKSPACE_BRANCH,
2425
commit: undefined,
2526
description: undefined,
2627
deps: {

extension/src/test/fixtures/expShow/base/tableData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import rowsFixture from './rows'
33
import columnsFixture from './columns'
44

55
const tableDataFixture: TableData = {
6+
selectedBranches: [],
67
cliError: null,
78
changes: [],
89
columnOrder: [],

extension/src/test/fixtures/expShow/dataTypes/rows.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { EXPERIMENT_WORKSPACE_ID } from '../../../../cli/dvc/contract'
2-
import { Commit } from '../../../../experiments/webview/contract'
2+
import {
3+
Commit,
4+
WORKSPACE_BRANCH
5+
} from '../../../../experiments/webview/contract'
36

47
const data: Commit[] = [
58
{
6-
branch: undefined,
9+
branch: WORKSPACE_BRANCH,
710
displayColor: undefined,
811
id: EXPERIMENT_WORKSPACE_ID,
912
label: EXPERIMENT_WORKSPACE_ID,

extension/src/test/fixtures/expShow/deeplyNested/rows.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { EXPERIMENT_WORKSPACE_ID } from '../../../../cli/dvc/contract'
2+
import { WORKSPACE_BRANCH } from '../../../../experiments/webview/contract'
23

34
export const data = [
45
{
5-
branch: undefined,
6+
branch: WORKSPACE_BRANCH,
67
id: EXPERIMENT_WORKSPACE_ID,
78
label: EXPERIMENT_WORKSPACE_ID,
89
params: {

extension/src/test/fixtures/expShow/survival/rows.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { join } from '../../../util/path'
2-
import { Commit } from '../../../../experiments/webview/contract'
2+
import {
3+
Commit,
4+
WORKSPACE_BRANCH
5+
} from '../../../../experiments/webview/contract'
36
import { EXPERIMENT_WORKSPACE_ID } from '../../../../cli/dvc/contract'
47

58
const data: Commit[] = [
69
{
7-
branch: undefined,
10+
branch: WORKSPACE_BRANCH,
811
id: EXPERIMENT_WORKSPACE_ID,
912
label: EXPERIMENT_WORKSPACE_ID,
1013
metrics: {

webview/src/experiments/components/App.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,6 @@ describe('App', () => {
17281728

17291729
const multipleBranches = {
17301730
...tableDataFixture,
1731-
branches,
17321731
hasData: true,
17331732
rows: [
17341733
workspace as Commit,
@@ -1747,7 +1746,8 @@ describe('App', () => {
17471746
branch: branches[2],
17481747
subRows: undefined
17491748
}))
1750-
]
1749+
],
1750+
selectedBranches: branches.slice(1)
17511751
}
17521752

17531753
renderTable(multipleBranches)

webview/src/experiments/components/App.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { TableData } from 'dvc/src/experiments/webview/contract'
88
import Experiments from './Experiments'
99
import {
1010
update,
11+
updateSelectedBranches,
1112
updateChanges,
1213
updateCliError,
1314
updateColumnOrder,
@@ -87,6 +88,9 @@ export const App: React.FC<Record<string, unknown>> = () => {
8788
case 'rows':
8889
dispatch(updateRows(data.data.rows))
8990
continue
91+
case 'selectedBranches':
92+
dispatch(updateSelectedBranches(data.data.selectedBranches))
93+
continue
9094
case 'selectedForPlotsCount':
9195
dispatch(
9296
updateSelectedForPlotsCount(data.data.selectedForPlotsCount)

0 commit comments

Comments
 (0)