Skip to content

Commit 859dead

Browse files
author
Roman.Sergeenko
committed
#RI-2174 - change ttl format
1 parent 1c81000 commit 859dead

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

redisinsight/ui/src/pages/browser/components/key-list/KeyList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
formatLongName,
1717
replaceSpaces,
1818
truncateTTLToDuration,
19-
truncateTTLToRange,
19+
truncateTTLToFirstUnit,
2020
truncateTTLToSeconds,
2121
} from 'uiSrc/utils'
2222
import {
@@ -192,7 +192,7 @@ const KeyList = (props: Props) => {
192192
},
193193
{
194194
id: 'ttl',
195-
label: 'TTL(s)',
195+
label: 'TTL',
196196
absoluteWidth: 65,
197197
minWidth: 65,
198198
truncateText: true,
@@ -221,7 +221,7 @@ const KeyList = (props: Props) => {
221221
</>
222222
)}
223223
>
224-
<>{truncateTTLToRange(cellData)}</>
224+
<>{truncateTTLToFirstUnit(cellData)}</>
225225
</EuiToolTip>
226226
</div>
227227
</EuiText>

redisinsight/ui/src/utils/tests/truncateTTL.spec.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
truncateTTLToDuration,
3+
truncateTTLToFirstUnit,
34
truncateTTLToRange,
45
truncateTTLToSeconds,
56
} from '../truncateTTL'
@@ -101,16 +102,15 @@ describe('Truncate TTL util tests', () => {
101102
const expectedResponse2 = '25 min, 34 s'
102103
const expectedResponse3 = '15 h, 5 min, 34 s'
103104
const expectedResponse4 = '1 mo, 19 d, 1 h, 33 min, 54 s'
104-
// TODO started failing
105-
// const expectedResponse5 = '3 yr, 6 mo, 19 d, 10 h, 32 min, 10 s';
106-
// const expectedResponse6 = '67 yr, 2 mo, 6 d, 12 h, 38 min, 20 s';
105+
const expectedResponse5 = '3 yr, 6 mo, 19 d, 10 h, 32 min, 10 s'
106+
const expectedResponse6 = '67 yr, 2 mo, 6 d, 12 h, 38 min, 20 s'
107107

108108
expect(truncateTTLToDuration(ttl1)).toEqual(expectedResponse1)
109109
expect(truncateTTLToDuration(ttl2)).toEqual(expectedResponse2)
110110
expect(truncateTTLToDuration(ttl3)).toEqual(expectedResponse3)
111111
expect(truncateTTLToDuration(ttl4)).toEqual(expectedResponse4)
112-
// expect(truncateTTLToDuration(ttl5)).toEqual(expectedResponse5);
113-
// expect(truncateTTLToDuration(ttl6)).toEqual(expectedResponse6);
112+
expect(truncateTTLToDuration(ttl5)).toEqual(expectedResponse5)
113+
expect(truncateTTLToDuration(ttl6)).toEqual(expectedResponse6)
114114
})
115115
})
116116

@@ -132,4 +132,29 @@ describe('Truncate TTL util tests', () => {
132132
expect(truncateTTLToSeconds(ttl4)).toEqual(expectedResponse4)
133133
})
134134
})
135+
136+
describe('truncateTTLToFirstUnit', () => {
137+
it('truncateTTLToFirstUnit should return appropriate value', () => {
138+
const ttl1 = 100
139+
const ttl2 = 1_534
140+
const ttl3 = 54_334
141+
const ttl4 = 4_325_634
142+
const ttl5 = 112_012_330
143+
const ttl6 = 2_120_042_300
144+
145+
const expectedResponse1 = '1 min' // '1 min, 40 s'
146+
const expectedResponse2 = '25 min' // '25 min, 34 s'
147+
const expectedResponse3 = '15 h' // '15 h, 5 min, 34 s'
148+
const expectedResponse4 = '1 mo' // '1 mo, 19 d, 1 h, 33 min, 54 s'
149+
const expectedResponse5 = '3 yr' // '3 yr, 6 mo, 19 d, 10 h, 32 min, 10 s'
150+
const expectedResponse6 = '67 yr' // '67 yr, 2 mo, 6 d, 12 h, 38 min, 20 s'
151+
152+
expect(truncateTTLToFirstUnit(ttl1)).toEqual(expectedResponse1)
153+
expect(truncateTTLToFirstUnit(ttl2)).toEqual(expectedResponse2)
154+
expect(truncateTTLToFirstUnit(ttl3)).toEqual(expectedResponse3)
155+
expect(truncateTTLToFirstUnit(ttl4)).toEqual(expectedResponse4)
156+
expect(truncateTTLToFirstUnit(ttl5)).toEqual(expectedResponse5)
157+
expect(truncateTTLToFirstUnit(ttl6)).toEqual(expectedResponse6)
158+
})
159+
})
135160
})

redisinsight/ui/src/utils/truncateTTL.ts

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

44
import { MAX_TTL_NUMBER } from './validations'
55

6+
const TRUNCATE_DELIMITER = ', '
67
// Replace default strings of duration to cutted
78
// 94 years, 9 month, 3 minutes => 94 yr, 9mo, 3min
89
const cutDurationText = (text = '') => text
@@ -60,11 +61,11 @@ export const truncateTTLToDuration = (ttl: number): string => {
6061
end: ttl * 1_000,
6162
})
6263

63-
const formatedDuration = formatDuration(duration, {
64-
delimiter: ', ',
64+
const formattedDuration = formatDuration(duration, {
65+
delimiter: TRUNCATE_DELIMITER,
6566
})
6667

67-
return cutDurationText(formatedDuration)
68+
return cutDurationText(formattedDuration)
6869
} catch (e) {
6970
return ''
7071
}
@@ -74,4 +75,8 @@ export const truncateTTLToDuration = (ttl: number): string => {
7475
// 500 => 500
7576
// 1500 => 1 500
7677
// 2500000 => 2 500 000
77-
export const truncateTTLToSeconds = (ttl: number) => ttl?.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ') ?? ''
78+
export const truncateTTLToSeconds = (ttl: number) =>
79+
ttl?.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ') ?? ''
80+
81+
export const truncateTTLToFirstUnit = (ttl: number): string =>
82+
truncateTTLToDuration(ttl).split(TRUNCATE_DELIMITER)[0]

0 commit comments

Comments
 (0)