Skip to content

Commit 2c0be4e

Browse files
#RI-2913-table height, fetchstream requests, #RI-2912-cursor (#665)
* #RI-2913-table height, fetchstream requests, #RI-2912-cursor
1 parent 8bb820e commit 2c0be4e

File tree

6 files changed

+91
-37
lines changed

6 files changed

+91
-37
lines changed

redisinsight/ui/src/components/range-filter/RangeFilter.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('RangeFilter', () => {
2626
)
2727
const startRangeInput = screen.getByTestId(startRangeTestId)
2828

29-
fireEvent.change(
29+
fireEvent.mouseUp(
3030
startRangeInput,
3131
{ target: { value: 123 } }
3232
)
@@ -45,7 +45,7 @@ describe('RangeFilter', () => {
4545
)
4646
const endRangeInput = screen.getByTestId(endRangeTestId)
4747

48-
fireEvent.change(
48+
fireEvent.mouseUp(
4949
endRangeInput,
5050
{ target: { value: 15 } }
5151
)

redisinsight/ui/src/components/range-filter/RangeFilter.tsx

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useRef } from 'react'
1+
import React, { useCallback, useState, useEffect, useRef } from 'react'
22
import cx from 'classnames'
33

44
import { getFormatTime, } from 'uiSrc/utils/streamUtils'
@@ -27,6 +27,9 @@ function usePrevious(value: any) {
2727
const RangeFilter = (props: Props) => {
2828
const { max, min, start, end, handleChangeStart, handleChangeEnd } = props
2929

30+
const [startVal, setStartVal] = useState(start)
31+
const [endVal, setEndVal] = useState(end)
32+
3033
const getPercent = useCallback(
3134
(value) => Math.round(((value - min) / (max - min)) * 100),
3235
[min, max]
@@ -47,43 +50,63 @@ const RangeFilter = (props: Props) => {
4750
)
4851

4952
const onChangeStart = useCallback(
50-
(event) => {
51-
const value = Math.min(+event.target.value, end - 1)
53+
({ target: { value } }) => {
54+
setStartVal(value)
55+
},
56+
[]
57+
)
58+
59+
const onMouseUpStart = useCallback(
60+
({ target: { value } }) => {
5261
handleChangeStart(value)
5362
},
54-
[end]
63+
[]
5564
)
5665

57-
const onChangeEnd = useCallback(
58-
(event) => {
59-
const value = Math.max(+event.target.value, start + 1)
66+
const onMouseUpEnd = useCallback(
67+
({ target: { value } }) => {
6068
handleChangeEnd(value)
6169
},
62-
[start]
70+
[]
71+
)
72+
73+
const onChangeEnd = useCallback(
74+
({ target: { value } }) => {
75+
setEndVal(value)
76+
},
77+
[]
6378
)
6479

6580
useEffect(() => {
6681
if (maxValRef.current) {
67-
const minPercent = getPercent(start)
82+
const minPercent = getPercent(startVal)
6883
const maxPercent = getPercent(+maxValRef.current.value)
6984

7085
if (range.current) {
7186
range.current.style.left = `${minPercent}%`
7287
range.current.style.width = `${maxPercent - minPercent}%`
7388
}
7489
}
75-
}, [start, getPercent])
90+
}, [startVal, getPercent])
7691

7792
useEffect(() => {
7893
if (minValRef.current) {
7994
const minPercent = getPercent(+minValRef.current.value)
80-
const maxPercent = getPercent(end)
95+
const maxPercent = getPercent(endVal)
8196

8297
if (range.current) {
8398
range.current.style.width = `${maxPercent - minPercent}%`
8499
}
85100
}
86-
}, [end, getPercent])
101+
}, [endVal, getPercent])
102+
103+
useEffect(() => {
104+
setStartVal(start)
105+
}, [start])
106+
107+
useEffect(() => {
108+
setEndVal(end)
109+
}, [end])
87110

88111
useEffect(() => {
89112
if (max && prevValue && prevValue.max !== max && end === prevValue.max) {
@@ -117,19 +140,21 @@ const RangeFilter = (props: Props) => {
117140
type="range"
118141
min={min}
119142
max={max}
120-
value={start}
143+
value={startVal}
121144
ref={minValRef}
122145
onChange={onChangeStart}
146+
onMouseUp={onMouseUpStart}
123147
className={cx(styles.thumb, styles.thumbZindex3)}
124148
data-testid="range-start-input"
125149
/>
126150
<input
127151
type="range"
128152
min={min}
129153
max={max}
130-
value={end}
154+
value={endVal}
131155
ref={maxValRef}
132156
onChange={onChangeEnd}
157+
onMouseUp={onMouseUpEnd}
133158
className={cx(styles.thumb, styles.thumbZindex4)}
134159
data-testid="range-end-input"
135160
/>

redisinsight/ui/src/components/range-filter/styles.module.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
height: 12px;
9393
background-color: var(--euiColorPrimary);
9494
border: none;
95-
cursor: pointer;
95+
cursor: ew-resize;
9696
margin-top: 4px;
9797
pointer-events: all;
9898
position: relative;
@@ -111,7 +111,7 @@ input[type='range']::-webkit-slider-thumb {
111111
height: 12px;
112112
background-color: var(--euiColorPrimary);
113113
border: none;
114-
cursor: pointer;
114+
cursor: ew-resize;
115115
margin-top: 4px;
116116
pointer-events: all;
117117
position: relative;

redisinsight/ui/src/components/virtual-table/styles.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ $footerHeight: 38px;
162162
}
163163

164164
:global(.key-details-table) {
165-
height: calc(100% - 38px);
165+
height: calc(100% - 94px);
166166
position: relative;
167167
&:global(.footerOpened) {
168168
:global(.ReactVirtualized__Table__Grid) {

redisinsight/ui/src/pages/browser/components/stream-details/StreamDetails/StreamDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const StreamDetails = (props: Props) => {
9494
setSortedColumnName(column)
9595
setSortedColumnOrder(order)
9696

97-
dispatch(fetchStreamEntries(key, SCAN_COUNT_DEFAULT, order))
97+
dispatch(fetchStreamEntries(key, SCAN_COUNT_DEFAULT, order, false))
9898
}
9999

100100
const handleChangeStartFilter = useCallback(

redisinsight/ui/src/slices/browser/stream.ts

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
2-
import { AxiosError } from 'axios'
2+
import axios, { AxiosError, CancelTokenSource } from 'axios'
33
import { remove } from 'lodash'
44

55
import { apiService } from 'uiSrc/services'
66
import { SCAN_COUNT_DEFAULT } from 'uiSrc/constants/api'
77
import { ApiEndpoints, SortOrder } from 'uiSrc/constants'
88
import { fetchKeyInfo, refreshKeyInfoAction, } from 'uiSrc/slices/browser/keys'
9-
import { getApiErrorMessage, getUrl, isStatusSuccessful, Maybe } from 'uiSrc/utils'
9+
import { getApiErrorMessage, getUrl, isStatusSuccessful, Maybe, Nullable } from 'uiSrc/utils'
1010
import { getStreamRangeStart, getStreamRangeEnd } from 'uiSrc/utils/streamUtils'
1111
import successMessages from 'uiSrc/components/notifications/success-messages'
1212
import {
@@ -159,6 +159,9 @@ export const streamRangeSelector = (state: RootState) => state.browser.stream?.r
159159
// The reducer
160160
export default streamSlice.reducer
161161

162+
// eslint-disable-next-line import/no-mutable-exports
163+
export let sourceStreamFetch: Nullable<CancelTokenSource> = null
164+
162165
// Asynchronous thunk action
163166
export function fetchStreamEntries(
164167
key: string,
@@ -171,6 +174,11 @@ export function fetchStreamEntries(
171174
dispatch(loadEntries(resetData))
172175

173176
try {
177+
sourceStreamFetch?.cancel?.()
178+
179+
const { CancelToken } = axios
180+
sourceStreamFetch = CancelToken.source()
181+
174182
const state = stateInit()
175183
const start = getStreamRangeStart(state.browser.stream.range.start, state.browser.stream.data.firstEntry?.id)
176184
const end = getStreamRangeEnd(state.browser.stream.range.end, state.browser.stream.data.lastEntry?.id)
@@ -185,18 +193,22 @@ export function fetchStreamEntries(
185193
end,
186194
count,
187195
sortOrder
188-
}
196+
},
197+
{ cancelToken: sourceStreamFetch.token }
189198
)
190199

200+
sourceStreamFetch = null
191201
if (isStatusSuccessful(status)) {
192202
dispatch(loadEntriesSuccess([data, sortOrder]))
193203
onSuccess?.(data)
194204
}
195205
} catch (_err) {
196-
const error = _err as AxiosError
197-
const errorMessage = getApiErrorMessage(error)
198-
dispatch(addErrorNotification(error))
199-
dispatch(loadEntriesFailure(errorMessage))
206+
if (!axios.isCancel(_err)) {
207+
const error = _err as AxiosError
208+
const errorMessage = getApiErrorMessage(error)
209+
dispatch(addErrorNotification(error))
210+
dispatch(loadEntriesFailure(errorMessage))
211+
}
200212
}
201213
}
202214
}
@@ -210,6 +222,11 @@ export function refreshStreamEntries(
210222
dispatch(loadEntries(resetData))
211223

212224
try {
225+
sourceStreamFetch?.cancel?.()
226+
227+
const { CancelToken } = axios
228+
sourceStreamFetch = CancelToken.source()
229+
213230
const state = stateInit()
214231
const { sortOrder } = state.browser.stream
215232
const start = getStreamRangeStart(state.browser.stream.range.start, state.browser.stream.data.firstEntry?.id)
@@ -225,17 +242,21 @@ export function refreshStreamEntries(
225242
end,
226243
sortOrder,
227244
count: SCAN_COUNT_DEFAULT,
228-
}
245+
},
246+
{ cancelToken: sourceStreamFetch.token }
229247
)
230248

249+
sourceStreamFetch = null
231250
if (isStatusSuccessful(status)) {
232251
dispatch(loadEntriesSuccess([data, sortOrder]))
233252
}
234253
} catch (_err) {
235-
const error = _err as AxiosError
236-
const errorMessage = getApiErrorMessage(error)
237-
dispatch(addErrorNotification(error))
238-
dispatch(loadEntriesFailure(errorMessage))
254+
if (!axios.isCancel(_err)) {
255+
const error = _err as AxiosError
256+
const errorMessage = getApiErrorMessage(error)
257+
dispatch(addErrorNotification(error))
258+
dispatch(loadEntriesFailure(errorMessage))
259+
}
239260
}
240261
}
241262
}
@@ -253,6 +274,10 @@ export function fetchMoreStreamEntries(
253274
dispatch(loadMoreEntries())
254275

255276
try {
277+
sourceStreamFetch?.cancel?.()
278+
279+
const { CancelToken } = axios
280+
sourceStreamFetch = CancelToken.source()
256281
const state = stateInit()
257282
const { data, status } = await apiService.post<GetStreamEntriesResponse>(
258283
getUrl(
@@ -265,18 +290,22 @@ export function fetchMoreStreamEntries(
265290
end,
266291
count,
267292
sortOrder
268-
}
293+
},
294+
{ cancelToken: sourceStreamFetch.token }
269295
)
270296

297+
sourceStreamFetch = null
271298
if (isStatusSuccessful(status)) {
272299
dispatch(loadMoreEntriesSuccess(data))
273300
onSuccess?.(data)
274301
}
275302
} catch (_err) {
276-
const error = _err as AxiosError
277-
const errorMessage = getApiErrorMessage(error)
278-
dispatch(addErrorNotification(error))
279-
dispatch(loadMoreEntriesFailure(errorMessage))
303+
if (!axios.isCancel(_err)) {
304+
const error = _err as AxiosError
305+
const errorMessage = getApiErrorMessage(error)
306+
dispatch(addErrorNotification(error))
307+
dispatch(loadMoreEntriesFailure(errorMessage))
308+
}
280309
}
281310
}
282311
}

0 commit comments

Comments
 (0)