Skip to content

Commit e3e6a78

Browse files
authored
ENG-1575 Hide left sidebar settings tabs when feature flag is off (#1084)
* ENG-1575 Hide left sidebar settings tabs when feature flag is off Hide the Personal and Global "Left sidebar" tabs in the Settings dialog when the "Enable left sidebar" feature flag is disabled, using the same hidden prop pattern as the Admin tab. * ENG-1575 Sync left sidebar tab visibility with flag changes live Subscribe to the leftSidebarFlag setting change so the Left sidebar tabs hide/show immediately when the flag is toggled in the open settings dialog, matching the live sidebar mount/unmount in index.ts, instead of waiting for a tab switch or refresh. * ENG-1575 Fall back to Home when a hidden left sidebar tab is selected When the flag is off, derive the displayed tab so a left-sidebar tab that ends up selected (e.g. via a deep link from the command palette) falls back to the Home tab instead of being rendered as a hidden selection. * Extract settings tab ids into named constants
1 parent 92d3c56 commit e3e6a78

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ import { LeftSidebarPersonalSections } from "./LeftSidebarPersonalSettings";
3131
import { LeftSidebarGlobalSections } from "./LeftSidebarGlobalSettings";
3232
import posthog from "posthog-js";
3333
import { bulkReadSettings } from "./utils/accessors";
34+
import { onSettingChange, settingKeys } from "./utils/settingsEmitter";
35+
36+
const settingsTabIds = {
37+
homePersonal: "discourse-graph-home-personal",
38+
leftSidebarPersonal: "left-sidebar-personal-settings",
39+
leftSidebarGlobal: "left-sidebar-global-settings",
40+
} as const;
3441

3542
type SectionHeaderProps = {
3643
children: React.ReactNode;
@@ -86,17 +93,25 @@ export const SettingsDialog = ({
8693
const nodesNode = grammarNode?.children.find((node) => node.text === "nodes");
8794
const nodes = getDiscourseNodes().filter(excludeDefaultNodes);
8895
const [activeTabId, setActiveTabId] = useState<TabId>(
89-
selectedTabId ?? "discourse-graph-home-personal",
96+
selectedTabId ?? settingsTabIds.homePersonal,
9097
);
9198
// eslint-disable-next-line react-hooks/exhaustive-deps
9299
const settings = useMemo(() => bulkReadSettings(), [activeTabId]);
100+
const [leftSidebarEnabled, setLeftSidebarEnabled] = useState(
101+
settings.featureFlags["Enable left sidebar"],
102+
);
103+
useEffect(() => {
104+
return onSettingChange(settingKeys.leftSidebarFlag, (newValue) => {
105+
setLeftSidebarEnabled(Boolean(newValue));
106+
});
107+
}, []);
93108
const [showAdminPanel, setShowAdminPanel] = useState(
94109
window.roamAlphaAPI.graph.name === "discourse-graphs" || false,
95110
);
96111

97112
useEffect(() => {
98113
posthog.capture("Settings: Dialog Opened", {
99-
initialTabId: String(selectedTabId ?? "discourse-graph-home-personal"),
114+
initialTabId: String(selectedTabId ?? settingsTabIds.homePersonal),
100115
});
101116
}, [selectedTabId]);
102117

@@ -114,6 +129,13 @@ export const SettingsDialog = ({
114129
window.addEventListener("keydown", handleKeyPress);
115130
return () => window.removeEventListener("keydown", handleKeyPress);
116131
}, []);
132+
const leftSidebarTabHidden =
133+
!leftSidebarEnabled &&
134+
(activeTabId === settingsTabIds.leftSidebarPersonal ||
135+
activeTabId === settingsTabIds.leftSidebarGlobal);
136+
const visibleTabId = leftSidebarTabHidden
137+
? settingsTabIds.homePersonal
138+
: activeTabId;
117139
return (
118140
<Dialog
119141
isOpen={isOpen}
@@ -161,15 +183,15 @@ export const SettingsDialog = ({
161183
tabId: String(id),
162184
});
163185
}}
164-
selectedTabId={activeTabId}
186+
selectedTabId={visibleTabId}
165187
vertical={true}
166188
renderActiveTabPanelOnly={true}
167189
>
168190
<SectionHeader className="text-lg font-semibold text-neutral-dark">
169191
Personal Settings
170192
</SectionHeader>
171193
<Tab
172-
id="discourse-graph-home-personal"
194+
id={settingsTabIds.homePersonal}
173195
title="Home"
174196
className="overflow-y-auto"
175197
panel={
@@ -201,7 +223,8 @@ export const SettingsDialog = ({
201223
}
202224
/>
203225
<Tab
204-
id="left-sidebar-personal-settings"
226+
id={settingsTabIds.leftSidebarPersonal}
227+
hidden={!leftSidebarEnabled}
205228
title="Left sidebar"
206229
className="overflow-y-auto"
207230
panel={
@@ -234,7 +257,8 @@ export const SettingsDialog = ({
234257
}
235258
/>
236259
<Tab
237-
id="left-sidebar-global-settings"
260+
id={settingsTabIds.leftSidebarGlobal}
261+
hidden={!leftSidebarEnabled}
238262
title="Left sidebar"
239263
className="overflow-y-auto"
240264
panel={

0 commit comments

Comments
 (0)