88 lines
3.4 KiB
Vue
88 lines
3.4 KiB
Vue
<script setup lang="ts">
|
||
import { ChevronRight, FileMinus2, FilePen, FilePlus2, FileSymlink } from "@lucide/vue";
|
||
import { createReusableTemplate } from "@vueuse/core";
|
||
import { computed } from "vue";
|
||
|
||
import { Button } from "@/components/ui/button";
|
||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
||
|
||
import { fileStatusLabel } from "./changed-files";
|
||
import { fileTree, type FileNode } from "./file-tree";
|
||
import type { Capture } from "./task-run";
|
||
|
||
/**
|
||
* One capture's files as a folder tree. The counts beside a path are the
|
||
* diffstat the daemon recorded at the producer, not a reading of the file on
|
||
* disk now.
|
||
*/
|
||
const props = defineProps<{ capture: Capture }>();
|
||
|
||
const files = computed(() => props.capture.files || []);
|
||
const tree = computed(() => fileTree(files.value));
|
||
const total = computed(
|
||
() => Number(props.capture.totals?.files) || files.value.length,
|
||
);
|
||
|
||
const ICONS: Record<string, typeof FilePen> = {
|
||
added: FilePlus2,
|
||
deleted: FileMinus2,
|
||
renamed: FileSymlink,
|
||
};
|
||
const TONES: Record<string, string> = {
|
||
added: "text-ok",
|
||
deleted: "text-danger",
|
||
};
|
||
|
||
const [DefineNode, ReuseNode] = createReusableTemplate<{ node: FileNode }>();
|
||
</script>
|
||
|
||
<template>
|
||
<p v-if="!files.length" class="py-3 text-xs text-fg-muted">No file entries recorded{{
|
||
total
|
||
? ` (diffstat covers ${total} file${total === 1 ? "" : "s"})`
|
||
: ""
|
||
}}.</p>
|
||
<template v-else>
|
||
<DefineNode v-slot="{ node }">
|
||
<Collapsible v-if="!node.file" default-open>
|
||
<CollapsibleTrigger as-child>
|
||
<Button variant="ghost" size="sm" class="w-full justify-start font-mono text-label font-normal aria-expanded:bg-transparent aria-expanded:hover:bg-muted dark:aria-expanded:hover:bg-muted/50">
|
||
<ChevronRight class="transition-transform group-data-[state=open]/button:rotate-90" />
|
||
{{ node.name }}
|
||
</Button>
|
||
</CollapsibleTrigger>
|
||
<CollapsibleContent>
|
||
<div class="ml-4 flex flex-col border-l border-border pl-1">
|
||
<ReuseNode v-for="child in node.children" :key="child.path" :node="child" />
|
||
</div>
|
||
</CollapsibleContent>
|
||
</Collapsible>
|
||
<div
|
||
v-else
|
||
class="flex min-h-8 items-center gap-2 px-2.5 py-1 font-mono text-label"
|
||
:title="fileStatusLabel(node.file.status)"
|
||
>
|
||
<component
|
||
:is="ICONS[node.file.status ?? ''] ?? FilePen"
|
||
class="size-4 shrink-0"
|
||
:class="TONES[node.file.status ?? ''] ?? 'text-fg-muted'"
|
||
:aria-label="fileStatusLabel(node.file.status)"
|
||
/>
|
||
<span class="min-w-0 flex-1 break-all">
|
||
<span v-if="node.file.old_path" class="text-fg-muted">{{ node.file.old_path }} → </span>{{ node.name }}
|
||
<!-- binary means "no textual hunks were recorded", not "this is a
|
||
binary file on disk": the counts beside it are still real. -->
|
||
<span v-if="node.file.binary" class="ml-1 text-xs text-fg-muted">no textual hunks</span>
|
||
</span>
|
||
<span class="shrink-0 whitespace-nowrap">
|
||
<span v-if="node.file.additions" class="text-ok">+{{ node.file.additions }}</span>
|
||
<span v-if="node.file.deletions" class="ml-1.5 text-danger">−{{ node.file.deletions }}</span>
|
||
</span>
|
||
</div>
|
||
</DefineNode>
|
||
<div class="flex flex-col py-1">
|
||
<ReuseNode v-for="node in tree" :key="node.path" :node="node" />
|
||
</div>
|
||
</template>
|
||
</template>
|