feat(board/relation): add support for more APIs

This commit is contained in:
Elian Doran 2025-11-15 10:50:55 +02:00
parent 0f000ccd93
commit d1e80815d5
No known key found for this signature in database
2 changed files with 32 additions and 14 deletions

View File

@ -60,6 +60,23 @@ function removeOwnedLabelByName(note: FNote, labelName: string) {
return false; return false;
} }
/**
* Removes a relation identified by its name from the given note, if it exists. Note that the relation must be owned, i.e.
* it will not remove inherited attributes.
*
* @param note the note from which to remove the relation.
* @param relationName the name of the relation to remove.
* @returns `true` if an attribute was identified and removed, `false` otherwise.
*/
function removeOwnedRelationByName(note: FNote, relationName: string) {
const label = note.getOwnedRelation(relationName);
if (label) {
removeAttributeById(note.noteId, label.attributeId);
return true;
}
return false;
}
/** /**
* Sets the attribute of the given note to the provided value if its truthy, or removes the attribute if the value is falsy. * Sets the attribute of the given note to the provided value if its truthy, or removes the attribute if the value is falsy.
* For an attribute with an empty value, pass an empty string instead. * For an attribute with an empty value, pass an empty string instead.
@ -129,5 +146,6 @@ export default {
setAttribute, setAttribute,
removeAttributeById, removeAttributeById,
removeOwnedLabelByName, removeOwnedLabelByName,
removeOwnedRelationByName,
isAffecting isAffecting
}; };

View File

@ -1,3 +1,4 @@
import { BulkAction } from "@triliumnext/commons";
import { BoardViewData } from "."; import { BoardViewData } from ".";
import appContext from "../../../components/app_context"; import appContext from "../../../components/app_context";
import FNote from "../../../entities/fnote"; import FNote from "../../../entities/fnote";
@ -83,13 +84,11 @@ export default class BoardApi {
async removeColumn(column: string) { async removeColumn(column: string) {
// Remove the value from the notes. // Remove the value from the notes.
const noteIds = this.byColumn?.get(column)?.map(item => item.note.noteId) || []; const noteIds = this.byColumn?.get(column)?.map(item => item.note.noteId) || [];
await executeBulkActions(noteIds, [
{
name: "deleteLabel",
labelName: this.statusAttribute
}
]);
const action: BulkAction = this.isRelationMode
? { name: "deleteRelation", relationName: this.statusAttribute }
: { name: "deleteLabel", labelName: this.statusAttribute }
await executeBulkActions(noteIds, [ action ]);
this.viewConfig.columns = (this.viewConfig.columns ?? []).filter(col => col.value !== column); this.viewConfig.columns = (this.viewConfig.columns ?? []).filter(col => col.value !== column);
this.saveConfig(this.viewConfig); this.saveConfig(this.viewConfig);
} }
@ -98,13 +97,10 @@ export default class BoardApi {
const noteIds = this.byColumn?.get(oldValue)?.map(item => item.note.noteId) || []; const noteIds = this.byColumn?.get(oldValue)?.map(item => item.note.noteId) || [];
// Change the value in the notes. // Change the value in the notes.
await executeBulkActions(noteIds, [ const action: BulkAction = this.isRelationMode
{ ? { name: "updateRelationTarget", relationName: this.statusAttribute, targetNoteId: newValue }
name: "updateLabelValue", : { name: "updateLabelValue", labelName: this.statusAttribute, labelValue: newValue }
labelName: this.statusAttribute, await executeBulkActions(noteIds, [ action ]);
labelValue: newValue
}
]);
// Rename the column in the persisted data. // Rename the column in the persisted data.
for (const column of this.viewConfig.columns || []) { for (const column of this.viewConfig.columns || []) {
@ -181,7 +177,11 @@ export default class BoardApi {
removeFromBoard(noteId: string) { removeFromBoard(noteId: string) {
const note = froca.getNoteFromCache(noteId); const note = froca.getNoteFromCache(noteId);
if (!note) return; if (!note) return;
return attributes.removeOwnedLabelByName(note, this.statusAttribute); if (this.isRelationMode) {
return attributes.removeOwnedRelationByName(note, this.statusAttribute);
} else {
return attributes.removeOwnedLabelByName(note, this.statusAttribute);
}
} }
async moveWithinBoard(noteId: string, sourceBranchId: string, sourceIndex: number, targetIndex: number, sourceColumn: string, targetColumn: string) { async moveWithinBoard(noteId: string, sourceBranchId: string, sourceIndex: number, targetIndex: number, sourceColumn: string, targetColumn: string) {