Skip to content

Commit f2a5815

Browse files
committed
chore: update
1 parent af349b7 commit f2a5815

2 files changed

Lines changed: 106 additions & 17 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<script setup lang="ts">
2+
import { Dropdown as VDropdown } from 'floating-vue'
3+
import { computed, nextTick, ref } from 'vue'
4+
5+
const props = defineProps<{ names: string[] }>()
6+
const excluded = defineModel<string[]>('excluded', { required: true })
7+
const selectedNames = computed(() => props.names.filter(name => !excluded.value.includes(name)))
8+
const label = computed(() => {
9+
if (!excluded.value.length)
10+
return 'Task name'
11+
return selectedNames.value.length === 1 ? `Task name: ${selectedNames.value[0]}` : `Task names · ${selectedNames.value.length}`
12+
})
13+
const query = ref('')
14+
const trigger = ref<HTMLButtonElement>()
15+
const searchInput = ref<HTMLInputElement>()
16+
const visibleNames = computed(() => props.names.filter(name => name.toLowerCase().includes(query.value.trim().toLowerCase())))
17+
</script>
18+
19+
<template>
20+
<VDropdown placement="bottom-end" no-auto-focus @apply-show="nextTick(() => searchInput?.focus())">
21+
<template #default="{ shown }">
22+
<button ref="trigger" class="btn-action whitespace-nowrap focus-visible:bg-active focus-visible:op100 focus-visible:outline-none" :class="{ 'bg-active': excluded.length }" :aria-expanded="shown">
23+
<span class="truncate max-w-32">{{ label }}</span>
24+
<span aria-hidden="true" class="i-ph-caret-down-duotone shrink-0 op60" />
25+
</button>
26+
</template>
27+
<template #popper="{ hide }">
28+
<div class="w-60 max-w-80vw text-sm" @keydown.esc.stop.prevent="hide(); trigger?.focus()">
29+
<div class="flex items-center gap2 px3 border-b border-base">
30+
<span aria-hidden="true" class="i-ph-magnifying-glass-duotone op40 flex-none" />
31+
<input ref="searchInput" v-model="query" aria-label="Search task names" placeholder="Search task names" class="min-w-0 flex-1 bg-transparent py2 outline-none">
32+
<button
33+
class="flex shrink-0 p1 rounded op70 hover:bg-active hover:op100"
34+
:title="selectedNames.length ? 'Select none' : 'Select all'"
35+
:aria-label="selectedNames.length ? 'Select none' : 'Select all'"
36+
@click="excluded = selectedNames.length ? [...names] : []"
37+
>
38+
<span :class="selectedNames.length ? 'i-ph-selection-plus-duotone' : 'i-ph-selection-slash-duotone'" />
39+
</button>
40+
</div>
41+
<div class="max-h-56 of-auto p1">
42+
<label v-for="name in visibleNames" :key="name" class="flex items-center gap2 px2 py1 rounded hover:bg-active">
43+
<input type="checkbox" :checked="!excluded.includes(name)" @change="excluded = excluded.includes(name) ? excluded.filter(item => item !== name) : [...excluded, name]">
44+
<span class="break-all">{{ name }}</span>
45+
</label>
46+
<div v-if="!visibleNames.length" class="px2 py1 op60">
47+
No matching names
48+
</div>
49+
</div>
50+
</div>
51+
</template>
52+
</VDropdown>
53+
</template>

‎packages/vite-task/src/app/pages/index.vue‎

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { computed, onMounted, provide, ref, shallowRef, watch } from 'vue'
88
import { useRoute, useRouter } from '#app/composables/router'
99
import TaskDetails from '../components/TaskDetails.vue'
1010
import TaskGraphView from '../components/TaskGraphView.vue'
11-
import TaskId from '../components/TaskId.vue'
11+
import TaskNameFilter from '../components/TaskNameFilter.vue'
1212
import { useRpc } from '../composables/rpc'
1313
import { getTaskPackageKey, isTaskInGraphKey } from '../utils/task-plan'
1414
@@ -25,18 +25,18 @@ const planLoading = ref(false)
2525
const graphError = ref('')
2626
const planError = ref('')
2727
const unsupportedVersion = ref(false)
28-
const filters = ref<{ search: string, selected: string[] | null }>({ search: '', selected: null })
28+
const filters = ref({ search: '' })
29+
const excludedNames = ref<string[]>([])
2930
const isolatedTasksVisible = ref(false)
3031
const taskEntries = computed(() => Object.entries(graph.value?.tasks || {}))
31-
// DataSearchPanel requires icon and always renders its element; hidden removes the empty flex slot.
32-
const taskRules = computed(() => [...new Set(taskEntries.value.map(([, task]) => task.name))].sort().map(name => ({ name, match: /.*/, icon: 'hidden' })))
32+
const taskNames = computed(() => [...new Set(taskEntries.value.map(([, task]) => task.name))].sort())
3333
const matchedTasks = computed(() => taskEntries.value.filter(([id, task]) =>
34-
(!filters.value.selected || filters.value.selected.includes(task.name))
34+
!excludedNames.value.includes(task.name)
3535
&& `${id} ${graph.value?.packages[task.package]?.name || ''}`.toLowerCase().includes(filters.value.search.toLowerCase()),
3636
))
3737
const matchedIds = computed(() => new Set(matchedTasks.value.map(([id]) => id)))
3838
const connectedTaskIds = computed(() => new Set(taskEntries.value.flatMap(([id, task]) => task.dependsOn?.length ? [id, ...task.dependsOn] : [])))
39-
const isolatedCount = computed(() => taskEntries.value.filter(([id]) => !connectedTaskIds.value.has(id)).length)
39+
const isolatedCount = computed(() => matchedTasks.value.filter(([id]) => !connectedTaskIds.value.has(id)).length)
4040
const visibleGraph = computed<TaskGraph | undefined>((previous) => {
4141
if (!graph.value)
4242
return undefined
@@ -71,7 +71,34 @@ const visibleGraph = computed<TaskGraph | undefined>((previous) => {
7171
})
7272
const intermediateTaskCount = computed(() => Object.keys(visibleGraph.value?.tasks || {}).filter(id => !matchedIds.value.has(id)).length)
7373
const view = ref<'list' | 'graph'>('list')
74-
const sortedTasks = computed(() => [...matchedTasks.value].sort(([, a], [, b]) => a.package.localeCompare(b.package) || a.name.localeCompare(b.name)))
74+
const packageGroups = computed(() => {
75+
const groups = new Map<string, typeof matchedTasks.value>()
76+
for (const entry of matchedTasks.value) {
77+
const path = entry[1].package
78+
const tasks = groups.get(path)
79+
if (tasks)
80+
tasks.push(entry)
81+
else
82+
groups.set(path, [entry])
83+
}
84+
return [...groups].sort(([a], [b]) => a.localeCompare(b)).map(([path, tasks]) => ({
85+
path,
86+
label: path === '.' ? 'Workspace root' : graph.value?.packages[path]?.name || path,
87+
tasks: tasks.sort(([, a], [, b]) => a.name.localeCompare(b.name)),
88+
}))
89+
})
90+
const collapsedPackages = ref(new Set<string>())
91+
const collapsedSearchResults = ref(new Set<string>())
92+
watch(() => filters.value.search, () => collapsedSearchResults.value.clear())
93+
const collapsed = computed(() => filters.value.search ? collapsedSearchResults.value : collapsedPackages.value)
94+
95+
function togglePackage(path: string) {
96+
if (collapsed.value.has(path))
97+
collapsed.value.delete(path)
98+
else
99+
collapsed.value.add(path)
100+
}
101+
75102
let planRequestVersion = 0
76103
77104
async function loadPlan(id: string) {
@@ -115,6 +142,7 @@ async function refresh() {
115142
if (result === 'unsupported-version')
116143
return
117144
graph.value = result
145+
excludedNames.value = excludedNames.value.filter(name => taskNames.value.includes(name))
118146
if (selected.value && graph.value.tasks[selected.value])
119147
await loadPlan(selected.value)
120148
else
@@ -168,9 +196,10 @@ onMounted(refresh)
168196
</div>
169197
<div v-else class="text-sm relative" :class="view === 'graph' ? 'h-full flex flex-col max-h-screen of-hidden' : ''">
170198
<div class="z-panel-nav p4" :class="view === 'list' ? 'sticky left-4 right-4 top-4' : 'shrink-0'">
171-
<DataSearchPanel v-model="filters" :rules="taskRules">
199+
<DataSearchPanel v-model="filters" :rules="[]">
172200
<template #search-end>
173-
<div class="h10 mr2 flex items-center">
201+
<div class="h10 mr2 flex items-center gap2">
202+
<TaskNameFilter v-model:excluded="excludedNames" :names="taskNames" />
174203
<DisplayIconButton v-tooltip="'Refresh tasks'" title="Refresh tasks" :class-icon="graphLoading ? 'i-ph-arrow-clockwise-duotone animate-spin' : 'i-ph-arrow-clockwise-duotone'" :disabled="graphLoading" @click="refresh" />
175204
</div>
176205
</template>
@@ -194,14 +223,21 @@ onMounted(refresh)
194223
</div>
195224
<VisualLoading v-if="graphLoading && !graph" text="Loading tasks…" />
196225
<section v-else-if="graph && view === 'list'" class="p4 pb16" aria-label="Tasks">
197-
<div v-for="[id, task] in sortedTasks" :key="id" class="flex pb2">
198-
<button class="hover:bg-active flex items-center gap2 px2 py1 w-full border border-base rounded text-left" :class="selected === id ? 'bg-active' : ''" :title="id" :aria-pressed="selected === id" :disabled="graphLoading" @click="selectTask(id)">
199-
<span class="i-ph-terminal-window-duotone op-fade shrink-0" />
200-
<TaskId :id="id" class="truncate" />
201-
<span v-if="task.dependsOn?.length" v-tooltip="`Depends on ${task.dependsOn.length} ${task.dependsOn.length === 1 ? 'task' : 'tasks'}`" class="ml-auto text-xs op-fade flex items-center gap1"><span class="i-ph-graph-duotone" />{{ task.dependsOn.length }}</span>
202-
</button>
203-
</div>
204-
<div v-if="!sortedTasks.length" class="w-full h-48 flex items-center justify-center text-sm op50 italic">
226+
<details v-for="group in packageGroups" :key="group.path" :open="!collapsed.has(group.path)" class="mb2">
227+
<summary class="cursor-default select-none flex gap-1 items-center px1 py1 rounded hover:bg-active" :title="group.path" @click.prevent="togglePackage(group.path)">
228+
<span class="i-ph-caret-right-duotone transition op50" :class="{ 'rotate-90': !collapsed.has(group.path) }" />
229+
<span class="op70 text-sm">{{ group.label }}</span>
230+
<span class="op40 text-xs font-mono">{{ group.tasks.length }}</span>
231+
</summary>
232+
<div class="flex flex-col gap2 pl4 pt2">
233+
<button v-for="[id, task] in group.tasks" :key="id" class="hover:bg-active flex items-center gap2 px2 py1 w-full border border-base rounded text-left" :class="selected === id ? 'bg-active' : ''" :title="id" :aria-pressed="selected === id" :disabled="graphLoading" @click="selectTask(id)">
234+
<span class="i-ph-terminal-window-duotone op-fade shrink-0" />
235+
<span class="font-mono truncate">{{ task.name }}</span>
236+
<span v-if="task.dependsOn?.length" v-tooltip="`Depends on ${task.dependsOn.length} ${task.dependsOn.length === 1 ? 'task' : 'tasks'}`" class="ml-auto text-xs op-fade flex items-center gap1"><span class="i-ph-graph-duotone" />{{ task.dependsOn.length }}</span>
237+
</button>
238+
</div>
239+
</details>
240+
<div v-if="!packageGroups.length" class="w-full h-48 flex items-center justify-center text-sm op50 italic">
205241
<p>No tasks</p>
206242
</div>
207243
</section>

0 commit comments

Comments
 (0)