( searchBox: Ref<HTMLInputElement | undefined>, selectProject: Ref<HTMLSelectElement | undefined>, sortProject: Ref<HTMLSelectElement | undefined>, )
| 24 | } from './state' |
| 25 | |
| 26 | export function useSearch( |
| 27 | searchBox: Ref<HTMLInputElement | undefined>, |
| 28 | selectProject: Ref<HTMLSelectElement | undefined>, |
| 29 | sortProject: Ref<HTMLSelectElement | undefined>, |
| 30 | ) { |
| 31 | const disableFilter = computed(() => { |
| 32 | if (isFilteredByStatus.value) { |
| 33 | return false |
| 34 | } |
| 35 | |
| 36 | return !filter.onlyTests |
| 37 | }) |
| 38 | |
| 39 | const disableClearSearch = computed(() => search.value === '') |
| 40 | const debouncedSearch = ref(search.value) |
| 41 | const disableClearProjectSort = computed(() => projectSort.value === 'default') |
| 42 | |
| 43 | // Reset project-specific sort when multiple projects are no longer available |
| 44 | watch(() => enableProjects.value, (enabled) => { |
| 45 | if (!enabled && (projectSort.value === 'asc' || projectSort.value === 'desc')) { |
| 46 | projectSort.value = 'default' |
| 47 | } |
| 48 | }) |
| 49 | |
| 50 | debouncedWatch(() => search.value, (value) => { |
| 51 | debouncedSearch.value = value?.trim() ?? '' |
| 52 | }, { debounce: 256 }) |
| 53 | |
| 54 | function clearSearch(focus: boolean) { |
| 55 | search.value = '' |
| 56 | if (focus) { |
| 57 | searchBox.value?.focus() |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | function clearFilter(focus: boolean) { |
| 62 | filter.failed = false |
| 63 | filter.success = false |
| 64 | filter.skipped = false |
| 65 | filter.slow = false |
| 66 | filter.onlyTests = false |
| 67 | if (focus) { |
| 68 | searchBox.value?.focus() |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | function clearProject(focus: boolean) { |
| 73 | currentProject.value = ALL_PROJECTS |
| 74 | if (focus) { |
| 75 | selectProject.value?.focus() |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | function clearProjectSort(focus: boolean) { |
| 80 | projectSort.value = 'default' |
| 81 | if (focus) { |
| 82 | sortProject.value?.focus() |
| 83 | } |
nothing calls this directly
no test coverage detected