Skip to content
Open
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
1 change: 0 additions & 1 deletion apps/obsidian/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@repo/utils": "workspace:*",
"@supabase/supabase-js": "catalog:",
"date-fns": "^4.1.0",
"gray-matter": "^4.0.3",
"mime-types": "^3.0.1",
"nanoid": "^4.0.2",
"react": "catalog:obsidian",
Expand Down
20 changes: 17 additions & 3 deletions apps/obsidian/src/components/ImportNodesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import { getAvailableGroupIds } from "@repo/database/lib/groups";
import {
fetchUserNames,
getPublishedNodesForGroups,
getLocalNodeInstanceIds,
getSpaceNameFromIds,
getSpaceUris,
importSelectedNodes,
} from "~/utils/importNodes";
import {
getImportedNodeKey,
getImportedNodesInfo,
} from "~/utils/relationsStore";
import { getLoggedInClient, getSupabaseContext } from "~/utils/supabaseContext";
import {
computeImportPreview,
Expand Down Expand Up @@ -70,11 +73,20 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
currentSpaceId: context.spaceId,
});

const localNodeInstanceIds = getLocalNodeInstanceIds(plugin);
const { nodeKeys: importedNodeKeys } = await getImportedNodesInfo({
plugin,
client,
});

// Filter out nodes that already exist locally
const importableNodes = publishedNodes.filter(
(node) => !localNodeInstanceIds.has(node.source_local_id),
(node) =>
!importedNodeKeys.has(
getImportedNodeKey({
spaceId: node.space_id,
sourceLocalId: node.source_local_id,
}),
),
);

const uniqueSpaceIds = [
Expand Down Expand Up @@ -219,6 +231,7 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
keyToRid: previewData.keyToRid,
keyToRelationEndpointId: previewData.keyToRelationEndpointId,
relationInstancesBySpace: previewData.relationInstancesBySpace,
sourceNodeTypeIdByKey: previewData.sourceNodeTypeIdByKey,
}
: undefined,
});
Expand All @@ -228,6 +241,7 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
`Import completed with some issues:\n${result.success} files imported successfully\n${result.failed} files failed`,
5000,
);
console.error("Import errors:", result.errors);
} else {
new Notice(`Successfully imported ${result.success} node(s)`, 3000);
}
Expand Down
7 changes: 4 additions & 3 deletions apps/obsidian/src/services/QueryEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,15 @@ export class QueryEngine {
}

/**
* Return all markdown pages under import/ that have importedFromRid and nodeInstanceId.
* Return all markdown pages that have importedFromRid and nodeInstanceId,
* wherever they now live: the frontmatter pair identifies an imported node,
* and users move notes out of import/ after importing them.
* Uses DataCore when available; falls back to vault iteration otherwise.
*/
getImportedNodePages = (): TFile[] => {
if (this.dc) {
try {
const dcQuery = `@page and path("import") and exists(importedFromRid) and exists(nodeInstanceId)`;
const dcQuery = `@page and exists(importedFromRid) and exists(nodeInstanceId)`;
const pages = this.dc.query(dcQuery);
const files: TFile[] = [];
for (const page of pages) {
Expand Down Expand Up @@ -498,7 +500,6 @@ export class QueryEngine {
const files: TFile[] = [];
const allFiles = this.app.vault.getMarkdownFiles();
for (const f of allFiles) {
if (!f.path.startsWith("import/")) continue;
const fm = this.app.metadataCache.getFileCache(f)?.frontmatter;
if (
(fm as Record<string, unknown> | undefined)?.importedFromRid &&
Expand Down
Loading