mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
Sort repos by org and name (#1548)
Ensure that repos are sorted in the UI after doing a search. See #1466 Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
parent
003773540b
commit
156b321c2d
1 changed files with 15 additions and 2 deletions
|
@ -3,6 +3,16 @@ import { computed, Ref } from 'vue';
|
|||
|
||||
import { Repo } from '~/lib/api/types';
|
||||
|
||||
/*
|
||||
* Compares Repos lexicographically using owner/name .
|
||||
*/
|
||||
function repoCompare(a: Repo, b: Repo) {
|
||||
const x = `${a.owner}/${a.name}`;
|
||||
const y = `${b.owner}/${b.name}`;
|
||||
// eslint-disable-next-line no-nested-ternary
|
||||
return x === y ? 0 : x > y ? 1 : -1;
|
||||
}
|
||||
|
||||
export function useRepoSearch(repos: Ref<Repo[] | undefined>, search: Ref<string>) {
|
||||
const searchIndex = computed(
|
||||
() =>
|
||||
|
@ -15,10 +25,13 @@ export function useRepoSearch(repos: Ref<Repo[] | undefined>, search: Ref<string
|
|||
|
||||
const searchedRepos = computed(() => {
|
||||
if (search.value === '') {
|
||||
return repos.value;
|
||||
return repos.value?.sort(repoCompare);
|
||||
}
|
||||
|
||||
return searchIndex.value.search(search.value).map((result) => result.item);
|
||||
return searchIndex.value
|
||||
.search(search.value)
|
||||
.map((result) => result.item)
|
||||
.sort(repoCompare);
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue