Skip to content

Commit 062f46a

Browse files
trangdoan982claude
andauthored
ENG-1638 Add view-only notice for imported nodes (#966)
* ENG-1638 Add view-only notice for imported nodes in Discourse context panel Adds an amber "View only" badge with an info tooltip to the Discourse context view when the active file is an imported node. The tooltip (shown on hover or click) displays the source space and warns that direct edits will be overwritten on refresh. Tooltip uses explicit dark/light-adaptive colours for readability in both Obsidian themes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * address PR comments and increase contrast * use setTooltip --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9a43f51 commit 062f46a

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

apps/obsidian/src/components/DiscourseContextView.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getDiscourseNodeFormatExpression } from "~/utils/getDiscourseNodeFormat
1313
import { RelationshipSection } from "~/components/RelationshipSection";
1414
import { VIEW_TYPE_DISCOURSE_CONTEXT } from "~/types";
1515
import { PluginProvider, usePlugin } from "~/components/PluginContext";
16-
import { getNodeTypeById } from "~/utils/typeUtils";
16+
import { getNodeTypeById, getAndFormatImportSource } from "~/utils/typeUtils";
1717
import { refreshImportedFile } from "~/utils/importNodes";
1818
import { publishNode } from "~/utils/publishNode";
1919
import { createBaseForNodeType } from "~/utils/baseForNodeType";
@@ -23,6 +23,21 @@ type DiscourseContextProps = {
2323
activeFile: TFile | null;
2424
};
2525

26+
type InfoTooltipProps = {
27+
content: string;
28+
};
29+
30+
const InfoTooltip = ({ content }: InfoTooltipProps) => (
31+
<button
32+
ref={(el) => {
33+
if (el) setTooltip(el, content);
34+
}}
35+
className="clickable-icon text-muted hover:text-normal flex h-4 w-4 items-center justify-center"
36+
>
37+
<div ref={(el) => (el && setIcon(el, "info")) || undefined} />
38+
</button>
39+
);
40+
2641
const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
2742
const plugin = usePlugin();
2843
const [isRefreshing, setIsRefreshing] = useState(false);
@@ -211,8 +226,19 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
211226
)}
212227
</div>
213228

229+
{isImported && (
230+
<div className="mt-3 flex items-center gap-1.5">
231+
<span className="cursor-default rounded bg-amber-300 px-2 py-1 text-xs font-semibold text-amber-950 dark:bg-amber-900/40 dark:text-amber-300">
232+
View only
233+
</span>
234+
<InfoTooltip
235+
content={`Imported from ${getAndFormatImportSource(frontmatter.importedFromRid as string, plugin.settings.spaceNames)}. Direct edits will be overwritten when refreshed.`}
236+
/>
237+
</div>
238+
)}
239+
214240
{nodeType.format && (
215-
<div className="mb-1">
241+
<div className="mb-1 mt-2">
216242
<span className="font-bold">Content: </span>
217243
{extractContentFromTitle(nodeType.format, activeFile.basename)}
218244
</div>

0 commit comments

Comments
 (0)