Skip to content

Commit e9b7e15

Browse files
Merge pull request #2523 from RedisInsight/fe/bugfix/RI-4904_set_default_region
#RI-4904 - update default region
2 parents 195c6ed + 154ca8f commit e9b7e15

File tree

4 files changed

+130
-22
lines changed

4 files changed

+130
-22
lines changed

redisinsight/ui/src/components/oauth/oauth-select-plan/OAuthSelectPlan.spec.tsx

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { cloneDeep } from 'lodash'
33
import { cleanup, fireEvent, mockedStore, render, within } from 'uiSrc/utils/test-utils'
44
import { TelemetryEvent, sendEventTelemetry } from 'uiSrc/telemetry'
55
import { addFreeDb, oauthCloudPlanSelector, oauthCloudSelector, initialState } from 'uiSrc/slices/oauth/cloud'
6+
import { appFeatureFlagsFeaturesSelector } from 'uiSrc/slices/app/features'
67
import { OAuthSocialSource } from 'uiSrc/slices/interfaces'
7-
import { MOCK_NO_TF_REGION, MOCK_REGIONS, MOCK_RS_PREVIEW_REGION } from 'uiSrc/constants/mocks/mock-sso'
8+
import { MOCK_NO_TF_REGION, MOCK_REGIONS, MOCK_RS_PREVIEW_REGION, MOCK_CUSTOM_REGIONS } from 'uiSrc/constants/mocks/mock-sso'
89
import OAuthSelectPlan from './OAuthSelectPlan'
910

1011
jest.mock('uiSrc/telemetry', () => ({
@@ -131,6 +132,15 @@ describe('OAuthSelectPlan', () => {
131132
expect(tfIconEl).toBeInTheDocument()
132133
})
133134

135+
it('if source is not Trigger and Functions region with RS should be selected by default', async () => {
136+
const container = render(<OAuthSelectPlan />)
137+
138+
const { queryByTestId } = within(container.queryByTestId('select-oauth-region') as HTMLElement)
139+
const tfIconEl = queryByTestId(/rs-text-/)
140+
141+
expect(tfIconEl).toBeInTheDocument()
142+
})
143+
134144
it('Should display region with RS preview text', async () => {
135145
(oauthCloudPlanSelector as jest.Mock).mockReturnValue({
136146
isOpenDialog: true,
@@ -145,6 +155,49 @@ describe('OAuthSelectPlan', () => {
145155
expect(rsTextEl).toBeInTheDocument()
146156
})
147157

158+
it('should be selected first region by default', async () => {
159+
(oauthCloudPlanSelector as jest.Mock).mockReturnValue({
160+
isOpenDialog: true,
161+
data: MOCK_CUSTOM_REGIONS,
162+
})
163+
164+
const container = render(<OAuthSelectPlan />)
165+
166+
const { queryByTestId } = within(container.queryByTestId('select-oauth-region') as HTMLElement)
167+
const selectedEl = queryByTestId('option-custom-1')
168+
169+
expect(selectedEl).toBeInTheDocument()
170+
})
171+
172+
it('should be selected us-east-2 region by default', async () => {
173+
(oauthCloudPlanSelector as jest.Mock).mockReturnValue({
174+
isOpenDialog: true,
175+
data: [MOCK_NO_TF_REGION, MOCK_RS_PREVIEW_REGION, ...MOCK_CUSTOM_REGIONS],
176+
});
177+
(appFeatureFlagsFeaturesSelector as jest.Mock).mockReturnValueOnce({})
178+
179+
const container = render(<OAuthSelectPlan />)
180+
181+
const { queryByTestId } = within(container.queryByTestId('select-oauth-region') as HTMLElement)
182+
const selectedEl = queryByTestId('option-us-east-2')
183+
184+
expect(selectedEl).toBeInTheDocument()
185+
})
186+
187+
it('Should select region with RS preview text by default', async () => {
188+
(oauthCloudPlanSelector as jest.Mock).mockReturnValue({
189+
isOpenDialog: true,
190+
data: [MOCK_RS_PREVIEW_REGION, ...MOCK_CUSTOM_REGIONS],
191+
})
192+
193+
const container = render(<OAuthSelectPlan />)
194+
195+
const { queryByTestId } = within(container.queryByTestId('select-oauth-region') as HTMLElement)
196+
const rsTextEl = queryByTestId(/rs-text-/)
197+
198+
expect(rsTextEl).toBeInTheDocument()
199+
})
200+
148201
it('should display text if no Trigger and Function regions available on this vendor', async () => {
149202
(oauthCloudPlanSelector as jest.Mock).mockReturnValue({
150203
isOpenDialog: true,

redisinsight/ui/src/components/oauth/oauth-select-plan/OAuthSelectPlan.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ import { CloudSubscriptionPlanResponse } from 'apiSrc/modules/cloud/subscription
3737
import { OAuthProvider, OAuthProviders } from './constants'
3838
import styles from './styles.module.scss'
3939

40-
export const DEFAULT_REGION = 'us-east-2'
41-
export const DEFAULT_REGION_2 = 'asia-northeast-1'
40+
export const DEFAULT_REGIONS = ['us-east-2', 'asia-northeast-1']
4241
export const DEFAULT_PROVIDER = OAuthProvider.AWS
4342

44-
const getTFProviderRegions = (regions: Region[], provider: OAuthProvider) =>
43+
const getProviderRegions = (regions: Region[], provider: OAuthProvider) =>
4544
(find(regions, { provider }) || {}).regions || []
4645

4746
const OAuthSelectPlan = () => {
@@ -56,35 +55,37 @@ const OAuthSelectPlan = () => {
5655
const [plans, setPlans] = useState(plansInit || [])
5756
const [planIdSelected, setPlanIdSelected] = useState('')
5857
const [providerSelected, setProviderSelected] = useState<OAuthProvider>(DEFAULT_PROVIDER)
59-
const [tfProviderRegions, setTfProviderRegions] = useState(getTFProviderRegions(tfRegions, providerSelected))
58+
const [tfProviderRegions, setTfProviderRegions] = useState(getProviderRegions(tfRegions, providerSelected))
59+
const [rsProviderRegions, setRsProviderRegions] = useState(getProviderRegions(rsRegions, providerSelected))
6060

6161
const dispatch = useDispatch()
6262

6363
const isTFSource = source?.endsWith(OAuthSocialSource.TriggersAndFunctions)
6464

6565
useEffect(() => {
66-
setTfProviderRegions(getTFProviderRegions(tfRegions, providerSelected))
67-
}, [providerSelected])
66+
setTfProviderRegions(getProviderRegions(tfRegions, providerSelected))
67+
setRsProviderRegions(getProviderRegions(rsRegions, providerSelected))
68+
}, [providerSelected, plansInit])
6869

6970
useEffect(() => {
7071
if (!plansInit.length) {
7172
return
7273
}
7374

7475
const defaultRegions = isTFSource
75-
? tfProviderRegions || [DEFAULT_REGION, DEFAULT_REGION_2]
76-
: [DEFAULT_REGION, DEFAULT_REGION_2]
76+
? [tfProviderRegions, DEFAULT_REGIONS].find((arr) => arr?.length)
77+
: DEFAULT_REGIONS
7778

7879
const filteredPlans = filter(plansInit, { provider: providerSelected })
7980
.sort((a, b) => (a?.details?.displayOrder || 0) - (b?.details?.displayOrder || 0))
8081

8182
const defaultPlan = filteredPlans.find(({ region = '' }) => defaultRegions?.includes(region))
82-
83-
const planId = (defaultPlan || first(filteredPlans) || {}).id?.toString() || ''
83+
const rsPreviewPlan = filteredPlans.find(({ region = '' }) => rsProviderRegions?.includes(region))
84+
const planId = (defaultPlan || rsPreviewPlan || first(filteredPlans) || {}).id?.toString() || ''
8485

8586
setPlans(filteredPlans)
8687
setPlanIdSelected(planId)
87-
}, [isTFSource, plansInit, providerSelected, tfProviderRegions])
88+
}, [isTFSource, plansInit, providerSelected, tfProviderRegions, rsProviderRegions])
8889

8990
const handleOnClose = useCallback(() => {
9091
sendEventTelemetry({
@@ -104,7 +105,7 @@ const OAuthSelectPlan = () => {
104105
const rsProviderRegions: string[] = find(rsRegions, { provider })?.regions || []
105106

106107
return (
107-
<EuiText color="subdued" size="s">
108+
<EuiText color="subdued" size="s" data-testid={`option-${region}`}>
108109
{`${countryName} (${cityName})`}
109110
<EuiTextColor className={styles.regionName}>{region}</EuiTextColor>
110111
{rsProviderRegions?.includes(region) && (
@@ -165,7 +166,7 @@ const OAuthSelectPlan = () => {
165166
</EuiTitle>
166167
<section className={styles.providers}>
167168
{ OAuthProviders.map(({ icon, id, label }) => (
168-
<div className={styles.provider}>
169+
<div className={styles.provider} key={id}>
169170
{id === providerSelected
170171
&& <div className={cx(styles.providerActiveIcon)}><EuiIcon type="check" /></div>}
171172
<EuiButton

redisinsight/ui/src/constants/mocks/mock-sso.ts

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ export const MOCK_NO_TF_REGION = {
44
name: 'Cache 30MB',
55
provider: 'AWS',
66
price: 0,
7-
region: 'eu-west-1',
7+
region: 'us-east-2',
88
regionId: 4,
99
details: {
1010
id: 4,
11-
name: 'eu-west-1',
11+
name: 'us-east-2',
1212
cloud: 'AWS',
1313
displayOrder: 4,
1414
countryName: 'Europe',
@@ -98,3 +98,63 @@ export const MOCK_REGIONS = [
9898
}
9999
}
100100
]
101+
102+
export const MOCK_CUSTOM_REGIONS = [
103+
{
104+
id: 12150,
105+
type: 'fixed',
106+
name: 'Cache 30MB',
107+
provider: 'AWS',
108+
price: 0,
109+
region: 'custom-1',
110+
regionId: 11,
111+
details: {
112+
id: 11,
113+
name: 'custom-1',
114+
cloud: 'AWS',
115+
displayOrder: 2,
116+
countryName: 'Asia Pacific',
117+
cityName: 'Singapore',
118+
regionId: 11,
119+
flag: 'sg'
120+
}
121+
},
122+
{
123+
id: 12152,
124+
type: 'fixed',
125+
name: 'Cache 30MB',
126+
provider: 'Azure',
127+
price: 0,
128+
region: 'custom-2',
129+
regionId: 16,
130+
details: {
131+
id: 16,
132+
name: 'custom-2',
133+
cloud: 'Azure',
134+
displayOrder: 10,
135+
countryName: 'East US',
136+
cityName: 'Virginia',
137+
regionId: 16,
138+
flag: 'us'
139+
}
140+
},
141+
{
142+
id: 12153,
143+
type: 'fixed',
144+
name: 'Cache 30MB',
145+
provider: 'GCP',
146+
price: 0,
147+
region: 'custom-3',
148+
regionId: 27,
149+
details: {
150+
id: 27,
151+
name: 'custom-3',
152+
cloud: 'GCP',
153+
displayOrder: 17,
154+
countryName: 'North America',
155+
cityName: 'Iowa',
156+
regionId: 27,
157+
flag: 'us'
158+
}
159+
}
160+
]

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useHistory } from 'react-router-dom'
55
import {
66
fetchPlans,
77
fetchUserInfo,
8-
oauthCloudUserDataSelector,
98
setJob,
109
setOAuthCloudSource,
1110
setSignInDialogState,
@@ -22,7 +21,6 @@ import { INFINITE_MESSAGES, InfiniteMessagesIds } from 'uiSrc/components/notific
2221

2322
const ConfigOAuth = () => {
2423
const { isAutodiscoverySSO } = useSelector(cloudSelector)
25-
const userData = useSelector(oauthCloudUserDataSelector)
2624

2725
const isAutodiscoverySSORef = useRef(isAutodiscoverySSO)
2826

@@ -36,10 +34,6 @@ const ConfigOAuth = () => {
3634
// dispatch(fetchUserInfo(fetchUserInfoSuccess))
3735
}, [])
3836

39-
useEffect(() => {
40-
console.log({ userData })
41-
}, [userData])
42-
4337
useEffect(() => {
4438
isAutodiscoverySSORef.current = isAutodiscoverySSO
4539
}, [isAutodiscoverySSO])

0 commit comments

Comments
 (0)