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-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 11:57:18 +02:00
|
|
|
import { PromotedAttributesContent, usePromotedAttributeData } from "../PromotedAttributes";
|
2025-12-14 20:34:55 +02:00
|
|
|
import Collapsible 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 11:57:18 +02:00
|
|
|
const { note, ntxId, componentId } = 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 11:57:18 +02:00
|
|
|
note && <PromotedAttributes note={note} componentId={componentId} />,
|
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
|
|
|
|
|
|
|
|
function PromotedAttributes({ note, componentId }: { note: FNote | null | undefined, componentId: string }) {
|
|
|
|
|
const [ cells, setCells ] = usePromotedAttributeData(note, componentId);
|
|
|
|
|
if (!cells?.length) return false;
|
|
|
|
|
|
|
|
|
|
return (note && (
|
|
|
|
|
<Collapsible
|
|
|
|
|
title={t("promoted_attributes.promoted_attributes")}
|
|
|
|
|
>
|
|
|
|
|
<PromotedAttributesContent note={note} componentId={componentId} cells={cells} setCells={setCells} />
|
|
|
|
|
</Collapsible>
|
|
|
|
|
));
|
|
|
|
|
}
|