Skip to content

Commit 2daf0ec

Browse files
committed
fixed fuzzy search for type
1 parent 3755cb5 commit 2daf0ec

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

src/sidebars/SecretSidebar.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,9 @@ export default {
164164
return true
165165
},
166166
typeLabel() {
167-
if (!this.secret) return null
168-
if (this.secret.type) return this.secret.type
169-
if (this.secret.typeId) {
170-
const match = this.secretTypeStore.types.find(t => t.id === this.secret.typeId)
171-
return match?.label ?? null
172-
}
173-
return null
167+
if (!this.secret?.typeId) return null
168+
const match = this.secretTypeStore.types.find(t => t.id === this.secret.typeId)
169+
return match?.label ?? null
174170
},
175171
createdDate() {
176172
if (!this.secret?.createdAt) return null

src/views/SecretList.vue

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@
8787

8888
<template #column-type="{ row }">
8989
<!-- eslint-disable-next-line vue/no-v-html -->
90-
<span v-html="highlight(row.type, row.id, 'type')" />
90+
<span v-if="row.typeName" v-html="highlight(row.typeName, row.id, 'typeName')" />
91+
<span v-else class="secret-list__empty-cell">—</span>
9192
</template>
9293

9394
<template #column-createdAt="{ row }">
@@ -116,6 +117,7 @@ import PencilIcon from 'vue-material-design-icons/Pencil.vue'
116117
import CreateSecretDialog from '../dialog/CreateSecretDialog.vue'
117118
import { useFolderStore } from '../store/modules/folder.js'
118119
import { useSecretStore } from '../store/modules/secret.js'
120+
import { useSecretTypeStore } from '../store/modules/secretType.js'
119121
import { useSettingsStore } from '../store/modules/settings.js'
120122
import { getFaviconUrl } from '../utils/favicon.js'
121123
@@ -154,9 +156,19 @@ export default {
154156
secretStore() {
155157
return useSecretStore()
156158
},
159+
secretTypeStore() {
160+
return useSecretTypeStore()
161+
},
157162
settingsStore() {
158163
return useSettingsStore()
159164
},
165+
typesById() {
166+
const map = {}
167+
for (const t of this.secretTypeStore.types) {
168+
map[t.id] = t.label
169+
}
170+
return map
171+
},
160172
pageTitle() {
161173
if (this.folderId) {
162174
const folder = this.folderStore.folders.find(f => f.id === this.folderId)
@@ -172,9 +184,15 @@ export default {
172184
{ key: 'createdAt', label: t('doriath', 'Created'), sortable: true },
173185
]
174186
},
187+
enrichedSecrets() {
188+
return this.secretStore.secrets.map(s => ({
189+
...s,
190+
typeName: this.typesById[s.typeId] || '',
191+
}))
192+
},
175193
fuse() {
176-
return new Fuse(this.secretStore.secrets, {
177-
keys: ['name', 'url', 'type'],
194+
return new Fuse(this.enrichedSecrets, {
195+
keys: ['name', 'url', 'typeName'],
178196
threshold: 0.4,
179197
includeMatches: true,
180198
})
@@ -185,7 +203,7 @@ export default {
185203
return this.fuse.search(query)
186204
},
187205
filteredSecrets() {
188-
if (!this.fuseResults) return this.secretStore.secrets
206+
if (!this.fuseResults) return this.enrichedSecrets
189207
return this.fuseResults.map(r => r.item)
190208
},
191209
matchesById() {
@@ -231,7 +249,10 @@ export default {
231249
},
232250
},
233251
async created() {
234-
await this.loadSecrets()
252+
await Promise.all([
253+
this.loadSecrets(),
254+
this.secretTypeStore.fetchTypes(),
255+
])
235256
},
236257
methods: {
237258
async loadSecrets() {

0 commit comments

Comments
 (0)