Skip to content

Commit c031c3c

Browse files
committed
ENG-1819: Make global left sidebar fold toggle personal
Fold state moves from the shared global setting to a per-user personal setting (PERSONAL_KEYS.globalSectionFolded, legacy dual-write via a {userUid}/Global-Section-Folded marker block). The admin Collapsable flag is removed: the global section is now always foldable per user. Based on prior branch commit d51649d reconciled onto current main.
1 parent 0d85690 commit c031c3c

8 files changed

Lines changed: 47 additions & 152 deletions

File tree

apps/roam/src/components/LeftSidebarView.tsx

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
isQueryBlockRef,
3333
type LeftSidebarConfig,
3434
type LeftSidebarPersonalSectionConfig,
35+
getGlobalSectionFoldedMarkerText,
3536
mergeGlobalSectionWithAccessor,
3637
mergePersonalSectionsWithAccessor,
3738
} from "~/utils/getLeftSidebarSettings";
@@ -51,7 +52,6 @@ import {
5152
PERSONAL_KEYS,
5253
GLOBAL_KEYS,
5354
LEFT_SIDEBAR_KEYS,
54-
LEFT_SIDEBAR_SETTINGS_KEYS,
5555
} from "~/components/settings/utils/settingKeys";
5656
import type { LeftSidebarGlobalSettings } from "~/components/settings/utils/zodSchema";
5757
import { createBlock } from "roamjs-components/writes";
@@ -617,53 +617,45 @@ const PersonalSections = ({
617617

618618
const GlobalSection = ({
619619
config,
620+
folded,
621+
leftSidebarUid,
620622
onGlobalChildrenReorder,
621623
onloadArgs,
622624
}: {
623625
config: LeftSidebarConfig["global"];
626+
folded: boolean;
627+
leftSidebarUid: string;
624628
onGlobalChildrenReorder: (oldIndex: number, newIndex: number) => void;
625629
onloadArgs: OnloadArgs;
626630
}) => {
627-
const [isOpen, setIsOpen] = useState<boolean>(!config.settings?.folded.value);
631+
const [isOpen, setIsOpen] = useState<boolean>(!folded);
628632
const isTogglingRef = useRef(false);
629633
if (!config.children?.length) return null;
630-
const isCollapsable = config.settings?.collapsable.value;
631634

632635
const handleToggle = async () => {
633-
if (!isCollapsable || !config.settings) return;
634636
if (isTogglingRef.current) return;
635637
isTogglingRef.current = true;
636638
try {
637-
const settings = config.settings;
638639
const nextIsOpen = !isOpen;
639640
setIsOpen(nextIsOpen);
641+
const markerText = getGlobalSectionFoldedMarkerText(
642+
window.roamAlphaAPI.user.uid() || "",
643+
);
640644
if (nextIsOpen) {
641-
const children = getBasicTreeByParentUid(settings.uid);
645+
const children = getBasicTreeByParentUid(leftSidebarUid);
642646
await Promise.all(
643647
children
644-
.filter((c) => c.text === "Folded")
648+
.filter((c) => c.text === markerText)
645649
.map((c) => deleteBlock(c.uid)),
646650
);
647-
settings.folded.uid = undefined;
648-
settings.folded.value = false;
649651
} else {
650-
const newUid = window.roamAlphaAPI.util.generateUID();
651652
await createBlock({
652-
parentUid: settings.uid,
653-
node: { text: "Folded", uid: newUid },
653+
parentUid: leftSidebarUid,
654+
node: { text: markerText },
654655
});
655-
settings.folded.uid = newUid;
656-
settings.folded.value = true;
657656
}
658657
refreshConfigTree();
659-
setGlobalSetting(
660-
[
661-
GLOBAL_KEYS.leftSidebar,
662-
LEFT_SIDEBAR_KEYS.settings,
663-
LEFT_SIDEBAR_SETTINGS_KEYS.folded,
664-
],
665-
!nextIsOpen,
666-
);
658+
setPersonalSetting([PERSONAL_KEYS.globalSectionFolded], !nextIsOpen);
667659
} finally {
668660
isTogglingRef.current = false;
669661
}
@@ -690,18 +682,12 @@ const GlobalSection = ({
690682
>
691683
<div className="flex w-full items-center justify-between">
692684
<span>GLOBAL</span>
693-
{isCollapsable && (
694-
<span className="sidebar-title-button-chevron p-1">
695-
<Icon icon={isOpen ? "chevron-down" : "chevron-right"} />
696-
</span>
697-
)}
685+
<span className="sidebar-title-button-chevron p-1">
686+
<Icon icon={isOpen ? "chevron-down" : "chevron-right"} />
687+
</span>
698688
</div>
699689
</div>
700-
{isCollapsable ? (
701-
<Collapse isOpen={isOpen}>{children}</Collapse>
702-
) : (
703-
children
704-
)}
690+
<Collapse isOpen={isOpen}>{children}</Collapse>
705691
</>
706692
);
707693
};
@@ -718,6 +704,9 @@ const buildConfig = (snapshot?: SettingsSnapshot): LeftSidebarConfig => {
718704
: getPersonalSetting<
719705
ReturnType<typeof getPersonalSettings>[typeof PERSONAL_KEYS.leftSidebar]
720706
>([PERSONAL_KEYS.leftSidebar]);
707+
const globalSectionFoldedValue = snapshot
708+
? snapshot.personalSettings[PERSONAL_KEYS.globalSectionFolded]
709+
: getPersonalSetting<boolean>([PERSONAL_KEYS.globalSectionFolded]);
721710

722711
// Read UIDs from old system (needed for fold CRUD during dual-write)
723712
const oldConfig = getCurrentLeftSidebarConfig();
@@ -727,6 +716,10 @@ const buildConfig = (snapshot?: SettingsSnapshot): LeftSidebarConfig => {
727716
favoritesMigrated: oldConfig.favoritesMigrated,
728717
sidebarMigrated: oldConfig.sidebarMigrated,
729718
global: mergeGlobalSectionWithAccessor(oldConfig.global, globalValues),
719+
globalSectionFolded: {
720+
uid: oldConfig.globalSectionFolded.uid,
721+
value: globalSectionFoldedValue ?? oldConfig.globalSectionFolded.value,
722+
},
730723
personal: {
731724
uid: oldConfig.personal.uid,
732725
sections: mergePersonalSectionsWithAccessor(
@@ -916,6 +909,8 @@ const LeftSidebarView = ({
916909
<FavoritesPopover onloadArgs={onloadArgs} />
917910
<GlobalSection
918911
config={config.global}
912+
folded={config.globalSectionFolded.value}
913+
leftSidebarUid={config.uid}
919914
onGlobalChildrenReorder={reorderGlobalChildren}
920915
onloadArgs={onloadArgs}
921916
/>

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import React, { useCallback, useEffect, useMemo, useState, memo } from "react";
22
import { Button, ButtonGroup, Collapse } from "@blueprintjs/core";
33
import { arrayMove } from "@dnd-kit/sortable";
4-
import { GlobalFlagPanel } from "~/components/settings/components/BlockPropSettingPanels";
54
import {
65
setGlobalSetting,
76
type SettingsSnapshot,
87
} from "~/components/settings/utils/accessors";
98
import {
109
GLOBAL_KEYS,
1110
LEFT_SIDEBAR_KEYS,
12-
LEFT_SIDEBAR_SETTINGS_KEYS,
1311
} from "~/components/settings/utils/settingKeys";
1412
import AutocompleteInput from "roamjs-components/components/AutocompleteInput";
1513
import getAllPageNames from "roamjs-components/queries/getAllPageNames";
@@ -118,11 +116,6 @@ const LeftSidebarGlobalSectionsContent = ({
118116
order: 0,
119117
node: { text: globalSectionText },
120118
});
121-
const settingsUid = await createBlock({
122-
parentUid: globalSectionUid,
123-
order: 0,
124-
node: { text: "Settings" },
125-
});
126119
const childrenUid = await createBlock({
127120
parentUid: globalSectionUid,
128121
order: 0,
@@ -132,11 +125,6 @@ const LeftSidebarGlobalSectionsContent = ({
132125
setPages([]);
133126
setGlobalSection({
134127
uid: globalSectionUid,
135-
settings: {
136-
uid: settingsUid,
137-
collapsable: { uid: undefined, value: false },
138-
folded: { uid: undefined, value: false },
139-
},
140128
childrenUid,
141129
children: [],
142130
});
@@ -289,27 +277,6 @@ const LeftSidebarGlobalSectionsContent = ({
289277

290278
return (
291279
<div className="flex flex-col gap-4 p-1">
292-
<div
293-
className="global-section-settings rounded-md p-3 hover:bg-gray-50"
294-
style={{
295-
border: "1px solid rgba(51, 51, 51, 0.2)",
296-
}}
297-
>
298-
<GlobalFlagPanel
299-
title="Collapsable"
300-
description="Make global section collapsable"
301-
settingKeys={[
302-
GLOBAL_KEYS.leftSidebar,
303-
LEFT_SIDEBAR_KEYS.settings,
304-
LEFT_SIDEBAR_SETTINGS_KEYS.collapsable,
305-
]}
306-
initialValue={globalSection.settings?.collapsable?.value || false}
307-
order={0}
308-
uid={globalSection.settings?.collapsable?.uid || ""}
309-
parentUid={globalSection.settings?.uid || ""}
310-
/>
311-
</div>
312-
313280
<div
314281
className="global-section-children rounded-md p-3 hover:bg-gray-50"
315282
style={{

apps/roam/src/components/settings/utils/accessors.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ const getLegacyPersonalSetting = (keys: string[]): unknown => {
307307
return readPathValue(leftSidebarSettings, keys.slice(1));
308308
}
309309

310+
if (keys[0] === "Global section folded") {
311+
return getLeftSidebarSettings(discourseConfigRef.tree).globalSectionFolded
312+
.value;
313+
}
314+
310315
return undefined;
311316
};
312317

@@ -403,14 +408,6 @@ const getLegacyGlobalSetting = (keys: string[]): unknown => {
403408
leftSidebarSettings["Children"] = sidebar.global.children.map(
404409
(c) => c.text,
405410
);
406-
const sidebarSettingValues: Record<string, unknown> = {};
407-
sidebarSettingValues["Collapsable"] =
408-
sidebar.global.settings?.collapsable.value ??
409-
DEFAULT_GLOBAL_SETTINGS["Left sidebar"].Settings.Collapsable;
410-
sidebarSettingValues["Folded"] =
411-
sidebar.global.settings?.folded.value ??
412-
DEFAULT_GLOBAL_SETTINGS["Left sidebar"].Settings.Folded;
413-
leftSidebarSettings["Settings"] = sidebarSettingValues;
414411
if (keys.length === 1) return leftSidebarSettings;
415412
return readPathValue(leftSidebarSettings, keys.slice(1));
416413
}

apps/roam/src/components/settings/utils/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const ensureLegacyConfigBlocks = async (pageUid: string): Promise<void> => {
125125
const globalSectionMap = buildBlockMap(leftSidebarMap["Global-Section"]);
126126
await ensureBlocksExist(
127127
leftSidebarMap["Global-Section"],
128-
["Children", "Settings"],
128+
["Children"],
129129
globalSectionMap,
130130
);
131131

apps/roam/src/components/settings/utils/settingKeys.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const PERSONAL_KEYS = {
3232
personalNodeMenuTrigger: "Personal node menu trigger",
3333
nodeSearchMenuTrigger: "Node search menu trigger",
3434
leftSidebar: "Left sidebar",
35+
globalSectionFolded: "Global section folded",
3536
query: "Query",
3637
reifiedRelationTriples: "Reified relation triples",
3738
canvasNodeShortcuts: "Canvas node shortcuts",
@@ -61,7 +62,6 @@ export const SUGGESTIVE_MODE_KEYS = {
6162

6263
export const LEFT_SIDEBAR_KEYS = {
6364
children: "Children",
64-
settings: "Settings",
6565
} as const satisfies Record<string, keyof LeftSidebarGlobalSettings>;
6666

6767
export const EXPORT_KEYS = {
@@ -74,14 +74,6 @@ export const EXPORT_KEYS = {
7474
frontmatter: "Frontmatter",
7575
} as const satisfies Record<string, keyof ExportSettings>;
7676

77-
export const LEFT_SIDEBAR_SETTINGS_KEYS = {
78-
collapsable: "Collapsable",
79-
folded: "Folded",
80-
} as const satisfies Record<
81-
string,
82-
keyof LeftSidebarGlobalSettings["Settings"]
83-
>;
84-
8577
export const DISCOURSE_NODE_KEYS = {
8678
canvasSettings: "canvasSettings",
8779
overlay: "overlay",

apps/roam/src/components/settings/utils/zodSchema.example.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,13 @@ const suggestiveModeGlobalSettings: SuggestiveModeGlobalSettings = {
137137

138138
const leftSidebarGlobalSettings: LeftSidebarGlobalSettings = {
139139
Children: ["daily-notes-uid", "quick-capture-uid", "inbox-uid"],
140-
Settings: {
141-
Collapsable: true,
142-
Folded: false,
143-
},
144140
};
145141

146142
const globalSettings: GlobalSettings = {
147143
Trigger: ";;",
148144
"Canvas page format": "Canvas - {date} - {title}",
149145
"Left sidebar": {
150146
Children: ["daily-notes-uid", "quick-capture-uid", "inbox-uid"],
151-
Settings: {
152-
Collapsable: true,
153-
Folded: false,
154-
},
155147
},
156148
Export: {
157149
"Remove special characters": true,
@@ -255,10 +247,6 @@ const defaultGlobalSettings: GlobalSettings = {
255247
"Canvas page format": "",
256248
"Left sidebar": {
257249
Children: [],
258-
Settings: {
259-
Collapsable: false,
260-
Folded: false,
261-
},
262250
},
263251
Export: {
264252
"Remove special characters": false,
@@ -372,6 +360,7 @@ const personalSettings: PersonalSettings = {
372360
},
373361
},
374362
],
363+
"Global section folded": false,
375364
"Personal node menu trigger": { modifiers: 0, key: ";;" },
376365
"Node search menu trigger": "//",
377366
"Discourse tool shortcut": { modifiers: 0, key: "d" },
@@ -404,6 +393,7 @@ const personalSettings: PersonalSettings = {
404393

405394
const defaultPersonalSettings: PersonalSettings = {
406395
"Left sidebar": [],
396+
"Global section folded": false,
407397
"Personal node menu trigger": { modifiers: 0, key: "" },
408398
"Node search menu trigger": "",
409399
"Discourse tool shortcut": { modifiers: 0, key: "" },

apps/roam/src/components/settings/utils/zodSchema.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,6 @@ export const SuggestiveModeGlobalSettingsSchema = z.object({
185185

186186
export const LeftSidebarGlobalSettingsSchema = z.object({
187187
Children: z.array(z.string()).default([]),
188-
Settings: z
189-
.object({
190-
Collapsable: z.boolean().default(false),
191-
Folded: z.boolean().default(false),
192-
})
193-
.default({}),
194188
});
195189

196190
export const GlobalSettingsSchema = z.object({
@@ -242,6 +236,7 @@ export const QuerySettingsSchema = z.object({
242236

243237
export const PersonalSettingsSchema = z.object({
244238
"Left sidebar": LeftSidebarPersonalSettingsSchema,
239+
"Global section folded": z.boolean().default(false),
245240
"Personal node menu trigger": z
246241
.union([
247242
z.object({ modifiers: z.number(), key: z.string() }),

0 commit comments

Comments
 (0)