Skip to content

Commit 1f9145b

Browse files
authored
ENG-1840 Refactor admin panel integration in Settings component (#1112)
- Introduced ADMIN_TAB_ID constant for better maintainability. - Updated admin panel visibility logic and button rendering. - Captured analytics events for admin panel interactions. - Improved version display logic in the footer.
1 parent d804d1a commit 1f9145b

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

apps/roam/src/components/settings/Settings.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const settingsTabIds = {
3939
leftSidebarGlobal: "left-sidebar-global-settings",
4040
} as const;
4141

42+
const ADMIN_TAB_ID = "secret-admin-panel";
43+
4244
type SectionHeaderProps = {
4345
children: React.ReactNode;
4446
className?: string;
@@ -108,6 +110,12 @@ export const SettingsDialog = ({
108110
const [showAdminPanel, setShowAdminPanel] = useState(
109111
window.roamAlphaAPI.graph.name === "discourse-graphs" || false,
110112
);
113+
const { version, buildDate } = getVersionWithDate();
114+
const openAdminPanel = (): void => {
115+
setShowAdminPanel(true);
116+
setActiveTabId(ADMIN_TAB_ID);
117+
posthog.capture("Settings: Admin Panel Opened from Footer");
118+
};
111119

112120
useEffect(() => {
113121
posthog.capture("Settings: Dialog Opened", {
@@ -121,7 +129,7 @@ export const SettingsDialog = ({
121129
e.stopPropagation();
122130
e.preventDefault();
123131
setShowAdminPanel(true);
124-
setActiveTabId("secret-admin-panel");
132+
setActiveTabId(ADMIN_TAB_ID);
125133
posthog.capture("Settings: Admin Panel Opened via Shortcut");
126134
}
127135
};
@@ -309,8 +317,8 @@ export const SettingsDialog = ({
309317
<Tabs.Expander />
310318
{/* Secret Admin Panel */}
311319
<Tab
312-
hidden={!showAdminPanel}
313-
id="secret-admin-panel"
320+
hidden={true}
321+
id={ADMIN_TAB_ID}
314322
title="Admin"
315323
className="overflow-y-auto"
316324
panel={<AdminPanel globalSettings={settings.globalSettings} />}
@@ -330,9 +338,19 @@ export const SettingsDialog = ({
330338
Send Feedback
331339
</Button>
332340
</div>
333-
<div className="absolute bottom-4 right-4">
341+
<div className="absolute bottom-4 right-4 flex items-center gap-2">
342+
{showAdminPanel && (
343+
<Button
344+
minimal={true}
345+
outlined={true}
346+
small={true}
347+
onClick={openAdminPanel}
348+
>
349+
Admin
350+
</Button>
351+
)}
334352
<span className="text-xs text-gray-500">
335-
v{getVersionWithDate().version}-{getVersionWithDate().buildDate}
353+
v{version}-{buildDate}
336354
</span>
337355
</div>
338356
{/* <Button

0 commit comments

Comments
 (0)