Skip to content

Commit eb033f5

Browse files
committed
#RI-5206 - fix button state for editing
#RI-5207 - fix string details heights
1 parent 6752c81 commit eb033f5

File tree

4 files changed

+35
-25
lines changed

4 files changed

+35
-25
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: 8 additions & 13 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
132-
}
133-
if (calculatedRows < MIN_ROWS) {
134-
setRows(MIN_ROWS)
135-
return
128+
if (calculatedRows > MIN_ROWS) {
129+
setRows(calculatedRows)
136130
}
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"
@@ -199,6 +192,7 @@ const StringDetailsTable = (props: Props) => {
199192
)}
200193
{!isEditItem && (
201194
<EuiText
195+
className={styles.stringValue}
202196
onClick={() => isEditable && setIsEdit(true)}
203197
style={{ whiteSpace: 'break-spaces' }}
204198
data-testid="string-value"
@@ -253,6 +247,7 @@ const StringDetailsTable = (props: Props) => {
253247
disabled={loading}
254248
inputRef={textAreaRef}
255249
className={cx(styles.stringTextArea, { [styles.areaWarning]: isDisabled })}
250+
style={{ maxHeight: containerRef.current ? containerRef.current?.clientHeight - 80 : '100%' }}
256251
data-testid="string-value"
257252
/>
258253
</InlineItemEditor>

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

Lines changed: 6 additions & 10 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,6 +25,11 @@ $outer-height-mobile: 340px;
2925
}
3026

3127
.stringValue {
28+
@include euiScrollBar;
29+
overflow-y: auto;
30+
overflow-x: hidden;
31+
word-break: break-word;
32+
3233
font: inherit !important;
3334
color: inherit !important;
3435
padding: 0 !important;
@@ -41,11 +42,6 @@ $outer-height-mobile: 340px;
4142
}
4243

4344
.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-
4945
&.areaWarning {
5046
border-color: var(--euiColorWarningLight) !important;
5147
background-image: none !important;

0 commit comments

Comments
 (0)