diff --git a/extension/package.json b/extension/package.json index 4e113ab021..c46765ad3d 100644 --- a/extension/package.json +++ b/extension/package.json @@ -117,6 +117,11 @@ "command": "dvc.addStudioAccessToken", "category": "DVC" }, + { + "title": "Update Studio Access Token", + "command": "dvc.updateStudioAccessToken", + "category": "DVC" + }, { "title": "Add", "command": "dvc.addTarget", @@ -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", diff --git a/extension/src/commands/external.ts b/extension/src/commands/external.ts index ba8899f4ab..5443d9c59a 100644 --- a/extension/src/commands/external.ts +++ b/extension/src/commands/external.ts @@ -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' } diff --git a/extension/src/connect/register.ts b/extension/src/connect/register.ts index ef618aacf6..f8ebc756df 100644 --- a/extension/src/connect/register.ts +++ b/extension/src/connect/register.ts @@ -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() diff --git a/extension/src/telemetry/constants.ts b/extension/src/telemetry/constants.ts index 0932e9e91f..c6a0a3cb4e 100644 --- a/extension/src/telemetry/constants.ts +++ b/extension/src/telemetry/constants.ts @@ -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 } diff --git a/webview/src/connect/components/App.test.tsx b/webview/src/connect/components/App.test.tsx index d4bdf8039f..b86924891c 100644 --- a/webview/src/connect/components/App.test.tsx +++ b/webview/src/connect/components/App.test.tsx @@ -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 + }) + }) }) }) diff --git a/webview/src/connect/components/Studio.tsx b/webview/src/connect/components/Studio.tsx index c7754637e9..d9159a72f5 100644 --- a/webview/src/connect/components/Studio.tsx +++ b/webview/src/connect/components/Studio.tsx @@ -82,7 +82,7 @@ const Settings: React.FC<{ appearance="primary" isNested={false} text={'Update Token'} - onClick={openStudio} + onClick={saveStudioToken} />