Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-expand model library tree on search #1357

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/components/sidebar/tabs/ModelLibrarySidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
class="model-lib-search-box p-4"
v-model:modelValue="searchQuery"
:placeholder="$t('searchModels') + '...'"
@search="handleSearch"
/>
</template>
<template #body>
Expand Down Expand Up @@ -60,7 +61,7 @@ import type {
RenderedTreeExplorerNode,
TreeExplorerNode
} from '@/types/treeExplorerTypes'
import { computed, ref, watch, toRef, onMounted } from 'vue'
import { computed, ref, watch, toRef, onMounted, nextTick } from 'vue'
import type { TreeNode } from 'primevue/treenode'
import { app } from '@/scripts/app'
import { buildTree } from '@/utils/treeUtil'
Expand All @@ -69,17 +70,26 @@ const modelToNodeStore = useModelToNodeStore()
const settingStore = useSettingStore()
const searchQuery = ref<string>('')
const expandedKeys = ref<Record<string, boolean>>({})
const { toggleNodeOnEvent } = useTreeExpansion(expandedKeys)
const { expandNode, toggleNodeOnEvent } = useTreeExpansion(expandedKeys)

const filteredModels = computed<ComfyModelDef[]>(() => {
if (searchQuery.value) {
const search = searchQuery.value.toLocaleLowerCase()
return modelStore.models.filter((model: ComfyModelDef) => {
return model.searchable.includes(search)
})
const filteredModels = ref<ComfyModelDef[]>([])
const handleSearch = async (query: string) => {
if (!query) {
filteredModels.value = modelStore.models
expandedKeys.value = {}
return
}
return modelStore.models
})
// Load all models to ensure we have the latest data
await modelStore.loadModels()
const search = query.toLocaleLowerCase()
filteredModels.value = modelStore.models.filter((model: ComfyModelDef) => {
return model.searchable.includes(search)
})

nextTick(() => {
expandNode(root.value)
})
}

type ModelOrFolder = ComfyModelDef | ModelFolder

Expand Down
Loading