Skip to content

Commit

Permalink
feat(ui): allow case insensitive search & optmize search (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecuvii committed Mar 27, 2022
1 parent a880d3f commit c6dd63a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
18 changes: 18 additions & 0 deletions package.json
Expand Up @@ -66,5 +66,23 @@
"overrides": {
"vite": "^2.8.6"
}
},
"vite": {
"optimizeDeps": {
"include": [
"@vueuse/core",
"birpc",
"codemirror",
"codemirror/addon/display/placeholder",
"codemirror/mode/javascript/javascript",
"codemirror/mode/jsx/jsx",
"codemirror/mode/xml/xml",
"d3-graph-controller",
"flatted",
"floating-vue",
"splitpanes",
"vue-router"
]
}
}
}
1 change: 0 additions & 1 deletion packages/ui/client/auto-imports.d.ts
Expand Up @@ -39,7 +39,6 @@ declare global {
const makeDestructurable: typeof import('@vueuse/core')['makeDestructurable']
const markRaw: typeof import('vue')['markRaw']
const nextTick: typeof import('vue')['nextTick']
const note: typeof import('@vueuse/core')['note']
const onActivated: typeof import('vue')['onActivated']
const onBeforeMount: typeof import('vue')['onBeforeMount']
const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
Expand Down
5 changes: 4 additions & 1 deletion packages/ui/client/components/TaskTree.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
import type { Task } from '#types'
import { caseInsensitiveMatch } from '~/utils/task'
withDefaults(defineProps<{
task: Task
Expand All @@ -20,8 +21,10 @@ export default {
</script>

<template>
<!-- maybe provide a KEEP STRUCTURE mode, do not filter by search keyword -->
<!-- v-if = keepStructure || (!search || caseInsensitiveMatch(task.name, search))-->
<TaskItem
v-if="!search || task.name.includes(search)"
v-if="!search || caseInsensitiveMatch(task.name, search)"
v-bind="$attrs"
:task="task"
:style="{ paddingLeft: `${indent * 0.75 + 1}rem`}"
Expand Down
26 changes: 25 additions & 1 deletion packages/ui/client/components/TasksList.vue
Expand Up @@ -3,6 +3,7 @@ import type { ComputedRef } from 'vue'
import type { File, Task } from '#types'
import { findById, testRunState } from '~/composables/client'
import { activeFileId } from '~/composables/params'
import { caseInsensitiveMatch, isSuite } from '~/utils/task'
const props = withDefaults(defineProps<{
tasks: Task[]
Expand All @@ -23,10 +24,33 @@ const emit = defineEmits<{
const search = ref('')
const isFiltered = computed(() => search.value.trim() !== '')
const matchTasks = (tasks: Task[], search: string): boolean => {
let result = false
for (let i = 0; i < tasks.length; i++) {
const task = tasks[i]
if (caseInsensitiveMatch(task.name, search)) {
result = true
break
}
// walk whole task tree
if (isSuite(task) && task.tasks) {
result = matchTasks(task.tasks, search)
if (result)
break
}
}
return result
}
const filtered = computed(() => {
if (!search.value.trim())
return props.tasks
return props.tasks.filter(task => task.name.includes(search.value))
return props.tasks.filter(task => matchTasks([task], search.value))
})
const filteredTests: ComputedRef<File[]> = computed(() => isFiltered.value ? filtered.value.map(task => findById(task.id)!).filter(Boolean) : [])
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/components/views/ViewReport.vue
Expand Up @@ -40,7 +40,7 @@ function relative(p: string) {
<div v-for="({ file: efile, line, column }, i) of task.result.error.stacks || []" :key="i" class="op80 flex gap-x-2 items-center">
<pre> - {{ relative(efile) }}:{{ line }}:{{ column }}</pre>
<div
v-if="shouldOpenInEditor(efile, props.file.name)"
v-if="shouldOpenInEditor(efile, props.file?.name)"
class="i-carbon-launch text-red-900 hover:cursor-pointer"
tabindex="0"
title="Open in IDE"
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/client/utils/task.ts
@@ -0,0 +1,11 @@

import type { Suite, Task } from '#types'

export function isSuite(task: Task): task is Suite {
return Object.hasOwnProperty.call(task, 'tasks')
}

export function caseInsensitiveMatch(target: string, str2: string) {
if (typeof target !== 'string' || typeof str2 !== 'string') return false
return target.toLowerCase().includes(str2.toLowerCase())
}

0 comments on commit c6dd63a

Please sign in to comment.