Skip to content

Commit 19b24be

Browse files
Merge pull request #246 from RedisInsight/feature/RI-6522_Long_vector_string_is_not_displayed
#RI-6522 - [Regression] Long vector string is not displayed
2 parents 0059123 + 392bf5f commit 19b24be

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

l10n/bundle.l10n.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@
310310
"Privacy": "Privacy",
311311
"To optimize your experience, Redis for VS Code uses third-party tools. All data collected is anonymized and will not be used for any purpose without your consent.": "To optimize your experience, Redis for VS Code uses third-party tools. All data collected is anonymized and will not be used for any purpose without your consent.",
312312
"Analytics": "Analytics",
313+
"Auto refresh:": "Auto refresh:",
314+
"Last refresh:": "Last refresh:",
315+
"Auto Refresh": "Auto Refresh",
313316
"Add": "Add",
314317
"Release Notes": "Release Notes",
315318
"Redis for VS Code extension updated to {0}.": "Redis for VS Code extension updated to {0}."

src/webviews/src/modules/key-details/components/string-details/string-details-value/StringDetailsValue.spec.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import React from 'react'
22
import { instance, mock } from 'ts-mockito'
33

44
import * as utils from 'uiSrc/utils'
5-
import { bufferToString } from 'uiSrc/utils'
5+
import { bufferToASCII, bufferToString } from 'uiSrc/utils'
66
import { downloadFile } from 'uiSrc/utils/dom/downloadFile'
77
import { useSelectedKeyStore } from 'uiSrc/store'
8+
import { KeyValueFormat } from 'uiSrc/constants'
9+
import * as useContext from 'uiSrc/store/hooks/use-context/useContext'
810
import { render, screen, fireEvent, constants, waitForStack } from 'testSrc/helpers'
911
import { StringDetailsValue, Props } from './StringDetailsValue'
1012
import * as useString from '../hooks/useStringStore'
@@ -146,6 +148,25 @@ describe('StringDetailsValue', () => {
146148
expect(screen.getByTestId(STRING_VALUE)).toHaveTextContent(`${bufferToString(constants.KEY_1_VALUE)}...`)
147149
})
148150

151+
it('Should render partValue in the Unicode format', async () => {
152+
useStringStore.setState((state) => ({
153+
...state,
154+
data: { value: constants.VECTOR_32_VALUE_1 },
155+
}))
156+
157+
const useContextInContext = vi.spyOn(useContext, 'useContextInContext')
158+
useContextInContext.mockImplementation(() => KeyValueFormat.Vector32Bit)
159+
160+
render(
161+
<StringDetailsValue
162+
{...instance(mockedProps)}
163+
/>,
164+
)
165+
166+
expect(screen.getByTestId(STRING_VALUE)).toHaveTextContent('@...')
167+
expect(screen.getByTestId(STRING_VALUE)).not.toHaveTextContent('[object Object]')
168+
})
169+
149170
it('Should not add "..." in the end of the full value', async () => {
150171
useStringStore.setState((state) => ({
151172
...state,

src/webviews/src/modules/key-details/components/string-details/string-details-value/StringDetailsValue.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
decompressingBuffer,
2626
} from 'uiSrc/utils'
2727
import {
28+
KeyValueFormat,
2829
TEXT_DISABLED_COMPRESSED_VALUE,
2930
TEXT_FAILED_CONVENT_FORMATTER,
3031
TEXT_INVALID_VALUE,
@@ -89,10 +90,15 @@ const StringDetailsValue = (props: Props) => {
8990
const { value: decompressedValue, isCompressed } = decompressingBuffer(initialValue, compressor)
9091

9192
const initialValueString = bufferToString(decompressedValue, viewFormat)
92-
const { value: formattedValue, isValid } = formattingBuffer(decompressedValue, viewFormatProp, { expanded: true })
93+
const fullStringLoaded = isFullStringLoaded(initialValue?.data?.length, length)
94+
const { value: formattedValue, isValid } = formattingBuffer(
95+
decompressedValue,
96+
fullStringLoaded ? viewFormatProp : KeyValueFormat.Unicode,
97+
{ expanded: true },
98+
)
9399
setAreaValue(initialValueString)
94100

95-
setValue(!isFullStringLoaded(initialValue?.data?.length, length) ? `${formattedValue}...` : formattedValue)
101+
setValue(!fullStringLoaded ? `${formattedValue}...` : formattedValue)
96102
setIsValid(isValid)
97103
setIsDisabled(
98104
!isNonUnicodeFormatter(viewFormatProp, isValid)
@@ -101,7 +107,7 @@ const StringDetailsValue = (props: Props) => {
101107
setIsEditable(
102108
!isCompressed
103109
&& isFormatEditable(viewFormatProp)
104-
&& isFullStringLoaded(initialValue?.data?.length, length),
110+
&& fullStringLoaded,
105111
)
106112
setNoEditableText(isCompressed ? TEXT_DISABLED_COMPRESSED_VALUE : TEXT_FAILED_CONVENT_FORMATTER(viewFormatProp))
107113

src/webviews/src/utils/formatters/bufferFormatters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const bufferToASCII = (reply: RedisString): string => {
9595
return result
9696
}
9797

98-
const anyToBuffer = (reply: UintArray): RedisString =>
98+
const anyToBuffer = (reply: UintArray | ArrayBuffer): RedisString =>
9999
({ data: reply, type: RedisResponseBufferType.Buffer }) as RedisString
100100

101101
const ASCIIToBuffer = (strInit: string) => {

src/webviews/test/helpers/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { v4 as uuidv4 } from 'uuid'
22
import { DEFAULT_ERROR_MESSAGE, DEFAULT_SEARCH_MATCH, KeyTypes, VscodeMessageAction } from 'uiSrc/constants'
33
import { CliAction, KeyInfo, SelectKeyAction } from 'uiSrc/interfaces'
44
import { Certificate } from 'uiSrc/store/hooks/use-certificates-store/interface'
5-
import { UTF8ToArray, stringToBuffer } from 'uiSrc/utils'
5+
import { UTF8ToArray, anyToBuffer, stringToBuffer } from 'uiSrc/utils'
66
import { Database } from 'uiSrc/store'
77
import { SuperSelectOption } from 'uiSrc/components'
88

@@ -122,6 +122,8 @@ export const constants = {
122122
KEY_5_MEMBER_2: UTF8ToArray('member2'),
123123
KEY_5_MEMBER_3: UTF8ToArray('member3'),
124124

125+
VECTOR_32_VALUE_1: anyToBuffer(new Float32Array([2.0, 2.0, 2.0]).buffer),
126+
125127
get LIST_DATA_RESPONSE() {
126128
return LIST_DATA_RESPONSE
127129
},

0 commit comments

Comments
 (0)