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
8 changes: 3 additions & 5 deletions apps/obsidian/src/components/ImportNodesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StrictMode, useState, useEffect, useCallback } from "react";
import type DiscourseGraphPlugin from "../index";
import type { ImportableNode, GroupWithNodes } from "~/types";
import {
getAvailableGroups,
getAvailableGroupIds,
getPublishedNodesForGroups,
getLocalNodeInstanceIds,
getSpaceNameFromIds,
Expand Down Expand Up @@ -45,15 +45,13 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
return;
}

const groups = await getAvailableGroups(client);
if (groups.length === 0) {
const groupIds = await getAvailableGroupIds(client);
if (groupIds.length === 0) {
new Notice("You are not a member of any groups");
onClose();
return;
}

const groupIds = groups.map((g) => g.group_id);

const publishedNodes = await getPublishedNodesForGroups({
client,
groupIds,
Expand Down
2 changes: 1 addition & 1 deletion apps/obsidian/src/components/RelationshipSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ const CurrentRelationships = ({

const group = tempRelationships.get(relationKey)!;
const otherId = isSource ? r.destination : r.source;
const linkedFile = await getFileForNodeInstanceId(plugin, otherId);
const linkedFile = getFileForNodeInstanceId(plugin, otherId);
if (
linkedFile &&
!group.linkedFiles.some((f) => f.path === linkedFile.path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,7 @@ const computeRelations = async (
const nodeInstanceId = await getNodeInstanceIdForFile(plugin, file);
if (!nodeInstanceId) return [];

const relations = await getRelationsForNodeInstanceId(
plugin,
nodeInstanceId,
);
const relations = await getRelationsForNodeInstanceId(plugin, nodeInstanceId);
const result = new Map<string, GroupedRelation>();

for (const relationType of plugin.settings.relationTypes) {
Expand Down Expand Up @@ -573,7 +570,7 @@ const computeRelations = async (
const group = result.get(key)!;
for (const r of instanceRels) {
const otherId = r.source === nodeInstanceId ? r.destination : r.source;
const linked = await getFileForNodeInstanceId(plugin, otherId);
const linked = getFileForNodeInstanceId(plugin, otherId);
if (linked && !group.linkedFiles.some((f) => f.path === linked.path)) {
group.linkedFiles.push(linked);
}
Expand Down
29 changes: 29 additions & 0 deletions apps/obsidian/src/services/QueryEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class QueryEngine {
this.app = app;
}

functional = () => !!this.dc;

/**
* Search across all discourse nodes (files that have frontmatter nodeTypeId)
*/
Expand Down Expand Up @@ -81,6 +83,33 @@ export class QueryEngine {
}
};

/**
* Search across all discourse nodes that have nodeInstanceId
*/
getDiscourseNodeById = (nodeInstanceId: string): TFile | null => {
if (!this.dc) {
console.warn(
"Datacore API not available. Search functionality is not available.",
);
return null;
}

if (!nodeInstanceId.match(/^[-.+\w]+$/)) {
console.error("Malformed id:", nodeInstanceId);
return null;
}
try {
const dcQuery = `@page and exists(nodeInstanceId) and nodeInstanceId = "${nodeInstanceId}"`;
const potentialNodes = this.dc.query(dcQuery);
const path = potentialNodes.at(0)?.$path;
if (!path) return null;
return this.app.vault.getFileByPath(path);
} catch (error) {
console.error("Error in searchDiscourseNodeById:", error);
return null;
}
};

searchCompatibleNodeByTitle = async ({
query,
compatibleNodeTypeIds,
Expand Down
3 changes: 2 additions & 1 deletion apps/obsidian/src/utils/conceptConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ const orderConceptsRec = ({
remainder: { [key: string]: LocalConceptDataInput };
processed: Set<string>;
}): Set<string> => {
// Add to processed at the start to prevent cycles
processed.add(concept.source_local_id!);
const relatedConceptIds = relatedConcepts(concept);
let missing: Set<string> = new Set();
while (relatedConceptIds.length > 0) {
Expand All @@ -310,7 +312,6 @@ const orderConceptsRec = ({
}
}
ordered.push(concept);
processed.add(concept.source_local_id!);
delete remainder[concept.source_local_id!];
return missing;
};
Expand Down
6 changes: 3 additions & 3 deletions apps/obsidian/src/utils/importNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type { DiscourseNode, ImportableNode } from "~/types";
import { QueryEngine } from "~/services/QueryEngine";
import { spaceUriAndLocalIdToRid, ridToSpaceUriAndLocalId } from "./rid";

export const getAvailableGroups = async (
export const getAvailableGroupIds = async (
client: DGSupabaseClient,
): Promise<{ group_id: string }[]> => {
): Promise<string[]> => {
const { data, error } = await client
.from("group_membership")
.select("group_id")
Expand All @@ -22,7 +22,7 @@ export const getAvailableGroups = async (
throw new Error(`Failed to fetch groups: ${error.message}`);
}

return data || [];
return (data || []).map((g) => g.group_id);
};

export const getPublishedNodesForGroups = async ({
Expand Down
Loading