Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/obsidian/src/components/DiscourseContextView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
WorkspaceLeaf,
Notice,
FrontMatterCache,
setIcon,
} from "obsidian";
import { createRoot, Root } from "react-dom/client";
import DiscourseGraphPlugin from "~/index";
Expand All @@ -14,6 +15,7 @@ import { PluginProvider, usePlugin } from "~/components/PluginContext";
import { getNodeTypeById } from "~/utils/typeUtils";
import { refreshImportedFile } from "~/utils/importNodes";
import { publishNode } from "~/utils/publishNode";
import { createBaseForNodeType } from "~/utils/baseForNodeType";
import { useState, useEffect } from "react";

type DiscourseContextProps = {
Expand Down Expand Up @@ -154,6 +156,18 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
/>
)}
{nodeType.name || "Unnamed Node Type"}
<button
onClick={() => {
void createBaseForNodeType(plugin, nodeType);
}}
className="clickable-icon ml-1"
title={`Create Base view for ${nodeType.name}`}
aria-label={`Create Base view for ${nodeType.name}`}
>
<div
ref={(el) => (el && setIcon(el, "layout-list")) || undefined}
/>
</button>
{isImported && (
<button
onClick={() => {
Expand Down
28 changes: 13 additions & 15 deletions apps/obsidian/src/components/NodeTypeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import { App, Editor, SuggestModal, TFile, Notice } from "obsidian";
import { DiscourseNode } from "~/types";
import { createDiscourseNode } from "~/utils/createNode";
import { SuggestModal } from "obsidian";
import type { DiscourseNode } from "~/types";
import type DiscourseGraphPlugin from "~/index";

export class NodeTypeModal extends SuggestModal<DiscourseNode> {
private nodeTypes: DiscourseNode[];
private onSelect: (nodeType: DiscourseNode) => void;

constructor(
private editor: Editor,
private nodeTypes: DiscourseNode[],
private plugin: DiscourseGraphPlugin,
plugin: DiscourseGraphPlugin,
onSelect: (nodeType: DiscourseNode) => void,
) {
super(plugin.app);
this.nodeTypes = plugin.settings.nodeTypes;
this.onSelect = onSelect;
}

getItemText(item: DiscourseNode): string {
return item.name;
}

getSuggestions() {
getSuggestions(): DiscourseNode[] {
const query = this.inputEl.value.toLowerCase();
return this.nodeTypes.filter((node) =>
this.getItemText(node).toLowerCase().includes(query),
);
}

renderSuggestion(nodeType: DiscourseNode, el: HTMLElement) {
renderSuggestion(nodeType: DiscourseNode, el: HTMLElement): void {
const container = el.createDiv({ cls: "flex items-center gap-2" });
if (nodeType.color) {
container.createDiv({
Expand All @@ -34,12 +37,7 @@ export class NodeTypeModal extends SuggestModal<DiscourseNode> {
container.createDiv({ text: nodeType.name });
}

async onChooseSuggestion(nodeType: DiscourseNode) {
await createDiscourseNode({
plugin: this.plugin,
editor: this.editor,
nodeType,
text: this.editor.getSelection().trim() || "",
});
onChooseSuggestion(nodeType: DiscourseNode): void {
this.onSelect(nodeType);
}
}
20 changes: 20 additions & 0 deletions apps/obsidian/src/components/NodeTypeSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getAndFormatImportSource,
} from "~/utils/typeUtils";
import { FolderSuggestInput } from "./GeneralSettings";
import { createBaseForNodeType } from "~/utils/baseForNodeType";

const generateTagPlaceholder = (format: string, nodeName?: string): string => {
if (!format) return "Enter tag (e.g., clm-candidate)";
Expand Down Expand Up @@ -709,6 +710,25 @@ const NodeTypeSettings = () => {
/>
</div>
</div>
{selectedNodeIndex !== null && selectedNodeIndex < nodeTypes.length && (
<div className="setting-item">
<div className="setting-item-info">
<div className="setting-item-name">Base view</div>
<div className="setting-item-description">
Create a new Base view filtered to this node type
</div>
</div>
<div className="setting-item-control">
<button
onClick={() =>
void createBaseForNodeType(plugin, editingNodeType)
}
>
Create Base view
</button>
</div>
</div>
)}
</div>
);
};
Expand Down
47 changes: 47 additions & 0 deletions apps/obsidian/src/utils/baseForNodeType.ts
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);
}
};
20 changes: 19 additions & 1 deletion apps/obsidian/src/utils/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { publishNode } from "./publishNode";
import { addRelationIfRequested } from "~/components/canvas/utils/relationJsonUtils";
import type { DiscourseNode } from "~/types";
import { TldrawView } from "~/components/canvas/TldrawView";
import { createBaseForNodeType } from "./baseForNodeType";

type ModifyNodeSubmitParams = {
nodeType: DiscourseNode;
Expand Down Expand Up @@ -65,7 +66,14 @@ export const registerCommands = (plugin: DiscourseGraphPlugin) => {
const hasSelection = !!editor.getSelection();

if (hasSelection) {
new NodeTypeModal(editor, plugin.settings.nodeTypes, plugin).open();
new NodeTypeModal(plugin, (nodeType) => {
void createDiscourseNode({
plugin,
editor,
nodeType,
text: editor.getSelection().trim() || "",
});
}).open();
} else {
const currentFile =
plugin.app.workspace.getActiveViewOfType(MarkdownView)?.file ||
Expand Down Expand Up @@ -249,6 +257,16 @@ export const registerCommands = (plugin: DiscourseGraphPlugin) => {
return true;
},
});
plugin.addCommand({
id: "create-base-for-node-type",
name: "Create Base view for node type",
callback: () => {
new NodeTypeModal(plugin, (nodeType) => {
void createBaseForNodeType(plugin, nodeType);
}).open();
},
});

plugin.addCommand({
id: "publish-discourse-node",
name: "Publish current node to lab space",
Expand Down
4 changes: 4 additions & 0 deletions apps/website/app/(docs)/docs/obsidian/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export const navigation: NavigationList = [
title: "Node tags",
href: `${ROOT}/node-tags`,
},
{
title: "Querying your discourse graph",
href: `${ROOT}/querying-discourse-graph`,
},
],
},

Expand Down
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

![base-from-command.png](/docs/obsidian/base-from-command.png)

### 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 -->

![base-from-setting.png](/docs/obsidian/base-from-setting.png)

### 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

![base-from-context.png](/docs/obsidian/base-from-context.png)

## 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.
Loading