chore(client/ts): port widgets/attribute_editor

This commit is contained in:
Elian Doran
2024-12-22 21:59:08 +02:00
parent b01725101d
commit a349223e54
8 changed files with 207 additions and 72 deletions

View File

@@ -1,6 +1,7 @@
import server from './server.js';
import froca from './froca.js';
import FNote from '../entities/fnote.js';
import { AttributeRow } from './load_results.js';
async function addLabel(noteId: string, name: string, value: string = "") {
await server.put(`notes/${noteId}/attribute`, {
@@ -23,18 +24,18 @@ async function removeAttributeById(noteId: string, attributeId: string) {
}
/**
* @returns {boolean} - returns true if this attribute has the potential to influence the note in the argument.
* @returns - returns true if this attribute has the potential to influence the note in the argument.
* That can happen in multiple ways:
* 1. attribute is owned by the note
* 2. attribute is owned by the template of the note
* 3. attribute is owned by some note's ancestor and is inheritable
*/
function isAffecting(this: { isInheritable: boolean }, attrRow: { noteId: string }, affectedNote: FNote) {
function isAffecting(attrRow: AttributeRow, affectedNote: FNote) {
if (!affectedNote || !attrRow) {
return false;
}
const attrNote = froca.notes[attrRow.noteId];
const attrNote = attrRow.noteId && froca.notes[attrRow.noteId];
if (!attrNote) {
// the note (owner of the attribute) is not even loaded into the cache, so it should not affect anything else
@@ -50,6 +51,7 @@ function isAffecting(this: { isInheritable: boolean }, attrRow: { noteId: string
}
// TODO: This doesn't seem right.
//@ts-ignore
if (this.isInheritable) {
for (const owningNote of owningNotes) {
if (owningNote.hasAncestor(attrNote.noteId, true)) {