From 1c322fdac5eaec3e3eb8dd6a315914236fa6c912 Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:19:30 +0800 Subject: [PATCH] pref: correct display raw value for list/set/zset --- backend/services/browser_service.go | 10 +++++----- backend/types/redis_wrapper.go | 2 +- .../components/content_value/ContentValueList.vue | 14 +++++++------- .../components/content_value/ContentValueSet.vue | 14 +++++++------- .../components/content_value/ContentValueZSet.vue | 14 +++++++------- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/backend/services/browser_service.go b/backend/services/browser_service.go index 50508c6..fa4a5ab 100644 --- a/backend/services/browser_service.go +++ b/backend/services/browser_service.go @@ -877,7 +877,7 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS } items = append(items, types.ListEntryItem{ Index: len(items), - Value: val, + Value: strutil.EncodeRedisKey(val), }) if doConvert { if dv, _, _ := convutil.ConvertTo(val, param.Decode, param.Format, decoder); dv != val { @@ -994,7 +994,7 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS } for _, val := range loadedKey { items = append(items, types.SetEntryItem{ - Value: val, + Value: strutil.EncodeRedisKey(val), }) if doConvert { if dv, _, _ := convutil.ConvertTo(val, param.Decode, param.Format, decoder); dv != val { @@ -1015,7 +1015,7 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS loadedKey, cursor, subErr = client.SScan(ctx, key, cursor, matchPattern, scanSize).Result() items = make([]types.SetEntryItem, len(loadedKey)) for i, val := range loadedKey { - items[i].Value = val + items[i].Value = strutil.EncodeRedisKey(val) if doConvert { if dv, _, _ := convutil.ConvertTo(val, param.Decode, param.Format, decoder); dv != val { items[i].DisplayValue = dv @@ -1061,7 +1061,7 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS for i := 0; i < len(loadedVal); i += 2 { if score, err = strconv.ParseFloat(loadedVal[i+1], 64); err == nil { items = append(items, types.ZSetEntryItem{ - Value: loadedVal[i], + Value: strutil.EncodeRedisKey(loadedVal[i]), Score: score, }) if doConvert { @@ -1095,7 +1095,7 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS continue } entry := types.ZSetEntryItem{ - Value: val, + Value: strutil.EncodeRedisKey(val), } if math.IsInf(z.Score, 1) { entry.ScoreStr = "+inf" diff --git a/backend/types/redis_wrapper.go b/backend/types/redis_wrapper.go index 102fd81..697e704 100644 --- a/backend/types/redis_wrapper.go +++ b/backend/types/redis_wrapper.go @@ -33,7 +33,7 @@ type SetEntryItem struct { type ZSetEntryItem struct { Score float64 `json:"s"` ScoreStr string `json:"ss,omitempty"` - Value string `json:"v"` + Value any `json:"v"` DisplayValue string `json:"dv,omitempty"` } diff --git a/frontend/src/components/content_value/ContentValueList.vue b/frontend/src/components/content_value/ContentValueList.vue index c4a96c1..7c8cc43 100644 --- a/frontend/src/components/content_value/ContentValueList.vue +++ b/frontend/src/components/content_value/ContentValueList.vue @@ -22,6 +22,7 @@ import { TextAlignType } from '@/consts/text_align_type.js' import AlignLeft from '@/components/icons/AlignLeft.vue' import AlignCenter from '@/components/icons/AlignCenter.vue' import SwitchButton from '@/components/common/SwitchButton.vue' +import { nativeRedisKey } from '@/utils/key_convert.js' const i18n = useI18n() const themeVars = useThemeVars() @@ -105,17 +106,16 @@ const valueColumn = computed(() => ({ }, filterOptionValue: valueFilterOption.value, className: inEdit.value ? 'clickable' : '', - filter: (value, row) => { - if (row.dv) { - return !!~row.dv.indexOf(value.toString()) - } - return !!~row.v.indexOf(value.toString()) + filter: (filterValue, row) => { + const val = row.dv || nativeRedisKey(row.v) + return !!~val.indexOf(filterValue.toString()) }, render: (row) => { + const val = row.dv || nativeRedisKey(row.v) if (isCode.value) { - return h('pre', { class: 'pre-wrap' }, row.dv || row.v) + return h('pre', { class: 'pre-wrap' }, val) } - return row.dv || row.v + return val }, })) diff --git a/frontend/src/components/content_value/ContentValueSet.vue b/frontend/src/components/content_value/ContentValueSet.vue index c480163..561ba77 100644 --- a/frontend/src/components/content_value/ContentValueSet.vue +++ b/frontend/src/components/content_value/ContentValueSet.vue @@ -22,6 +22,7 @@ import AlignLeft from '@/components/icons/AlignLeft.vue' import AlignCenter from '@/components/icons/AlignCenter.vue' import SwitchButton from '@/components/common/SwitchButton.vue' import { TextAlignType } from '@/consts/text_align_type.js' +import { nativeRedisKey } from '@/utils/key_convert.js' const i18n = useI18n() const themeVars = useThemeVars() @@ -104,17 +105,16 @@ const valueColumn = computed(() => ({ }, filterOptionValue: valueFilterOption.value, className: inEdit.value ? 'clickable' : '', - filter: (value, row) => { - if (row.dv) { - return !!~row.dv.indexOf(value.toString()) - } - return !!~row.v.indexOf(value.toString()) + filter: (filterValue, row) => { + const val = row.dv || nativeRedisKey(row.v) + return !!~val.indexOf(filterValue.toString()) }, render: (row) => { + const val = row.dv || nativeRedisKey(row.v) if (isCode.value) { - return h('pre', { class: 'pre-wrap' }, row.dv || row.v) + return h('pre', { class: 'pre-wrap' }, val) } - return row.dv || row.v + return val }, })) diff --git a/frontend/src/components/content_value/ContentValueZSet.vue b/frontend/src/components/content_value/ContentValueZSet.vue index 431c998..28ace88 100644 --- a/frontend/src/components/content_value/ContentValueZSet.vue +++ b/frontend/src/components/content_value/ContentValueZSet.vue @@ -22,6 +22,7 @@ import { TextAlignType } from '@/consts/text_align_type.js' import AlignLeft from '@/components/icons/AlignLeft.vue' import AlignCenter from '@/components/icons/AlignCenter.vue' import SwitchButton from '@/components/common/SwitchButton.vue' +import { nativeRedisKey } from '@/utils/key_convert.js' const i18n = useI18n() const themeVars = useThemeVars() @@ -153,18 +154,17 @@ const valueColumn = computed(() => ({ }, filterOptionValue: valueFilterOption.value, className: inEdit.value ? 'clickable' : '', - filter(value, row) { - if (row.dv) { - return !!~row.dv.indexOf(value.toString()) - } - return !!~row.v.indexOf(value.toString()) + filter(filterValue, row) { + const val = row.dv || nativeRedisKey(row.v) + return !!~val.indexOf(filterValue.toString()) }, // sorter: (row1, row2) => row1.value - row2.value, render: (row) => { + const val = row.dv || nativeRedisKey(row.v) if (isCode.value) { - return h('pre', { class: 'pre-wrap' }, row.dv || row.v) + return h('pre', { class: 'pre-wrap' }, val) } - return row.dv || row.v + return val }, }))