Skip to content

Commit 322d6db

Browse files
authored
Merge pull request #2820 from RedisInsight/fe/bugfix/regression_2.38
#RI-5206 - fix button state for editing
2 parents 8b9b140 + c90a784 commit 322d6db

File tree

4 files changed

+58
-48
lines changed

4 files changed

+58
-48
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import { instance, mock } from 'ts-mockito'
33
import { render, screen } from 'uiSrc/utils/test-utils'
4-
import { stringDataSelector } from 'uiSrc/slices/browser/string'
4+
import { stringDataSelector, stringSelector } from 'uiSrc/slices/browser/string'
55
import { Props, StringDetails } from './StringDetails'
66

77
const mockedProps = mock<Props>()
@@ -15,6 +15,9 @@ jest.mock('uiSrc/slices/browser/string', () => ({
1515
data: [49, 50, 51, 52],
1616
}
1717
}),
18+
stringSelector: jest.fn().mockReturnValue({
19+
isCompressed: false
20+
})
1821
}))
1922

2023
jest.mock('uiSrc/slices/browser/keys', () => ({
@@ -64,6 +67,22 @@ describe('StringDetails', () => {
6467
expect(editValueBtn).toHaveProperty('disabled', true)
6568
})
6669

70+
it('should not be able to change value (compressed)', () => {
71+
const stringSelectorMock = jest.fn().mockReturnValue({
72+
isCompressed: true
73+
})
74+
stringSelector.mockImplementation(stringSelectorMock)
75+
76+
render(
77+
<StringDetails
78+
{...mockedProps}
79+
/>
80+
)
81+
82+
const editValueBtn = screen.getByTestId(`${EDIT_VALUE_BTN_TEST_ID}`)
83+
expect(editValueBtn).toHaveProperty('disabled', true)
84+
})
85+
6786
it('"edit-key-value-btn" should render', () => {
6887
const { queryByTestId } = render(<StringDetails {...instance(mockedProps)} />)
6988
expect(queryByTestId('edit-key-value-btn')).toBeInTheDocument()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const StringDetails = (props: Props) => {
5656
<EditItemAction
5757
title="Edit Value"
5858
tooltipContent={editToolTip}
59-
isEditable={isStringEditable}
59+
isEditable={isStringEditable && isEditable}
6060
onEditItem={() => setEditItem(!editItem)}
6161
/>
6262
)

redisinsight/ui/src/pages/browser/modules/key-details/components/string-details/string-details-table/StringDetailsTable.tsx

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ import { IFetchKeyArgs } from 'uiSrc/constants/prop-types/keys'
5151

5252
import styles from './styles.module.scss'
5353

54-
const MAX_ROWS = 25
55-
const MIN_ROWS = 4
54+
const MIN_ROWS = 8
5655
const APPROXIMATE_WIDTH_OF_SIGN = 8.6
5756
const MAX_LENGTH = STRING_MAX_LENGTH + 1
5857

@@ -72,7 +71,7 @@ const StringDetailsTable = (props: Props) => {
7271
const { name: key, type: keyType, length } = useSelector(selectedKeyDataSelector) ?? { name: '' }
7372
const { viewFormat: viewFormatProp } = useSelector(selectedKeySelector)
7473

75-
const [rows, setRows] = useState<number>(5)
74+
const [rows, setRows] = useState<number>(MIN_ROWS)
7675
const [value, setValue] = useState<JSX.Element | string>('')
7776
const [areaValue, setAreaValue] = useState<string>('')
7877
const [viewFormat, setViewFormat] = useState(viewFormatProp)
@@ -83,6 +82,7 @@ const StringDetailsTable = (props: Props) => {
8382

8483
const textAreaRef: Ref<HTMLTextAreaElement> = useRef(null)
8584
const viewValueRef: Ref<HTMLPreElement> = useRef(null)
85+
const containerRef: Ref<HTMLDivElement> = useRef(null)
8686

8787
const dispatch = useDispatch()
8888

@@ -125,16 +125,9 @@ const StringDetailsTable = (props: Props) => {
125125
return
126126
}
127127
const calculatedRows = calculateTextareaLines(areaValue, textAreaRef.current.clientWidth, APPROXIMATE_WIDTH_OF_SIGN)
128-
129-
if (calculatedRows > MAX_ROWS) {
130-
setRows(MAX_ROWS)
131-
return
128+
if (calculatedRows > MIN_ROWS) {
129+
setRows(calculatedRows)
132130
}
133-
if (calculatedRows < MIN_ROWS) {
134-
setRows(MIN_ROWS)
135-
return
136-
}
137-
setRows(calculatedRows)
138131
}, [viewValueRef, isEditItem])
139132

140133
useMemo(() => {
@@ -188,7 +181,7 @@ const StringDetailsTable = (props: Props) => {
188181

189182
return (
190183
<>
191-
<div className={styles.container} data-testid="string-details">
184+
<div className={styles.container} ref={containerRef} data-testid="string-details">
192185
{isLoading && (
193186
<EuiProgress
194187
color="primary"
@@ -198,27 +191,24 @@ const StringDetailsTable = (props: Props) => {
198191
/>
199192
)}
200193
{!isEditItem && (
201-
<EuiText
202-
onClick={() => isEditable && setIsEdit(true)}
203-
style={{ whiteSpace: 'break-spaces' }}
204-
data-testid="string-value"
194+
<EuiToolTip
195+
title={!isValid ? noEditableText : undefined}
196+
anchorClassName={styles.tooltipAnchor}
197+
className={styles.tooltip}
198+
position="left"
199+
data-testid="string-value-tooltip"
205200
>
206-
{areaValue !== ''
207-
? (isValid
201+
<EuiText
202+
className={styles.stringValue}
203+
onClick={() => isEditable && setIsEdit(true)}
204+
style={{ whiteSpace: 'break-spaces' }}
205+
data-testid="string-value"
206+
>
207+
{areaValue !== ''
208208
? value
209-
: (
210-
<EuiToolTip
211-
title={noEditableText}
212-
className={styles.tooltip}
213-
position="bottom"
214-
data-testid="string-value-tooltip"
215-
>
216-
<>{value}</>
217-
</EuiToolTip>
218-
)
219-
)
220-
: (!isLoading && (<span style={{ fontStyle: 'italic' }}>Empty</span>))}
221-
</EuiText>
209+
: (!isLoading && (<span style={{ fontStyle: 'italic' }}>Empty</span>))}
210+
</EuiText>
211+
</EuiToolTip>
222212
)}
223213
{isEditItem && (
224214
<InlineItemEditor
@@ -253,6 +243,7 @@ const StringDetailsTable = (props: Props) => {
253243
disabled={loading}
254244
inputRef={textAreaRef}
255245
className={cx(styles.stringTextArea, { [styles.areaWarning]: isDisabled })}
246+
style={{ maxHeight: containerRef.current ? containerRef.current?.clientHeight - 80 : '100%' }}
256247
data-testid="string-value"
257248
/>
258249
</InlineItemEditor>

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ $outer-height: 220px;
66
$outer-height-mobile: 340px;
77

88
.container {
9-
@include euiScrollBar;
109
padding: 20px 16px 20px;
11-
1210
max-height: calc(100vh - #{$outer-height});
13-
overflow-y: auto;
14-
overflow-x: hidden;
15-
word-break: break-word;
1611

12+
overflow: hidden;
1713
color: var(--euiTextSubduedColor);
1814
flex: 1;
1915
position: relative;
@@ -29,10 +25,12 @@ $outer-height-mobile: 340px;
2925
}
3026

3127
.stringValue {
32-
font: inherit !important;
33-
color: inherit !important;
34-
padding: 0 !important;
35-
background: inherit !important;
28+
@include euiScrollBar;
29+
overflow-y: auto;
30+
overflow-x: hidden;
31+
word-break: break-word;
32+
line-height: 1.2;
33+
width: 100%;
3634

3735
pre {
3836
background-color: transparent !important;
@@ -41,17 +39,19 @@ $outer-height-mobile: 340px;
4139
}
4240

4341
.stringTextArea {
44-
max-height: calc(100vh - #{$outer-height} - 55px);
45-
@media only screen and (max-width: 767px) {
46-
max-height: calc(100vh - #{$outer-height-mobile} - 55px);
47-
}
48-
4942
&.areaWarning {
5043
border-color: var(--euiColorWarningLight) !important;
5144
background-image: none !important;
5245
}
5346
}
5447

48+
.tooltipAnchor {
49+
display: inline-flex !important;
50+
height: auto;
51+
max-height: 100%;
52+
width: 100%;
53+
}
54+
5555
.stringFooterBtn {
5656
&:global(.euiButton) {
5757
color: var(--euiTextSubduedColor) !important;

0 commit comments

Comments
 (0)