fix(views/table): relation display sometimes not showing up

This commit is contained in:
Elian Doran 2025-07-17 22:31:48 +03:00
parent 6fe5a854a7
commit 1298b968f2
No known key found for this signature in database
4 changed files with 49 additions and 14 deletions

View File

@ -405,7 +405,7 @@ function linkContextMenu(e: PointerEvent) {
linkContextMenuService.openContextMenu(notePath, e, viewScope, null);
}
export async function loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string | null | undefined = null) {
async function loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string | null | undefined = null) {
const $link = $el[0].tagName === "A" ? $el : $el.find("a");
href = href || $link.attr("href");

View File

@ -67,7 +67,6 @@ export function buildColumnDefinitions(info: AttributeDefinitionInformation[], m
width: 400
}
];
console.log("Log ", rowNumberHint, columnDefs[0].width);
const seenFields = new Set<string>();
for (const { name, title, type } of info) {

View File

@ -1,5 +1,6 @@
import { CellComponent } from "tabulator-tables";
import { loadReferenceLinkTitle } from "../../../services/link.js";
import froca from "../../../services/froca.js";
import FNote from "../../../entities/fnote.js";
/**
* Custom formatter to represent a note, with the icon and note title being rendered.
@ -12,11 +13,39 @@ export function NoteFormatter(cell: CellComponent, _formatterParams, onRendered)
return "";
}
onRendered(async () => {
const { $noteRef, href } = buildNoteLink(noteId);
await loadReferenceLinkTitle($noteRef, href);
cell.getElement().appendChild($noteRef[0]);
});
function buildLink(note: FNote | undefined) {
if (!note) {
return;
}
const iconClass = note.getIcon();
const title = note.title;
const { $noteRef } = buildNoteLink(noteId);
$noteRef.text(title);
$noteRef.prepend($("<span>").addClass(iconClass));
return $noteRef[0];
}
const cachedNote = froca.getNoteFromCache(noteId);
if (cachedNote) {
// Cache hit, build the link immediately
const el = buildLink(cachedNote);
return el?.outerHTML;
} else {
// Cache miss, load the note asynchronously
onRendered(async () => {
const note = await froca.getNote(noteId);
if (!note) {
return;
}
const el = buildLink(note);
if (el) {
cell.getElement().appendChild(el);
}
});
}
return "";
}

View File

@ -21,23 +21,30 @@ export function RelationEditor(cell: CellComponent, onRendered, success, cancel,
editor.style.boxSizing = "border-box";
//Set value of editor to the current value of the cell
const noteId = cell.getValue();
if (noteId) {
const note = froca.getNoteFromCache(noteId);
const originalNoteId = cell.getValue();
if (originalNoteId) {
const note = froca.getNoteFromCache(originalNoteId);
editor.value = note.title;
} else {
editor.value = "";
}
//set focus on the select box when the editor is selected
onRendered(function(){
let noteId = "";
let newNoteId = originalNoteId;
note_autocomplete.initNoteAutocomplete($editor, {
allowCreatingNotes: true,
hideAllButtons: true
}).on("autocomplete:noteselected", (event, suggestion, dataset) => {
const notePath = suggestion.notePath;
noteId = (notePath ?? "").split("/").at(-1);
}).on("blur", () => success(noteId));
newNoteId = (notePath ?? "").split("/").at(-1);
}).on("blur", () => {
if (!editor.value) {
newNoteId = "";
}
success(newNoteId);
});
editor.focus();
});