Skip to content

Commit 2213026

Browse files
authored
feat: search for chunks (#140)
1 parent 424a733 commit 2213026

File tree

2 files changed

+70
-41
lines changed

2 files changed

+70
-41
lines changed

packages/vite/src/app/components/display/ModuleGraph.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ onMounted(() => {
6161
<svg pointer-events-none absolute left-0 top-0 z-graph-link :width="width" :height="height">
6262
<g>
6363
<template v-for="link of links" :key="link.id">
64-
<slot name="link" :link="link" :d="generateModuleGraphLink<T, I>(link, spacing)!" :link-class="getModuleGraphLinkColor<T, I>(link)">
64+
<slot v-if="link.target" name="link" :link="link" :d="generateModuleGraphLink<T, I>(link, spacing)!" :link-class="getModuleGraphLinkColor<T, I>(link)">
6565
<path
6666
:key="link.id"
6767
:d="generateModuleGraphLink<T, I>(link, spacing)!"

packages/vite/src/app/pages/session/[session]/chunks.vue

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import type { SessionContext } from '~~/shared/types/data'
33
import type { ClientSettings } from '~/state/settings'
44
import { useRpc } from '#imports'
5-
import { useAsyncState } from '@vueuse/core'
6-
import { computed } from 'vue'
5+
import { computedWithControl, useAsyncState } from '@vueuse/core'
6+
import Fuse from 'fuse.js'
7+
import { computed, ref } from 'vue'
78
import { settings } from '~/state/settings'
89
910
const props = defineProps<{
@@ -28,6 +29,10 @@ const chunkViewTypes = [
2829
},
2930
] as const
3031
32+
const searchValue = ref<{ search: string }>({
33+
search: '',
34+
})
35+
3136
const rpc = useRpc()
3237
const { state: chunks, isLoading } = useAsyncState(
3338
async () => {
@@ -38,11 +43,31 @@ const { state: chunks, isLoading } = useAsyncState(
3843
},
3944
null,
4045
)
46+
4147
const normalizedChunks = computed(() => chunks.value?.map(x => ({
4248
...x,
4349
id: `${x.chunk_id}`,
4450
})) ?? [])
4551
52+
const fuse = computedWithControl(
53+
() => normalizedChunks.value,
54+
() => new Fuse(normalizedChunks.value!, {
55+
includeScore: true,
56+
keys: ['name'],
57+
ignoreLocation: true,
58+
threshold: 0.4,
59+
}),
60+
)
61+
62+
const searched = computed(() => {
63+
if (!searchValue.value.search) {
64+
return normalizedChunks.value!
65+
}
66+
return fuse.value
67+
.search(searchValue.value.search)
68+
.map(r => r.item)
69+
})
70+
4671
function toggleDisplay(type: ClientSettings['chunkViewType']) {
4772
settings.value.chunkViewType = type
4873
}
@@ -52,46 +77,50 @@ function toggleDisplay(type: ClientSettings['chunkViewType']) {
5277
<VisualLoading v-if="isLoading" />
5378
<div v-else relative max-h-screen of-hidden>
5479
<div absolute left-4 top-4 z-panel-nav>
55-
<div flex="~ gap-2 items-center" p2 border="~ base rounded-xl" bg-glass>
56-
<span op50 pl2 text-sm>View as</span>
57-
<button
58-
v-for="viewType of chunkViewTypes"
59-
:key="viewType.value"
60-
btn-action
61-
:class="settings.chunkViewType === viewType.value ? 'bg-active' : 'grayscale op50'"
62-
@click="toggleDisplay(viewType.value)"
63-
>
64-
<div :class="viewType.icon" />
65-
{{ viewType.label }}
66-
</button>
67-
</div>
80+
<DataSearchPanel v-model="searchValue" :rules="[]">
81+
<div flex="~ gap-2 items-center" p2 border="t base">
82+
<span op50 pl2 text-sm>View as</span>
83+
<button
84+
v-for="viewType of chunkViewTypes"
85+
:key="viewType.value"
86+
btn-action
87+
:class="settings.chunkViewType === viewType.value ? 'bg-active' : 'grayscale op50'"
88+
@click="toggleDisplay(viewType.value)"
89+
>
90+
<div :class="viewType.icon" />
91+
{{ viewType.label }}
92+
</button>
93+
</div>
94+
</DataSearchPanel>
6895
</div>
69-
<template v-if="settings.chunkViewType === 'list'">
70-
<div class="px5 pt24 of-auto h-screen" flex="~ col gap-4">
71-
<ChunksFlatList
72-
:session="session"
73-
:chunks="normalizedChunks"
74-
/>
75-
</div>
76-
</template>
77-
<template v-if="settings.chunkViewType === 'detailed-list'">
78-
<div class="px5 pt24 of-auto h-screen" flex="~ col gap-4">
79-
<template v-for="chunk of chunks" :key="chunk.id">
80-
<DataChunkDetails
81-
border="~ base rounded-lg"
82-
p3
83-
:chunk="chunk"
84-
:chunks="chunks!"
96+
<div of-auto h-screen flex="~ col gap-2" pt12>
97+
<template v-if="settings.chunkViewType === 'list'">
98+
<div class="px5 pt24 of-auto h-screen" flex="~ col gap-4">
99+
<ChunksFlatList
85100
:session="session"
101+
:chunks="searched"
86102
/>
87-
</template>
88-
</div>
89-
</template>
90-
<template v-else-if="settings.chunkViewType === 'graph'">
91-
<ChunksGraph
92-
:session="session"
93-
:chunks="normalizedChunks"
94-
/>
95-
</template>
103+
</div>
104+
</template>
105+
<template v-if="settings.chunkViewType === 'detailed-list'">
106+
<div class="px5 pt24 of-auto h-screen" flex="~ col gap-4">
107+
<template v-for="chunk of searched" :key="chunk.id">
108+
<DataChunkDetails
109+
border="~ base rounded-lg"
110+
p3
111+
:chunk="chunk"
112+
:chunks="searched!"
113+
:session="session"
114+
/>
115+
</template>
116+
</div>
117+
</template>
118+
<template v-else-if="settings.chunkViewType === 'graph'">
119+
<ChunksGraph
120+
:session="session"
121+
:chunks="searched"
122+
/>
123+
</template>
124+
</div>
96125
</div>
97126
</template>

0 commit comments

Comments
 (0)