feat: add full search for hash

This commit is contained in:
Lykin 2023-11-20 18:38:23 +08:00
parent db4e2385fc
commit eca640fc87
4 changed files with 31 additions and 70 deletions

View File

@ -692,6 +692,12 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS
} }
case "hash": case "hash":
if !strings.HasPrefix(matchPattern, "*") {
matchPattern = "*" + matchPattern
}
if !strings.HasSuffix(matchPattern, "*") {
matchPattern = matchPattern + "*"
}
loadHashHandle := func() ([]types.HashEntryItem, bool, bool, error) { loadHashHandle := func() ([]types.HashEntryItem, bool, bool, error) {
var items []types.HashEntryItem var items []types.HashEntryItem
var loadedVal []string var loadedVal []string
@ -699,11 +705,11 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS
var reset bool var reset bool
var subErr error var subErr error
scanSize := int64(Preferences().GetScanSize()) scanSize := int64(Preferences().GetScanSize())
if param.Full { if param.Full || matchPattern != "*" {
// load all // load all
cursor, reset = 0, true cursor, reset = 0, true
for { for {
loadedVal, cursor, subErr = client.HScan(ctx, key, cursor, "*", scanSize).Result() loadedVal, cursor, subErr = client.HScan(ctx, key, cursor, matchPattern, scanSize).Result()
if subErr != nil { if subErr != nil {
return nil, reset, false, subErr return nil, reset, false, subErr
} }

View File

@ -3,8 +3,6 @@ import { computed, reactive } from 'vue'
import { isEmpty, trim } from 'lodash' import { isEmpty, trim } from 'lodash'
import { NButton, NInput } from 'naive-ui' import { NButton, NInput } from 'naive-ui'
const props = defineProps({})
const emit = defineEmits(['filterChanged', 'matchChanged']) const emit = defineEmits(['filterChanged', 'matchChanged'])
/** /**

View File

@ -3,7 +3,7 @@ import { computed, h, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import ContentToolbar from './ContentToolbar.vue' import ContentToolbar from './ContentToolbar.vue'
import AddLink from '@/components/icons/AddLink.vue' import AddLink from '@/components/icons/AddLink.vue'
import { NButton, NCode, NIcon, NInput, useThemeVars } from 'naive-ui' import { NButton, NCode, NIcon, useThemeVars } from 'naive-ui'
import { types, types as redisTypes } from '@/consts/support_redis_type.js' import { types, types as redisTypes } from '@/consts/support_redis_type.js'
import EditableTableColumn from '@/components/common/EditableTableColumn.vue' import EditableTableColumn from '@/components/common/EditableTableColumn.vue'
import useDialogStore from 'stores/dialog.js' import useDialogStore from 'stores/dialog.js'
@ -18,6 +18,7 @@ import ContentEntryEditor from '@/components/content_value/ContentEntryEditor.vu
import Edit from '@/components/icons/Edit.vue' import Edit from '@/components/icons/Edit.vue'
import FormatSelector from '@/components/content_value/FormatSelector.vue' import FormatSelector from '@/components/content_value/FormatSelector.vue'
import { decodeRedisKey } from '@/utils/key_convert.js' import { decodeRedisKey } from '@/utils/key_convert.js'
import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue'
const i18n = useI18n() const i18n = useI18n()
const themeVars = useThemeVars() const themeVars = useThemeVars()
@ -52,7 +53,7 @@ const props = defineProps({
loading: Boolean, loading: Boolean,
}) })
const emit = defineEmits(['loadmore', 'loadall', 'reload', 'rename', 'delete']) const emit = defineEmits(['loadmore', 'loadall', 'reload', 'rename', 'delete', 'match'])
/** /**
* *
@ -62,18 +63,6 @@ const keyName = computed(() => {
return !isEmpty(props.keyCode) ? props.keyCode : props.keyPath return !isEmpty(props.keyCode) ? props.keyCode : props.keyPath
}) })
const filterOption = [
{
value: 1,
label: i18n.t('common.field'),
},
{
value: 2,
label: i18n.t('common.value'),
},
]
const filterType = ref(1)
const browserStore = useBrowserStore() const browserStore = useBrowserStore()
const dialogStore = useDialogStore() const dialogStore = useDialogStore()
const keyType = redisTypes.HASH const keyType = redisTypes.HASH
@ -114,7 +103,7 @@ const fieldColumn = computed(() => ({
const displayCode = computed(() => { const displayCode = computed(() => {
return props.format === formatTypes.JSON return props.format === formatTypes.JSON
}) })
const valueFilterOption = ref(null) // const valueFilterOption = ref(null)
const valueColumn = computed(() => ({ const valueColumn = computed(() => ({
key: 'value', key: 'value',
title: i18n.t('common.value'), title: i18n.t('common.value'),
@ -126,14 +115,14 @@ const valueColumn = computed(() => ({
: { : {
tooltip: true, tooltip: true,
}, },
filterOptionValue: valueFilterOption.value, // filterOptionValue: valueFilterOption.value,
className: inEdit.value ? 'clickable' : '', className: inEdit.value ? 'clickable' : '',
filter: (value, row) => { // filter: (value, row) => {
if (row.dv) { // if (row.dv) {
return !!~row.dv.indexOf(value.toString()) // return !!~row.dv.indexOf(value.toString())
} // }
return !!~row.v.indexOf(value.toString()) // return !!~row.v.indexOf(value.toString())
}, // },
render: (row) => { render: (row) => {
if (displayCode.value) { if (displayCode.value) {
return h(NCode, { language: 'json', wordWrap: true, code: row.dv || row.v }) return h(NCode, { language: 'json', wordWrap: true, code: row.dv || row.v })
@ -283,50 +272,28 @@ const onAddRow = () => {
dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.HASH) dialogStore.openAddFieldsDialog(props.name, props.db, props.keyPath, props.keyCode, types.HASH)
} }
const filterValue = ref('')
const onFilterInput = (val) => { const onFilterInput = (val) => {
switch (filterType.value) {
case filterOption[0].value:
// filter field
valueFilterOption.value = null
fieldFilterOption.value = val fieldFilterOption.value = val
break
case filterOption[1].value:
// filter value
fieldFilterOption.value = null
valueFilterOption.value = val
break
}
} }
const onChangeFilterType = (type) => { const onMatchInput = (matchVal, filterVal) => {
onFilterInput(filterValue.value) fieldFilterOption.value = filterVal
} emit('match', matchVal)
const clearFilter = () => {
fieldFilterOption.value = null
valueFilterOption.value = null
} }
const onUpdateFilter = (filters, sourceColumn) => { const onUpdateFilter = (filters, sourceColumn) => {
switch (filterType.value) {
case filterOption[0].value:
fieldFilterOption.value = filters[sourceColumn.key] fieldFilterOption.value = filters[sourceColumn.key]
break
case filterOption[1].value:
valueFilterOption.value = filters[sourceColumn.key]
break
}
} }
const onFormatChanged = (selDecode, selFormat) => { const onFormatChanged = (selDecode, selFormat) => {
emit('reload', selDecode, selFormat) emit('reload', selDecode, selFormat)
} }
const searchInputRef = ref(null)
defineExpose({ defineExpose({
reset: () => { reset: () => {
clearFilter()
resetEdit() resetEdit()
searchInputRef.value?.reset()
}, },
}) })
</script> </script>
@ -347,20 +314,10 @@ defineExpose({
@rename="emit('rename')" /> @rename="emit('rename')" />
<div class="tb2 value-item-part flex-box-h"> <div class="tb2 value-item-part flex-box-h">
<div class="flex-box-h"> <div class="flex-box-h">
<n-input-group> <content-search-input
<n-select ref="searchInputRef"
v-model:value="filterType" @filter-changed="onFilterInput"
:consistent-menu-width="false" @match-changed="onMatchInput" />
:options="filterOption"
style="width: 120px"
@update:value="onChangeFilterType" />
<n-input
v-model:value="filterValue"
:placeholder="$t('interface.search')"
clearable
@clear="clearFilter"
@update:value="onFilterInput" />
</n-input-group>
</div> </div>
<div class="flex-item-expand"></div> <div class="flex-item-expand"></div>
<n-button-group> <n-button-group>

View File

@ -176,7 +176,7 @@ watch(() => data.value?.keyPath, initContent)
</template> </template>
</n-empty> </n-empty>
<!-- FIXME: keep alive may cause virtual list null value error. --> <!-- FIXME: keep alive may cause virtual list null value error. -->
<!-- <keep-alive v-else>--> <!-- <keep-alive v-else> -->
<component <component
:is="valueComponents[data.type]" :is="valueComponents[data.type]"
v-else v-else