diff --git a/apps/roam/src/components/settings/ExportSettings.tsx b/apps/roam/src/components/settings/ExportSettings.tsx index b3761c2a2..fbc475cb5 100644 --- a/apps/roam/src/components/settings/ExportSettings.tsx +++ b/apps/roam/src/components/settings/ExportSettings.tsx @@ -1,80 +1,63 @@ import React from "react"; -import { getFormattedConfigTree } from "~/utils/discourseConfigRef"; -import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel"; -import NumberPanel from "roamjs-components/components/ConfigPanels/NumberPanel"; -import MultiTextPanel from "roamjs-components/components/ConfigPanels/MultiTextPanel"; -import SelectPanel from "roamjs-components/components/ConfigPanels/SelectPanel"; +import { + GlobalFlagPanel, + GlobalNumberPanel, + GlobalSelectPanel, + GlobalMultiTextPanel, +} from "./components/BlockPropSettingPanels"; -const DiscourseGraphExport = ({}: {}) => { - const settings = getFormattedConfigTree(); - const exportSettings = settings.export; - const parentUid = settings.export.exportUid; +const DiscourseGraphExport = () => { return (
- - - -
-
- -
); diff --git a/apps/roam/src/components/settings/GeneralSettings.tsx b/apps/roam/src/components/settings/GeneralSettings.tsx index f664bf968..9c24eead0 100644 --- a/apps/roam/src/components/settings/GeneralSettings.tsx +++ b/apps/roam/src/components/settings/GeneralSettings.tsx @@ -1,33 +1,20 @@ -import React, { useMemo } from "react"; -import TextPanel from "roamjs-components/components/ConfigPanels/TextPanel"; -import { getFormattedConfigTree } from "~/utils/discourseConfigRef"; -import refreshConfigTree from "~/utils/refreshConfigTree"; +import React from "react"; import { DEFAULT_CANVAS_PAGE_FORMAT } from "~/index"; -import { FeatureFlagPanel } from "./components/BlockPropSettingPanels"; +import { FeatureFlagPanel, GlobalTextPanel } from "./components/BlockPropSettingPanels"; const DiscourseGraphHome = () => { - const settings = useMemo(() => { - refreshConfigTree(); - return getFormattedConfigTree(); - }, []); - return (
- - { + // Keep old config tree for PageGroups (not yet migrated) const settings = getFormattedConfigTree(); + const pageGroupsUid = settings.suggestiveMode.pageGroups.uid; const [suggestiveModeUid, setSuggestiveModeUid] = useState( settings.suggestiveMode.parentUid, ); - const pageGroupsUid = settings.suggestiveMode.pageGroups.uid; - const [includePageRelations, setIncludePageRelations] = useState( - settings.suggestiveMode.includePageRelations.value, + // Track includePageRelations to control the disabled state of includeParentAndChildren + const [includePageRelations, setIncludePageRelations] = useState(() => + getGlobalSetting([ + "Suggestive Mode", + "Include Current Page Relations", + ]), ); + // Keep this useEffect for PageGroups compatibility (old system) useEffect(() => { if (suggestiveModeUid) return; void (async () => { @@ -33,9 +40,6 @@ const SuggestiveModeSettings = () => { })(); }, [suggestiveModeUid]); - const effectiveSuggestiveModeUid = - suggestiveModeUid || settings.suggestiveMode.parentUid; - const [selectedTabId, setSelectedTabId] = useState("page-groups"); return ( @@ -64,35 +68,21 @@ const SuggestiveModeSettings = () => { panel={
- { - setIncludePageRelations(checked); - }, - }} + settingKeys={["Suggestive Mode", "Include Current Page Relations"]} + onChange={setIncludePageRelations} /> -
diff --git a/apps/roam/src/utils/getExportSettings.ts b/apps/roam/src/utils/getExportSettings.ts index 21cadbc5c..0e33a1aa9 100644 --- a/apps/roam/src/utils/getExportSettings.ts +++ b/apps/roam/src/utils/getExportSettings.ts @@ -3,6 +3,8 @@ import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTit import { RoamBasicNode } from "roamjs-components/types"; import { getSubTree } from "roamjs-components/util"; import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/utils/renderNodeConfigPage"; +import { getGlobalSetting } from "~/components/settings/utils/accessors"; +import type { ExportSettings } from "~/components/settings/utils/zodSchema"; type UidPair = { uid?: string; @@ -110,16 +112,18 @@ export const getExportSettingsAndUids = (): ExportConfigWithUids => { }; export const getExportSettings = (): Omit => { - const settings = getExportSettingsAndUids(); + // Zod schema applies defaults, so we can trust the values exist + const exportSettings = getGlobalSetting(["Export"])!; + return { - maxFilenameLength: settings.maxFilenameLength.value, - openSidebar: settings.openSidebar.value, - removeSpecialCharacters: settings.removeSpecialCharacters.value, - simplifiedFilename: settings.simplifiedFilename.value, - optsEmbeds: settings.optsEmbeds.value, - optsRefs: settings.optsRefs.value, - linkType: settings.linkType.value, - appendRefNodeContext: settings.appendRefNodeContext.value, - frontmatter: settings.frontmatter.values, + maxFilenameLength: exportSettings["Max Filename Length"], + openSidebar: false, // Only in old config page, not in Settings dialog + removeSpecialCharacters: exportSettings["Remove Special Characters"], + simplifiedFilename: false, // Only in old config page, not in Settings dialog + optsEmbeds: exportSettings["Resolve Block Embeds"], + optsRefs: exportSettings["Resolve Block References"], + linkType: exportSettings["Link Type"], + appendRefNodeContext: exportSettings["Append Referenced Node"], + frontmatter: exportSettings["Frontmatter"], }; }; diff --git a/apps/roam/src/utils/initializeObserversAndListeners.ts b/apps/roam/src/utils/initializeObserversAndListeners.ts index 9a596a0fa..536d71bc3 100644 --- a/apps/roam/src/utils/initializeObserversAndListeners.ts +++ b/apps/roam/src/utils/initializeObserversAndListeners.ts @@ -31,8 +31,6 @@ import getDiscourseNodes from "~/utils/getDiscourseNodes"; import { OnloadArgs } from "roamjs-components/types"; import refreshConfigTree from "~/utils/refreshConfigTree"; import { render as renderGraphOverviewExport } from "~/components/ExportDiscourseContext"; -import getBasicTreeByParentUid from "roamjs-components/queries/getBasicTreeByParentUid"; -import { getSettingValueFromTree } from "roamjs-components/util"; import { getModifiersFromCombo, render as renderDiscourseNodeMenu, @@ -52,7 +50,10 @@ import { getSetting } from "./extensionSettings"; import { mountLeftSidebar, cacheOnloadArgs } from "~/components/LeftSidebarView"; import { getUidAndBooleanSetting } from "./getExportSettings"; import { getCleanTagText } from "~/components/settings/NodeConfig"; -import { getFeatureFlag } from "~/components/settings/utils/accessors"; +import { + getFeatureFlag, + getGlobalSetting, +} from "~/components/settings/utils/accessors"; import getPleasingColors from "@repo/utils/getPleasingColors"; import { colord } from "colord"; import { renderPossibleDuplicates } from "~/components/VectorDuplicateMatches"; @@ -239,12 +240,9 @@ export const initObservers = async ({ } }; - const configTree = getBasicTreeByParentUid(configPageUid); - const globalTrigger = getSettingValueFromTree({ - tree: configTree, - key: "trigger", - defaultValue: "\\", - }).trim(); + const globalTrigger = ( + getGlobalSetting(["Trigger"]) || "\\" + ).trim(); const personalTriggerCombo = (onloadArgs.extensionAPI.settings.get( "personal-node-menu-trigger", diff --git a/apps/roam/src/utils/isCanvasPage.ts b/apps/roam/src/utils/isCanvasPage.ts index 591ccea5c..c2dcd2177 100644 --- a/apps/roam/src/utils/isCanvasPage.ts +++ b/apps/roam/src/utils/isCanvasPage.ts @@ -1,9 +1,10 @@ import { DEFAULT_CANVAS_PAGE_FORMAT } from ".."; -import { getFormattedConfigTree } from "./discourseConfigRef"; +import { getGlobalSetting } from "~/components/settings/utils/accessors"; export const isCanvasPage = ({ title }: { title: string }) => { - const { canvasPageFormat } = getFormattedConfigTree(); - const format = canvasPageFormat.value || DEFAULT_CANVAS_PAGE_FORMAT; + const format = + getGlobalSetting(["Canvas Page Format"]) || + DEFAULT_CANVAS_PAGE_FORMAT; const canvasRegex = new RegExp(`^${format}$`.replace(/\*/g, ".+")); return canvasRegex.test(title); };