Skip to content

Commit 25f9781

Browse files
committed
add the sso dialog to the route components so it could be opened as a panel; create an action to modify the state to open the dialog;
1 parent 0e357d9 commit 25f9781

File tree

8 files changed

+26
-6
lines changed

8 files changed

+26
-6
lines changed

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export enum ViewId {
66
EditDatabase = 'ri-edit-database',
77
Welcome = 'ri-welcome',
88
Eula = 'ri-eula',
9+
OAuthSsoDialog = 'ri-oauth-sso-dialog',
910
}
1011

1112
export const MAX_TITLE_KEY_LENGTH = 30

src/extension.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable import/no-mutable-exports */
22
import * as vscode from 'vscode'
33
import * as dotenv from 'dotenv'
4+
import { WebviewOptions } from 'vscode'
45
import * as path from 'path'
56
import { WebviewPanel } from './Webview'
67
import { startBackend, getBackendGracefulShutdown } from './server/bootstrapBackend'
@@ -214,8 +215,13 @@ export async function activate(context: vscode.ExtensionContext) {
214215
sidebarProvider.view?.webview.postMessage({ action: 'RefreshTree' })
215216
}),
216217

217-
vscode.commands.registerCommand('RedisForVSCode.OpenOAuthSsoDialog', (args) => {
218-
vscode.window.showInformationMessage('This is a modal', { modal: true })
218+
vscode.commands.registerCommand('RedisForVSCode.openOAuthSsoDialog', (args) => {
219+
WebviewPanel.getInstance({
220+
context,
221+
route: 'main/oauth_sso_dialog',
222+
title: 'Redis Cloud account',
223+
viewId: ViewId.OAuthSsoDialog,
224+
}).postMessage({ action: 'OpenOAuthSsoDialog', data: args })
219225
}),
220226
)
221227

src/utils/handleMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const handleMessage = async (message: any = {}) => {
8585
break
8686

8787
case 'OpenOAuthSsoDialog':
88-
vscode.commands.executeCommand('RedisForVSCode.OpenOAuthSsoDialog', message.data)
88+
vscode.commands.executeCommand('RedisForVSCode.openOAuthSsoDialog', message.data)
8989
break
9090

9191
default:

src/webviews/src/Routes.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
WelcomePage,
2020
} from 'uiSrc/pages'
2121

22+
import { OAuthSsoDialog } from './modules/oauth'
23+
2224
const rootEl = document.getElementById('root')
2325

2426
export const AppRoutes = () => {
@@ -39,6 +41,7 @@ export const AppRoutes = () => {
3941
<Route path="settings" element={<SettingsPage />} />
4042
<Route path="eula" element={<EulaPage />} />
4143
<Route path="welcome" element={<WelcomePage />} />
44+
<Route path="oauth_sso_dialog" element={<OAuthSsoDialog />} />
4245
</Route>
4346
<Route path="*" element={<NotFoundPage />} />
4447
</Routes>

src/webviews/src/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import {
77
fetchEditedDatabase,
88
fetchCerts,
99
useDatabasesStore,
10+
useOAuthStore,
1011
} from 'uiSrc/store'
1112
import { Config } from 'uiSrc/modules'
1213
import { AppRoutes } from 'uiSrc/Routes'
1314
import { PostMessage, SelectKeyAction, SetDatabaseAction } from 'uiSrc/interfaces'
14-
import { VscodeMessageAction } from 'uiSrc/constants'
15+
import { OAuthSocialSource, VscodeMessageAction } from 'uiSrc/constants'
1516
import { migrateLocalStorageData } from 'uiSrc/services'
1617
import { useAppInfoStore } from './store/hooks/use-app-info-store/useAppInfoStore'
1718
import {
@@ -88,6 +89,10 @@ document.addEventListener('DOMContentLoaded', () => {
8889
case VscodeMessageAction.OAuthCallback:
8990
processOauthCallback(message.data as CloudAuthResponse)
9091
break
92+
case VscodeMessageAction.OpenOAuthSsoDialog:
93+
useOAuthStore.getState().setSSOFlow(message.data?.ssoFlow)
94+
useOAuthStore.getState().setSocialDialogState(message.data?.source)
95+
break
9196
default:
9297
break
9398
}

src/webviews/src/interfaces/vscode/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AllKeyTypes, KeyTypes, OAuthSocialAction, OAuthStrategy, SelectedKeyActionType, VscodeMessageAction } from 'uiSrc/constants'
1+
import { AllKeyTypes, KeyTypes, OAuthSocialAction, OAuthSocialSource, OAuthStrategy, SelectedKeyActionType, VscodeMessageAction } from 'uiSrc/constants'
22
import { Database } from 'uiSrc/store'
33
import { AppInfoStore, GetAppSettingsResponse } from 'uiSrc/store/hooks/use-app-info-store/interface'
44
import { CloudAuthResponse } from 'uiSrc/modules/oauth/interfaces'
@@ -135,7 +135,8 @@ export interface CloseEulaAction {
135135
export interface OpenOAuthSsoDialogAction {
136136
action: VscodeMessageAction.OpenOAuthSsoDialog
137137
data: {
138-
ssoFlow: OAuthSocialAction
138+
ssoFlow: OAuthSocialAction,
139+
source: OAuthSocialSource,
139140
}
140141
}
141142

src/webviews/src/modules/oauth/oauth-create-free-db/OAuthCreateFreeDb.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const OAuthCreateFreeDb = ({ source, compressed }: Props) => {
3232
action: VscodeMessageAction.OpenOAuthSsoDialog,
3333
data: {
3434
ssoFlow: OAuthSocialAction.Create,
35+
source,
3536
},
3637
})
3738

src/webviews/src/modules/oauth/oauth-sso-dialog/OAuthSsoDialog.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const OAuthSsoDialog = () => {
3232
},
3333
})
3434
setSocialDialogState(null)
35+
36+
// TODO [DA]: dispose the dummy panel if the dialog was opened from it,
37+
// and not from add db page panel
3538
}, [ssoFlow])
3639

3740
if (!isOpenSocialDialog || !ssoFlow) {

0 commit comments

Comments
 (0)