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

WIP: feat (ui): insert filter by workspace in vitest ui #7157

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/ui/client/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare module 'vue' {
Explorer: typeof import('./components/explorer/Explorer.vue')['default']
ExplorerItem: typeof import('./components/explorer/ExplorerItem.vue')['default']
FileDetails: typeof import('./components/FileDetails.vue')['default']
FilterSelect: typeof import('./components/FilterSelect.vue')['default']
FilterStatus: typeof import('./components/FilterStatus.vue')['default']
IconAction: typeof import('./components/IconAction.vue')['default']
IconButton: typeof import('./components/IconButton.vue')['default']
Expand Down
40 changes: 40 additions & 0 deletions packages/ui/client/components/FilterSelect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script setup lang="ts">
defineProps<{ options: string[] }>()
const emit = defineEmits(['update'])

const selected = ref('All')

function onChange() {
emit('update', selected.value)
}
</script>

<template>
<div>
<label for="select">Projects</label>
<select id="select" v-model="selected" @change="onChange">
<option value="All">
All
</option>
<option v-for="(option, index) in options" :key="index" :value="option">
{{ option }}
</option>
</select>
</div>
</template>

<style scoped>
label {
margin-top: 10px;
font-size: 14px;
margin-bottom: 8px;
display: block;
}
select {
padding: 6px;
width: 150%;
font-size: 12px;
border-radius: 4px;
border: 1px solid #ccc;
}
</style>
2 changes: 2 additions & 0 deletions packages/ui/client/components/explorer/Explorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const {
filteredFiles,
testsTotal,
uiEntries,
workspaceProjects,
} = useSearch(searchBox)

const filterClass = ref<string>('grid-cols-2')
Expand Down Expand Up @@ -123,6 +124,7 @@ watch(() => windowWidth.value * (panels.navigation / 100), (width) => {
<FilterStatus v-model="filter.success" label="Pass" />
<FilterStatus v-model="filter.skipped" label="Skip" />
<FilterStatus v-model="filter.onlyTests" label="Only Tests" />
<FilterSelect v-model="filter.project" :options="(workspaceProjects as string[])" @update="(e) => console.log(e)" />
</div>
</div>
<div class="scrolls" flex-auto py-1 @scroll.passive="hideAllPoppers">
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/client/composables/explorer/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export function useSearch(searchBox: Ref<HTMLDivElement | undefined>) {
const disableClearSearch = computed(() => search.value === '')
const debouncedSearch = ref(search.value)

const workspaceProjects = computed(() => [...new Set(uiEntries.value.filter(entry => entry.parentId === 'root').map(entry => entry.projectName))])

debouncedWatch(() => search.value, (value) => {
debouncedSearch.value = value?.trim() ?? ''
}, { debounce: 256 })
Expand All @@ -40,6 +42,7 @@ export function useSearch(searchBox: Ref<HTMLDivElement | undefined>) {
filter.success = false
filter.skipped = false
filter.onlyTests = false
filter.project = 'All'
if (focus) {
searchBox.value?.focus()
}
Expand Down Expand Up @@ -103,5 +106,6 @@ export function useSearch(searchBox: Ref<HTMLDivElement | undefined>) {
filteredFiles,
testsTotal,
uiEntries,
workspaceProjects,
}
}
2 changes: 2 additions & 0 deletions packages/ui/client/composables/explorer/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const treeFilter = useLocalStorage<TreeFilterState>(
skipped: false,
onlyTests: false,
search: '',
project: 'All',
},
)
export const search = ref<string>(treeFilter.value.search)
Expand All @@ -42,6 +43,7 @@ export const filter = reactive<Filter>({
success: treeFilter.value.success,
skipped: treeFilter.value.skipped,
onlyTests: treeFilter.value.onlyTests,
project: treeFilter.value.project,
})
export const isFilteredByStatus = computed(() => {
if (filter.failed) {
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/client/composables/explorer/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class ExplorerTree {
success: filter.success,
skipped: filter.skipped,
onlyTests: filter.onlyTests,
project: filter.project,
},
)
}
Expand Down Expand Up @@ -107,6 +108,7 @@ export class ExplorerTree {
success: filter.success,
skipped: filter.skipped,
onlyTests: filter.onlyTests,
project: filter.project,
},
)
})
Expand All @@ -122,6 +124,7 @@ export class ExplorerTree {
success: filter.success,
skipped: filter.skipped,
onlyTests: filter.onlyTests,
project: filter.project,
},
)
}
Expand All @@ -138,6 +141,7 @@ export class ExplorerTree {
success: filter.success,
skipped: filter.skipped,
onlyTests: filter.onlyTests,
project: filter.project,
})
}

Expand All @@ -154,6 +158,7 @@ export class ExplorerTree {
success: filter.success,
skipped: filter.skipped,
onlyTests: filter.onlyTests,
project: filter.project,
})
})
}
Expand All @@ -171,6 +176,7 @@ export class ExplorerTree {
success: filter.success,
skipped: filter.skipped,
onlyTests: filter.onlyTests,
project: filter.project,
})
})
}
Expand All @@ -182,6 +188,7 @@ export class ExplorerTree {
success: filter.success,
skipped: filter.skipped,
onlyTests: filter.onlyTests,
project: filter.project,
})
})
}
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/client/composables/explorer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface UITaskTreeNode extends TaskTreeNode {
indent: number
state?: TaskState
duration?: number
projectName?: string
}

export interface TestTreeNode extends UITaskTreeNode {
Expand Down Expand Up @@ -69,6 +70,7 @@ export interface Filter {
success: boolean
skipped: boolean
onlyTests: boolean
project: string
}

export interface TreeFilterState extends Filter {
Expand Down
Loading