fix: disable type filter when redis server below 5.x (#274)

This commit is contained in:
Lykin 2024-07-01 17:28:35 +08:00
parent e2093a89bf
commit ea44253c02
6 changed files with 56 additions and 9 deletions

View File

@ -23,6 +23,7 @@ import (
"tinyrdm/backend/types" "tinyrdm/backend/types"
"tinyrdm/backend/utils/coll" "tinyrdm/backend/utils/coll"
convutil "tinyrdm/backend/utils/convert" convutil "tinyrdm/backend/utils/convert"
maputil "tinyrdm/backend/utils/map"
redis2 "tinyrdm/backend/utils/redis" redis2 "tinyrdm/backend/utils/redis"
sliceutil "tinyrdm/backend/utils/slice" sliceutil "tinyrdm/backend/utils/slice"
strutil "tinyrdm/backend/utils/string" strutil "tinyrdm/backend/utils/string"
@ -222,11 +223,20 @@ func (b *browserService) OpenConnection(name string) (resp types.JSResp) {
} }
} }
// get redis server version
var version string
if res, err := client.Info(ctx, "server").Result(); err == nil || errors.Is(err, redis.Nil) {
info := b.parseInfo(res)
serverInfo := maputil.Get(info, "Server", map[string]string{})
version = maputil.Get(serverInfo, "redis_version", "1.0.0")
}
resp.Success = true resp.Success = true
resp.Data = map[string]any{ resp.Data = map[string]any{
"db": dbs, "db": dbs,
"view": selConn.KeyView, "view": selConn.KeyView,
"lastDB": selConn.LastDB, "lastDB": selConn.LastDB,
"version": version,
} }
return return
} }

View File

@ -14,6 +14,10 @@ const props = defineProps({
type: String, type: String,
default: 'bottom-start', default: 'bottom-start',
}, },
disabled: {
type: Boolean,
default: false,
},
}) })
const emit = defineEmits(['update:value', 'select']) const emit = defineEmits(['update:value', 'select'])
@ -83,6 +87,7 @@ const handleSelect = (select) => {
<template> <template>
<n-dropdown <n-dropdown
:disabled="props.disabled"
:options="options" :options="options"
:placement="props.placement" :placement="props.placement"
:render-icon="renderIcon" :render-icon="renderIcon"
@ -92,6 +97,7 @@ const handleSelect = (select) => {
<n-tag <n-tag
:bordered="true" :bordered="true"
:color="{ color: backgroundColor, textColor: fontColor }" :color="{ color: backgroundColor, textColor: fontColor }"
:disabled="props.disabled"
class="redis-tag" class="redis-tag"
size="medium" size="medium"
strong> strong>

View File

@ -27,6 +27,7 @@ import { ConnectionType } from '@/consts/connection_type.js'
import Import from '@/components/icons/Import.vue' import Import from '@/components/icons/Import.vue'
import Checkbox from '@/components/icons/Checkbox.vue' import Checkbox from '@/components/icons/Checkbox.vue'
import Timer from '@/components/icons/Timer.vue' import Timer from '@/components/icons/Timer.vue'
import { toVersionArray } from '@/utils/version.js'
const props = defineProps({ const props = defineProps({
server: String, server: String,
@ -78,6 +79,12 @@ const dbSelectOptions = computed(() => {
}) })
}) })
const showTypeFilter = computed(() => {
const version = browserStore.getServerVersion(props.server)
const verArr = toVersionArray(version)
return verArr[0] > 5
})
const moreOptions = [ const moreOptions = [
{ key: 'import', label: 'interface.import_key', icon: Import }, { key: 'import', label: 'interface.import_key', icon: Import },
{ key: 'divider1', type: 'divider' }, { key: 'divider1', type: 'divider' },
@ -301,7 +308,10 @@ watch(
@filter-changed="onFilterInput" @filter-changed="onFilterInput"
@match-changed="onMatchInput"> @match-changed="onMatchInput">
<template #prepend> <template #prepend>
<redis-type-selector v-model:value="filterForm.type" @update:value="onSelectFilterType" /> <redis-type-selector
v-model:value="filterForm.type"
:disabled="!showTypeFilter"
@update:value="onSelectFilterType" />
</template> </template>
</content-search-input> </content-search-input>
<n-button-group> <n-button-group>

View File

@ -28,6 +28,7 @@ export class RedisServerState {
* @param {LoadingState} loadingState all loading state in opened connections map by server and LoadingState * @param {LoadingState} loadingState all loading state in opened connections map by server and LoadingState
* @param {KeyViewType} viewType view type selection for all opened connections group by 'server' * @param {KeyViewType} viewType view type selection for all opened connections group by 'server'
* @param {Map<string, RedisNodeItem>} nodeMap map nodes by "type#key" * @param {Map<string, RedisNodeItem>} nodeMap map nodes by "type#key"
* @param {string} version redis server version
*/ */
constructor({ constructor({
name, name,
@ -40,6 +41,7 @@ export class RedisServerState {
loadingState = {}, loadingState = {},
viewType = KeyViewType.Tree, viewType = KeyViewType.Tree,
nodeMap = new Map(), nodeMap = new Map(),
version = '',
}) { }) {
this.name = name this.name = name
this.db = db this.db = db
@ -52,6 +54,7 @@ export class RedisServerState {
this.loadingState = loadingState this.loadingState = loadingState
this.viewType = viewType this.viewType = viewType
this.nodeMap = nodeMap this.nodeMap = nodeMap
this.version = version
this.decodeHistory = new Map() this.decodeHistory = new Map()
this.decodeHistoryLimit = 100 this.decodeHistoryLimit = 100
this.getRoot() this.getRoot()

View File

@ -111,7 +111,7 @@ const useBrowserStore = defineStore('browser', {
/** /**
* get database info list * get database info list
* @param server * @param {string} server
* @return {RedisDatabaseItem[]} * @return {RedisDatabaseItem[]}
*/ */
getDBList(server) { getDBList(server) {
@ -122,6 +122,18 @@ const useBrowserStore = defineStore('browser', {
return [] return []
}, },
/**
* get server version
* @param {string} server
*/
getServerVersion(server) {
const serverInst = this.servers[server]
if (serverInst != null) {
return serverInst.version
}
return '1.0.0'
},
/** /**
* get database by server name and database index * get database by server name and database index
* @param {string} server * @param {string} server
@ -240,7 +252,7 @@ const useBrowserStore = defineStore('browser', {
// if (connNode == null) { // if (connNode == null) {
// throw new Error('no such connection') // throw new Error('no such connection')
// } // }
const { db, view = KeyViewType.Tree, lastDB } = data const { db, view = KeyViewType.Tree, lastDB, version } = data
if (isEmpty(db)) { if (isEmpty(db)) {
throw new Error('no db loaded') throw new Error('no db loaded')
} }
@ -249,6 +261,7 @@ const useBrowserStore = defineStore('browser', {
separator: this.getSeparator(name), separator: this.getSeparator(name),
db: -1, db: -1,
viewType: view, viewType: view,
version,
}) })
/** @type {Object.<number,RedisDatabaseItem>} **/ /** @type {Object.<number,RedisDatabaseItem>} **/
const databases = {} const databases = {}

View File

@ -1,6 +1,11 @@
import { get, isEmpty, map, size, split, trimStart } from 'lodash' import { get, isEmpty, map, size, split, trimStart } from 'lodash'
const toVerArr = (ver) => { /**
* convert version string to number array
* @param ver
* @return {number[]}
*/
export const toVersionArray = (ver) => {
const v = trimStart(ver, 'v') const v = trimStart(ver, 'v')
let vParts = split(v, '.') let vParts = split(v, '.')
if (isEmpty(vParts)) { if (isEmpty(vParts)) {
@ -20,8 +25,8 @@ const toVerArr = (ver) => {
*/ */
export const compareVersion = (v1, v2) => { export const compareVersion = (v1, v2) => {
if (v1 !== v2) { if (v1 !== v2) {
const v1Nums = toVerArr(v1) const v1Nums = toVersionArray(v1)
const v2Nums = toVerArr(v2) const v2Nums = toVersionArray(v2)
const length = Math.max(size(v1Nums), size(v2Nums)) const length = Math.max(size(v1Nums), size(v2Nums))
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {