Skip to content
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
3 changes: 2 additions & 1 deletion extension/src/connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import { openUrl } from '../vscode/external'
import { ContextKey, setContextValue } from '../vscode/context'
import { RegisteredCommands } from '../commands/external'
import { Modal } from '../vscode/modal'
import { GLOBAL_WEBVIEW_DVCROOT } from '../webview/factory'

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

private readonly secrets: SecretStorage

constructor(context: ExtensionContext, webviewIcon: Resource) {
super('', webviewIcon)
super(GLOBAL_WEBVIEW_DVCROOT, webviewIcon)

this.secrets = context.secrets

Expand Down
3 changes: 2 additions & 1 deletion extension/src/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { EventName } from '../telemetry/constants'
import { WorkspaceScale } from '../telemetry/collect'
import { gitPath } from '../cli/git/constants'
import { DOT_DVC } from '../cli/dvc/constants'
import { GLOBAL_WEBVIEW_DVCROOT } from '../webview/factory'

export type SetupWebviewWebview = BaseWebview<TSetupData>

Expand Down Expand Up @@ -96,7 +97,7 @@ export class Setup
webviewIcon: Resource,
collectWorkspaceScale: () => Promise<WorkspaceScale>
) {
super('', webviewIcon)
super(GLOBAL_WEBVIEW_DVCROOT, webviewIcon)

this.config = config
this.dvcExecutor = dvcExecutor
Expand Down
4 changes: 0 additions & 4 deletions extension/src/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,3 @@ export type MessageToWebview<T extends WebviewData> = {
export enum MessageToWebviewType {
SET_DATA = 'setData'
}

export interface WebviewState {
dvcRoot: string
}
29 changes: 7 additions & 22 deletions extension/src/webview/factory.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Uri, ViewColumn, WebviewPanel, window } from 'vscode'
import { BaseWebview } from '.'
import { ViewKey, WebviewDetails } from './constants'
import { WebviewState, WebviewData } from './contract'
import { Resource } from '../resourceLocator'
import { getWorkspaceRootUris } from '../vscode/workspaceFolders'

export const isValidDvcRoot = (dvcRoot?: string): dvcRoot is string => !!dvcRoot
export const GLOBAL_WEBVIEW_DVCROOT = 'n/a'

const isValidDvcRoot = (dvcRoot?: string): dvcRoot is string => !!dvcRoot

const create = (
viewKey: ViewKey,
webviewPanel: WebviewPanel,
dvcRoot: string,
bypassDvcRoot?: boolean
dvcRoot: string
) => {
if (!bypassDvcRoot && !isValidDvcRoot(dvcRoot)) {
if (!isValidDvcRoot(dvcRoot)) {
throw new Error(`trying to set invalid state into ${viewKey}`)
}

Expand All @@ -26,8 +26,7 @@ export const createWebview = async (
viewKey: ViewKey,
dvcRoot: string,
iconPath: Resource,
viewColumn?: ViewColumn,
bypassDvcRoot?: boolean
viewColumn?: ViewColumn
) => {
const { title, distPath } = WebviewDetails[viewKey]

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

webviewPanel.iconPath = iconPath

const view = create(viewKey, webviewPanel, dvcRoot, bypassDvcRoot)
const view = create(viewKey, webviewPanel, dvcRoot)
await view.isReady()
return view
}

export const restoreWebview = <T extends WebviewData>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[F] This is a relic from a previous feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🪦

viewKey: ViewKey,
webviewPanel: WebviewPanel,
state: WebviewState
): Promise<BaseWebview<T>> => {
return new Promise((resolve, reject) => {
try {
resolve(create(viewKey, webviewPanel, state.dvcRoot))
} catch (error: unknown) {
reject(error)
}
})
}
3 changes: 1 addition & 2 deletions extension/src/webview/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export abstract class BaseRepository<
this.viewKey,
this.dvcRoot,
this.webviewIcon,
viewColumn,
[ViewKey.CONNECT, ViewKey.SETUP].includes(this.viewKey)
viewColumn
)

this.setWebview(webview)
Expand Down