|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { RolldownPluginBuildMetrics, SessionContext } from '~~/shared/types/data' |
| 3 | +import type { FilterMatchRule } from '~/utils/icon' |
| 4 | +import { useCycleList } from '@vueuse/core' |
| 5 | +import { Menu as VMenu } from 'floating-vue' |
| 6 | +import { computed, ref } from 'vue' |
| 7 | +import { settings } from '~~/app/state/settings' |
| 8 | +import { parseReadablePath } from '~/utils/filepath' |
| 9 | +import { getFileTypeFromModuleId, ModuleTypeRules } from '~/utils/icon' |
| 10 | +
|
| 11 | +const props = defineProps<{ |
| 12 | + session: SessionContext |
| 13 | + buildMetrics: RolldownPluginBuildMetrics |
| 14 | + selectedFields: string[] |
| 15 | +}>() |
| 16 | +
|
| 17 | +const HOOK_NAME_MAP = { |
| 18 | + resolve: 'Resolve Id', |
| 19 | + load: 'Load', |
| 20 | + transform: 'Transform', |
| 21 | +} |
| 22 | +
|
| 23 | +const parsedPaths = computed(() => props.session.modulesList.map((mod) => { |
| 24 | + const path = parseReadablePath(mod.id, props.session.meta.cwd) |
| 25 | + const type = getFileTypeFromModuleId(mod.id) |
| 26 | + return { |
| 27 | + mod, |
| 28 | + path, |
| 29 | + type, |
| 30 | + } |
| 31 | +})) |
| 32 | +
|
| 33 | +const searchFilterTypes = computed(() => ModuleTypeRules.filter(rule => parsedPaths.value.some(mod => rule.match.test(mod.mod.id)))) |
| 34 | +
|
| 35 | +const filterModuleTypes = ref<string[]>(settings.value.pluginDetailsModuleTypes ?? searchFilterTypes.value.map(i => i.name)) |
| 36 | +const { state: durationSortType, next } = useCycleList(['', 'desc', 'asc'], { |
| 37 | + initialValue: settings.value.pluginDetailsDurationSortType, |
| 38 | +}) |
| 39 | +const filtered = computed(() => { |
| 40 | + const sorted = durationSortType.value |
| 41 | + ? [...props.buildMetrics.calls].sort((a, b) => { |
| 42 | + if (durationSortType.value === 'asc') { |
| 43 | + return a.duration - b.duration |
| 44 | + } |
| 45 | + return b.duration - a.duration |
| 46 | + }) |
| 47 | + : props.buildMetrics.calls |
| 48 | + return sorted.filter((i) => { |
| 49 | + const matched = getFileTypeFromModuleId(i.module) |
| 50 | + return filterModuleTypes.value.includes(matched.name) |
| 51 | + }).filter(settings.value.pluginDetailSelectedHook ? i => i.type === settings.value.pluginDetailSelectedHook : Boolean) |
| 52 | +}) |
| 53 | +
|
| 54 | +function toggleModuleType(rule: FilterMatchRule) { |
| 55 | + if (filterModuleTypes.value?.includes(rule.name)) { |
| 56 | + filterModuleTypes.value = filterModuleTypes.value?.filter(t => t !== rule.name) |
| 57 | + } |
| 58 | + else { |
| 59 | + filterModuleTypes.value?.push(rule.name) |
| 60 | + } |
| 61 | + settings.value.pluginDetailsModuleTypes = filterModuleTypes.value |
| 62 | +} |
| 63 | +
|
| 64 | +function normalizeTimestamp(timestamp: number) { |
| 65 | + return new Date(timestamp).toLocaleString(undefined, { |
| 66 | + hour12: false, |
| 67 | + year: 'numeric', |
| 68 | + month: '2-digit', |
| 69 | + day: '2-digit', |
| 70 | + hour: '2-digit', |
| 71 | + minute: '2-digit', |
| 72 | + second: '2-digit', |
| 73 | + fractionalSecondDigits: 3, |
| 74 | + }) |
| 75 | +} |
| 76 | +
|
| 77 | +function toggleDurationSortType() { |
| 78 | + next() |
| 79 | + settings.value.pluginDetailsDurationSortType = durationSortType.value |
| 80 | +} |
| 81 | +</script> |
| 82 | + |
| 83 | +<template> |
| 84 | + <table w-full border-separate border-spacing-0> |
| 85 | + <thead border="b base"> |
| 86 | + <tr px2 class="[&_th]:(sticky top-0 z10 border-b border-base)"> |
| 87 | + <th v-if="selectedFields.includes('hookName')" bg-base w32 ws-nowrap p1 text-center font-600> |
| 88 | + Hook name |
| 89 | + </th> |
| 90 | + <th v-if="selectedFields.includes('module')" bg-base min-w100 ws-nowrap p1 text-left font-600> |
| 91 | + <button flex="~ row gap1 items-center" w-full> |
| 92 | + Module |
| 93 | + <VMenu> |
| 94 | + <span w-6 h-6 rounded-full cursor-pointer hover="bg-active" flex="~ items-center justify-center"> |
| 95 | + <i text-xs class="i-carbon-filter" :class="filterModuleTypes.length !== searchFilterTypes.length ? 'text-primary op100' : 'op50'" /> |
| 96 | + </span> |
| 97 | + <template #popper> |
| 98 | + <div class="p2" flex="~ col gap2"> |
| 99 | + <label |
| 100 | + v-for="rule of searchFilterTypes" |
| 101 | + :key="rule.name" |
| 102 | + border="~ base rounded-md" px2 py1 |
| 103 | + flex="~ items-center gap-1" |
| 104 | + select-none |
| 105 | + :title="rule.description" |
| 106 | + class="cursor-pointer module-type-filter" |
| 107 | + > |
| 108 | + <input |
| 109 | + type="checkbox" |
| 110 | + mr1 |
| 111 | + :checked="filterModuleTypes?.includes(rule.name)" |
| 112 | + @change="toggleModuleType(rule)" |
| 113 | + > |
| 114 | + <div :class="rule.icon" icon-catppuccin /> |
| 115 | + <div text-sm>{{ rule.description || rule.name }}</div> |
| 116 | + </label> |
| 117 | + </div> |
| 118 | + </template> |
| 119 | + </VMenu> |
| 120 | + </button> |
| 121 | + </th> |
| 122 | + <th v-if="selectedFields.includes('startTime')" rounded-tr-2 bg-base ws-nowrap p1 text-center font-600> |
| 123 | + Start Time |
| 124 | + </th> |
| 125 | + <th v-if="selectedFields.includes('endTime')" rounded-tr-2 bg-base ws-nowrap p1 text-center font-600> |
| 126 | + End Time |
| 127 | + </th> |
| 128 | + <th v-if="selectedFields.includes('duration')" rounded-tr-2 bg-base ws-nowrap p1 text-center font-600> |
| 129 | + <button flex="~ row gap1 items-center justify-center" w-full @click="toggleDurationSortType"> |
| 130 | + Duration |
| 131 | + <span w-6 h-6 rounded-full cursor-pointer hover="bg-active" flex="~ items-center justify-center"> |
| 132 | + <i text-xs :class="[durationSortType !== 'asc' ? 'i-carbon-arrow-down' : 'i-carbon-arrow-up', durationSortType ? 'op100 text-primary' : 'op50']" /> |
| 133 | + </span> |
| 134 | + </button> |
| 135 | + </th> |
| 136 | + </tr> |
| 137 | + </thead> |
| 138 | + <tbody v-if="filtered.length"> |
| 139 | + <tr v-for="(item, index) in filtered" :key="item.id" class="[&_td]:(border-base border-b-1 border-dashed)" :class="[index === filtered.length - 1 ? '[&_td]:(border-b-0)' : '']"> |
| 140 | + <td v-if="selectedFields.includes('hookName')" w32 ws-nowrap text-center text-sm op80> |
| 141 | + {{ HOOK_NAME_MAP[item.type] }} |
| 142 | + </td> |
| 143 | + <td v-if="selectedFields.includes('module')" min-w100 text-left text-ellipsis line-clamp-2> |
| 144 | + <DisplayModuleId |
| 145 | + :id="item.module" |
| 146 | + w-full border-none |
| 147 | + :session="session" |
| 148 | + :link="`/session/${session.id}/graph?module=${item.module}`" |
| 149 | + hover="bg-active" |
| 150 | + border="~ base rounded" block px2 py1 |
| 151 | + /> |
| 152 | + </td> |
| 153 | + <td v-if="selectedFields.includes('startTime')" text-center font-mono text-sm min-w52 op80> |
| 154 | + <time v-if="item.timestamp_start" :datetime="new Date(item.timestamp_start).toISOString()">{{ normalizeTimestamp(item.timestamp_start) }}</time> |
| 155 | + </td> |
| 156 | + <td v-if="selectedFields.includes('endTime')" text-center font-mono text-sm min-w52 op80> |
| 157 | + <time v-if="item.timestamp_end" :datetime="new Date(item.timestamp_end).toISOString()">{{ normalizeTimestamp(item.timestamp_end) }}</time> |
| 158 | + </td> |
| 159 | + <td v-if="selectedFields.includes('duration')" text-center text-sm> |
| 160 | + <DisplayDuration :duration="item.duration" /> |
| 161 | + </td> |
| 162 | + </tr> |
| 163 | + </tbody> |
| 164 | + <tbody v-else> |
| 165 | + <tr> |
| 166 | + <td :colspan="selectedFields.length" p4> |
| 167 | + <div w-full h-48 flex="~ items-center justify-center" op50 italic> |
| 168 | + No data |
| 169 | + </div> |
| 170 | + </td> |
| 171 | + </tr> |
| 172 | + </tbody> |
| 173 | + </table> |
| 174 | +</template> |
0 commit comments