Give kanban columns a header menu, new groups and reordering
CI / go (Server) (push) Failing after 29m45s
CI / go (Media) (push) Canceled after 0s
CI / go (Web-App) (push) Canceled after 2s
CI / frontend (push) Failing after 12m56s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / mobile (push) Canceled after 0s
CI / docker (push) Canceled after 0s
CI / desktop (ubuntu-latest) (push) Failing after 3h2m54s

Each column shows a coloured dot, its count, and on hover a menu to
rename, recolour or delete the choice, plus a button that adds a card at
the top. A last column adds a new choice, and dragging a column by its
header reorders the choices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tajniak81andClaude Opus 5.5 committed 2026-11-17 14:20:03 +01:00
1 parent 94b5eb7278
commit 30c2d82f26
8 files changed
+236 -18

No files matched your search

+4
View File
@@ -195,6 +195,10 @@ export const englishDatabaseLabels = {
optionColor: "Colour",
deleteOption: "Delete choice",
renameOption: "Rename choice",
groupMenu: "Group options",
newGroup: "New group",
newGroupPlaceholder: "Name the group",
deleteGroupConfirm: "Delete the choice “{n}”? Its cards move to No value.",
searchPeople: "Find a person",
noPeople: "Nobody found",
upload: "Upload a file",
+146 -11
View File
@@ -6,6 +6,7 @@
import type { IconName } from "@docwell/ui/icons";
import { openBlockMenu, type BlockAction } from "../blockmenu";
import { palette } from "../colors";
import { editCell, inlineTypes, readOnlyTypes, renderCell, typeIcons, type DbContext } from "./cells";
import { formatDelimited, fromCSV, matchHeader, parseCell, parseDelimited, toCSV } from "./csv";
import { closePopover, download, h, icon, iconButton, pickFile, popover, textInput } from "./dom";
@@ -27,6 +28,8 @@ import {
isoDay,
monthGrid,
moveToGroup,
newId,
nextColor,
niceMax,
timelineScale,
timelineScales,
@@ -41,6 +44,7 @@ import {
type Group,
type ChartPoint,
type Row,
type SelectOption,
type TimelineScale,
type View,
type ViewType,
@@ -466,7 +470,7 @@ export class DatabaseView {
});
}
private addRow(cells: Record<string, unknown> = {}, open = false) {
private addRow(cells: Record<string, unknown> = {}, open = false, at?: number) {
const store = this.host.store;
if (!store) return;
const v = this.view;
@@ -478,7 +482,7 @@ export class DatabaseView {
if (f.op === "contains" && col.type === "multiSelect" && f.value) cells[col.id] = [f.value];
if (f.op === "checked") cells[col.id] = true;
}
const id = store.addRow(cells);
const id = store.addRow(cells, at);
if (open || v.type !== "table") this.openRow(id);
else {
this.sel = { row: id, col: titleColumn(this.db).id };
@@ -1144,17 +1148,40 @@ export class DatabaseView {
}
});
};
// Choices of a select can be renamed, recoloured, reordered and added from the board.
const choices = this.editable && (col.type === "select" || col.type === "multiSelect");
const blank: Row = { id: "", cells: {}, createdAt: 0, createdBy: null };
const cellsFor = (key: string) => (key || col.type === "checkbox" ? { [col.id]: moveToGroup(blank, col, "", key, people) } : {});
for (const g of groups) {
if (!g.key && !g.rows.length && col.type !== "checkbox" && (col.options?.length ?? 0) > 0) continue;
const list = h("div", { class: "dw-db-k__cards", dataset: { group: g.key } });
const option = col.options?.find((o) => o.id === g.key);
const head = h(
"div",
{ class: "dw-db-k__head" },
g.key && col.type !== "checkbox" && col.type !== "member" && col.type !== "createdBy"
? h("span", { class: "dw-db-tag", dataset: { color: g.color ?? "gray" } }, g.label)
: h("span", { class: "dw-db-k__label" }, g.label),
h("span", { class: "dw-db-t__count" }, String(g.rows.length)),
option
? h("span", { class: "dw-db-k__dot", dataset: { color: option.color }, "aria-hidden": "true" })
: col.type === "checkbox"
? h("span", { class: g.key === "true" ? "dw-db-check is-on" : "dw-db-check", "aria-hidden": "true" }, g.key === "true" ? icon("check", 12) : null)
: null,
h("span", { class: "dw-db-k__label", title: g.label }, g.label),
h("span", { class: "dw-db-k__count" }, String(g.rows.length)),
);
if (this.editable) {
const tools = h("span", { class: "dw-db-k__tools" });
if (choices && option) {
tools.append(iconButton("more", l.groupMenu, (e) => this.groupMenu(e.currentTarget as HTMLElement, col, option.id)));
}
// A card at the top of the column (where it stays unless the view sorts).
tools.append(
iconButton("plus", l.newRow, () => {
const store = this.host.store;
const at = g.rows.length && !v.sorts.length && store ? store.rowIndex(g.rows[0]!.id) : undefined;
this.addRow(cellsFor(g.key), true, at);
}),
);
head.append(tools);
}
for (const r of g.rows.slice(0, this.limit)) {
const card = h(
"div",
@@ -1206,10 +1233,7 @@ export class DatabaseView {
}
if (this.editable) {
const add = h("button", { type: "button", class: "dw-db-t__new" }, icon("plus", 14), h("span", {}, l.newRow));
add.addEventListener("click", () => {
const blank: Row = { id: "", cells: {}, createdAt: 0, createdBy: null };
this.addRow(g.key || col.type === "checkbox" ? { [col.id]: moveToGroup(blank, col, "", g.key, people) } : {}, true);
});
add.addEventListener("click", () => this.addRow(cellsFor(g.key), true));
list.append(add);
list.addEventListener("dragover", (e) => {
if (!e.dataTransfer?.types.includes("application/x-docwell-card")) return;
@@ -1230,11 +1254,122 @@ export class DatabaseView {
dropCard(row, from, g.key, (e.target as HTMLElement).closest<HTMLElement>(".dw-db-k__card")?.dataset.row);
});
}
board.append(h("section", { class: "dw-db-k__col", "aria-label": g.label }, head, list));
const section = h("section", { class: "dw-db-k__col", "aria-label": g.label, dataset: { group: g.key } }, head, list);
if (choices && option) this.reorderableGroup(section, head, col, option.id);
board.append(section);
}
if (choices) board.append(this.newGroupColumn(col));
this.body.replaceChildren(board);
}
/** Rename, recolour or delete the choice a kanban column stands for. */
private groupMenu(anchor: HTMLElement, col: Column, id: string) {
const l = this.labels;
const store = this.host.store;
const options = col.options ?? [];
const o = options.find((x) => x.id === id);
if (!store || !o) return;
const set = (patch: Partial<SelectOption>) => store.setOptions(col.id, options.map((x) => (x.id === id ? { ...x, ...patch } : x)));
openBlockMenu(
anchor,
[
{
id: "rename",
label: l.renameOption,
icon: "pencil",
run: () => {
const name = window.prompt(l.renameOption, o.name)?.trim();
if (name) set({ name });
},
},
{
id: "color",
label: l.optionColor,
icon: "palette",
children: palette.map((c) => ({
id: c,
label: this.host.colorNames[c] ?? c,
icon: c === o.color ? "check" : "drop",
run: () => set({ color: c }),
})),
},
{
id: "delete",
label: l.deleteOption,
icon: "trash",
danger: true,
run: () => {
// Its cards move to "No value"; the choice's id stays in their cells, unseen, like a choice deleted from a cell.
if (window.confirm(fill(l.deleteGroupConfirm, o.name))) store.setOptions(col.id, options.filter((x) => x.id !== id));
},
},
],
l.groupMenu,
);
}
/** A kanban column dragged by its header moves its choice, so the columns follow. */
private reorderableGroup(section: HTMLElement, head: HTMLElement, col: Column, id: string) {
const type = "application/x-docwell-group";
head.draggable = true;
head.addEventListener("dragstart", (e) => {
// A drag that starts on a button is not a column drag.
if ((e.target as HTMLElement).closest?.("button")) return;
e.dataTransfer?.setData(type, id);
if (e.dataTransfer) e.dataTransfer.effectAllowed = "move";
section.classList.add("is-dragging");
});
head.addEventListener("dragend", () => section.classList.remove("is-dragging"));
section.addEventListener("dragover", (e) => {
if (!e.dataTransfer?.types.includes(type)) return;
e.preventDefault();
section.classList.add("is-drop-col");
});
section.addEventListener("dragleave", (e) => {
if (!section.contains(e.relatedTarget as Node)) section.classList.remove("is-drop-col");
});
section.addEventListener("drop", (e) => {
section.classList.remove("is-drop-col");
const moved = e.dataTransfer?.getData(type);
const store = this.host.store;
if (!moved || moved === id || !store) return;
e.preventDefault();
const options = col.options ?? [];
const item = options.find((o) => o.id === moved);
if (!item) return;
const rest = options.filter((o) => o.id !== moved);
// Dropped on the right half: after this column; on the left half: before it.
const box = section.getBoundingClientRect();
const at = rest.findIndex((o) => o.id === id) + (e.clientX > box.left + box.width / 2 ? 1 : 0);
rest.splice(at, 0, item);
store.setOptions(col.id, rest);
});
}
/** The last kanban column: adds a choice, and with it a column. */
private newGroupColumn(col: Column): HTMLElement {
const l = this.labels;
const wrap = h("div", { class: "dw-db-k__add" });
const button = h("button", { type: "button", class: "dw-db-t__new" }, icon("plus", 14), h("span", {}, l.newGroup));
button.addEventListener("click", () => {
const input = textInput("", {
placeholder: l.newGroupPlaceholder,
onCommit: (value) => {
const name = value.trim();
const options = col.options ?? [];
if (name && this.host.store) {
this.host.store.setOptions(col.id, [...options, { id: newId(), name, color: nextColor(options) }]);
} else wrap.replaceChildren(button);
},
onCancel: () => wrap.replaceChildren(button),
});
wrap.replaceChildren(input);
input.focus();
});
wrap.append(button);
return wrap;
}
// ---------------------------------------------------------------- list and gallery
/**
+66 -7
View File
@@ -2203,29 +2203,88 @@
overflow-x: auto;
}
.dw-db-k__col {
flex: 0 0 260px;
flex: 0 0 272px;
display: flex;
flex-direction: column;
gap: 8px;
gap: 4px;
min-width: 0;
padding: 4px 6px 6px;
border-radius: var(--radius-md);
background: var(--color-surface-sunken);
}
.dw-db-k__col.is-dragging {
opacity: 0.4;
}
.dw-db-k__col.is-drop-col {
outline: 2px solid var(--color-accent);
outline-offset: -2px;
}
.dw-db-k__head {
display: flex;
align-items: center;
gap: 8px;
min-height: 24px;
gap: 6px;
min-height: 32px;
padding: 0 2px 0 6px;
font-size: 13px;
}
.dw-db-k__head[draggable="true"] {
cursor: grab;
}
.dw-db-k__dot {
flex: none;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--dw-c, var(--dw-c-gray));
}
.dw-db-k__label {
min-width: 0;
overflow: hidden;
font-weight: 600;
white-space: nowrap;
text-overflow: ellipsis;
}
.dw-db-k__count {
flex: none;
color: var(--color-ink-faint);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.dw-db-k__tools {
display: flex;
gap: 2px;
margin-left: auto;
opacity: 0;
transition: opacity 0.12s;
}
.dw-db-k__col:hover .dw-db-k__tools,
.dw-db-k__tools:focus-within {
opacity: 1;
}
@media (hover: none) {
.dw-db-k__tools {
opacity: 1;
}
}
.dw-db-k__tools .dw-db__btn {
min-height: 24px;
padding: 2px 4px;
color: var(--color-ink-muted);
}
.dw-db-k__cards {
display: flex;
flex-direction: column;
gap: 6px;
min-height: 48px;
padding: 4px;
border-radius: var(--radius-md);
background: var(--color-surface-sunken);
padding: 2px;
border-radius: var(--radius-sm);
}
.dw-db-k__add {
flex: 0 0 200px;
padding-top: 4px;
}
.dw-db-k__add .dw-db-input {
width: 100%;
}
.dw-db-k__cards.is-drop {
outline: 2px dashed var(--color-accent);
+4
View File
@@ -891,6 +891,10 @@
"optionColor": "Farbe",
"deleteOption": "Option löschen",
"renameOption": "Option umbenennen",
"groupMenu": "Gruppenoptionen",
"newGroup": "Neue Gruppe",
"newGroupPlaceholder": "Name der Gruppe",
"deleteGroupConfirm": "Option „{n}“ löschen? Ihre Karten wandern zu „Kein Wert“.",
"searchPeople": "Person suchen",
"noPeople": "Niemand gefunden",
"upload": "Datei hochladen",
+4
View File
@@ -891,6 +891,10 @@
"optionColor": "Colour",
"deleteOption": "Delete choice",
"renameOption": "Rename choice",
"groupMenu": "Group options",
"newGroup": "New group",
"newGroupPlaceholder": "Name the group",
"deleteGroupConfirm": "Delete the choice “{n}”? Its cards move to No value.",
"searchPeople": "Find a person",
"noPeople": "Nobody found",
"upload": "Upload a file",
+4
View File
@@ -891,6 +891,10 @@
"optionColor": "Color",
"deleteOption": "Eliminar opción",
"renameOption": "Cambiar nombre de la opción",
"groupMenu": "Opciones del grupo",
"newGroup": "Nuevo grupo",
"newGroupPlaceholder": "Nombre del grupo",
"deleteGroupConfirm": "¿Eliminar la opción «{n}»? Sus tarjetas pasan a «Sin valor».",
"searchPeople": "Buscar una persona",
"noPeople": "No se encontró a nadie",
"upload": "Subir un archivo",
+4
View File
@@ -891,6 +891,10 @@
"optionColor": "Couleur",
"deleteOption": "Supprimer l’option",
"renameOption": "Renommer l’option",
"groupMenu": "Options du groupe",
"newGroup": "Nouveau groupe",
"newGroupPlaceholder": "Nom du groupe",
"deleteGroupConfirm": "Supprimer l’option « {n} » ? Ses cartes passent dans « Aucune valeur ».",
"searchPeople": "Chercher une personne",
"noPeople": "Personne trouvée",
"upload": "Téléverser un fichier",
+4
View File
@@ -891,6 +891,10 @@
"optionColor": "Kolor",
"deleteOption": "Usuń opcję",
"renameOption": "Zmień nazwę opcji",
"groupMenu": "Opcje grupy",
"newGroup": "Nowa grupa",
"newGroupPlaceholder": "Nazwa grupy",
"deleteGroupConfirm": "Usunąć opcję „{n}”? Jej karty trafią do „Brak wartości”.",
"searchPeople": "Znajdź osobę",
"noPeople": "Nikogo nie znaleziono",
"upload": "Prześlij plik",