Skip to content

Commit c5efb54

Browse files
committed
#RI-2493 - Autoscroll in CLI does not work when executing command
1 parent 85dd551 commit c5efb54

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

redisinsight/ui/src/components/cli/components/cli-body/CliBody/CliBody.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Ref, useEffect, useRef, useState } from 'react'
22
import { EuiFlexGroup, EuiFlexItem, keys } from '@elastic/eui'
33
import { useDispatch, useSelector } from 'react-redux'
44

5-
import { Nullable } from 'uiSrc/utils'
5+
import { Nullable, scrollIntoView } from 'uiSrc/utils'
66
import { isModifiedEvent } from 'uiSrc/services'
77
import { ClearCommand } from 'uiSrc/constants/cliOutput'
88
import { outputSelector } from 'uiSrc/slices/cli/cli-output'
@@ -41,7 +41,7 @@ const CliBody = (props: Props) => {
4141

4242
useEffect(() => {
4343
inputEl?.focus()
44-
scrollDivRef?.current?.scrollIntoView({
44+
scrollIntoView(scrollDivRef?.current, {
4545
behavior: 'smooth',
4646
block: 'nearest',
4747
inline: 'end',

redisinsight/ui/src/components/field-message/FieldMessage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Ref, useEffect, useRef } from 'react'
22
import cx from 'classnames'
33
import { EuiIcon, EuiTextColor } from '@elastic/eui'
44

5+
import { scrollIntoView } from 'uiSrc/utils'
56
import styles from './styles.module.scss'
67

78
type Colors = 'default' | 'secondary' | 'accent' | 'warning' | 'danger' | 'subdued' | 'ghost'
@@ -19,7 +20,7 @@ const FieldMessage = ({ children, color, testID, icon, scrollViewOnAppear }: Pro
1920
useEffect(() => {
2021
// componentDidMount
2122
if (scrollViewOnAppear) {
22-
divRef?.current?.scrollIntoView({
23+
scrollIntoView(divRef?.current, {
2324
behavior: 'smooth',
2425
block: 'nearest',
2526
inline: 'end',

redisinsight/ui/src/pages/workbench/components/wb-view/WBViewWrapper.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
removeMonacoComments,
1010
splitMonacoValuePerLines,
1111
getMultiCommands,
12+
scrollIntoView,
1213
} from 'uiSrc/utils'
1314
import {
1415
sendWBCommandAction,
@@ -165,7 +166,7 @@ const WBViewWrapper = () => {
165166
}
166167

167168
const scrollResults = (inline: ScrollLogicalPosition = 'start') => {
168-
scrollDivRef?.current?.scrollIntoView({
169+
scrollIntoView(scrollDivRef?.current, {
169170
behavior: 'smooth',
170171
block: 'nearest',
171172
inline,

redisinsight/ui/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export * from './monitorUtils'
3636
export * from './handlePlatforms'
3737
export * from './plugins'
3838
export * from './redistack'
39+
export * from './polyfills'
3940

4041
export {
4142
Maybe,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Nullable } from './types'
2+
3+
const isScrollBehaviorSupported = (): boolean =>
4+
'scrollBehavior' in globalThis.document.documentElement.style
5+
6+
export const scrollIntoView = (el: Nullable<HTMLDivElement>, opts?: ScrollIntoViewOptions) => {
7+
if (el && isScrollBehaviorSupported()) {
8+
el?.scrollIntoView(opts)
9+
} else {
10+
el?.scrollIntoView(true)
11+
}
12+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { scrollIntoView } from 'uiSrc/utils'
2+
3+
describe('scrollIntoView', () => {
4+
it('should called with options for all browser except Safari', () => {
5+
const mockScrollIntoView = jest.fn()
6+
const opts: ScrollIntoViewOptions = {
7+
behavior: 'smooth',
8+
inline: 'end',
9+
block: 'nearest',
10+
}
11+
const newDiv = document.createElement('div')
12+
newDiv.scrollIntoView = mockScrollIntoView
13+
scrollIntoView(newDiv, opts)
14+
expect(mockScrollIntoView).toBeCalledWith(opts)
15+
})
16+
17+
it('should called with "true" instead of options for Safari', () => {
18+
const mockScrollIntoView = jest.fn()
19+
const opts: ScrollIntoViewOptions = {
20+
behavior: 'smooth',
21+
inline: 'end',
22+
block: 'nearest',
23+
}
24+
25+
Object.defineProperty(global.document.documentElement, 'style', { value: {} })
26+
const newDiv = document.createElement('div')
27+
newDiv.scrollIntoView = mockScrollIntoView
28+
scrollIntoView(newDiv, opts)
29+
expect(mockScrollIntoView).toBeCalledWith(true)
30+
})
31+
})

0 commit comments

Comments
 (0)