Skip to content

Commit 55a74c8

Browse files
trangdoan982maparentdevin-ai-integration[bot]
authored
[ENG-1295 & ENG-1350 & ENG-1297] F5 import and refresh published nodes (#722)
* eng-1344 f10b upload obsidian relations and their schemas * current progress * feature finished * address PR comments * address PR comments * remove local test file * curr progress * revert what is handled in #721 * Use SpaceURI rather than spaceId in frontmatter * address PR comments * address PR comments * cleanup * Update apps/obsidian/src/utils/importNodes.ts Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> * normalize on using numbers for dates * correction * apply ctime, mtime to assets * spurious log * Preserve ctime, mtime in processFrontMatter. Also timezone correction * add lastModified in frontMatter * make sure import image works * add recursive folder creation * modify the fetchNodeContent flow; simplify the pathMapping * WIP: shuffle the filePath around * send originalPathDepth * actually send path itself * clarify var name * make sure fileImport works for all possible settings * store relative path when rewrite the wikilink instead of default to fileToLinkText * cleanup logs * nit * AI corrections * Update apps/obsidian/src/utils/importNodes.ts Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> * address PR comments --------- Co-authored-by: Marc-Antoine Parent <maparent@acm.org> Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 290a9f5 commit 55a74c8

13 files changed

Lines changed: 2071 additions & 87 deletions

apps/obsidian/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
"@octokit/core": "^6.1.2",
2020
"@repo/eslint-config": "workspace:*",
2121
"@repo/typescript-config": "workspace:*",
22+
"@types/mime-types": "3.0.1",
2223
"@types/node": "^20",
2324
"@types/react": "catalog:obsidian",
2425
"@types/react-dom": "catalog:obsidian",
25-
"@types/mime-types": "3.0.1",
2626
"autoprefixer": "^10.4.21",
2727
"builtin-modules": "3.3.0",
2828
"dotenv": "^16.4.5",
@@ -43,6 +43,7 @@
4343
"@repo/utils": "workspace:*",
4444
"@supabase/supabase-js": "catalog:",
4545
"date-fns": "^4.1.0",
46+
"gray-matter": "^4.0.3",
4647
"mime-types": "^3.0.1",
4748
"nanoid": "^4.0.2",
4849
"react": "catalog:obsidian",

apps/obsidian/src/components/DiscourseContextView.tsx

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
import { ItemView, TFile, WorkspaceLeaf } from "obsidian";
1+
import { ItemView, TFile, WorkspaceLeaf, Notice } from "obsidian";
22
import { createRoot, Root } from "react-dom/client";
33
import DiscourseGraphPlugin from "~/index";
44
import { getDiscourseNodeFormatExpression } from "~/utils/getDiscourseNodeFormatExpression";
55
import { RelationshipSection } from "~/components/RelationshipSection";
66
import { VIEW_TYPE_DISCOURSE_CONTEXT } from "~/types";
77
import { PluginProvider, usePlugin } from "~/components/PluginContext";
88
import { getNodeTypeById } from "~/utils/typeUtils";
9+
import { refreshImportedFile } from "~/utils/importNodes";
10+
import { useState } from "react";
911

1012
type DiscourseContextProps = {
1113
activeFile: TFile | null;
1214
};
1315

1416
const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
1517
const plugin = usePlugin();
18+
const [isRefreshing, setIsRefreshing] = useState(false);
1619

1720
const extractContentFromTitle = (format: string, title: string): string => {
1821
if (!format) return "";
@@ -21,6 +24,30 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
2124
return match?.[1] ?? title;
2225
};
2326

27+
const handleRefresh = async () => {
28+
if (!activeFile || isRefreshing) return;
29+
30+
setIsRefreshing(true);
31+
try {
32+
const result = await refreshImportedFile({ plugin, file: activeFile });
33+
if (result.success) {
34+
new Notice("File refreshed successfully", 3000);
35+
} else {
36+
new Notice(
37+
`Failed to refresh file: ${result.error || "Unknown error"}`,
38+
5000,
39+
);
40+
}
41+
} catch (error) {
42+
const errorMessage =
43+
error instanceof Error ? error.message : String(error);
44+
new Notice(`Refresh failed: ${errorMessage}`, 5000);
45+
console.error("Refresh failed:", error);
46+
} finally {
47+
setIsRefreshing(false);
48+
}
49+
};
50+
2451
const renderContent = () => {
2552
if (!activeFile) {
2653
return <div>No file is open</div>;
@@ -45,6 +72,20 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
4572
if (!nodeType) {
4673
return <div>Unknown node type: {frontmatter.nodeTypeId}</div>;
4774
}
75+
76+
const isImported = !!frontmatter.importedFromSpaceUri;
77+
const modifiedAt =
78+
typeof frontmatter.lastModified === "number"
79+
? frontmatter.lastModified
80+
: activeFile.stat.mtime;
81+
const sourceDates =
82+
isImported && activeFile?.stat
83+
? {
84+
createdAt: new Date(activeFile.stat.ctime).toLocaleString(),
85+
modifiedAt: new Date(modifiedAt).toLocaleString(),
86+
}
87+
: null;
88+
4889
return (
4990
<>
5091
<div className="mb-6">
@@ -56,6 +97,18 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
5697
/>
5798
)}
5899
{nodeType.name || "Unnamed Node Type"}
100+
{isImported && (
101+
<button
102+
onClick={() => {
103+
void handleRefresh();
104+
}}
105+
disabled={isRefreshing}
106+
className="ml-auto rounded border px-2 py-1 text-xs"
107+
title="Refresh from source"
108+
>
109+
{isRefreshing ? "Refreshing..." : "🔄 Refresh"}
110+
</button>
111+
)}
59112
</div>
60113

61114
{nodeType.format && (
@@ -64,6 +117,13 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
64117
{extractContentFromTitle(nodeType.format, activeFile.basename)}
65118
</div>
66119
)}
120+
121+
{isImported && sourceDates && (
122+
<div className="text-modifier-text mt-2 text-xs">
123+
<div>Created in source: {sourceDates.createdAt}</div>
124+
<div>Last modified in source: {sourceDates.modifiedAt}</div>
125+
</div>
126+
)}
67127
</div>
68128

69129
<div>

0 commit comments

Comments
 (0)