-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-1608: Add command to create Base view for a node type #935
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
trangdoan982
merged 4 commits into
main
from
eng-1608-create-command-to-create-a-base-for-a-node-type
Apr 3, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { Notice } from "obsidian"; | ||
| import type DiscourseGraphPlugin from "~/index"; | ||
| import type { DiscourseNode } from "~/types"; | ||
|
|
||
| const generateBaseYaml = (nodeType: DiscourseNode): string => { | ||
| return [ | ||
| "views:", | ||
| " - type: table", | ||
| ` name: "${nodeType.name.replace(/\\/g, "\\\\").replace(/"/g, '\\"')} Nodes"`, | ||
| " order:", | ||
| " - file.name", | ||
| " filters:", | ||
| " and:", | ||
| ` - nodeTypeId == "${nodeType.id}"`, | ||
| "", | ||
| ].join("\n"); | ||
| }; | ||
|
|
||
| const getAvailableFilename = ( | ||
| plugin: DiscourseGraphPlugin, | ||
| baseName: string, | ||
| ): string => { | ||
| if (!plugin.app.vault.getAbstractFileByPath(`${baseName}.base`)) { | ||
| return `${baseName}.base`; | ||
| } | ||
| let i = 1; | ||
| while (plugin.app.vault.getAbstractFileByPath(`${baseName} ${i}.base`)) { | ||
| i++; | ||
| } | ||
| return `${baseName} ${i}.base`; | ||
| }; | ||
|
|
||
| export const createBaseForNodeType = async ( | ||
| plugin: DiscourseGraphPlugin, | ||
| nodeType: DiscourseNode, | ||
| ): Promise<void> => { | ||
| try { | ||
| const filename = getAvailableFilename(plugin, `${nodeType.name} Nodes`); | ||
| const content = generateBaseYaml(nodeType); | ||
| await plugin.app.vault.create(filename, content); | ||
| await plugin.app.workspace.openLinkText(filename, ""); | ||
| new Notice(`Created Base view for ${nodeType.name}`); | ||
| } catch (e) { | ||
| new Notice(e instanceof Error ? e.message : "Failed to create Base view"); | ||
| console.error("Failed to create Base view:", e); | ||
| } | ||
| }; | ||
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
51 changes: 51 additions & 0 deletions
51
apps/website/app/(docs)/docs/obsidian/pages/querying-discourse-graph.md
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,51 @@ | ||
| --- | ||
| title: "Querying your discourse graph" | ||
| date: "2026-04-02" | ||
| author: "" | ||
| published: true | ||
| --- | ||
|
|
||
| As your discourse graph grows, you'll want to view and filter nodes by type — for example, seeing all your Claims or all your Questions in one place. Discourse Graphs integrates with Obsidian's [Bases](https://obsidian.md/blog/bases/) feature to create filtered table views for any node type. | ||
|
|
||
| ## What is a Base view? | ||
|
|
||
| A Base view is a `.base` file that Obsidian renders as a filterable, sortable table. Discourse Graphs can generate these files pre-configured to show only nodes of a specific type, using the `nodeTypeId` frontmatter property as a filter. | ||
|
|
||
| ## Creating a Base view | ||
|
|
||
| There are three ways to create a Base view for a node type: | ||
|
|
||
| ### From the command palette | ||
|
|
||
| 1. Open the command palette (`Cmd/Ctrl + P`) | ||
| 2. Search for "Create Base view for node type" | ||
| 3. Select the node type you want to query | ||
|
|
||
|  | ||
|
|
||
| ### From node type settings | ||
|
|
||
| 1. Open Discourse Graphs settings | ||
| 2. Click on a node type to edit it | ||
| 3. Click the **Create Base view** button at the bottom of the edit form | ||
|
|
||
| <!-- TODO: Add screenshot of the "Create Base view" button in node type settings --> | ||
|
|
||
|  | ||
|
|
||
| ### From the discourse context panel | ||
|
|
||
| When viewing a discourse node, you can create a Base view for its node type directly from the context panel: | ||
|
|
||
| 1. Open the [Discourse context panel](./discourse-context) for any discourse node | ||
| 2. Click the table icon next to the node type name | ||
|
|
||
|  | ||
|
|
||
| ## How it works | ||
|
|
||
| Each time you create a Base view, a new `.base` file is created at the root of your vault with the name `{Node Type} Nodes.base` (e.g., `Claim Nodes.base`). If a file with that name already exists, a numbered suffix is added (e.g., `Claim Nodes 1.base`). | ||
|
|
||
| The generated file contains a table view filtered to show only nodes matching the selected node type. You can then further customize the view in Obsidian — add columns, change sorting, or add additional filters. | ||
|
|
||
| > **Note:** A new Base file is always created rather than opening an existing one. This ensures you always get a fresh view with the correct filter, even if you've modified a previous Base view. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
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.