Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,7 +34,7 @@ const StringDetails = (props: Props) => {
const { isEditItem, setIsEdit } = props

const [rows, setRows] = useState<number>(5)
const [value, setValue] = useState<string>('')
const [value, setValue] = useState<Nullable<string>>(null)
const [areaValue, setAreaValue] = useState<string>('')

const { loading } = useSelector(stringSelector)
Expand All @@ -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
}

Expand Down Expand Up @@ -78,24 +84,31 @@ const StringDetails = (props: Props) => {
}

const onDeclineChanges = () => {
setAreaValue(value)
setAreaValue(value || '')
setIsEdit(false)
}

const isLoading = loading || value === null

return (
<div className={styles.container}>
{!isEditItem && !loading && (
{isLoading && (
<div className={styles.spinnerWrapper}>
<EuiLoadingSpinner size="xl" />
</div>
)}
{!isEditItem && !isLoading && (
<EuiText
onClick={() => setIsEdit(true)}
>
<pre className={styles.stringValue} data-testid="string-value">
{value.length ? value : (<span style={{ fontStyle: 'italic' }}>Empty</span>)}
{value !== '' ? value : (<span style={{ fontStyle: 'italic' }}>Empty</span>)}
</pre>
</EuiText>
)}
{isEditItem && (
<InlineItemEditor
initialValue={value}
initialValue={value || ''}
controlsPosition="bottom"
placeholder="Enter Value"
fieldName="value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ $outer-height-mobile: 340px;
background: inherit !important;
}

.spinnerWrapper {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

.stringTextArea {
max-height: calc(100vh - #{$outer-height} - 55px);
@media only screen and (max-width: 767px) {
Expand Down
10 changes: 10 additions & 0 deletions redisinsight/ui/src/slices/interfaces/string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Nullable } from 'uiSrc/utils'

export interface StringState {
loading: boolean
error: string
data: {
key: string
value: Nullable<string>
}
}
7 changes: 4 additions & 3 deletions redisinsight/ui/src/slices/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -51,7 +52,7 @@ const stringSlice = createSlice({
},
resetStringValue: (state) => {
state.data.key = ''
state.data.value = ''
state.data.value = null
},
},
})
Expand Down