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

[Feature] Filtering of available modules in the "Install New Module" list. closes #780 #786

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 17 additions & 4 deletions packages/devtools/client/components/ModuleInstallList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import Fuse from 'fuse.js'
import { computed, ref } from 'vue'
// @ts-expect-error missing types
import { RecycleScroller } from 'vue-virtual-scroller'
import { useModulesList } from '~/composables/state-modules'
import { useInstalledModules, useModulesList } from '~/composables/state-modules'

type SortingFunction<T> = (a: T, b: T) => number

const emit = defineEmits(['close'])

const collection = useModulesList()
const installedModules = useInstalledModules()

const sortingOptions = ['downloads', 'stars', 'updated', 'created'] as const
const ascendingOrder = ref(false)
const selectedSortingOption = ref<typeof sortingOptions[number]>(sortingOptions[0])
const installedFilter = ref(false)

const sortingFactors: Record<typeof sortingOptions[number], SortingFunction<ModuleStaticInfo>> = {
downloads: (a, b) => a.stats.downloads - b.stats.downloads,
Expand Down Expand Up @@ -45,9 +47,13 @@ const fuse = computed(() => new Fuse(collection.value || [], {
}))

const items = computed(() => {
let filteredItems = sortedItems.value
if (installedFilter.value) {
filteredItems = (filteredItems || []).filter(item => !installedModules.value.some(installed => installed.name === item.name))
}
if (!search.value)
return sortedItems.value
return fuse.value.search(search.value).map(r => r.item)
return filteredItems
return fuse.value.search(search.value).map(r => r.item).filter(item => filteredItems?.includes(item))
})
</script>

Expand All @@ -59,7 +65,7 @@ const items = computed(() => {
icon="i-carbon-intent-request-create"
text="Install Module"
/>
<NNavbar v-model:search="search" no-padding px-6 pb-5 pt-2>
<NNavbar v-model:search="search" no-padding px-6 pb-3 pt-2>
<template #actions>
<NDropdown direction="end" n="sm primary">
<template #trigger="{ click }">
Expand Down Expand Up @@ -96,6 +102,13 @@ const items = computed(() => {
</div>
</NDropdown>
</template>
<NCheckbox v-model="installedFilter" n="primary md">
<span op75>Hide installed modules</span>
</NCheckbox>
<div flex="~ gap1" text-sm op50>
<span v-if="search || installedFilter">{{ items?.length }} matched Β· </span>
<span>{{ collection?.length }} modules in total</span>
</div>
</NNavbar>

<div flex-auto of-auto flex="~ col gap-2" pl6 pr4>
Expand Down