Skip to content

Commit f6669c5

Browse files
authored
[ENG-1237] Create feature flag infra for Obsdian (#672)
* current progress * hide the modal * address PR comments * address PR comments
1 parent 48bc955 commit f6669c5

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useState } from "react";
2+
import { usePlugin } from "./PluginContext";
3+
import { Notice } from "obsidian";
4+
5+
export const AdminPanelSettings = () => {
6+
const plugin = usePlugin();
7+
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
8+
9+
const handleSave = async () => {
10+
await plugin.saveSettings();
11+
new Notice("Admin panel settings saved");
12+
setHasUnsavedChanges(false);
13+
};
14+
15+
return (
16+
<div className="general-settings">
17+
{/* Add more admin panel settings sections here */}
18+
19+
<div className="setting-item">
20+
<button
21+
onClick={() => void handleSave()}
22+
className={hasUnsavedChanges ? "mod-cta" : ""}
23+
disabled={!hasUnsavedChanges}
24+
>
25+
Save Changes
26+
</button>
27+
</div>
28+
29+
{hasUnsavedChanges && (
30+
<div className="text-muted mt-2">You have unsaved changes</div>
31+
)}
32+
</div>
33+
);
34+
};

apps/obsidian/src/components/Settings.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StrictMode, useState } from "react";
1+
import { StrictMode, useState, useEffect } from "react";
22
import { App, PluginSettingTab } from "obsidian";
33
import type DiscourseGraphPlugin from "~/index";
44
import { Root, createRoot } from "react-dom/client";
@@ -7,11 +7,26 @@ import RelationshipTypeSettings from "./RelationshipTypeSettings";
77
import RelationshipSettings from "./RelationshipSettings";
88
import NodeTypeSettings from "./NodeTypeSettings";
99
import GeneralSettings from "./GeneralSettings";
10+
import { AdminPanelSettings } from "./AdminPanelSettings";
1011
import { PluginProvider } from "./PluginContext";
1112

1213
const Settings = () => {
1314
const [activeTab, setActiveTab] = useState("general");
1415

16+
useEffect(() => {
17+
const handleKeyPress = (e: KeyboardEvent) => {
18+
const isMod = e.metaKey || e.ctrlKey;
19+
if (isMod && e.shiftKey && e.key.toLowerCase() === "a") {
20+
e.stopPropagation();
21+
e.preventDefault();
22+
setActiveTab("admin-panel");
23+
}
24+
};
25+
26+
window.addEventListener("keydown", handleKeyPress);
27+
return () => window.removeEventListener("keydown", handleKeyPress);
28+
}, []);
29+
1530
return (
1631
<div className="flex flex-col gap-4">
1732
<h2 className="dg-h2">Discourse Graph Settings</h2>
@@ -56,13 +71,20 @@ const Settings = () => {
5671
>
5772
Discourse Relations
5873
</button>
74+
{/* Hidden Admin Panel tab - only visible when activeTab is "admin-panel" */}
75+
{activeTab === "admin-panel" && (
76+
<button className="!bg-modifier-hover accent-border-bottom mr-2 cursor-pointer border-0 px-4 py-2">
77+
Admin Panel
78+
</button>
79+
)}
5980
</div>
6081

6182
{activeTab === "general" && <GeneralSettings />}
6283
{activeTab === "nodeTypes" && <NodeTypeSettings />}
6384
{activeTab === "relationTypes" && <RelationshipTypeSettings />}
6485
{activeTab === "relations" && <RelationshipSettings />}
6586
{activeTab === "frontmatter" && <GeneralSettings />}
87+
{activeTab === "admin-panel" && <AdminPanelSettings />}
6688
</div>
6789
);
6890
};

apps/obsidian/src/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ export const DEFAULT_SETTINGS: Settings = {
7171
canvasAttachmentsFolderPath: "attachments",
7272
nodeTagHotkey: "\\",
7373
};
74+
75+
export const FEATURE_FLAGS = {
76+
// settings for these features are in the Admin Panel (hidden tab in Settings, toggle with Ctrl+Shift+A)
77+
DATABASE_SYNC: "databaseSync",
78+
} as const;
79+
80+
export type FeatureFlagKey = (typeof FEATURE_FLAGS)[keyof typeof FEATURE_FLAGS];
7481
export const FRONTMATTER_KEY = "tldr-dg";
7582
export const TLDATA_DELIMITER_START =
7683
"!!!_START_OF_TLDRAW_DG_DATA__DO_NOT_CHANGE_THIS_PHRASE_!!!";

apps/obsidian/src/utils/registerCommands.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ export const registerCommands = (plugin: DiscourseGraphPlugin) => {
5151
} else {
5252
await createDiscourseNode({
5353
plugin,
54-
nodeType,
55-
text: title,
56-
editor,
57-
});
54+
nodeType,
55+
text: title,
56+
editor,
57+
});
5858
}
5959
},
6060
}).open();

0 commit comments

Comments
 (0)