fix(view/table): most type errors

This commit is contained in:
Elian Doran 2025-07-01 12:09:13 +03:00
parent 84db4ed57c
commit 2cbb49681a
No known key found for this signature in database
7 changed files with 34 additions and 17 deletions

View File

@ -34,7 +34,8 @@ export const byNoteType: Record<Exclude<NoteType, "book">, string | null> = {
export const byBookType: Record<ViewTypeOptions, string | null> = { export const byBookType: Record<ViewTypeOptions, string | null> = {
list: null, list: null,
grid: null, grid: null,
calendar: "xWbu3jpNWapp" calendar: "xWbu3jpNWapp",
table: null
}; };
export default class ContextualHelpButton extends NoteContextAwareWidget { export default class ContextualHelpButton extends NoteContextAwareWidget {

View File

@ -65,7 +65,13 @@ export default class SearchResultWidget extends NoteContextAwareWidget {
return; return;
} }
const noteListRenderer = new NoteListRenderer(this.$content, note, note.getChildNoteIds(), true); // this.$content, note, note.getChildNoteIds(), true
const noteListRenderer = new NoteListRenderer({
$parent: this.$content,
parentNote: note,
noteIds: note.getChildNoteIds(),
showNotePath: true
});
await noteListRenderer.renderList(); await noteListRenderer.renderList();
} }

View File

@ -4,6 +4,7 @@ import type { ColumnDefinition } from "tabulator-tables";
import link from "../../../services/link.js"; import link from "../../../services/link.js";
export type TableData = { export type TableData = {
iconClass: string;
noteId: string; noteId: string;
title: string; title: string;
labels: Record<string, boolean | string | null>; labels: Record<string, boolean | string | null>;
@ -120,7 +121,7 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
} }
export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], infos: PromotedAttributeInformation[]) { export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], infos: PromotedAttributeInformation[]) {
const definitions: GridOptions<TableData>["rowData"] = []; const definitions: TableData[] = [];
for (const branch of parentNote.getChildBranches()) { for (const branch of parentNote.getChildBranches()) {
const note = await branch.getNote(); const note = await branch.getNote();
if (!note) { if (!note) {

View File

@ -8,10 +8,10 @@ export default function applyHeaderCustomization(baseEl: HTMLElement, api: GridA
return; return;
} }
header.addEventListener("contextmenu", (e) => { header.addEventListener("contextmenu", (_e) => {
const e = _e as MouseEvent;
e.preventDefault(); e.preventDefault();
contextMenu.show({ contextMenu.show({
items: [ items: [
{ {

View File

@ -1,16 +1,17 @@
import type { CellComponent, MenuObject, Tabulator } from "tabulator-tables";
export function applyHeaderMenu(columns) { export function applyHeaderMenu(columns) {
//apply header menu to each column //apply header menu to each column
for(let column of columns){ for (let column of columns) {
column.headerMenu = headerMenu; column.headerMenu = headerMenu;
} }
} }
function headerMenu(){ function headerMenu(this: Tabulator) {
var menu = []; const menu: MenuObject<CellComponent>[] = [];
var columns = this.getColumns(); const columns = this.getColumns();
for(let column of columns){
for (let column of columns) {
//create checkbox element using font awesome icons //create checkbox element using font awesome icons
let icon = document.createElement("i"); let icon = document.createElement("i");
icon.classList.add("bx"); icon.classList.add("bx");
@ -27,8 +28,8 @@ function headerMenu(){
//create menu item //create menu item
menu.push({ menu.push({
label:label, label: label,
action:function(e){ action: function (e) {
//prevent menu closing //prevent menu closing
e.stopPropagation(); e.stopPropagation();
@ -36,10 +37,10 @@ function headerMenu(){
column.toggle(); column.toggle();
//change menu item icon //change menu item icon
if(column.isVisible()){ if (column.isVisible()) {
icon.classList.remove("bx-empty"); icon.classList.remove("bx-empty");
icon.classList.add("bx-check"); icon.classList.add("bx-check");
}else{ } else {
icon.classList.remove("bx-check"); icon.classList.remove("bx-check");
icon.classList.add("bx-empty"); icon.classList.add("bx-empty");
} }
@ -47,5 +48,5 @@ function headerMenu(){
}); });
} }
return menu; return menu;
}; };

View File

@ -224,12 +224,20 @@ export default class TableView extends ViewMode<StateInfo> {
} }
#manageColumnUpdate() { #manageColumnUpdate() {
if (!this.api) {
return;
}
const info = getPromotedAttributeInformation(this.parentNote); const info = getPromotedAttributeInformation(this.parentNote);
const columnDefs = buildColumnDefinitions(info); const columnDefs = buildColumnDefinitions(info);
this.api.setColumns(columnDefs); this.api.setColumns(columnDefs);
} }
async #manageRowsUpdate() { async #manageRowsUpdate() {
if (!this.api) {
return;
}
const notes = await froca.getNotes(this.args.noteIds); const notes = await froca.getNotes(this.args.noteIds);
const info = getPromotedAttributeInformation(this.parentNote); const info = getPromotedAttributeInformation(this.parentNote);
this.api.setData(await buildRowDefinitions(this.parentNote, notes, info)); this.api.setData(await buildRowDefinitions(this.parentNote, notes, info));

View File

@ -7,7 +7,7 @@ import ViewModeStorage from "./view_mode_storage.js";
export interface ViewModeArgs { export interface ViewModeArgs {
$parent: JQuery<HTMLElement>; $parent: JQuery<HTMLElement>;
parentNote: FNote; parentNote: FNote;
parentNotePath: string | null | undefined; parentNotePath?: string | null;
noteIds: string[]; noteIds: string[];
showNotePath?: boolean; showNotePath?: boolean;
} }