diff --git a/apps/roam/src/components/LeftSidebarView.tsx b/apps/roam/src/components/LeftSidebarView.tsx index 5f7035304..7d57e5f1a 100644 --- a/apps/roam/src/components/LeftSidebarView.tsx +++ b/apps/roam/src/components/LeftSidebarView.tsx @@ -65,7 +65,6 @@ import renderOverlay from "roamjs-components/util/renderOverlay"; import getBasicTreeByParentUid from "roamjs-components/queries/getBasicTreeByParentUid"; import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/data/constants"; import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid"; -import { migrateLeftSidebarSettings } from "~/utils/migrateLeftSidebarSettings"; import posthog from "posthog-js"; import { commands, cleanCommandName } from "~/components/LeftSidebarCommands"; import { isSmartBlockUid } from "~/utils/isSmartBlockUid"; @@ -730,7 +729,6 @@ const buildConfig = (snapshot?: SettingsSnapshot): LeftSidebarConfig => { return { uid: oldConfig.uid, favoritesMigrated: oldConfig.favoritesMigrated, - sidebarMigrated: oldConfig.sidebarMigrated, global: mergeGlobalSectionWithAccessor(oldConfig.global, globalValues), globalSectionFolded: { uid: oldConfig.globalSectionFolded.uid, @@ -743,7 +741,6 @@ const buildConfig = (snapshot?: SettingsSnapshot): LeftSidebarConfig => { personalValues, ), }, - allPersonalSections: oldConfig.allPersonalSections, }; }; @@ -1067,7 +1064,6 @@ export const mountLeftSidebar = async ({ let root = wrapper.querySelector(`#${id}`) as HTMLDivElement; if (!root) { await migrateFavorites(); - await migrateLeftSidebarSettings(); wrapper.innerHTML = ""; root = document.createElement("div"); root.id = id; diff --git a/apps/roam/src/utils/getLeftSidebarSettings.ts b/apps/roam/src/utils/getLeftSidebarSettings.ts index a2d306029..36ec6eb7c 100644 --- a/apps/roam/src/utils/getLeftSidebarSettings.ts +++ b/apps/roam/src/utils/getLeftSidebarSettings.ts @@ -74,10 +74,8 @@ export type LeftSidebarGlobalSectionConfig = { export type LeftSidebarConfig = { uid: string; favoritesMigrated: BooleanSetting; - sidebarMigrated: BooleanSetting; global: LeftSidebarGlobalSectionConfig; globalSectionFolded: BooleanSetting; - allPersonalSections: AllUsersPersonalSections; personal: { uid: string; sections: LeftSidebarPersonalSectionConfig[]; @@ -146,13 +144,6 @@ const getPersonalSectionSettings = ( }; }; -export type AllUsersPersonalSections = { - [userUid: string]: { - uid: string; - sections: LeftSidebarPersonalSectionConfig[]; - }; -}; - export const getLeftSidebarPersonalSectionConfig = ( leftSidebarChildren: RoamBasicNode[], userUid?: string, @@ -202,24 +193,6 @@ export const getLeftSidebarPersonalSectionConfig = ( sections, }; }; -export const getAllLeftSidebarPersonalSectionConfigs = ( - leftSidebarChildren: RoamBasicNode[], -): AllUsersPersonalSections => { - const result: AllUsersPersonalSections = {}; - - leftSidebarChildren - .filter((node) => node.text.endsWith("/Personal-Section")) - .forEach((node) => { - const userUid = node.text.replace("/Personal-Section", ""); - result[userUid] = getLeftSidebarPersonalSectionConfig( - leftSidebarChildren, - userUid, - ); - }); - - return result; -}; - export const mergeGlobalSectionWithAccessor = ( config: LeftSidebarGlobalSectionConfig, globalValues: LeftSidebarGlobalSettings | undefined, @@ -306,17 +279,10 @@ export const getLeftSidebarSettings = ( const leftSidebarChildren = leftSidebarNode?.children || []; const global = getLeftSidebarGlobalSectionConfig(leftSidebarChildren); const personal = getLeftSidebarPersonalSectionConfig(leftSidebarChildren); - // TODO: remove this on complete migration task [ENG-1171: Remove `migrateLeftSideBarSettings`](https://linear.app/discourse-graphs/issue/ENG-1171/remove-migrateleftsidebarsettings) - const allPersonalSections = - getAllLeftSidebarPersonalSectionConfigs(leftSidebarChildren); const favoritesMigrated = getUidAndBooleanSetting({ tree: leftSidebarChildren, text: "Favorites Migrated", }); - const sidebarMigrated = getUidAndBooleanSetting({ - tree: leftSidebarChildren, - text: "Sidebar Migrated", - }); const currentUserUid = window.roamAlphaAPI.user.uid(); const globalSectionFolded: BooleanSetting = currentUserUid ? getUidAndBooleanSetting({ @@ -327,10 +293,8 @@ export const getLeftSidebarSettings = ( return { uid: leftSidebarUid, favoritesMigrated, - sidebarMigrated, global, globalSectionFolded, personal, - allPersonalSections, }; }; diff --git a/apps/roam/src/utils/migrateLeftSidebarSettings.ts b/apps/roam/src/utils/migrateLeftSidebarSettings.ts deleted file mode 100644 index b88ab5192..000000000 --- a/apps/roam/src/utils/migrateLeftSidebarSettings.ts +++ /dev/null @@ -1,74 +0,0 @@ -import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle"; -import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid"; -import updateBlock from "roamjs-components/writes/updateBlock"; -import createBlock from "roamjs-components/writes/createBlock"; -import discourseConfigRef from "./discourseConfigRef"; -import { getLeftSidebarSettings } from "./getLeftSidebarSettings"; -import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/data/constants"; -import refreshConfigTree from "./refreshConfigTree"; - -const migrateSectionChildren = async ( - children: { uid: string; text: string }[], -) => { - const promises = children.map(async (child) => { - const currentText = child.text; - - const titleFromUid = getPageTitleByPageUid(currentText); - if (titleFromUid) { - return; - } - - const uidFromTitle = getPageUidByPageTitle(currentText); - if (uidFromTitle) { - try { - await updateBlock({ - uid: child.uid, - text: uidFromTitle, - }); - console.log( - `Migrated sidebar item "${currentText}" to UID "${uidFromTitle}"`, - ); - } catch (e) { - console.error(`Failed to migrate sidebar item "${currentText}"`, e); - } - } - }); - - await Promise.all(promises); -}; - -export const migrateLeftSidebarSettings = async () => { - const leftSidebarSettings = getLeftSidebarSettings(discourseConfigRef.tree); - - if (!leftSidebarSettings.uid) return; - - if (leftSidebarSettings.sidebarMigrated.value) return; - - const configPageUid = getPageUidByPageTitle(DISCOURSE_CONFIG_PAGE_TITLE); - if (!configPageUid) return; - - const globalChildren = leftSidebarSettings.global.children; - if (globalChildren.length > 0) { - await migrateSectionChildren(globalChildren); - } - - const allPersonalSections = leftSidebarSettings.allPersonalSections; - - for (const userPersonalSection of Object.values(allPersonalSections)) { - for (const section of userPersonalSection.sections) { - const children = section.children || []; - if (children.length > 0) { - await migrateSectionChildren(children); - } - } - } - - if (leftSidebarSettings.uid) { - await createBlock({ - parentUid: leftSidebarSettings.uid, - node: { text: "Sidebar Migrated" }, - }); - } - - refreshConfigTree(); -};