2025-12-14 20:34:55 +02:00
|
|
|
import "./NoteTitleActions.css";
|
|
|
|
|
|
2025-12-14 21:38:02 +02:00
|
|
|
import clsx from "clsx";
|
2025-12-15 12:10:05 +02:00
|
|
|
import { useEffect, useState } from "preact/hooks";
|
2025-12-14 21:38:02 +02:00
|
|
|
|
2025-12-15 12:10:05 +02:00
|
|
|
import NoteContext from "../../components/note_context";
|
2025-12-14 20:34:55 +02:00
|
|
|
import FNote from "../../entities/fnote";
|
|
|
|
|
import { t } from "../../services/i18n";
|
2025-12-13 11:46:42 +02:00
|
|
|
import CollectionProperties from "../note_bars/CollectionProperties";
|
2025-12-15 12:10:05 +02:00
|
|
|
import { checkFullHeight, getExtendedWidgetType } from "../NoteDetail";
|
2025-12-15 11:57:18 +02:00
|
|
|
import { PromotedAttributesContent, usePromotedAttributeData } from "../PromotedAttributes";
|
2025-12-15 12:10:05 +02:00
|
|
|
import Collapsible, { ExternallyControlledCollapsible } from "../react/Collapsible";
|
2025-12-13 11:46:42 +02:00
|
|
|
import { useNoteContext, useNoteProperty } from "../react/hooks";
|
2025-12-14 20:34:55 +02:00
|
|
|
import SearchDefinitionTab from "../ribbon/SearchDefinitionTab";
|
2025-12-09 22:22:28 +02:00
|
|
|
|
2025-12-13 11:46:42 +02:00
|
|
|
export default function NoteTitleActions() {
|
2025-12-15 12:10:05 +02:00
|
|
|
const { note, ntxId, componentId, noteContext } = useNoteContext();
|
2025-12-12 20:21:55 +02:00
|
|
|
const isHiddenNote = note && note.noteId !== "_search" && note.noteId.startsWith("_");
|
2025-12-11 18:53:48 +02:00
|
|
|
const noteType = useNoteProperty(note, "type");
|
2025-12-09 22:22:28 +02:00
|
|
|
|
2025-12-14 21:38:02 +02:00
|
|
|
const items = [
|
2025-12-15 12:10:05 +02:00
|
|
|
note && <PromotedAttributes note={note} componentId={componentId} noteContext={noteContext} />,
|
2025-12-14 21:38:02 +02:00
|
|
|
note && noteType === "search" && <SearchProperties note={note} ntxId={ntxId} />,
|
|
|
|
|
note && !isHiddenNote && noteType === "book" && <CollectionProperties note={note} />
|
|
|
|
|
].filter(Boolean);
|
|
|
|
|
|
2025-12-11 18:53:48 +02:00
|
|
|
return (
|
2025-12-14 21:38:02 +02:00
|
|
|
<div className={clsx("title-actions", items.length > 0 && "visible")}>
|
|
|
|
|
{items}
|
2025-12-09 22:22:28 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-14 20:34:55 +02:00
|
|
|
|
|
|
|
|
function SearchProperties({ note, ntxId }: { note: FNote, ntxId: string | null | undefined }) {
|
2025-12-14 21:29:10 +02:00
|
|
|
return (note &&
|
2025-12-14 20:34:55 +02:00
|
|
|
<Collapsible
|
|
|
|
|
title={t("search_definition.search_parameters")}
|
2025-12-14 21:29:10 +02:00
|
|
|
initiallyExpanded={note.isInHiddenSubtree()} // not saved searches
|
2025-12-14 20:34:55 +02:00
|
|
|
>
|
|
|
|
|
<SearchDefinitionTab note={note} ntxId={ntxId} hidden={false} />
|
|
|
|
|
</Collapsible>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-15 11:57:18 +02:00
|
|
|
|
2025-12-15 12:10:05 +02:00
|
|
|
function PromotedAttributes({ note, componentId, noteContext }: {
|
|
|
|
|
note: FNote | null | undefined,
|
|
|
|
|
componentId: string,
|
|
|
|
|
noteContext: NoteContext | undefined
|
|
|
|
|
}) {
|
2025-12-15 11:57:18 +02:00
|
|
|
const [ cells, setCells ] = usePromotedAttributeData(note, componentId);
|
2025-12-15 12:10:05 +02:00
|
|
|
const [ expanded, setExpanded ] = useState(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
getExtendedWidgetType(note, noteContext).then(extendedNoteType => {
|
|
|
|
|
const fullHeight = checkFullHeight(noteContext, extendedNoteType);
|
|
|
|
|
setExpanded(!fullHeight);
|
|
|
|
|
});
|
|
|
|
|
}, [ note, noteContext ]);
|
2025-12-15 11:57:18 +02:00
|
|
|
|
2025-12-15 12:10:05 +02:00
|
|
|
if (!cells?.length) return false;
|
2025-12-15 11:57:18 +02:00
|
|
|
return (note && (
|
2025-12-15 12:10:05 +02:00
|
|
|
<ExternallyControlledCollapsible
|
|
|
|
|
key={note.noteId}
|
2025-12-15 11:57:18 +02:00
|
|
|
title={t("promoted_attributes.promoted_attributes")}
|
2025-12-15 12:10:05 +02:00
|
|
|
expanded={expanded} setExpanded={setExpanded}
|
2025-12-15 11:57:18 +02:00
|
|
|
>
|
|
|
|
|
<PromotedAttributesContent note={note} componentId={componentId} cells={cells} setCells={setCells} />
|
2025-12-15 12:10:05 +02:00
|
|
|
</ExternallyControlledCollapsible>
|
2025-12-15 11:57:18 +02:00
|
|
|
));
|
|
|
|
|
}
|