Skip to content

Commit 2fab18b

Browse files
authored
Merge pull request #90 from bfritscher/fix-collection-sorting
feat: collection drop down sorted and searchable in navmenu
2 parents 51c4d72 + b1d9354 commit 2fab18b

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/components/NavMenu.vue

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,17 @@
7777
<q-select
7878
v-model="currentCollection"
7979
borderless
80-
:options="store.data.collections"
80+
:options="filteredCollections"
81+
use-input
82+
fill-input
83+
hide-selected
84+
input-debounce="0"
8185
label="Collection"
8286
option-label="name"
8387
color="white"
8488
label-color="white"
8589
dark
90+
@filter="collectionFilterFn"
8691
/>
8792
</q-item-section>
8893
</q-item>
@@ -161,11 +166,33 @@
161166

162167
<script setup lang="ts">
163168
import type { CollectionSchema } from 'typesense/lib/Typesense/Collection';
164-
import { computed } from 'vue';
169+
import { computed, ref } from 'vue';
165170
import { useNodeStore } from 'src/stores/node';
166171
167172
const store = useNodeStore();
168173
174+
const sortedCollections = computed(() =>
175+
store.data.collections.slice(0).sort((a, b) => a.name.localeCompare(b.name)),
176+
);
177+
178+
const filteredCollections = ref<CollectionSchema[]>([]);
179+
180+
function collectionFilterFn(val: string, update: (fn: () => void) => void) {
181+
if (val === '') {
182+
update(() => {
183+
filteredCollections.value = sortedCollections.value;
184+
});
185+
return;
186+
}
187+
188+
update(() => {
189+
const needle = val.toLowerCase();
190+
filteredCollections.value = sortedCollections.value.filter((v) =>
191+
v.name.toLowerCase().includes(needle),
192+
);
193+
});
194+
}
195+
169196
const currentCollection = computed({
170197
get() {
171198
return store.currentCollection;

src/pages/Aliases.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ const state = reactive({
109109
] as QTableProps['columns'],
110110
});
111111
112-
const collectionNames = computed(() => store.data.collections.map((collection) => collection.name));
112+
const collectionNames = computed(() =>
113+
store.data.collections.map((collection) => collection.name).sort(),
114+
);
113115
const isUpdate = computed(() => store.data.aliases.map((a) => a.name).includes(state.alias.name));
114116
async function createAlias() {
115117
await store.createAlias({

0 commit comments

Comments
 (0)