mirror of
https://github.com/zadam/trilium.git
synced 2025-11-26 02:24:23 +01:00
chore(react/promoted_attributes): add logic to filter out tables
This commit is contained in:
parent
9bed6b7e22
commit
5b9401fafe
@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useState } from "preact/hooks";
|
||||||
import "./PromotedAttributes.css";
|
import "./PromotedAttributes.css";
|
||||||
import { useNoteContext } from "./react/hooks";
|
import { useNoteContext, useNoteLabel } from "./react/hooks";
|
||||||
import { Attribute } from "../services/attribute_parser";
|
import { Attribute } from "../services/attribute_parser";
|
||||||
import FAttribute from "../entities/fattribute";
|
import FAttribute from "../entities/fattribute";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
@ -17,9 +17,13 @@ interface Cell {
|
|||||||
export default function PromotedAttributes() {
|
export default function PromotedAttributes() {
|
||||||
const { note } = useNoteContext();
|
const { note } = useNoteContext();
|
||||||
const [ cells, setCells ] = useState<Cell[]>();
|
const [ cells, setCells ] = useState<Cell[]>();
|
||||||
|
const [ viewType ] = useNoteLabel(note, "viewType");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!note) return;
|
if (!note || viewType === "table") {
|
||||||
|
setCells([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const promotedDefAttrs = note.getPromotedDefinitionAttributes();
|
const promotedDefAttrs = note.getPromotedDefinitionAttributes();
|
||||||
const ownedAttributes = note.getOwnedAttributes();
|
const ownedAttributes = note.getOwnedAttributes();
|
||||||
// attrs are not resorted if position changes after the initial load
|
// attrs are not resorted if position changes after the initial load
|
||||||
@ -53,7 +57,7 @@ export default function PromotedAttributes() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
setCells(cells);
|
setCells(cells);
|
||||||
}, [ note ]);
|
}, [ note, viewType ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="promoted-attributes-widget">
|
<div className="promoted-attributes-widget">
|
||||||
|
|||||||
@ -19,36 +19,6 @@ interface AttributeResult {
|
|||||||
|
|
||||||
export default class PromotedAttributesWidget extends NoteContextAwareWidget {
|
export default class PromotedAttributesWidget extends NoteContextAwareWidget {
|
||||||
|
|
||||||
private $container!: JQuery<HTMLElement>;
|
|
||||||
|
|
||||||
doRender() {
|
|
||||||
this.contentSized();
|
|
||||||
}
|
|
||||||
|
|
||||||
async refreshWithNote(note: FNote) {
|
|
||||||
this.$container.empty();
|
|
||||||
|
|
||||||
if (promotedDefAttrs.length === 0 || note.getLabelValue("viewType") === "table") {
|
|
||||||
this.toggleInt(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const $cells: JQuery<HTMLElement>[] = [];
|
|
||||||
|
|
||||||
for (const valueAttr of valueAttrs) {
|
|
||||||
const $cell = await this.createPromotedAttributeCell(definitionAttr, valueAttr, valueName);
|
|
||||||
|
|
||||||
if ($cell) {
|
|
||||||
$cells.push($cell);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// we replace the whole content in one step, so there can't be any race conditions
|
|
||||||
// (previously we saw promoted attributes doubling)
|
|
||||||
this.$container.empty().append(...$cells);
|
|
||||||
this.toggleInt(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
async createPromotedAttributeCell(definitionAttr: FAttribute, valueAttr: Attribute, valueName: string) {
|
async createPromotedAttributeCell(definitionAttr: FAttribute, valueAttr: Attribute, valueName: string) {
|
||||||
const definition = definitionAttr.getDefinition();
|
const definition = definitionAttr.getDefinition();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user