Skip to content

Commit 1636be9

Browse files
authored
Clean up webview factory (#3277)
1 parent 7390615 commit 1636be9

File tree

5 files changed

+12
-30
lines changed

5 files changed

+12
-30
lines changed

extension/src/connect/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import { openUrl } from '../vscode/external'
1313
import { ContextKey, setContextValue } from '../vscode/context'
1414
import { RegisteredCommands } from '../commands/external'
1515
import { Modal } from '../vscode/modal'
16+
import { GLOBAL_WEBVIEW_DVCROOT } from '../webview/factory'
1617

1718
export class Connect extends BaseRepository<undefined> {
1819
public readonly viewKey = ViewKey.CONNECT
1920

2021
private readonly secrets: SecretStorage
2122

2223
constructor(context: ExtensionContext, webviewIcon: Resource) {
23-
super('', webviewIcon)
24+
super(GLOBAL_WEBVIEW_DVCROOT, webviewIcon)
2425

2526
this.secrets = context.secrets
2627

extension/src/setup/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { EventName } from '../telemetry/constants'
4343
import { WorkspaceScale } from '../telemetry/collect'
4444
import { gitPath } from '../cli/git/constants'
4545
import { DOT_DVC } from '../cli/dvc/constants'
46+
import { GLOBAL_WEBVIEW_DVCROOT } from '../webview/factory'
4647

4748
export type SetupWebviewWebview = BaseWebview<TSetupData>
4849

@@ -96,7 +97,7 @@ export class Setup
9697
webviewIcon: Resource,
9798
collectWorkspaceScale: () => Promise<WorkspaceScale>
9899
) {
99-
super('', webviewIcon)
100+
super(GLOBAL_WEBVIEW_DVCROOT, webviewIcon)
100101

101102
this.config = config
102103
this.dvcExecutor = dvcExecutor

extension/src/webview/contract.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,3 @@ export type MessageToWebview<T extends WebviewData> = {
218218
export enum MessageToWebviewType {
219219
SET_DATA = 'setData'
220220
}
221-
222-
export interface WebviewState {
223-
dvcRoot: string
224-
}

extension/src/webview/factory.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { Uri, ViewColumn, WebviewPanel, window } from 'vscode'
22
import { BaseWebview } from '.'
33
import { ViewKey, WebviewDetails } from './constants'
4-
import { WebviewState, WebviewData } from './contract'
54
import { Resource } from '../resourceLocator'
65
import { getWorkspaceRootUris } from '../vscode/workspaceFolders'
76

8-
export const isValidDvcRoot = (dvcRoot?: string): dvcRoot is string => !!dvcRoot
7+
export const GLOBAL_WEBVIEW_DVCROOT = 'n/a'
8+
9+
const isValidDvcRoot = (dvcRoot?: string): dvcRoot is string => !!dvcRoot
910

1011
const create = (
1112
viewKey: ViewKey,
1213
webviewPanel: WebviewPanel,
13-
dvcRoot: string,
14-
bypassDvcRoot?: boolean
14+
dvcRoot: string
1515
) => {
16-
if (!bypassDvcRoot && !isValidDvcRoot(dvcRoot)) {
16+
if (!isValidDvcRoot(dvcRoot)) {
1717
throw new Error(`trying to set invalid state into ${viewKey}`)
1818
}
1919

@@ -26,8 +26,7 @@ export const createWebview = async (
2626
viewKey: ViewKey,
2727
dvcRoot: string,
2828
iconPath: Resource,
29-
viewColumn?: ViewColumn,
30-
bypassDvcRoot?: boolean
29+
viewColumn?: ViewColumn
3130
) => {
3231
const { title, distPath } = WebviewDetails[viewKey]
3332

@@ -44,21 +43,7 @@ export const createWebview = async (
4443

4544
webviewPanel.iconPath = iconPath
4645

47-
const view = create(viewKey, webviewPanel, dvcRoot, bypassDvcRoot)
46+
const view = create(viewKey, webviewPanel, dvcRoot)
4847
await view.isReady()
4948
return view
5049
}
51-
52-
export const restoreWebview = <T extends WebviewData>(
53-
viewKey: ViewKey,
54-
webviewPanel: WebviewPanel,
55-
state: WebviewState
56-
): Promise<BaseWebview<T>> => {
57-
return new Promise((resolve, reject) => {
58-
try {
59-
resolve(create(viewKey, webviewPanel, state.dvcRoot))
60-
} catch (error: unknown) {
61-
reject(error)
62-
}
63-
})
64-
}

extension/src/webview/repository.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ export abstract class BaseRepository<
4747
this.viewKey,
4848
this.dvcRoot,
4949
this.webviewIcon,
50-
viewColumn,
51-
[ViewKey.CONNECT, ViewKey.SETUP].includes(this.viewKey)
50+
viewColumn
5251
)
5352

5453
this.setWebview(webview)

0 commit comments

Comments
 (0)