Skip to content

Commit 9580d63

Browse files
committed
client/pageurl: migrate note origin to info bar
1 parent 1ca46e3 commit 9580d63

File tree

5 files changed

+48
-30
lines changed

5 files changed

+48
-30
lines changed

apps/client/src/layouts/desktop_layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import ScrollingContainer from "../widgets/containers/scrolling_container.js";
3131
import ScrollPadding from "../widgets/scroll_padding.js";
3232
import SearchResult from "../widgets/search_result.jsx";
3333
import SharedInfo from "../widgets/shared_info.jsx";
34+
import OriginInfo from "../widgets/note_origin.jsx";
3435
import SpacerWidget from "../widgets/spacer.js";
3536
import SplitNoteContainer from "../widgets/containers/split_note_container.js";
3637
import SqlResults from "../widgets/sql_result.js";
@@ -137,6 +138,7 @@ export default class DesktopLayout {
137138
new ScrollingContainer()
138139
.filling()
139140
.child(new ContentHeader()
141+
.child(<OriginInfo />)
140142
.child(<ReadOnlyNoteInfoBar />)
141143
.child(<SharedInfo />)
142144
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { t } from "../services/i18n";
2+
import { useNoteContext, useTriliumEvent, useTriliumOption } from "./react/hooks";
3+
import { useEffect, useState } from "preact/hooks";
4+
import attributes from "../services/attributes";
5+
import InfoBar from "./react/InfoBar";
6+
import RawHtml from "./react/RawHtml";
7+
import FNote from "../entities/fnote";
8+
9+
export default function OriginInfo() {
10+
const { note } = useNoteContext();
11+
const [link, setLink] = useState<string>();
12+
13+
function refresh() {
14+
if (!note) return;
15+
const pageUrl = getPageUrl(note);
16+
if (!pageUrl) {
17+
setLink(undefined);
18+
return;
19+
}
20+
setLink(`<a href="${pageUrl}" class="external tn-link">${pageUrl}</a>`);
21+
}
22+
23+
useEffect(refresh, [note]);
24+
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
25+
if (loadResults.getAttributeRows().find((attr) => attr.type === "label" && attr.name?.toString() === "pageUrl" && attributes.isAffecting(attr, note))) {
26+
refresh();
27+
}
28+
});
29+
30+
return (
31+
<InfoBar className="origin-info-widget" type="subtle" style={{ display: (!link) ? "none" : undefined }}>
32+
{link && (
33+
<RawHtml
34+
html={`${t("note_properties.this_note_was_originally_taken_from")} ${link}`}
35+
/>
36+
)}
37+
</InfoBar>
38+
)
39+
}
40+
41+
function getPageUrl(note: FNote) {
42+
return note.getOwnedLabelValue("pageUrl");
43+
}

apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function CollectionPropertiesTab({ note }: TabContext) {
2828
const defaultViewType = (note?.type === "search" ? "list" : "grid");
2929
const viewTypeWithDefault = (viewType ?? defaultViewType) as ViewTypeOptions;
3030
const properties = bookPropertiesConfig[viewTypeWithDefault].properties;
31-
31+
console.warn('CollectionPropertiesTab:', properties)
3232
return (
3333
<div className="book-properties-widget">
3434
{note && (
@@ -137,7 +137,7 @@ function NumberPropertyView({ note, property }: { note: FNote, property: NumberP
137137

138138
function ComboBoxPropertyView({ note, property }: { note: FNote, property: ComboBoxProperty }) {
139139
const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
140-
140+
console.warn('ComboBoxPropertyView:', value)
141141
return (
142142
<LabelledEntry label={property.label}>
143143
<FormSelectWithGroups
@@ -150,6 +150,7 @@ function ComboBoxPropertyView({ note, property }: { note: FNote, property: Combo
150150
}
151151

152152
function LabelledEntry({ label, children }: { label: string, children: ComponentChildren }) {
153+
console.warn('LabelledEntry:', label)
153154
return (
154155
<>
155156
<label>

apps/client/src/widgets/ribbon/NotePropertiesTab.tsx

Lines changed: 0 additions & 20 deletions
This file was deleted.

apps/client/src/widgets/ribbon/RibbonDefinition.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ScriptTab from "./ScriptTab";
22
import EditedNotesTab from "./EditedNotesTab";
3-
import NotePropertiesTab from "./NotePropertiesTab";
43
import NoteInfoTab from "./NoteInfoTab";
54
import SimilarNotesTab from "./SimilarNotesTab";
65
import FilePropertiesTab from "./FilePropertiesTab";
@@ -59,13 +58,6 @@ export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [
5958
show: ({ note }) => note?.type === "book" || note?.type === "search",
6059
toggleCommand: "toggleRibbonTabBookProperties"
6160
},
62-
{
63-
title: t("note_properties.info"),
64-
icon: "bx bx-info-square",
65-
content: NotePropertiesTab,
66-
show: ({ note }) => !!note?.getLabelValue("pageUrl"),
67-
activate: true
68-
},
6961
{
7062
title: t("file_properties.title"),
7163
icon: "bx bx-file",

0 commit comments

Comments
 (0)