Skip to content

Commit eea04b6

Browse files
authored
Merge pull request #3415 from RedisInsight/fe/bugfix/RI-5781
#RI-5781 - change format of seconds for rate limit
2 parents 8bd6c79 + a442cf6 commit eea04b6

File tree

7 files changed

+53
-5
lines changed

7 files changed

+53
-5
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash'
33
import { useSelector } from 'react-redux'
44
import { AxiosError } from 'axios'
55
import { cleanup, clearStoreActions, mockedStore, render } from 'uiSrc/utils/test-utils'
6-
import { oauthCloudJobSelector, setJob } from 'uiSrc/slices/oauth/cloud'
6+
import { oauthCloudJobSelector, setJob, setSocialDialogState } from 'uiSrc/slices/oauth/cloud'
77
import { CloudJobStatus, CloudJobName, CloudJobStep } from 'uiSrc/electron/constants'
88
import { addErrorNotification, addInfiniteNotification, removeInfiniteNotification } from 'uiSrc/slices/app/notifications'
99
import { RootState } from 'uiSrc/slices/store'
@@ -132,6 +132,7 @@ describe('OAuthJobs', () => {
132132
const expectedActions = [
133133
addErrorNotification({ response: { data: error } } as AxiosError),
134134
setSSOFlow(),
135+
setSocialDialogState(null),
135136
removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress),
136137
]
137138
expect(clearStoreActions(store.getActions())).toEqual(
@@ -163,6 +164,7 @@ describe('OAuthJobs', () => {
163164
const expectedActions = [
164165
addInfiniteNotification(INFINITE_MESSAGES.DATABASE_EXISTS()),
165166
setSSOFlow(),
167+
setSocialDialogState(null),
166168
removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress),
167169
]
168170
expect(clearStoreActions(store.getActions())).toEqual(
@@ -194,6 +196,7 @@ describe('OAuthJobs', () => {
194196
const expectedActions = [
195197
addInfiniteNotification(INFINITE_MESSAGES.DATABASE_EXISTS()),
196198
setSSOFlow(),
199+
setSocialDialogState(null),
197200
removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress),
198201
]
199202
expect(clearStoreActions(store.getActions())).toEqual(

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import { get } from 'lodash'
55

66
import { CloudJobStatus, CloudJobName, CloudJobStep } from 'uiSrc/electron/constants'
77
import { fetchInstancesAction } from 'uiSrc/slices/instances/instances'
8-
import { createFreeDbJob, createFreeDbSuccess, oauthCloudJobSelector, oauthCloudSelector, setJob } from 'uiSrc/slices/oauth/cloud'
8+
import {
9+
createFreeDbJob,
10+
createFreeDbSuccess,
11+
oauthCloudJobSelector,
12+
oauthCloudSelector,
13+
setJob,
14+
setSocialDialogState
15+
} from 'uiSrc/slices/oauth/cloud'
916
import { CloudImportDatabaseResources } from 'uiSrc/slices/interfaces/cloud'
1017
import { addErrorNotification, addInfiniteNotification, removeInfiniteNotification } from 'uiSrc/slices/app/notifications'
1118
import { parseCloudOAuthError } from 'uiSrc/utils'
@@ -72,6 +79,7 @@ const OAuthJobs = () => {
7279
}
7380

7481
dispatch(setSSOFlow())
82+
dispatch(setSocialDialogState(null))
7583
dispatch(removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress))
7684
break
7785

redisinsight/ui/src/components/shortcuts-flyout/styles.module.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
&:global(.inMemoryTableDefault) {
1818
:global {
19-
.euiTableCellContent span {
19+
.euiTableCellContent .euiTableCellContent__text {
2020
padding-top: 0 !important;
2121
white-space: normal !important;
2222
}
@@ -29,6 +29,7 @@
2929
display: flex;
3030
justify-content: center;
3131
align-items: center;
32+
padding-top: 0 !important;
3233

3334
:global(.euiText) {
3435
font-weight: 500;

redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/shared/error-message/ErrorMessage.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('ErrorMessage', () => {
2929
}
3030
render(<ErrorMessage onRestart={jest.fn} error={error} />)
3131

32-
expect(screen.getByTestId('ai-chat-error-message')).toHaveTextContent(AI_CHAT_ERRORS.rateLimit(100))
32+
expect(screen.getByTestId('ai-chat-error-message')).toHaveTextContent('Exceeded rate limit. Try again in 1 minute.')
3333

3434
expect(screen.queryByTestId('ai-chat-error-restart-session-btn')).not.toBeInTheDocument()
3535
expect(screen.queryByTestId('ai-chat-error-report-link')).not.toBeInTheDocument()

redisinsight/ui/src/constants/apiErrors.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { secondsToMinutes } from 'uiSrc/utils/transformers/formatDate'
2+
13
enum ApiErrors {
24
SentinelParamsRequired = 'SENTINEL_PARAMS_REQUIRED',
35
KeytarUnavailable = 'KeytarUnavailable',
@@ -17,7 +19,14 @@ export const AI_CHAT_ERRORS = {
1719
default: () => 'An error occurred. Try again or restart the session.',
1820
unexpected: () => 'An unexpected error occurred. Try again later.',
1921
timeout: () => 'Timeout occurred. Try again later.',
20-
rateLimit: (limit = 5000) => `Exceeded rate limit. Try again in ${limit} seconds.`,
22+
rateLimit: (limit?: number) => {
23+
let error = 'Exceeded rate limit.'
24+
if (limit) {
25+
error += ` Try again in ${secondsToMinutes(limit)}.`
26+
}
27+
28+
return error
29+
},
2130
tokenLimit: () => 'Conversation is too long. Restart the session.'
2231
}
2332

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { secondsToMinutes } from 'uiSrc/utils'
2+
3+
const secondsToMinutesTests: any[] = [
4+
[0, '0 seconds'],
5+
[1, '1 second'],
6+
[25, '25 seconds'],
7+
[60, '1 minute'],
8+
[65, '1 minute'],
9+
[120, '2 minutes'],
10+
[1300, '21 minutes'],
11+
]
12+
13+
describe('secondsToMinutes', () => {
14+
it.each(secondsToMinutesTests)('should be output: %s, for value: $s',
15+
(input, output) => {
16+
const result = secondsToMinutes(input)
17+
expect(result).toBe(output)
18+
})
19+
})

redisinsight/ui/src/utils/transformers/formatDate.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ export const truncateMilliseconds = (milliseconds: number): string => {
2020

2121
return truncateNumberToFirstUnit(milliseconds / 1000)
2222
}
23+
24+
export const secondsToMinutes = (time: number) => {
25+
if (time < 60) {
26+
return `${time} second${time === 1 ? '' : 's'}`
27+
}
28+
const minutes = Math.floor(time / 60)
29+
return `${minutes} minute${minutes === 1 ? '' : 's'}`
30+
}

0 commit comments

Comments
 (0)