Skip to content

Commit d6d2171

Browse files
authored
ENG-1197: fix personal settings migration, for all users insted of only the user who instantiated it (#639)
* fix personal settings migration, for all users insted of only the user who instantiated it * coderabbit review points
1 parent 8433a55 commit d6d2171

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

apps/roam/src/utils/getLeftSidebarSettings.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export type LeftSidebarConfig = {
4545
favoritesMigrated: BooleanSetting;
4646
sidebarMigrated: BooleanSetting;
4747
global: LeftSidebarGlobalSectionConfig;
48+
allPersonalSections: AllUsersPersonalSections;
4849
personal: {
4950
uid: string;
5051
sections: LeftSidebarPersonalSectionConfig[];
@@ -125,14 +126,22 @@ const getPersonalSectionSettings = (
125126
};
126127
};
127128

129+
export type AllUsersPersonalSections = {
130+
[userUid: string]: {
131+
uid: string;
132+
sections: LeftSidebarPersonalSectionConfig[];
133+
};
134+
};
135+
128136
export const getLeftSidebarPersonalSectionConfig = (
129137
leftSidebarChildren: RoamBasicNode[],
138+
userUid?: string,
130139
): { uid: string; sections: LeftSidebarPersonalSectionConfig[] } => {
131-
const userUid = window.roamAlphaAPI.user.uid();
140+
const targetUserUid = userUid ?? window.roamAlphaAPI.user.uid();
132141

133142
const personalLeftSidebarNode = getSubTree({
134143
tree: leftSidebarChildren,
135-
key: userUid + "/Personal-Section",
144+
key: targetUserUid + "/Personal-Section",
136145
});
137146

138147
if (personalLeftSidebarNode.uid === "") {
@@ -173,7 +182,23 @@ export const getLeftSidebarPersonalSectionConfig = (
173182
sections,
174183
};
175184
};
185+
export const getAllLeftSidebarPersonalSectionConfigs = (
186+
leftSidebarChildren: RoamBasicNode[],
187+
): AllUsersPersonalSections => {
188+
const result: AllUsersPersonalSections = {};
189+
190+
leftSidebarChildren
191+
.filter((node) => node.text.endsWith("/Personal-Section"))
192+
.forEach((node) => {
193+
const userUid = node.text.replace("/Personal-Section", "");
194+
result[userUid] = getLeftSidebarPersonalSectionConfig(
195+
leftSidebarChildren,
196+
userUid,
197+
);
198+
});
176199

200+
return result;
201+
};
177202
export const getLeftSidebarSettings = (
178203
globalTree: RoamBasicNode[],
179204
): LeftSidebarConfig => {
@@ -184,6 +209,9 @@ export const getLeftSidebarSettings = (
184209
const leftSidebarChildren = leftSidebarNode?.children || [];
185210
const global = getLeftSidebarGlobalSectionConfig(leftSidebarChildren);
186211
const personal = getLeftSidebarPersonalSectionConfig(leftSidebarChildren);
212+
// TODO: remove this on complete migration task [ENG-1171: Remove `migrateLeftSideBarSettings`](https://linear.app/discourse-graphs/issue/ENG-1171/remove-migrateleftsidebarsettings)
213+
const allPersonalSections =
214+
getAllLeftSidebarPersonalSectionConfigs(leftSidebarChildren);
187215
const favoritesMigrated = getUidAndBooleanSetting({
188216
tree: leftSidebarChildren,
189217
text: "Favorites Migrated",
@@ -198,5 +226,6 @@ export const getLeftSidebarSettings = (
198226
sidebarMigrated,
199227
global,
200228
personal,
229+
allPersonalSections,
201230
};
202231
};

apps/roam/src/utils/migrateLeftSidebarSettings.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ export const migrateLeftSidebarSettings = async () => {
5151
await migrateSectionChildren(globalChildren);
5252
}
5353

54-
const personalSections = leftSidebarSettings.personal.sections;
55-
for (const section of personalSections) {
56-
const children = section.children || [];
57-
if (children.length > 0) {
58-
await migrateSectionChildren(children);
54+
55+
const allPersonalSections = leftSidebarSettings.allPersonalSections;
56+
57+
for (const [_, userPersonalSection] of Object.entries(
58+
allPersonalSections,
59+
)) {
60+
for (const section of userPersonalSection.sections) {
61+
const children = section.children || [];
62+
if (children.length > 0) {
63+
await migrateSectionChildren(children);
64+
}
5965
}
6066
}
6167

0 commit comments

Comments
 (0)