Skip to content

Commit 4a73f54

Browse files
authored
Improve table indicators (#4212)
1 parent 5d10153 commit 4a73f54

File tree

12 files changed

+130
-116
lines changed

12 files changed

+130
-116
lines changed

extension/src/experiments/webview/contract.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export type TableData = {
9797
columnOrder: string[]
9898
columns: Column[]
9999
columnWidths: Record<string, number>
100-
filteredCount: number
101100
filters: string[]
102101
hasBranchesToSelect: boolean
103102
hasCheckpoints: boolean

extension/src/experiments/webview/messages.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ export class WebviewMessages {
154154
return this.focusSortsTree()
155155

156156
case MessageFromWebviewType.OPEN_PLOTS_WEBVIEW:
157-
return this.showPlotsToSide()
157+
return this.showPlots()
158158

159159
case MessageFromWebviewType.SET_EXPERIMENTS_FOR_PLOTS:
160160
return this.setSelectedExperiments(message.payload)
161161

162162
case MessageFromWebviewType.SET_EXPERIMENTS_AND_OPEN_PLOTS:
163163
return Promise.all([
164164
this.setSelectedExperiments(message.payload),
165-
this.showPlotsToSide()
165+
this.showPlots()
166166
])
167167

168168
case MessageFromWebviewType.SET_EXPERIMENTS_HEADER_HEIGHT: {
@@ -262,7 +262,6 @@ export class WebviewMessages {
262262
columnOrder: this.columns.getColumnOrder(),
263263
columnWidths: this.columns.getColumnWidths(),
264264
columns: this.columns.getSelected(),
265-
filteredCount: this.experiments.getFilteredCount(),
266265
filters: this.experiments.getFilterPaths(),
267266
hasBranchesToSelect:
268267
this.experiments.getAvailableBranchesToShow().length > 0,
@@ -424,10 +423,7 @@ export class WebviewMessages {
424423
)
425424
}
426425

427-
private showPlotsToSide() {
428-
return commands.executeCommand(
429-
RegisteredCommands.EXPERIMENT_AND_PLOTS_SHOW,
430-
this.dvcRoot
431-
)
426+
private showPlots() {
427+
return commands.executeCommand(RegisteredCommands.PLOTS_SHOW, this.dvcRoot)
432428
}
433429
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const tableDataFixture: TableData = {
88
columnOrder: [],
99
columns: columnsFixture,
1010
columnWidths: {},
11-
filteredCount: 0,
1211
filters: [],
1312
hasBranchesToSelect: true,
1413
hasCheckpoints: true,

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ suite('Experiments Test Suite', () => {
135135
columnOrder: columnsOrderFixture,
136136
columnWidths: {},
137137
columns: columnsFixture,
138-
filteredCount: 0,
139138
filters: [],
140139
hasCheckpoints: true,
141140
hasColumns: true,
@@ -1070,7 +1069,6 @@ suite('Experiments Test Suite', () => {
10701069
columnOrder: columnsOrderFixture,
10711070
columnWidths: {},
10721071
columns: [],
1073-
filteredCount: 0,
10741072
filters: [],
10751073
rows: rowsFixture,
10761074
sorts: []
@@ -1316,6 +1314,37 @@ suite('Experiments Test Suite', () => {
13161314
expect(mockShowPlots).to.be.calledWith(dvcDemoPath)
13171315
}).timeout(WEBVIEW_TEST_TIMEOUT)
13181316

1317+
it('should be able to handle a message to open the plots webview', async () => {
1318+
stub(Setup.prototype, 'shouldBeShown').returns({
1319+
dvc: true,
1320+
experiments: true
1321+
})
1322+
const { experiments } = buildExperiments({
1323+
disposer: disposable
1324+
})
1325+
const mockShowPlots = stub(WorkspacePlots.prototype, 'showWebview')
1326+
const webviewOpened = new Promise(resolve =>
1327+
mockShowPlots.callsFake(() => {
1328+
resolve(undefined)
1329+
return Promise.resolve(undefined)
1330+
})
1331+
)
1332+
1333+
await experiments.isReady()
1334+
1335+
const webview = await experiments.showWebview()
1336+
const mockMessageReceived = getMessageReceivedEmitter(webview)
1337+
1338+
mockMessageReceived.fire({
1339+
type: MessageFromWebviewType.OPEN_PLOTS_WEBVIEW
1340+
})
1341+
1342+
await webviewOpened
1343+
1344+
expect(mockShowPlots).to.be.calledOnce
1345+
expect(mockShowPlots).to.be.calledWith(dvcDemoPath)
1346+
}).timeout(WEBVIEW_TEST_TIMEOUT)
1347+
13191348
it('should handle a message to stop experiments running', async () => {
13201349
const { experiments, dvcExecutor } = buildExperiments({
13211350
disposer: disposable

extension/src/test/suite/experiments/model/filterBy/tree.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ suite('Experiments Filter By Tree Test Suite', () => {
106106

107107
const filteredTableData: Partial<TableData> = {
108108
changes: workspaceChangesFixture,
109-
filteredCount: 1,
110109
filters: [accuracyPath],
111110
rows: filteredRows
112111
}
@@ -131,7 +130,6 @@ suite('Experiments Filter By Tree Test Suite', () => {
131130
const unfilteredTableData: Partial<TableData> = {
132131
changes: workspaceChangesFixture,
133132
columns: columnsFixture,
134-
filteredCount: 0,
135133
filters: [],
136134
rows: [workspace, main, fe2919b, _7df876c]
137135
}
@@ -371,7 +369,6 @@ suite('Experiments Filter By Tree Test Suite', () => {
371369
changes: workspaceChangesFixture,
372370
columnOrder: columnsOrderFixture,
373371
columns: columnsFixture,
374-
filteredCount: 6,
375372
filters: ['starred'],
376373
rows: filteredRows
377374
}

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

Lines changed: 81 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ describe('App', () => {
774774

775775
for (const segment of entireColumn) {
776776
fireEvent.contextMenu(segment, { bubbles: true })
777-
jest.advanceTimersByTime(100)
777+
advanceTimersByTime(100)
778778
const menuitems = screen
779779
.getAllByRole('menuitem')
780780
.filter(item => !item.className.includes('disabled'))
@@ -801,7 +801,7 @@ describe('App', () => {
801801

802802
for (const segment of entireColumn) {
803803
fireEvent.contextMenu(segment, { bubbles: true })
804-
jest.advanceTimersByTime(100)
804+
advanceTimersByTime(100)
805805
const menuitems = screen
806806
.getAllByRole('menuitem')
807807
.filter(item => !item.className.includes('disabled'))
@@ -821,7 +821,7 @@ describe('App', () => {
821821
)
822822
const placeholder = placeholders[0]
823823
fireEvent.contextMenu(placeholder, { bubbles: true })
824-
jest.advanceTimersByTime(100)
824+
advanceTimersByTime(100)
825825

826826
const hideOption = screen.getByText('Hide Column')
827827

@@ -1486,19 +1486,18 @@ describe('App', () => {
14861486
renderTable({
14871487
...tableDataFixture
14881488
})
1489+
jest.useFakeTimers()
14891490
const selectedForPlotsIndicator =
14901491
screen.getByLabelText('selected for plots')
14911492
expect(selectedForPlotsIndicator).toHaveTextContent('2')
14921493

14931494
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
14941495

14951496
fireEvent.mouseEnter(selectedForPlotsIndicator)
1496-
1497+
advanceTimersByTime(1000)
14971498
const tooltip = screen.getByRole('tooltip')
14981499

1499-
expect(tooltip).toHaveTextContent(
1500-
'2 Experiments Selected for Plotting (Max 7)'
1501-
)
1500+
expect(tooltip).toHaveTextContent('Show Plots')
15021501

15031502
setTableData({
15041503
...tableDataFixture,
@@ -1510,9 +1509,6 @@ describe('App', () => {
15101509
})
15111510

15121511
expect(selectedForPlotsIndicator).toHaveTextContent('')
1513-
expect(tooltip).toHaveTextContent(
1514-
'No Experiments Selected for Plotting (Max 7)'
1515-
)
15161512

15171513
setTableData({
15181514
...tableDataFixture,
@@ -1533,12 +1529,10 @@ describe('App', () => {
15331529
})
15341530

15351531
expect(selectedForPlotsIndicator).toHaveTextContent('1')
1536-
expect(tooltip).toHaveTextContent(
1537-
'1 Experiment Selected for Plotting (Max 7)'
1538-
)
1532+
jest.useRealTimers()
15391533
})
15401534

1541-
it('should show not change the plotted indicator when plotted experiments are hidden', () => {
1535+
it('should not change the plotted indicator when plotted experiments are hidden', () => {
15421536
const plottedExperiment = '4fb124a'
15431537

15441538
renderTable({
@@ -1547,49 +1541,30 @@ describe('App', () => {
15471541

15481542
expect(screen.getByText(plottedExperiment)).toBeInTheDocument()
15491543

1550-
const selectedForPlotsIndicator =
1551-
screen.getByLabelText('selected for plots')
1552-
expect(selectedForPlotsIndicator).toHaveTextContent('2')
1553-
1554-
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
1555-
1556-
fireEvent.mouseEnter(selectedForPlotsIndicator)
1557-
1558-
const expandedTooltip = screen.getByRole('tooltip')
1559-
1560-
expect(expandedTooltip).toHaveTextContent(
1561-
'2 Experiments Selected for Plotting (Max 7)'
1562-
)
1563-
1564-
fireEvent.mouseLeave(selectedForPlotsIndicator)
1544+
expect(screen.getByLabelText('selected for plots')).toHaveTextContent('2')
15651545

15661546
contractRow('main')
15671547

1568-
expect(screen.queryByText(plottedExperiment)).not.toBeInTheDocument()
1569-
fireEvent.mouseEnter(selectedForPlotsIndicator)
1570-
1571-
const contractedTooltip = screen.getByRole('tooltip')
1572-
1573-
expect(contractedTooltip).toHaveTextContent(
1574-
'2 Experiments Selected for Plotting (Max 7)'
1575-
)
1548+
expect(screen.getByLabelText('selected for plots')).toHaveTextContent('2')
15761549
})
15771550

15781551
it('should show an indicator with the amount of applied sorts', () => {
15791552
renderTable({
15801553
...tableDataFixture,
15811554
sorts: []
15821555
})
1556+
jest.useFakeTimers()
15831557
const sortIndicator = screen.getByLabelText('sorts')
15841558
expect(sortIndicator).toHaveTextContent('')
15851559

15861560
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
15871561

15881562
fireEvent.mouseEnter(sortIndicator)
1563+
advanceTimersByTime(1000)
15891564

15901565
const tooltip = screen.getByRole('tooltip')
15911566

1592-
expect(tooltip).toHaveTextContent('No Sorts Applied')
1567+
expect(tooltip).toHaveTextContent('Show Sorts')
15931568

15941569
const { columns } = tableDataFixture
15951570
const firstSortPath = columns[columns.length - 1].path
@@ -1599,7 +1574,6 @@ describe('App', () => {
15991574
sorts: [{ descending: true, path: firstSortPath }]
16001575
})
16011576
expect(sortIndicator).toHaveTextContent('1')
1602-
expect(tooltip).toHaveTextContent('1 Sort Applied')
16031577
setTableData({
16041578
...tableDataFixture,
16051579
sorts: [
@@ -1608,7 +1582,7 @@ describe('App', () => {
16081582
]
16091583
})
16101584
expect(sortIndicator).toHaveTextContent('2')
1611-
expect(tooltip).toHaveTextContent('2 Sorts Applied')
1585+
jest.useRealTimers()
16121586
})
16131587
})
16141588

@@ -1617,16 +1591,18 @@ describe('App', () => {
16171591
...tableDataFixture,
16181592
filters: []
16191593
})
1594+
jest.useFakeTimers()
16201595
const filterIndicator = screen.getByLabelText('filters')
16211596
expect(filterIndicator).toHaveTextContent('')
16221597

16231598
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
16241599

16251600
fireEvent.mouseEnter(filterIndicator)
1601+
advanceTimersByTime(1000)
16261602

16271603
const tooltip = screen.getByRole('tooltip')
16281604

1629-
expect(tooltip).toHaveTextContent('No Filters Applied')
1605+
expect(tooltip).toHaveTextContent('Show Filters')
16301606

16311607
const { columns } = tableDataFixture
16321608
const firstFilterPath = columns[columns.length - 1].path
@@ -1636,33 +1612,89 @@ describe('App', () => {
16361612
filters: [firstFilterPath]
16371613
})
16381614
expect(filterIndicator).toHaveTextContent('1')
1639-
expect(tooltip).toHaveTextContent('1 Filter Applied')
1640-
expect(tooltip).toHaveTextContent('No Experiments Filtered')
16411615

16421616
setTableData({
16431617
...tableDataFixture,
1644-
filteredCount: 1,
16451618
filters: [firstFilterPath, secondFilterPath]
16461619
})
16471620
expect(filterIndicator).toHaveTextContent('2')
1648-
expect(tooltip).toHaveTextContent('2 Filters Applied')
1649-
expect(tooltip).toHaveTextContent('1 Experiment Filtered')
16501621

16511622
setTableData({
16521623
...tableDataFixture,
1653-
filteredCount: 10000,
16541624
filters: [firstFilterPath, secondFilterPath]
16551625
})
16561626
expect(filterIndicator).toHaveTextContent('2')
1657-
expect(tooltip).toHaveTextContent('10000 Experiments Filtered')
16581627

16591628
setTableData({
16601629
...tableDataFixture,
1661-
filteredCount: 10000,
16621630
filters: []
16631631
})
16641632
expect(filterIndicator).toHaveTextContent('')
16651633
expect(tooltip).not.toHaveTextContent('Experiment')
1634+
jest.useRealTimers()
1635+
})
1636+
1637+
it('should show a tooltip for the branches indicator', () => {
1638+
renderTable({
1639+
...tableDataFixture
1640+
})
1641+
jest.useFakeTimers()
1642+
const branchesIndicator = screen.getByLabelText('branches')
1643+
expect(branchesIndicator).toHaveTextContent('')
1644+
1645+
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
1646+
1647+
fireEvent.mouseEnter(branchesIndicator)
1648+
advanceTimersByTime(1000)
1649+
1650+
const tooltip = screen.getByRole('tooltip')
1651+
1652+
expect(tooltip).toHaveTextContent('Select Branches')
1653+
jest.useRealTimers()
1654+
})
1655+
1656+
it('should show an indicator for the number of branches selected', () => {
1657+
const branches = ['main', 'other', 'third']
1658+
1659+
let workspace
1660+
const rowsWithoutWorkspace = []
1661+
for (const row of tableDataFixture.rows) {
1662+
if (row.id !== EXPERIMENT_WORKSPACE_ID) {
1663+
rowsWithoutWorkspace.push(row)
1664+
continue
1665+
}
1666+
workspace = row
1667+
}
1668+
1669+
const multipleBranches = {
1670+
...tableDataFixture,
1671+
branches,
1672+
hasData: true,
1673+
rows: [
1674+
workspace as Commit,
1675+
...rowsWithoutWorkspace.map(row => ({
1676+
...row,
1677+
branch: branches[0],
1678+
subRows: undefined
1679+
})),
1680+
...rowsWithoutWorkspace.map(row => ({
1681+
...row,
1682+
branch: branches[1],
1683+
subRows: undefined
1684+
})),
1685+
...rowsWithoutWorkspace.map(row => ({
1686+
...row,
1687+
branch: branches[2],
1688+
subRows: undefined
1689+
}))
1690+
]
1691+
}
1692+
1693+
renderTable(multipleBranches)
1694+
1695+
const [indicator] = screen.getAllByLabelText('branches')
1696+
1697+
expect(indicator).toHaveTextContent(`${branches.length - 1}`)
16661698
})
16671699

16681700
it('should send a message to focus the relevant tree when clicked', () => {

0 commit comments

Comments
 (0)