Skip to content

Commit b45162d

Browse files
committed
#RI-5781 - change format of seconds for rate limit
#RI-5772 - fix some styles
1 parent 8bd6c79 commit b45162d

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

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)