-
Notifications
You must be signed in to change notification settings - Fork 4
[ENG-40] Identify node obsidian #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mdroidian
merged 32 commits into
DiscourseGraphs:main
from
trangdoan982:eng-40/identify-node-obsidian
Mar 27, 2025
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
8d968e1
Rename trang.JPG to trang.jpg
mdroidian d4c636b
remove trang.jpg
mdroidian 95d426f
curr progress
trangdoan982 4a72b97
finished current settings
trangdoan982 c08d23d
small update
trangdoan982 34f6899
setting for hotkey
trangdoan982 f2de373
node instantiation finished
trangdoan982 833e246
address PR comments
trangdoan982 2ee0d28
add description
trangdoan982 9ae208c
address PR comments
trangdoan982 5eedbc4
fix the NodeType validation
trangdoan982 435233d
address PR review
trangdoan982 d9dc433
add Save button for new changes
trangdoan982 de5242e
types defined and basic settings up
trangdoan982 e00c251
fix the bug. now relationship is updated
trangdoan982 2c44ed9
change the style to show bidirectional relations visually
trangdoan982 4098e58
create plugin as context instead of passing in props
trangdoan982 9ff13f5
new type definitions + settings finished
trangdoan982 88466b5
rename
trangdoan982 3c8bdcd
Merge branch 'main' into trang/relationship-type-def
trangdoan982 0dbb188
check for duplicates
trangdoan982 c42d587
address PR comments
trangdoan982 bbc1871
Merge branch 'DiscourseGraphs:main' into trang/relationship-type-def
trangdoan982 585b631
current progress
trangdoan982 c4f591b
confirm before delete
trangdoan982 44e0c6b
first approach: registerMarkdownPostProcessor and eventListener on ac…
trangdoan982 957fd79
using ItemView approach
trangdoan982 a2c11f2
Merge branch 'DiscourseGraphs:main' into eng-40/identify-node-obsidian
trangdoan982 037d577
add some changes
trangdoan982 43d86f2
address PR comment
trangdoan982 4461c79
address PR comments
trangdoan982 3250a15
fix frontmatter issue
trangdoan982 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import { ItemView, TFile, WorkspaceLeaf } from "obsidian"; | ||
| import { createRoot, Root } from "react-dom/client"; | ||
| import DiscourseGraphPlugin from "~/index"; | ||
| import { getDiscourseNodeFormatExpression } from "~/utils/getDiscourseNodeFormatExpression"; | ||
| import { VIEW_TYPE_DISCOURSE_CONTEXT } from "~/types"; | ||
|
|
||
| interface DiscourseContextProps { | ||
| activeFile: TFile | null; | ||
| plugin: DiscourseGraphPlugin; | ||
| } | ||
|
|
||
| const DiscourseContext = ({ activeFile, plugin }: DiscourseContextProps) => { | ||
| const extractContentFromTitle = ( | ||
| format: string | undefined, | ||
| title: string, | ||
| ): string => { | ||
| if (!format) return ""; | ||
| const regex = getDiscourseNodeFormatExpression(format); | ||
| const match = title.match(regex); | ||
| return match?.[1] ?? title; | ||
| }; | ||
|
|
||
| const renderContent = () => { | ||
| if (!activeFile) { | ||
| return <div>No file is open</div>; | ||
| } | ||
|
|
||
| const fileMetadata = plugin.app.metadataCache.getFileCache(activeFile); | ||
| if (!fileMetadata) { | ||
| return <div>File metadata not available</div>; | ||
| } | ||
|
|
||
| const frontmatter = fileMetadata.frontmatter; | ||
| if (!frontmatter) { | ||
| return <div>No discourse node data found</div>; | ||
| } | ||
|
|
||
| if (!frontmatter.nodeTypeId) { | ||
| return <div>Not a discourse node (no nodeTypeId)</div>; | ||
| } | ||
|
|
||
| const nodeType = plugin.settings.nodeTypes.find( | ||
| (type) => type.id === frontmatter.nodeTypeId, | ||
| ); | ||
|
|
||
| if (!nodeType) { | ||
| return <div>Unknown node type: {frontmatter.nodeTypeId}</div>; | ||
| } | ||
| return ( | ||
| <div> | ||
| <div | ||
| style={{ | ||
| fontSize: "1.2em", | ||
| fontWeight: "bold", | ||
| marginBottom: "8px", | ||
| }} | ||
| > | ||
| {nodeType.name || "Unnamed Node Type"} | ||
| </div> | ||
|
|
||
| {nodeType.format && ( | ||
| <div style={{ marginBottom: "4px" }}> | ||
| <span style={{ fontWeight: "bold" }}>Content: </span> | ||
| {extractContentFromTitle(nodeType.format, activeFile.basename)} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <h4 style={{ marginTop: 0 }}>Discourse Context</h4> | ||
| {renderContent()} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export class DiscourseContextView extends ItemView { | ||
| private plugin: DiscourseGraphPlugin; | ||
| private activeFile: TFile | null = null; | ||
| private root: Root | null = null; | ||
|
|
||
| constructor(leaf: WorkspaceLeaf, plugin: DiscourseGraphPlugin) { | ||
| super(leaf); | ||
| this.plugin = plugin; | ||
| } | ||
|
|
||
| setActiveFile(file: TFile | null): void { | ||
| this.activeFile = file; | ||
| this.updateView(); | ||
| } | ||
|
|
||
| getViewType(): string { | ||
| return VIEW_TYPE_DISCOURSE_CONTEXT; | ||
| } | ||
|
|
||
| getDisplayText(): string { | ||
| return "Discourse Context"; | ||
| } | ||
|
|
||
| getIcon(): string { | ||
| return "telescope"; | ||
| } | ||
|
|
||
| async onOpen(): Promise<void> { | ||
| const container = this.containerEl.children[1]; | ||
| if (container) { | ||
| container.empty(); | ||
| container.addClass("discourse-context-container"); | ||
|
|
||
| this.root = createRoot(container); | ||
|
|
||
| this.activeFile = this.app.workspace.getActiveFile(); | ||
|
|
||
| this.updateView(); | ||
|
|
||
| this.registerEvent( | ||
| this.app.workspace.on("file-open", (file) => { | ||
| this.activeFile = file; | ||
| this.updateView(); | ||
| }), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| updateView(): void { | ||
| if (this.root) { | ||
| this.root.render( | ||
| <DiscourseContext activeFile={this.activeFile} plugin={this.plugin} />, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| async onClose(): Promise<void> { | ||
| if (this.root) { | ||
| this.root.unmount(); | ||
| this.root = null; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.