Skip to content

Commit

Permalink
apply review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Feb 16, 2023
1 parent a78e1ef commit bc9cf3a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
6 changes: 6 additions & 0 deletions extension/src/connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Title } from '../vscode/title'
import { openUrl } from '../vscode/external'
import { ContextKey, setContextValue } from '../vscode/context'
import { RegisteredCommands } from '../commands/external'
import { showInformation } from '../vscode/modal'

export class Connect extends BaseRepository<undefined> {
public readonly viewKey = ViewKey.CONNECT
Expand Down Expand Up @@ -90,6 +91,11 @@ export class Connect extends BaseRepository<undefined> {
private async setContext() {
const storedToken = await this.getSecret(STUDIO_ACCESS_TOKEN_KEY)
if (isStudioAccessToken(storedToken)) {
if (this.deferred.state === 'resolved') {
void showInformation(
'Studio is now connected. Use the "Share to Studio" command from an experiment\'s context menu to share experiments.'
)
}
this.webview?.dispose()
return setContextValue(ContextKey.STUDIO_CONNECTED, true)
}
Expand Down
2 changes: 1 addition & 1 deletion extension/src/connect/inputBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { validateTokenInput } from './inputBox'

describe('validateTokenInput', () => {
const mockedStudioAccessToken =
'isat_1Z4T0zVHvq9Cu03XEe9Zjvx2vkBihfGPdY7FfmEMAagOXfQxU'
'isat_1Z4T0zVHvq9Cu03XEe9Zjvx2vkBihfGPdY7FfmEMAagOXfQx'
it('should return the warning if the input is not valid', () => {
expect(
validateTokenInput(mockedStudioAccessToken.slice(0, -1))
Expand Down
2 changes: 1 addition & 1 deletion extension/src/connect/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export const isStudioAccessToken = (text?: string): boolean => {
if (!text) {
return false
}
return text.startsWith('isat_') && text.length === 54
return text.startsWith('isat_') && text.length >= 53
}
6 changes: 6 additions & 0 deletions extension/src/vscode/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ export const warnOfConsequences = (
...items: Response[]
): Thenable<string | undefined> =>
window.showWarningMessage(text, { modal: true }, ...items)

export const showInformation = (
text: string,
...items: Response[]
): Thenable<string | undefined> =>
window.showInformationMessage(text, { modal: true }, ...items)
17 changes: 3 additions & 14 deletions webview/src/connect/components/Studio.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import React from 'react'
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
import { STUDIO_URL } from 'dvc/src/connect/webview/contract'
import { openStudio, openStudioProfile, saveStudioToken } from './messages'
import { EmptyState } from '../../shared/components/emptyState/EmptyState'
import { Button } from '../../shared/components/button/Button'
import { sendMessage } from '../../shared/vscode'

export const Studio: React.FC = () => {
const openStudio = () =>
sendMessage({ type: MessageFromWebviewType.OPEN_STUDIO })

const openStudioProfile = () =>
sendMessage({ type: MessageFromWebviewType.OPEN_STUDIO_PROFILE })

const saveStudioToken = () =>
sendMessage({ type: MessageFromWebviewType.SAVE_STUDIO_TOKEN })

return (
<EmptyState>
<div>
<h1>
Connect to <a href={STUDIO_URL}>Studio</a>
</h1>
<p>
To share experiments and plots with collaborators directly from your
IDE.
Share experiments and plots with collaborators directly from your IDE.
</p>
<p>
An{' '}
Expand Down Expand Up @@ -52,7 +41,7 @@ export const Studio: React.FC = () => {
/>
<p>
{"Don't Have an account?\n"}
<a href={STUDIO_URL}>Sign-Up</a>
<a href={STUDIO_URL}>Get Started</a>
</p>
</div>
</EmptyState>
Expand Down
11 changes: 11 additions & 0 deletions webview/src/connect/components/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
import { sendMessage } from '../../shared/vscode'

export const openStudio = () =>
sendMessage({ type: MessageFromWebviewType.OPEN_STUDIO })

export const openStudioProfile = () =>
sendMessage({ type: MessageFromWebviewType.OPEN_STUDIO_PROFILE })

export const saveStudioToken = () =>
sendMessage({ type: MessageFromWebviewType.SAVE_STUDIO_TOKEN })

0 comments on commit bc9cf3a

Please sign in to comment.