diff --git a/apps/client/src/widgets/view_widgets/table_view/formatters.ts b/apps/client/src/widgets/view_widgets/table_view/formatters.ts index 8276bcdc4..68e529798 100644 --- a/apps/client/src/widgets/view_widgets/table_view/formatters.ts +++ b/apps/client/src/widgets/view_widgets/table_view/formatters.ts @@ -6,36 +6,40 @@ import { loadReferenceLinkTitle } from "../../../services/link.js"; * * The value of the cell must be the note ID. */ -export function NoteFormatter(cell: CellComponent, formatterParams, onRendered) { +export function NoteFormatter(cell: CellComponent, _formatterParams, onRendered) { let noteId = cell.getValue(); if (!noteId) { return ""; } onRendered(async () => { - const $noteRef = $(""); - const href = `#root/${noteId}`; - $noteRef.addClass("reference-link"); - $noteRef.attr("data-href", href); - + const { $noteRef, href } = buildNoteLink(noteId); await loadReferenceLinkTitle($noteRef, href); cell.getElement().appendChild($noteRef[0]); }); return ""; } -export function NoteTitleFormatter(cell: CellComponent, formatterParams, onRendered) { +/** + * Custom formatter for the note title that is quite similar to {@link NoteFormatter}, but where the title and icons are read from separate fields. + */ +export function NoteTitleFormatter(cell: CellComponent) { const { noteId, iconClass } = cell.getRow().getData(); if (!noteId) { return ""; } - const $noteRef = $(""); - const href = `#root/${noteId}`; - $noteRef.addClass("reference-link"); - $noteRef.attr("data-href", href); + const { $noteRef } = buildNoteLink(noteId); $noteRef.text(cell.getValue()); $noteRef.prepend($("").addClass(iconClass)); return $noteRef[0].outerHTML; } + +function buildNoteLink(noteId: string) { + const $noteRef = $(""); + const href = `#root/${noteId}`; + $noteRef.addClass("reference-link"); + $noteRef.attr("data-href", href); + return { $noteRef, href }; +}