Skip to content

Commit 188be27

Browse files
authored
Merge pull request #17 from RedisInsight/feature/RI-2051-string-loading
#RI-2051 - add spinner for loading string value
2 parents e16cf81 + 02204fc commit 188be27

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

redisinsight/ui/src/pages/browser/components/string-details/StringDetails.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import React, {
77
useState,
88
} from 'react'
99
import { useDispatch, useSelector } from 'react-redux'
10-
import { EuiText, EuiTextArea } from '@elastic/eui'
10+
import { EuiLoadingSpinner, EuiText, EuiTextArea } from '@elastic/eui'
1111

12+
import { Nullable } from 'uiSrc/utils'
1213
import {
14+
resetStringValue,
1315
stringDataSelector,
1416
stringSelector,
1517
updateStringValueAction,
@@ -32,7 +34,7 @@ const StringDetails = (props: Props) => {
3234
const { isEditItem, setIsEdit } = props
3335

3436
const [rows, setRows] = useState<number>(5)
35-
const [value, setValue] = useState<string>('')
37+
const [value, setValue] = useState<Nullable<string>>(null)
3638
const [areaValue, setAreaValue] = useState<string>('')
3739

3840
const { loading } = useSelector(stringSelector)
@@ -42,14 +44,18 @@ const StringDetails = (props: Props) => {
4244

4345
const dispatch = useDispatch()
4446

47+
useEffect(() => () => {
48+
dispatch(resetStringValue())
49+
}, [])
50+
4551
useEffect(() => {
4652
setValue(initialValue)
47-
setAreaValue(initialValue)
53+
setAreaValue(initialValue || '')
4854
}, [initialValue])
4955

5056
useEffect(() => {
5157
// Approximate calculation of textarea rows by initialValue
52-
if (!isEditItem || !textAreaRef.current) {
58+
if (!isEditItem || !textAreaRef.current || value === null) {
5359
return
5460
}
5561

@@ -78,24 +84,31 @@ const StringDetails = (props: Props) => {
7884
}
7985

8086
const onDeclineChanges = () => {
81-
setAreaValue(value)
87+
setAreaValue(value || '')
8288
setIsEdit(false)
8389
}
8490

91+
const isLoading = loading || value === null
92+
8593
return (
8694
<div className={styles.container}>
87-
{!isEditItem && !loading && (
95+
{isLoading && (
96+
<div className={styles.spinnerWrapper}>
97+
<EuiLoadingSpinner size="xl" />
98+
</div>
99+
)}
100+
{!isEditItem && !isLoading && (
88101
<EuiText
89102
onClick={() => setIsEdit(true)}
90103
>
91104
<pre className={styles.stringValue} data-testid="string-value">
92-
{value.length ? value : (<span style={{ fontStyle: 'italic' }}>Empty</span>)}
105+
{value !== '' ? value : (<span style={{ fontStyle: 'italic' }}>Empty</span>)}
93106
</pre>
94107
</EuiText>
95108
)}
96109
{isEditItem && (
97110
<InlineItemEditor
98-
initialValue={value}
111+
initialValue={value || ''}
99112
controlsPosition="bottom"
100113
placeholder="Enter Value"
101114
fieldName="value"

redisinsight/ui/src/pages/browser/components/string-details/styles.module.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ $outer-height-mobile: 340px;
3434
background: inherit !important;
3535
}
3636

37+
.spinnerWrapper {
38+
width: 100%;
39+
height: 100%;
40+
display: flex;
41+
align-items: center;
42+
justify-content: center;
43+
}
44+
3745
.stringTextArea {
3846
max-height: calc(100vh - #{$outer-height} - 55px);
3947
@media only screen and (max-width: 767px) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Nullable } from 'uiSrc/utils'
2+
3+
export interface StringState {
4+
loading: boolean
5+
error: string
6+
data: {
7+
key: string
8+
value: Nullable<string>
9+
}
10+
}

redisinsight/ui/src/slices/string.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { getApiErrorMessage, getUrl, isStatusSuccessful } from 'uiSrc/utils'
77
import { refreshKeyInfoAction } from './keys'
88
import { addErrorNotification } from './app/notifications'
99
import { AppDispatch, RootState } from './store'
10+
import { StringState } from './interfaces/string'
1011

11-
export const initialState = {
12+
export const initialState: StringState = {
1213
loading: false,
1314
error: '',
1415
data: {
1516
key: '',
16-
value: '',
17+
value: null,
1718
},
1819
}
1920

@@ -51,7 +52,7 @@ const stringSlice = createSlice({
5152
},
5253
resetStringValue: (state) => {
5354
state.data.key = ''
54-
state.data.value = ''
55+
state.data.value = null
5556
},
5657
},
5758
})

0 commit comments

Comments
 (0)