Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rearrange internals of base workspace webviews #1706

Merged
merged 1 commit into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions extension/src/experiments/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<

public readonly updatesPaused: EventEmitter<boolean>

private focusedWebviewDvcRoot: string | undefined

constructor(
internalCommands: InternalCommands,
updatesPaused: EventEmitter<boolean>,
Expand All @@ -40,13 +38,6 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
}
}

public getFocusedWebview(): Experiments | undefined {
if (!this.focusedWebviewDvcRoot) {
return undefined
}
return this.getRepository(this.focusedWebviewDvcRoot)
}

public async addFilter(overrideRoot?: string) {
const dvcRoot = await this.getDvcRoot(overrideRoot)
if (!dvcRoot) {
Expand Down Expand Up @@ -255,14 +246,6 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
return this.runCommand(commandId, cwd, experiment.name)
}

private async getDvcRoot(overrideRoot?: string) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[F] In #1701 we need this property to be in both classes derived from BaseWorkspaceWebviews

return overrideRoot || (await this.getFocusedOrOnlyOrPickProject())
}

private getFocusedOrOnlyOrPickProject() {
return this.focusedWebviewDvcRoot || this.getOnlyOrPickProject()
}

private pickCurrentExperiment(cwd: string) {
return this.getRepository(cwd).pickCurrentExperiment()
}
Expand Down
2 changes: 1 addition & 1 deletion extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class Extension extends Disposable implements IExtension {
)

registerExperimentCommands(this.experiments, this.internalCommands)
registerPlotsCommands(this.plots)
registerPlotsCommands(this.plots, this.internalCommands)

this.dispose.track(
commands.registerCommand(RegisteredCommands.STOP_EXPERIMENT, async () => {
Expand Down
16 changes: 11 additions & 5 deletions extension/src/plots/commands/register.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { commands } from 'vscode'
import { RegisteredCommands } from '../../commands/external'
import { InternalCommands } from '../../commands/internal'
import { WorkspacePlots } from '../workspace'

export const registerPlotsCommands = (plots: WorkspacePlots) => {
commands.registerCommand(RegisteredCommands.PLOTS_SHOW, () => {
Copy link
Member Author

@mattseddon mattseddon May 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[F] Having this registered in this way means we have no telemetry events for it so far 🤦🏻 .

plots.showWebview()
})
export const registerPlotsCommands = (
plots: WorkspacePlots,
internalCommands: InternalCommands
) => {
internalCommands.registerExternalCommand(
RegisteredCommands.PLOTS_SHOW,
() => {
plots.showWebview()
}
)
}
6 changes: 6 additions & 0 deletions extension/src/plots/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export class WorkspacePlots extends BaseWorkspaceWebviews<Plots, PlotsData> {
})
)

plots.dispose.track(
plots.onDidChangeIsWebviewFocused(
dvcRoot => (this.focusedWebviewDvcRoot = dvcRoot)
)
)

return plots
}
}
3 changes: 2 additions & 1 deletion extension/src/test/suite/plots/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { mockHasCheckpoints } from '../experiments/util'
import { MOCK_IMAGE_MTIME } from '../../fixtures/plotsDiff'
import { PathsModel } from '../../../plots/paths/model'
import { Color } from '../../../experiments/model/status/colors'
import { BaseWorkspaceWebviews } from '../../../webview/workspace'

export const buildPlots = async (
disposer: Disposer,
Expand Down Expand Up @@ -67,7 +68,7 @@ export const buildPlots = async (

await plots.isReady()

stub(WorkspaceExperiments.prototype, 'getDvcRoots').returns([dvcDemoPath])
stub(BaseWorkspaceWebviews.prototype, 'getDvcRoots').returns([dvcDemoPath])
stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)
stub(WorkspacePlots.prototype, 'getRepository').returns(plots)

Expand Down
17 changes: 17 additions & 0 deletions extension/src/webview/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export abstract class BaseWorkspaceWebviews<
> extends BaseWorkspace<T, ResourceLocator> {
protected readonly workspaceState: Memento

protected focusedWebviewDvcRoot: string | undefined

constructor(
internalCommands: InternalCommands,
workspaceState: Memento,
Expand All @@ -35,4 +37,19 @@ export abstract class BaseWorkspaceWebviews<
await repository.showWebview()
return repository
}

public getFocusedWebview(): T | undefined {
if (!this.focusedWebviewDvcRoot) {
return undefined
}
return this.getRepository(this.focusedWebviewDvcRoot)
}

protected async getDvcRoot(overrideRoot?: string) {
return overrideRoot || (await this.getFocusedOrOnlyOrPickProject())
}

protected getFocusedOrOnlyOrPickProject() {
return this.focusedWebviewDvcRoot || this.getOnlyOrPickProject()
}
}