Skip to content

Commit bb32e52

Browse files
Merge pull request #3382 from RedisInsight/bugfix/RI-5402-ai-assistant
#RI-5719 - fix oauth callback
2 parents b40db05 + cefeaef commit bb32e52

File tree

10 files changed

+28
-21
lines changed

10 files changed

+28
-21
lines changed

redisinsight/ui/src/components/oauth/oauth-jobs/OAuthJobs.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { INFINITE_MESSAGES, InfiniteMessagesIds } from 'uiSrc/components/notific
1313
import { TelemetryEvent, sendEventTelemetry } from 'uiSrc/telemetry'
1414
import { BrowserStorageItem, CustomErrorCodes } from 'uiSrc/constants'
1515
import { localStorageService } from 'uiSrc/services'
16+
import { setSSOFlow } from 'uiSrc/slices/instances/cloud'
1617

1718
const OAuthJobs = () => {
1819
const {
@@ -70,6 +71,7 @@ const OAuthJobs = () => {
7071
break
7172
}
7273

74+
dispatch(setSSOFlow())
7375
dispatch(removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress))
7476
break
7577

@@ -110,13 +112,15 @@ const OAuthJobs = () => {
110112
sendEventTelemetry({
111113
event: TelemetryEvent.CLOUD_IMPORT_EXISTING_DATABASE_FORM_CLOSED,
112114
})
115+
dispatch(setSSOFlow())
113116
dispatch(removeInfiniteNotification(InfiniteMessagesIds.databaseExists))
114117
}
115118

116119
const closeCreateFreeDatabase = () => {
117120
sendEventTelemetry({
118121
event: TelemetryEvent.CLOUD_CREATE_DATABASE_IN_SUBSCRIPTION_FORM_CLOSED,
119122
})
123+
dispatch(setSSOFlow())
120124
dispatch(removeInfiniteNotification(InfiniteMessagesIds.subscriptionExists))
121125
}
122126

redisinsight/ui/src/components/oauth/oauth-sso-handler-dialog/OAuthSsoHandlerDialog.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ const OAuthSsoHandlerDialog = ({ children }: Props) => {
4646
}
4747
e?.preventDefault()
4848

49-
dispatch(setSSOFlow(action))
50-
5149
if (action === OAuthSocialAction.Import && data) {
5250
// if user logged in - do not show dialog, just redirect to subscriptions page
5351
dispatch(fetchSubscriptionsRedisCloud(null, true, () => {
@@ -69,6 +67,7 @@ const OAuthSsoHandlerDialog = ({ children }: Props) => {
6967
})
7068
}
7169

70+
dispatch(setSSOFlow(action))
7271
dispatch(setSocialDialogState(source))
7372
}
7473

redisinsight/ui/src/components/oauth/oauth-sso/oauth-create-db/OAuthCreateDb.spec.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ describe('OAuthCreateDb', () => {
107107

108108
const expectedActions = [
109109
setSSOFlow(OAuthSocialAction.Create),
110-
setSocialDialogState(null),
111-
setJob({ id: '', name: CloudJobName.CreateFreeSubscriptionAndDatabase, status: '' }),
112110
showOAuthProgress(true),
113111
addInfiniteNotification(INFINITE_MESSAGES.PENDING_CREATE_DB(CloudJobStep.Credentials)),
114112
addFreeDb()
@@ -128,8 +126,6 @@ describe('OAuthCreateDb', () => {
128126

129127
const expectedActions = [
130128
setSSOFlow(OAuthSocialAction.Create),
131-
setSocialDialogState(null),
132-
setJob({ id: '', name: CloudJobName.CreateFreeSubscriptionAndDatabase, status: '' }),
133129
showOAuthProgress(true),
134130
addInfiniteNotification(INFINITE_MESSAGES.PENDING_CREATE_DB(CloudJobStep.Credentials)),
135131
getPlans()

redisinsight/ui/src/components/oauth/oauth-sso/oauth-create-db/OAuthCreateDb.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@ import {
55
createFreeDbJob,
66
fetchPlans,
77
oauthCloudUserSelector,
8-
setJob,
9-
setSocialDialogState,
108
showOAuthProgress
119
} from 'uiSrc/slices/oauth/cloud'
1210

1311
import { OAuthSocialAction, OAuthSocialSource } from 'uiSrc/slices/interfaces'
14-
import { BrowserStorageItem, FeatureFlags } from 'uiSrc/constants'
12+
import { FeatureFlags } from 'uiSrc/constants'
1513
import { appFeatureFlagsFeaturesSelector } from 'uiSrc/slices/app/features'
1614
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
1715
import { CloudJobName, CloudJobStep } from 'uiSrc/electron/constants'
1816
import { addInfiniteNotification, removeInfiniteNotification } from 'uiSrc/slices/app/notifications'
1917
import { INFINITE_MESSAGES, InfiniteMessagesIds } from 'uiSrc/components/notifications/components'
2018
import { setIsRecommendedSettingsSSO, setSSOFlow } from 'uiSrc/slices/instances/cloud'
21-
import { localStorageService } from 'uiSrc/services'
2219
import { Nullable } from 'uiSrc/utils'
2320
import { OAuthAdvantages, OAuthAgreement, OAuthRecommendedSettings, OAuthSocialButtons } from '../../shared'
2421
import styles from './styles.module.scss'
@@ -61,9 +58,6 @@ const OAuthCreateDb = (props: Props) => {
6158

6259
const handleClickCreate = () => {
6360
dispatch(setSSOFlow(OAuthSocialAction.Create))
64-
dispatch(setSocialDialogState(null))
65-
dispatch(setJob({ id: '', name: CloudJobName.CreateFreeSubscriptionAndDatabase, status: '' }))
66-
localStorageService.remove(BrowserStorageItem.OAuthJobId)
6761
dispatch(showOAuthProgress(true))
6862
dispatch(addInfiniteNotification(INFINITE_MESSAGES.PENDING_CREATE_DB(CloudJobStep.Credentials)))
6963

@@ -73,9 +67,6 @@ const OAuthCreateDb = (props: Props) => {
7367
resources: {
7468
isRecommendedSettings: isRecommended
7569
},
76-
onSuccessAction: () => {
77-
dispatch(addInfiniteNotification(INFINITE_MESSAGES.PENDING_CREATE_DB(CloudJobStep.Credentials)))
78-
},
7970
onFailAction: () => {
8071
dispatch(removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress))
8172
dispatch(setSSOFlow(undefined))

redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/welcome-ai-assistant/WelcomeAiAssistant.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import { OAuthAgreement, OAuthSocialButtons } from 'uiSrc/components/oauth/share
66
import { OAuthSocialAction, OAuthSocialSource } from 'uiSrc/slices/interfaces'
77
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
88
import { setSSOFlow } from 'uiSrc/slices/instances/cloud'
9+
import { setSocialDialogState } from 'uiSrc/slices/oauth/cloud'
910
import styles from './styles.module.scss'
1011

1112
const WelcomeAiAssistant = () => {
1213
const dispatch = useDispatch()
1314

1415
const handleSsoClick = (accountOption: string) => {
1516
dispatch(setSSOFlow(OAuthSocialAction.SignIn))
17+
dispatch(setSocialDialogState(OAuthSocialSource.AiChat))
18+
1619
sendEventTelemetry({
1720
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
1821
eventData: {

redisinsight/ui/src/electron/components/ConfigOAuth/ConfigOAuth.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const ConfigOAuth = () => {
2626

2727
const ssoFlowRef = useRef(ssoFlow)
2828
const isRecommendedSettingsRef = useRef(isRecommendedSettings)
29+
const isFlowStarted = useRef(false)
2930

3031
const history = useHistory()
3132
const dispatch = useDispatch()
@@ -36,6 +37,7 @@ const ConfigOAuth = () => {
3637

3738
useEffect(() => {
3839
ssoFlowRef.current = ssoFlow
40+
isFlowStarted.current = !!ssoFlow
3941
}, [ssoFlow])
4042

4143
useEffect(() => {
@@ -89,6 +91,8 @@ const ConfigOAuth = () => {
8991
}
9092

9193
const cloudOauthCallback = (_e: any, { status, message = '', error }: CloudAuthResponse) => {
94+
if (!isFlowStarted.current) return
95+
9296
if (status === CloudAuthStatus.Succeed) {
9397
dispatch(setJob({ id: '', name: CloudJobName.CreateFreeSubscriptionAndDatabase, status: '' }))
9498
localStorageService.remove(BrowserStorageItem.OAuthJobId)

redisinsight/ui/src/pages/home/components/capability-promotion/CapabilityPromotion.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash'
33
import reactRouterDom from 'react-router-dom'
44
import { cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
55

6-
import { changeSelectedTab, changeSidePanel } from 'uiSrc/slices/panels/sidePanels'
6+
import { changeSelectedTab, changeSidePanel, toggleSidePanel } from 'uiSrc/slices/panels/sidePanels'
77
import { InsightsPanelTabs, SidePanels } from 'uiSrc/slices/interfaces/insights'
88
import { sendEventTelemetry, TELEMETRY_EMPTY_VALUE, TelemetryEvent } from 'uiSrc/telemetry'
99
import { MOCK_EXPLORE_GUIDES } from 'uiSrc/constants/mocks/mock-explore-guides'
@@ -97,7 +97,7 @@ describe('CapabilityPromotion', () => {
9797

9898
const expectedActions = [
9999
changeSelectedTab(InsightsPanelTabs.Explore),
100-
changeSidePanel(SidePanels.Insights)
100+
toggleSidePanel(SidePanels.Insights)
101101
]
102102

103103
expect(store.getActions()).toEqual(expectedActions)

redisinsight/ui/src/pages/home/components/capability-promotion/CapabilityPromotion.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { filter } from 'lodash'
77

88
import {
99
changeSelectedTab,
10-
changeSidePanel,
1110
openTutorialByPath,
12-
sidePanelsSelector,
11+
sidePanelsSelector, toggleSidePanel,
1312
} from 'uiSrc/slices/panels/sidePanels'
1413
import { sendEventTelemetry, TELEMETRY_EMPTY_VALUE, TelemetryEvent } from 'uiSrc/telemetry'
1514
import { guideLinksSelector } from 'uiSrc/slices/content/guide-links'
@@ -54,13 +53,17 @@ const CapabilityPromotion = (props: Props) => {
5453
const tutorialPath = findTutorialPath({ id: id ?? '' })
5554
dispatch(openTutorialByPath(tutorialPath ?? '', history))
5655

56+
if (isInsightsOpen) {
57+
return
58+
}
59+
5760
sendTelemetry(id)
5861
}
5962

6063
const onClickExplore = () => {
6164
sendTelemetry()
6265
dispatch(changeSelectedTab(InsightsPanelTabs.Explore))
63-
dispatch(changeSidePanel(SidePanels.Insights))
66+
dispatch(toggleSidePanel(SidePanels.Insights))
6467
}
6568

6669
if (!data?.length) {

redisinsight/ui/src/slices/interfaces/cloud.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,7 @@ export enum CloudSsoUtmCampaign {
109109
Tutorial = 'tutorial',
110110
TriggersAndFunctions = 'redisinsight_triggers_and_functions',
111111
AutoDiscovery = 'auto_discovery',
112+
Copilot = 'ai_chat',
113+
UserProfile = 'account',
112114
Unknown = 'other',
113115
}

redisinsight/ui/src/utils/oauth/cloudSsoUtm.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ export const getCloudSsoUtmCampaign = (source?: string | null): CloudSsoUtmCampa
2525
case OAuthSocialSource.Tutorials:
2626
return CloudSsoUtmCampaign.Tutorial
2727
case OAuthSocialSource.Autodiscovery:
28+
case OAuthSocialSource.DiscoveryForm:
2829
return CloudSsoUtmCampaign.AutoDiscovery
30+
case OAuthSocialSource.AiChat:
31+
return CloudSsoUtmCampaign.Copilot
32+
case OAuthSocialSource.UserProfile:
33+
return CloudSsoUtmCampaign.UserProfile
2934
default:
3035
return CloudSsoUtmCampaign.Unknown
3136
}

0 commit comments

Comments
 (0)