fix(ui): clean dependencies and add task table sorting
This commit is contained in:
1 parent
11a3560346
commit
d5f0853676
11 files changed
+317
-5588
No files matched your search
@@ -0,0 +1,96 @@
|
||||
/* Local helpers for the vendored shadcn components. */
|
||||
@theme inline {
|
||||
@keyframes accordion-down {
|
||||
from {
|
||||
height: 0;
|
||||
}
|
||||
to {
|
||||
height: var(
|
||||
--reka-accordion-content-height,
|
||||
var(--accordion-panel-height, auto)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes accordion-up {
|
||||
from {
|
||||
height: var(
|
||||
--reka-accordion-content-height,
|
||||
var(--accordion-panel-height, auto)
|
||||
);
|
||||
}
|
||||
to {
|
||||
height: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Custom variants */
|
||||
@custom-variant data-open {
|
||||
&:where([data-state="open"]),
|
||||
&:where([data-open]:not([data-open="false"])) {
|
||||
@slot;
|
||||
}
|
||||
}
|
||||
|
||||
@custom-variant data-closed {
|
||||
&:where([data-state="closed"]),
|
||||
&:where([data-closed]:not([data-closed="false"])) {
|
||||
@slot;
|
||||
}
|
||||
}
|
||||
|
||||
@custom-variant data-checked {
|
||||
&:where([data-state="checked"]),
|
||||
&:where([data-checked]:not([data-checked="false"])) {
|
||||
@slot;
|
||||
}
|
||||
}
|
||||
|
||||
@custom-variant data-unchecked {
|
||||
&:where([data-state="unchecked"]),
|
||||
&:where([data-unchecked]:not([data-unchecked="false"])) {
|
||||
@slot;
|
||||
}
|
||||
}
|
||||
|
||||
@custom-variant data-selected {
|
||||
&:where([data-selected="true"]) {
|
||||
@slot;
|
||||
}
|
||||
}
|
||||
|
||||
@custom-variant data-disabled {
|
||||
&:where([data-disabled="true"]),
|
||||
&:where([data-disabled]:not([data-disabled="false"])) {
|
||||
@slot;
|
||||
}
|
||||
}
|
||||
|
||||
@custom-variant data-active {
|
||||
&:where([data-state="active"]),
|
||||
&:where([data-active]:not([data-active="false"])) {
|
||||
@slot;
|
||||
}
|
||||
}
|
||||
|
||||
@custom-variant data-horizontal {
|
||||
&:where([data-orientation="horizontal"]) {
|
||||
@slot;
|
||||
}
|
||||
}
|
||||
|
||||
@custom-variant data-vertical {
|
||||
&:where([data-orientation="vertical"]) {
|
||||
@slot;
|
||||
}
|
||||
}
|
||||
|
||||
@utility no-scrollbar {
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
@import "shadcn-vue/tailwind.css";
|
||||
@import "./shadcn.css";
|
||||
|
||||
/* ui/dist is committed, so nothing ignores it and Tailwind's automatic content
|
||||
detection scans it. That makes every build an input to the next one: class
|
||||
|
||||
+81
-17
@@ -1,5 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { ArrowDown, ArrowUp, ArrowUpDown } from "@lucide/vue";
|
||||
import {
|
||||
createColumnHelper,
|
||||
createSortedRowModel,
|
||||
rowSortingFeature,
|
||||
sortFn_basic,
|
||||
sortFn_text,
|
||||
tableFeatures,
|
||||
useTable,
|
||||
} from "@tanstack/vue-table";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
import {
|
||||
Table,
|
||||
@@ -11,12 +22,6 @@ import {
|
||||
} from "@/components/ui/table";
|
||||
import TaskRow, { type Task } from "./TaskRow.vue";
|
||||
|
||||
/**
|
||||
* The board. It renders the rows it is given and nothing else: which rows are
|
||||
* visible, and which state stands in when none are, are the page's decisions.
|
||||
* The `state` slot is drawn in the body's place so the columns stay announced
|
||||
* while the table has no rows to show.
|
||||
*/
|
||||
const props = withDefaults(
|
||||
defineProps<{ tasks: Task[]; showRepo?: boolean }>(),
|
||||
{ showRepo: true },
|
||||
@@ -24,6 +29,56 @@ const props = withDefaults(
|
||||
|
||||
const emit = defineEmits<{ done: [taskId: Task["id"]] }>();
|
||||
|
||||
const features = tableFeatures({
|
||||
rowSortingFeature,
|
||||
sortedRowModel: createSortedRowModel(),
|
||||
sortFns: { text: sortFn_text, basic: sortFn_basic },
|
||||
});
|
||||
const columnHelper = createColumnHelper<typeof features, Task>();
|
||||
const table = useTable({
|
||||
features,
|
||||
get data() {
|
||||
return props.tasks;
|
||||
},
|
||||
getRowId: (task: Task) => String(task.id),
|
||||
columns: columnHelper.columns([
|
||||
columnHelper.accessor((task) => `${task.owner ?? ""}/${task.repo ?? ""}`, {
|
||||
id: "repo",
|
||||
header: "Repo",
|
||||
sortFn: "text",
|
||||
}),
|
||||
columnHelper.accessor((task) => task.issue_number ?? 0, {
|
||||
id: "issue",
|
||||
header: "Issue",
|
||||
sortFn: "basic",
|
||||
}),
|
||||
columnHelper.accessor((task) => task.title ?? "untitled task", {
|
||||
id: "title",
|
||||
header: "Title",
|
||||
sortFn: "text",
|
||||
}),
|
||||
columnHelper.accessor((task) => task.status ?? "", {
|
||||
id: "status",
|
||||
header: "Status",
|
||||
sortFn: "text",
|
||||
}),
|
||||
columnHelper.accessor((task) => task.workflow ?? "", {
|
||||
id: "workflow",
|
||||
header: "Workflow",
|
||||
sortFn: "text",
|
||||
}),
|
||||
columnHelper.accessor((task) => Date.parse(task.updated_at ?? "") || 0, {
|
||||
id: "activity",
|
||||
header: "Last activity",
|
||||
sortFn: "basic",
|
||||
}),
|
||||
]),
|
||||
});
|
||||
const headers = computed(() =>
|
||||
table.getAllColumns().filter((column) => props.showRepo || column.id !== "repo"),
|
||||
);
|
||||
// shortcut: sorting covers loaded rows; use server sorting if all pages must be ordered.
|
||||
const rows = computed(() => table.getRowModel().rows);
|
||||
const columns = computed(() => (props.showRepo ? 7 : 6));
|
||||
</script>
|
||||
|
||||
@@ -31,14 +86,23 @@ const columns = computed(() => (props.showRepo ? 7 : 6));
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead v-if="props.showRepo">Repo</TableHead>
|
||||
<TableHead>Issue</TableHead>
|
||||
<!-- Title takes the slack: it is the only column that distinguishes one
|
||||
row from another, so it should be the one that grows. -->
|
||||
<TableHead class="w-full">Title</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead>Workflow</TableHead>
|
||||
<TableHead>Last activity</TableHead>
|
||||
<TableHead
|
||||
v-for="column in headers"
|
||||
:key="column.id"
|
||||
:class="column.id === 'title' ? 'w-full' : undefined"
|
||||
:aria-sort="
|
||||
column.getIsSorted() === 'asc' ? 'ascending' :
|
||||
column.getIsSorted() === 'desc' ? 'descending' : 'none'
|
||||
"
|
||||
>
|
||||
<Button variant="ghost" size="sm" @click="column.toggleSorting()">
|
||||
{{ column.columnDef.header }}
|
||||
<component
|
||||
:is="column.getIsSorted() === 'asc' ? ArrowUp : column.getIsSorted() === 'desc' ? ArrowDown : ArrowUpDown"
|
||||
data-icon="inline-end"
|
||||
/>
|
||||
</Button>
|
||||
</TableHead>
|
||||
<TableHead>Action</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
@@ -50,9 +114,9 @@ const columns = computed(() => (props.showRepo ? 7 : 6));
|
||||
</TableRow>
|
||||
<template v-else>
|
||||
<TaskRow
|
||||
v-for="task in props.tasks"
|
||||
:key="task.id"
|
||||
:task="task"
|
||||
v-for="row in rows"
|
||||
:key="row.id"
|
||||
:task="row.original"
|
||||
:show-repo="props.showRepo"
|
||||
@done="emit('done', $event)"
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user