Skip to content

Commit ed35e17

Browse files
authored
Move experiments webview message sending into WebviewMessages (#2030)
* Move experiments webview message sending into WebviewMessages * move webview messages creation out of constructor * change get webview to a protected method
1 parent bfd6dd9 commit ed35e17

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

extension/src/experiments/index.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class Experiments extends BaseRepository<TableData> {
7373
)
7474

7575
private readonly internalCommands: InternalCommands
76+
private readonly webviewMessages: WebviewMessages
7677

7778
constructor(
7879
dvcRoot: string,
@@ -119,7 +120,7 @@ export class Experiments extends BaseRepository<TableData> {
119120
})
120121
)
121122

122-
this.handleMessageFromWebview()
123+
this.webviewMessages = this.createWebviewMessageHandler()
123124
this.setupInitialData()
124125
this.setActiveEditorContext()
125126
}
@@ -339,7 +340,7 @@ export class Experiments extends BaseRepository<TableData> {
339340
}
340341

341342
public sendInitialWebviewData() {
342-
return this.sendWebviewData()
343+
return this.webviewMessages.sendWebviewMessage()
343344
}
344345

345346
public getSelectedRevisions() {
@@ -433,43 +434,27 @@ export class Experiments extends BaseRepository<TableData> {
433434

434435
private notifyColumnsChanged() {
435436
this.columnsChanged.fire()
436-
return this.sendWebviewData()
437-
}
438-
439-
private sendWebviewData() {
440-
this.webview?.show(this.getWebviewData())
441-
}
442-
443-
private getWebviewData() {
444-
return {
445-
changes: this.columns.getChanges(),
446-
columnOrder: this.columns.getColumnOrder(),
447-
columnWidths: this.columns.getColumnWidths(),
448-
columns: this.columns.getSelected(),
449-
filteredCounts: this.getFilteredCounts(),
450-
filters: this.experiments.getFilterPaths(),
451-
hasCheckpoints: this.hasCheckpoints(),
452-
hasColumns: this.columns.hasColumns(),
453-
hasRunningExperiment: this.experiments.hasRunningExperiment(),
454-
rows: this.experiments.getRowData(),
455-
sorts: this.experiments.getSorts()
456-
}
437+
return this.webviewMessages.sendWebviewMessage()
457438
}
458439

459-
private handleMessageFromWebview() {
440+
private createWebviewMessageHandler() {
460441
const webviewMessages = new WebviewMessages(
461442
this.dvcRoot,
462443
this.experiments,
463444
this.columns,
445+
this.checkpoints,
446+
() => this.getWebview(),
464447
() => this.notifyChanged(),
465448
() => this.selectColumns()
466449
)
467450

468451
this.dispose.track(
469452
this.onDidReceivedWebviewMessage(message =>
470-
webviewMessages.handleMessageFromWebview(message)
453+
this.webviewMessages.handleMessageFromWebview(message)
471454
)
472455
)
456+
457+
return webviewMessages
473458
}
474459

475460
private async checkAutoApplyFilters(...filterIdsToRemove: string[]) {

extension/src/experiments/webview/messages.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { commands, Uri, ViewColumn, window } from 'vscode'
2+
import { TableData } from './contract'
23
import {
34
RegisteredCliCommands,
45
RegisteredCommands
@@ -7,6 +8,7 @@ import { Logger } from '../../common/logger'
78
import { sendTelemetryEvent } from '../../telemetry'
89
import { EventName } from '../../telemetry/constants'
910
import { join } from '../../test/util/path'
11+
import { BaseWebview } from '../../webview'
1012
import {
1113
MessageFromWebview,
1214
MessageFromWebviewType
@@ -15,30 +17,42 @@ import { ColumnsModel } from '../columns/model'
1517
import { splitColumnPath } from '../columns/paths'
1618
import { ExperimentsModel } from '../model'
1719
import { SortDefinition } from '../model/sortBy'
20+
import { CheckpointsModel } from '../checkpoints/model'
1821

1922
export class WebviewMessages {
2023
private readonly dvcRoot: string
2124

2225
private readonly experiments: ExperimentsModel
2326
private readonly columns: ColumnsModel
27+
private readonly checkpoints: CheckpointsModel
2428

29+
private readonly getWebview: () => BaseWebview<TableData> | undefined
2530
private readonly notifyChanged: () => void
2631
private readonly selectColumns: () => void
2732

2833
constructor(
2934
dvcRoot: string,
3035
experiments: ExperimentsModel,
3136
columns: ColumnsModel,
37+
checkpoints: CheckpointsModel,
38+
getWebview: () => BaseWebview<TableData> | undefined,
3239
notifyChanged: () => void,
3340
selectColumns: () => void
3441
) {
3542
this.dvcRoot = dvcRoot
3643
this.experiments = experiments
3744
this.columns = columns
45+
this.checkpoints = checkpoints
46+
this.getWebview = getWebview
3847
this.notifyChanged = notifyChanged
3948
this.selectColumns = selectColumns
4049
}
4150

51+
public sendWebviewMessage() {
52+
const webview = this.getWebview()
53+
webview?.show(this.getWebviewData())
54+
}
55+
4256
public handleMessageFromWebview(message: MessageFromWebview) {
4357
switch (message.type) {
4458
case MessageFromWebviewType.REORDER_COLUMNS:
@@ -104,6 +118,24 @@ export class WebviewMessages {
104118
}
105119
}
106120

121+
private getWebviewData() {
122+
return {
123+
changes: this.columns.getChanges(),
124+
columnOrder: this.columns.getColumnOrder(),
125+
columnWidths: this.columns.getColumnWidths(),
126+
columns: this.columns.getSelected(),
127+
filteredCounts: this.experiments.getFilteredCounts(
128+
this.checkpoints.hasCheckpoints()
129+
),
130+
filters: this.experiments.getFilterPaths(),
131+
hasCheckpoints: this.checkpoints.hasCheckpoints(),
132+
hasColumns: this.columns.hasColumns(),
133+
hasRunningExperiment: this.experiments.hasRunningExperiment(),
134+
rows: this.experiments.getRowData(),
135+
sorts: this.experiments.getSorts()
136+
}
137+
}
138+
107139
private setColumnOrder(order: string[]) {
108140
this.columns.setColumnOrder(order)
109141
sendTelemetryEvent(

extension/src/webview/repository.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export abstract class BaseRepository<
8080
)
8181
}
8282

83+
protected getWebview() {
84+
return this.webview
85+
}
86+
8387
private resetWebview() {
8488
this.isWebviewFocusedChanged.fire(undefined)
8589
this.dispose.untrack(this.webview)

0 commit comments

Comments
 (0)