From c81c90e1667dacabd629b4d851ec33aec9d0c312 Mon Sep 17 00:00:00 2001 From: julieg18 Date: Tue, 7 Nov 2023 08:14:48 -0600 Subject: [PATCH] Apply review comments --- extension/src/setup/index.ts | 11 ++--------- extension/src/setup/inputBox.ts | 2 +- extension/src/setup/studio.ts | 27 +++++++++++++++++++-------- extension/src/setup/token.ts | 6 ------ 4 files changed, 22 insertions(+), 24 deletions(-) delete mode 100644 extension/src/setup/token.ts diff --git a/extension/src/setup/index.ts b/extension/src/setup/index.ts index 142626bfb6..c2b3ab2534 100644 --- a/extension/src/setup/index.ts +++ b/extension/src/setup/index.ts @@ -98,9 +98,6 @@ export class Setup new EventEmitter() ) - private readonly studioConnectionChanged: EventEmitter = - this.dispose.track(new EventEmitter()) - private readonly onDidChangeWorkspace: Event = this.workspaceChanged.event @@ -146,16 +143,12 @@ export class Setup } this.collectWorkspaceScale = collectWorkspaceScale - this.onDidChangeStudioConnection = this.studioConnectionChanged.event this.setCommandsAvailability(false) this.setProjectAvailability() - this.studio = new Studio( - internalCommands, - this.studioConnectionChanged, - () => this.getCwd() - ) + this.studio = new Studio(internalCommands, () => this.getCwd()) + this.onDidChangeStudioConnection = this.studio.onDidChangeStudioConnection this.webviewMessages = this.createWebviewMessageHandler() diff --git a/extension/src/setup/inputBox.ts b/extension/src/setup/inputBox.ts index c3c12893ca..54dca8dcce 100644 --- a/extension/src/setup/inputBox.ts +++ b/extension/src/setup/inputBox.ts @@ -1,4 +1,4 @@ -import { isStudioAccessToken } from './token' +import { isStudioAccessToken } from './studio' export const validateTokenInput = (input: string | undefined) => { if (!isStudioAccessToken(input)) { diff --git a/extension/src/setup/studio.ts b/extension/src/setup/studio.ts index ae29947238..8e35625cc8 100644 --- a/extension/src/setup/studio.ts +++ b/extension/src/setup/studio.ts @@ -1,26 +1,37 @@ -import { EventEmitter } from 'vscode' -import { isStudioAccessToken } from './token' +import { Event, EventEmitter } from 'vscode' import { AvailableCommands, InternalCommands } from '../commands/internal' import { getFirstWorkspaceFolder } from '../vscode/workspaceFolders' import { Args, ConfigKey, Flag } from '../cli/dvc/constants' import { ContextKey, setContextValue } from '../vscode/context' +import { Disposable } from '../class/dispose' -export class Studio { - protected studioConnectionChanged: EventEmitter +export const isStudioAccessToken = (text?: string): boolean => { + if (!text) { + return false + } + return text.startsWith('isat_') && text.length >= 53 +} + +export class Studio extends Disposable { + public readonly onDidChangeStudioConnection: Event + private readonly studioConnectionChanged: EventEmitter = + this.dispose.track(new EventEmitter()) + + private readonly getCwd: () => string | undefined + private readonly internalCommands: InternalCommands private studioAccessToken: string | undefined = undefined private studioIsConnected = false private shareLiveToStudio: boolean | undefined = undefined - private readonly getCwd: () => string | undefined - private readonly internalCommands: InternalCommands constructor( internalCommands: InternalCommands, - studioConnectionChanged: EventEmitter, getCwd: () => string | undefined ) { + super() + this.internalCommands = internalCommands - this.studioConnectionChanged = studioConnectionChanged this.getCwd = getCwd + this.onDidChangeStudioConnection = this.studioConnectionChanged.event } public getStudioAccessToken() { diff --git a/extension/src/setup/token.ts b/extension/src/setup/token.ts deleted file mode 100644 index d41d13800f..0000000000 --- a/extension/src/setup/token.ts +++ /dev/null @@ -1,6 +0,0 @@ -export const isStudioAccessToken = (text?: string): boolean => { - if (!text) { - return false - } - return text.startsWith('isat_') && text.length >= 53 -}