Skip to content

Commit 263be02

Browse files
authored
ENG-1461 Use full Rid instead of just spaceUri as marker of import (#808)
1 parent a922e2f commit 263be02

13 files changed

Lines changed: 205 additions & 116 deletions

apps/obsidian/src/components/DiscourseContextView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
3737
setIsPublished(false);
3838
return;
3939
}
40-
const isImported = !!frontmatter.importedFromSpaceUri;
40+
const isImported = !!frontmatter.importedFromRid;
4141
const publishedToGroups = frontmatter.publishedToGroups as unknown;
4242
const published =
4343
!isImported &&
@@ -125,7 +125,7 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
125125
return <div>Unknown node type: {frontmatter.nodeTypeId}</div>;
126126
}
127127

128-
const isImported = !!frontmatter.importedFromSpaceUri;
128+
const isImported = !!frontmatter.importedFromRid;
129129
const modifiedAt =
130130
typeof frontmatter.lastModified === "number"
131131
? frontmatter.lastModified

apps/obsidian/src/components/NodeTypeSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const generateTagPlaceholder = (format: string, nodeName?: string): string => {
2727

2828
type EditableFieldKey = keyof Omit<
2929
DiscourseNode,
30-
"id" | "shortcut" | "modified" | "created"
30+
"id" | "shortcut" | "modified" | "created" | "importedFromRid"
3131
>;
3232

3333
type BaseFieldConfig = {

apps/obsidian/src/components/RelationshipSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const RelationshipSettings = () => {
2121

2222
type EditableFieldKey = keyof Omit<
2323
DiscourseRelation,
24-
"id" | "modified" | "created"
24+
"id" | "modified" | "created" | "importedFromRid"
2525
>;
2626

2727
const handleRelationChange = async (

apps/obsidian/src/components/RelationshipTypeSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const RelationshipTypeSettings = () => {
9999

100100
type EditableFieldKey = keyof Omit<
101101
DiscourseRelationType,
102-
"id" | "modified" | "created"
102+
"id" | "modified" | "created" | "importedFromRid"
103103
>;
104104

105105
const handleRelationTypeChange = (

apps/obsidian/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export default class DiscourseGraphPlugin extends Plugin {
275275
keysToHide.push(
276276
...[
277277
"nodeTypeId",
278-
"importedFromSpaceUri",
278+
"importedFromRid",
279279
"nodeInstanceId",
280280
"publishedToGroups",
281281
"lastModified",

apps/obsidian/src/services/QueryEngine.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,23 @@ export class QueryEngine {
291291
}
292292

293293
/**
294-
* Find an existing imported file by nodeInstanceId and importedFromSpaceUri
294+
* Find an existing imported file by nodeInstanceId and importedFromRid
295295
* Uses DataCore when available; falls back to vault iteration otherwise
296296
* Returns the file if found, null otherwise
297297
*/
298298
findExistingImportedFile = (
299299
nodeInstanceId: string,
300-
importedFromSpaceUri: string,
300+
importedFromRid: string,
301301
): TFile | null => {
302302
if (this.dc) {
303303
try {
304304
const safeId = nodeInstanceId
305305
.replace(/\\/g, "\\\\")
306306
.replace(/"/g, '\\"');
307-
const safeUri = importedFromSpaceUri
307+
const safeUri = importedFromRid
308308
.replace(/\\/g, "\\\\")
309309
.replace(/"/g, '\\"');
310-
const dcQuery = `@page and nodeInstanceId = "${safeId}" and importedFromSpaceUri = "${safeUri}"`;
310+
const dcQuery = `@page and nodeInstanceId = "${safeId}" and importedFromRid = "${safeUri}"`;
311311
const results = this.dc.query(dcQuery);
312312

313313
for (const page of results) {
@@ -329,7 +329,7 @@ export class QueryEngine {
329329
const fm = this.app.metadataCache.getFileCache(f)?.frontmatter;
330330
if (
331331
fm?.nodeInstanceId === nodeInstanceId &&
332-
fm.importedFromSpaceUri === importedFromSpaceUri
332+
fm.importedFromRid === importedFromRid
333333
) {
334334
return f;
335335
}

apps/obsidian/src/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type DiscourseNode = {
1313
keyImage?: boolean;
1414
created: number;
1515
modified: number;
16+
importedFromRid?: string;
1617
};
1718

1819
export type DiscourseRelationType = {
@@ -22,6 +23,7 @@ export type DiscourseRelationType = {
2223
color: TldrawColorName;
2324
created: number;
2425
modified: number;
26+
importedFromRid?: string;
2527
};
2628

2729
export type DiscourseRelation = {
@@ -31,6 +33,19 @@ export type DiscourseRelation = {
3133
relationshipTypeId: string;
3234
created: number;
3335
modified: number;
36+
importedFromRid?: string;
37+
};
38+
39+
export type RelationInstance = {
40+
id: string;
41+
type: string;
42+
source: string;
43+
destination: string;
44+
created: number;
45+
author: string;
46+
lastModified?: number;
47+
publishedToGroupId?: string[];
48+
importedFromRid?: string;
3449
};
3550

3651
export type Settings = {

apps/obsidian/src/utils/fileChangeListener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class FileChangeListener {
9898
return false;
9999
}
100100

101-
if (frontmatter?.importedFromSpaceUri) {
101+
if (frontmatter?.importedFromRid) {
102102
return false;
103103
}
104104

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import type { TFile } from "obsidian";
2+
import type DiscourseGraphPlugin from "~/index";
3+
import { ensureNodeInstanceId } from "./nodeInstanceId";
4+
5+
export type DiscourseNodeInVault = {
6+
file: TFile;
7+
frontmatter: Record<string, unknown>;
8+
nodeTypeId: string;
9+
nodeInstanceId: string;
10+
};
11+
12+
/**
13+
* Step 1: Collect all discourse nodes from the vault
14+
* Filters markdown files that have nodeTypeId in frontmatter
15+
*/
16+
export const collectDiscourseNodesFromVault = async (
17+
plugin: DiscourseGraphPlugin,
18+
includeImported?: boolean,
19+
): Promise<DiscourseNodeInVault[]> => {
20+
const allFiles = plugin.app.vault.getMarkdownFiles();
21+
const dgNodes: DiscourseNodeInVault[] = [];
22+
23+
for (const file of allFiles) {
24+
const cache = plugin.app.metadataCache.getFileCache(file);
25+
const frontmatter = cache?.frontmatter;
26+
27+
// Not a discourse node
28+
if (!frontmatter?.nodeTypeId) {
29+
continue;
30+
}
31+
32+
if (
33+
// note: importedFromSpaceUri is legacy
34+
(frontmatter.importedFromRid || frontmatter.importedFromSpaceUri) &&
35+
includeImported !== true
36+
) {
37+
continue;
38+
}
39+
40+
const nodeTypeId = frontmatter.nodeTypeId as string;
41+
if (!nodeTypeId) {
42+
continue;
43+
}
44+
45+
const nodeInstanceId = await ensureNodeInstanceId(
46+
plugin,
47+
file,
48+
frontmatter as Record<string, unknown>,
49+
);
50+
51+
dgNodes.push({
52+
file,
53+
frontmatter: frontmatter as Record<string, unknown>,
54+
nodeTypeId,
55+
nodeInstanceId,
56+
});
57+
}
58+
59+
return dgNodes;
60+
};

0 commit comments

Comments
 (0)