mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
refactor(book/table): make clear what kind of attribute is being changed
This commit is contained in:
parent
9e57c14130
commit
168e224d3e
@ -6,7 +6,8 @@ import { default as getPromotedAttributeInformation, type PromotedAttributeInfor
|
|||||||
export type TableData = {
|
export type TableData = {
|
||||||
noteId: string;
|
noteId: string;
|
||||||
title: string;
|
title: string;
|
||||||
} & Record<string, string>;
|
labels: Record<string, boolean | string | null>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object';
|
type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object';
|
||||||
@ -33,7 +34,7 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
|
|||||||
|
|
||||||
for (const { name, title, type } of info) {
|
for (const { name, title, type } of info) {
|
||||||
columnDefs.push({
|
columnDefs.push({
|
||||||
field: name,
|
field: `labels.${name}`,
|
||||||
headerName: title,
|
headerName: title,
|
||||||
cellDataType: mapDataType(type),
|
cellDataType: mapDataType(type),
|
||||||
editable: true
|
editable: true
|
||||||
@ -64,20 +65,19 @@ function mapDataType(labelType: LabelType | undefined): GridLabelType {
|
|||||||
export function buildRowDefinitions(notes: FNote[], infos: PromotedAttributeInformation[]) {
|
export function buildRowDefinitions(notes: FNote[], infos: PromotedAttributeInformation[]) {
|
||||||
const definitions: GridOptions<TableData>["rowData"] = [];
|
const definitions: GridOptions<TableData>["rowData"] = [];
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
const data = {
|
const labels: typeof definitions[0]["labels"] = {};
|
||||||
noteId: note.noteId,
|
|
||||||
title: note.title
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const { name, type } of infos) {
|
for (const { name, type } of infos) {
|
||||||
if (type === "boolean") {
|
if (type === "boolean") {
|
||||||
data[name] = note.hasLabel(name);
|
labels[name] = note.hasLabel(name);
|
||||||
} else {
|
} else {
|
||||||
data[name] = note.getLabelValue(name);
|
labels[name] = note.getLabelValue(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
definitions.push({
|
||||||
definitions.push(data);
|
noteId: note.noteId,
|
||||||
|
title: note.title,
|
||||||
|
labels
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return definitions;
|
return definitions;
|
||||||
|
@ -42,8 +42,11 @@ function setupEditing(): GridOptions<TableData> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { newValue } = event;
|
if (name.startsWith("labels.")) {
|
||||||
setLabel(noteId, name, newValue);
|
const { newValue } = event;
|
||||||
|
const labelName = name.split(".", 2)[1];
|
||||||
|
setLabel(noteId, labelName, newValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user