Skip to content

Commit

Permalink
Switch add Studio access token to update when Studio is connected
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Mar 6, 2023
1 parent e3bdb7d commit 855c278
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
11 changes: 10 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
"command": "dvc.addStudioAccessToken",
"category": "DVC"
},
{
"title": "Update Studio Access Token",
"command": "dvc.updateStudioAccessToken",
"category": "DVC"
},
{
"title": "Add",
"command": "dvc.addTarget",
Expand Down Expand Up @@ -635,7 +640,11 @@
},
{
"command": "dvc.addStudioAccessToken",
"when": "dvc.commands.available && dvc.project.available"
"when": "dvc.commands.available && dvc.project.available && !dvc.studio.connected"
},
{
"command": "dvc.updateStudioAccessToken",
"when": "dvc.commands.available && dvc.project.available && dvc.studio.connected"
},
{
"command": "dvc.addTarget",
Expand Down
1 change: 1 addition & 0 deletions extension/src/commands/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export enum RegisteredCommands {
CONNECT_SHOW = 'dvc.showConnect',
OPEN_STUDIO_SETTINGS = 'dvc.showStudioSettings',
ADD_STUDIO_ACCESS_TOKEN = 'dvc.addStudioAccessToken',
UPDATE_STUDIO_ACCESS_TOKEN = 'dvc.updateStudioAccessToken',
REMOVE_STUDIO_ACCESS_TOKEN = 'dvc.removeStudioAccessToken',
EXPERIMENT_VIEW_SHARE_TO_STUDIO = 'dvc.views.experiments.shareExperimentToStudio'
}
5 changes: 5 additions & 0 deletions extension/src/connect/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export const registerConnectCommands = (
() => connect.saveStudioAccessToken()
)

internalCommands.registerExternalCommand(
RegisteredCommands.UPDATE_STUDIO_ACCESS_TOKEN,
() => connect.saveStudioAccessToken()
)

internalCommands.registerExternalCommand(
RegisteredCommands.REMOVE_STUDIO_ACCESS_TOKEN,
() => connect.removeStudioAccessToken()
Expand Down
1 change: 1 addition & 0 deletions extension/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,6 @@ export interface IEventNamePropertyMapping {
[EventName.CONNECT_SHOW]: undefined
[EventName.OPEN_STUDIO_SETTINGS]: undefined
[EventName.ADD_STUDIO_ACCESS_TOKEN]: undefined
[EventName.UPDATE_STUDIO_ACCESS_TOKEN]: undefined
[EventName.REMOVE_STUDIO_ACCESS_TOKEN]: undefined
}
11 changes: 11 additions & 0 deletions webview/src/connect/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,16 @@ describe('App', () => {
type: MessageFromWebviewType.SET_STUDIO_SHARE_EXPERIMENTS_LIVE
})
})

it('should enable the user to update their studio token', () => {
const shareExperimentsLive = false
renderApp(true, shareExperimentsLive)
mockPostMessage.mockClear()
const button = screen.getByText('Update Token')
fireEvent.click(button)
expect(mockPostMessage).toHaveBeenCalledWith({
type: MessageFromWebviewType.SAVE_STUDIO_TOKEN
})
})
})
})
2 changes: 1 addition & 1 deletion webview/src/connect/components/Studio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const Settings: React.FC<{
appearance="primary"
isNested={false}
text={'Update Token'}
onClick={openStudio}
onClick={saveStudioToken}
/>
<Button
appearance="secondary"
Expand Down

0 comments on commit 855c278

Please sign in to comment.