diff --git a/redisinsight/ui/src/pages/browser/components/string-details/StringDetails.tsx b/redisinsight/ui/src/pages/browser/components/string-details/StringDetails.tsx index 4ed8c4b128..5a0b813ef6 100644 --- a/redisinsight/ui/src/pages/browser/components/string-details/StringDetails.tsx +++ b/redisinsight/ui/src/pages/browser/components/string-details/StringDetails.tsx @@ -7,9 +7,11 @@ import React, { useState, } from 'react' import { useDispatch, useSelector } from 'react-redux' -import { EuiText, EuiTextArea } from '@elastic/eui' +import { EuiLoadingSpinner, EuiText, EuiTextArea } from '@elastic/eui' +import { Nullable } from 'uiSrc/utils' import { + resetStringValue, stringDataSelector, stringSelector, updateStringValueAction, @@ -32,7 +34,7 @@ const StringDetails = (props: Props) => { const { isEditItem, setIsEdit } = props const [rows, setRows] = useState(5) - const [value, setValue] = useState('') + const [value, setValue] = useState>(null) const [areaValue, setAreaValue] = useState('') const { loading } = useSelector(stringSelector) @@ -42,14 +44,18 @@ const StringDetails = (props: Props) => { const dispatch = useDispatch() + useEffect(() => () => { + dispatch(resetStringValue()) + }, []) + useEffect(() => { setValue(initialValue) - setAreaValue(initialValue) + setAreaValue(initialValue || '') }, [initialValue]) useEffect(() => { // Approximate calculation of textarea rows by initialValue - if (!isEditItem || !textAreaRef.current) { + if (!isEditItem || !textAreaRef.current || value === null) { return } @@ -78,24 +84,31 @@ const StringDetails = (props: Props) => { } const onDeclineChanges = () => { - setAreaValue(value) + setAreaValue(value || '') setIsEdit(false) } + const isLoading = loading || value === null + return (
- {!isEditItem && !loading && ( + {isLoading && ( +
+ +
+ )} + {!isEditItem && !isLoading && ( setIsEdit(true)} >
-            {value.length ? value : (Empty)}
+            {value !== '' ? value : (Empty)}
           
)} {isEditItem && ( + } +} diff --git a/redisinsight/ui/src/slices/string.ts b/redisinsight/ui/src/slices/string.ts index a40302a6f3..7b4c255cf4 100644 --- a/redisinsight/ui/src/slices/string.ts +++ b/redisinsight/ui/src/slices/string.ts @@ -7,13 +7,14 @@ import { getApiErrorMessage, getUrl, isStatusSuccessful } from 'uiSrc/utils' import { refreshKeyInfoAction } from './keys' import { addErrorNotification } from './app/notifications' import { AppDispatch, RootState } from './store' +import { StringState } from './interfaces/string' -export const initialState = { +export const initialState: StringState = { loading: false, error: '', data: { key: '', - value: '', + value: null, }, } @@ -51,7 +52,7 @@ const stringSlice = createSlice({ }, resetStringValue: (state) => { state.data.key = '' - state.data.value = '' + state.data.value = null }, }, })