Skip to content

Commit cc98e85

Browse files
authored
Merge pull request #1138 from RedisInsight/bugfix/RI-3447_formatter-editor
#RI-3447 - add space for formatter editor buttons, change calculating height behavior
2 parents 0b1c7e8 + 3d25d8b commit cc98e85

File tree

6 files changed

+35
-18
lines changed

6 files changed

+35
-18
lines changed

redisinsight/ui/src/pages/browser/components/hash-details/HashDetails.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import HelpTexts from 'uiSrc/constants/help-texts'
4343
import { KeyTypes, OVER_RENDER_BUFFER_COUNT, TableCellAlignment, TEXT_UNPRINTABLE_CHARACTERS } from 'uiSrc/constants'
4444
import { getColumnWidth } from 'uiSrc/components/virtual-grid'
4545
import { StopPropagation } from 'uiSrc/components/virtual-table'
46-
import { calculateTextareaLines } from 'uiSrc/utils/calculateTextareaLines'
4746
import { stringToBuffer } from 'uiSrc/utils/formatters/bufferFormatters'
4847
import {
4948
GetHashFieldsResponse,
@@ -256,6 +255,13 @@ const HashDetails = (props: Props) => {
256255
}
257256
}
258257

258+
const updateTextAreaHeight = () => {
259+
if (textAreaRef.current) {
260+
textAreaRef.current.style.height = '0px'
261+
textAreaRef.current.style.height = `${textAreaRef.current?.scrollHeight || 0}px`
262+
}
263+
}
264+
259265
const columns: ITableColumn[] = [
260266
{
261267
id: 'field',
@@ -315,9 +321,10 @@ const HashDetails = (props: Props) => {
315321
&& !isEqualBuffers(valueItem, stringToBuffer(value))
316322

317323
setTimeout(() => cellCache.clear(rowIndex, 1), 0)
324+
updateTextAreaHeight()
318325

319326
return (
320-
<AutoSizer disableHeight>
327+
<AutoSizer disableHeight onResize={() => setTimeout(updateTextAreaHeight, 0)}>
321328
{({ width }) => (
322329
<div style={{ width }}>
323330
<StopPropagation>
@@ -342,19 +349,20 @@ const HashDetails = (props: Props) => {
342349
fullWidth
343350
name="value"
344351
id="value"
345-
rows={calculateTextareaLines(areaValue, width + 80)}
346352
resize="none"
347353
placeholder="Enter Value"
348354
value={areaValue}
349355
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => {
350356
cellCache.clearAll()
351357
setAreaValue(e.target.value)
358+
updateTextAreaHeight()
352359
}}
353360
disabled={updateLoading}
354361
inputRef={textAreaRef}
355362
className={cx(styles.textArea, { [styles.areaWarning]: disabled })}
356363
spellCheck={false}
357364
data-testid="hash-value-editor"
365+
style={{ height: textAreaRef.current?.scrollHeight || 0 }}
358366
/>
359367
</InlineItemEditor>
360368
</StopPropagation>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
.textAreaControls {
99
right: -80px !important;
10-
bottom: -2px !important;
10+
bottom: -4px !important;
1111
top: auto !important;
1212
background-color: var(--euiPageBackgroundColor) !important;
1313
}
@@ -17,11 +17,14 @@
1717
border-color: var(--euiColorPrimary) !important;
1818
z-index: 3;
1919
padding-left: 20px;
20+
padding-bottom: 36px !important;
2021
margin: -8px -6px -8px -20px !important;
21-
height: calc(100% + 16px) !important;
2222
min-width: calc(100% + 120px) !important;
2323
font: normal normal normal 13px/18px Graphik, sans-serif;
2424
min-height: 43px;
25+
overflow: hidden;
26+
overflow-wrap: break-word;
27+
resize: none;
2528

2629
&:focus {
2730
background-image: none !important;

redisinsight/ui/src/pages/browser/components/list-details/ListDetails.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import {
4747
SetListElementDto,
4848
SetListElementResponse,
4949
} from 'apiSrc/modules/browser/dto'
50-
import { calculateTextareaLines } from 'uiSrc/utils/calculateTextareaLines'
5150

5251
import styles from './styles.module.scss'
5352

@@ -206,6 +205,13 @@ const ListDetails = (props: Props) => {
206205
cellCache.clearAll()
207206
}
208207

208+
const updateTextAreaHeight = () => {
209+
if (textAreaRef.current) {
210+
textAreaRef.current.style.height = '0px'
211+
textAreaRef.current.style.height = `${textAreaRef.current?.scrollHeight || 0}px`
212+
}
213+
}
214+
209215
const columns: ITableColumn[] = [
210216
{
211217
id: 'index',
@@ -263,7 +269,7 @@ const ListDetails = (props: Props) => {
263269
setTimeout(() => cellCache.clear(rowIndex, 1), 0)
264270

265271
return (
266-
<AutoSizer disableHeight>
272+
<AutoSizer disableHeight onResize={() => setTimeout(updateTextAreaHeight, 0)}>
267273
{({ width }) => (
268274
<div style={{ width }}>
269275
<StopPropagation>
@@ -289,19 +295,20 @@ const ListDetails = (props: Props) => {
289295
fullWidth
290296
name="value"
291297
id="value"
292-
rows={calculateTextareaLines(areaValue, width + 80)}
293298
resize="none"
294299
placeholder="Enter Element"
295300
value={areaValue}
296301
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => {
297302
cellCache.clearAll()
298303
setAreaValue(e.target.value)
304+
updateTextAreaHeight()
299305
}}
300306
disabled={updateLoading}
301307
inputRef={textAreaRef}
302308
className={cx(styles.textArea, { [styles.areaWarning]: disabled })}
303309
spellCheck={false}
304310
data-testid="element-value-editor"
311+
style={{ height: textAreaRef.current?.scrollHeight || 0 }}
305312
/>
306313
</InlineItemEditor>
307314
</div>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
.textAreaControls {
99
right: -56px !important;
10-
bottom: -2px !important;
10+
bottom: -4px !important;
1111
top: auto !important;
1212
background-color: var(--euiPageBackgroundColor) !important;
1313
}
@@ -17,11 +17,14 @@
1717
border-color: var(--euiColorPrimary) !important;
1818
z-index: 3;
1919
padding-left: 20px;
20+
padding-bottom: 36px !important;
2021
margin: -8px -6px -8px -20px !important;
21-
height: calc(100% + 16px) !important;
2222
min-width: calc(100% + 106px) !important;
2323
font: normal normal normal 13px/18px Graphik, sans-serif;
2424
min-height: 43px;
25+
overflow: hidden;
26+
overflow-wrap: break-word;
27+
resize: none;
2528

2629
&:focus {
2730
background-image: none !important;

redisinsight/ui/src/pages/workbench/components/wb-view/WBView/WBView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const WBView = (props: Props) => {
5555
scrollDivRef,
5656
} = props
5757
const [isMinimized, setIsMinimized] = useState<boolean>(
58-
(localStorageService?.get(BrowserStorageItem.isEnablementAreaMinimized) ?? 'false') === 'true'
58+
localStorageService?.get(BrowserStorageItem.isEnablementAreaMinimized) ?? false
5959
)
6060
const [isCodeBtnDisabled, setIsCodeBtnDisabled] = useState<boolean>(false)
6161

redisinsight/ui/src/services/storage.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,13 @@ class StorageService {
1515
} catch (error) {
1616
console.error(`getItem from storage error: ${error}`)
1717
}
18-
const numPatt = new RegExp(/^\d+$/)
19-
const jsonPatt = new RegExp(/[[{].*[}\]]/)
2018

2119
if (item) {
22-
if (jsonPatt.test(item)) {
20+
try {
2321
return JSON.parse(item)
22+
} catch (e) {
23+
return item
2424
}
25-
if (numPatt.test(item)) {
26-
return parseFloat(item)
27-
}
28-
return item
2925
}
3026
return null
3127
}

0 commit comments

Comments
 (0)