Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ const DiscourseNodeConfigPanel: React.FC<DiscourseNodeConfigPanelProps> = ({
type: valueUid,
shortcut,
format,
backedBy: "user",
}),
);
setNodes([
Expand Down
99 changes: 73 additions & 26 deletions apps/roam/src/components/settings/utils/accessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import { getSubTree } from "roamjs-components/util";
import getSettingValueFromTree from "roamjs-components/util/getSettingValueFromTree";
import internalError from "~/utils/internalError";
import { getSetting } from "~/utils/extensionSettings";
import discourseConfigRef, {
getFormattedConfigTree,
} from "~/utils/discourseConfigRef";
import { USE_REIFIED_RELATIONS } from "~/data/userSettings";
import discourseConfigRef from "~/utils/discourseConfigRef";
import { roamNodeToCondition } from "~/utils/parseQuery";
import type { DiscourseRelation } from "~/utils/getDiscourseRelations";
import type { DiscourseNode } from "~/utils/getDiscourseNodes";
import type { Condition } from "~/utils/types";
import { z } from "zod";
import { getUidAndBooleanSetting } from "~/utils/getExportSettings";
import {
getExportSettingsAndUids,
getUidAndBooleanSetting,
getUidAndStringSetting,
} from "~/utils/getExportSettings";
import { getSuggestiveModeConfigAndUids } from "~/utils/getSuggestiveModeConfigSettings";
import { getLeftSidebarSettings } from "~/utils/getLeftSidebarSettings";

import {
Expand All @@ -36,7 +40,7 @@ import {
type DiscourseNodeSettings,
type Condition as SchemaCondition,
} from "./zodSchema";
import { PERSONAL_KEYS, QUERY_KEYS } from "./settingKeys";
import { PERSONAL_KEYS, QUERY_KEYS, GLOBAL_KEYS } from "./settingKeys";

const isRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === "object" && value !== null && !Array.isArray(value);
Expand Down Expand Up @@ -342,85 +346,90 @@ const getLegacyRelationsSetting = (): Record<string, unknown> => {
);
};

// Reconstructs global settings from getFormattedConfigTree() shape to match block-props schema shape
// Reconstructs global settings from legacy Roam tree to match block-props schema shape
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving away from getFormattedConfigTree()

const getLegacyGlobalSetting = (keys: string[]): unknown => {
if (keys.length === 0) return undefined;

const settings = getFormattedConfigTree();
const tree = discourseConfigRef.tree;
const firstKey = keys[0];

if (firstKey === "Trigger") {
return settings.trigger.value || DEFAULT_GLOBAL_SETTINGS.Trigger;
return (
getUidAndStringSetting({ tree, text: "trigger" }).value ||
DEFAULT_GLOBAL_SETTINGS.Trigger
);
}

if (firstKey === "Canvas page format") {
return (
settings.canvasPageFormat.value ||
getUidAndStringSetting({ tree, text: "Canvas Page Format" }).value ||
DEFAULT_GLOBAL_SETTINGS["Canvas page format"]
);
}
Comment thread
sid597 marked this conversation as resolved.

if (firstKey === "Left sidebar") {
const sidebar = getLeftSidebarSettings(tree);
const leftSidebarSettings: Record<string, unknown> = {};
leftSidebarSettings["Children"] = settings.leftSidebar.global.children.map(
leftSidebarSettings["Children"] = sidebar.global.children.map(
(c) => c.text,
);
const sidebarSettingValues: Record<string, unknown> = {};
sidebarSettingValues["Collapsable"] =
settings.leftSidebar.global.settings?.collapsable.value ??
sidebar.global.settings?.collapsable.value ??
DEFAULT_GLOBAL_SETTINGS["Left sidebar"].Settings.Collapsable;
sidebarSettingValues["Folded"] =
settings.leftSidebar.global.settings?.folded.value ??
sidebar.global.settings?.folded.value ??
DEFAULT_GLOBAL_SETTINGS["Left sidebar"].Settings.Folded;
leftSidebarSettings["Settings"] = sidebarSettingValues;
if (keys.length === 1) return leftSidebarSettings;
return readPathValue(leftSidebarSettings, keys.slice(1));
}

if (firstKey === "Export") {
const exp = getExportSettingsAndUids();
const exportSettings: Record<string, unknown> = {};
exportSettings["Remove special characters"] =
settings.export.removeSpecialCharacters.value ??
exp.removeSpecialCharacters.value ??
DEFAULT_GLOBAL_SETTINGS.Export["Remove special characters"];
exportSettings["Resolve block references"] =
settings.export.optsRefs.value ??
exp.optsRefs.value ??
DEFAULT_GLOBAL_SETTINGS.Export["Resolve block references"];
exportSettings["Resolve block embeds"] =
settings.export.optsEmbeds.value ??
exp.optsEmbeds.value ??
DEFAULT_GLOBAL_SETTINGS.Export["Resolve block embeds"];
exportSettings["Append referenced node"] =
settings.export.appendRefNodeContext.value ??
exp.appendRefNodeContext.value ??
DEFAULT_GLOBAL_SETTINGS.Export["Append referenced node"];
exportSettings["Link type"] =
settings.export.linkType.value ||
DEFAULT_GLOBAL_SETTINGS.Export["Link type"];
exp.linkType.value || DEFAULT_GLOBAL_SETTINGS.Export["Link type"];
exportSettings["Max filename length"] =
settings.export.maxFilenameLength.value ??
exp.maxFilenameLength.value ??
DEFAULT_GLOBAL_SETTINGS.Export["Max filename length"];
exportSettings["Frontmatter"] =
settings.export.frontmatter.values ??
DEFAULT_GLOBAL_SETTINGS.Export.Frontmatter;
exp.frontmatter.values ?? DEFAULT_GLOBAL_SETTINGS.Export.Frontmatter;
if (keys.length === 1) return exportSettings;
return readPathValue(exportSettings, keys.slice(1));
}

if (firstKey === "Suggestive mode") {
const sm = getSuggestiveModeConfigAndUids(tree);
const suggestiveModeSettings: Record<string, unknown> = {};
suggestiveModeSettings["Include current page relations"] =
settings.suggestiveMode.includePageRelations.value ??
sm.includePageRelations.value ??
DEFAULT_GLOBAL_SETTINGS["Suggestive mode"][
"Include current page relations"
];
suggestiveModeSettings["Include parent and child blocks"] =
settings.suggestiveMode.includeParentAndChildren.value ??
sm.includeParentAndChildren.value ??
DEFAULT_GLOBAL_SETTINGS["Suggestive mode"][
"Include parent and child blocks"
];
suggestiveModeSettings["Page groups"] =
settings.suggestiveMode.pageGroups.groups.map((group) => ({
suggestiveModeSettings["Page groups"] = sm.pageGroups.groups.map(
(group) => ({
name: group.name,
pages: group.pages.map((page) => page.name),
}));
}),
);
if (keys.length === 1) return suggestiveModeSettings;
return readPathValue(suggestiveModeSettings, keys.slice(1));
}
Expand Down Expand Up @@ -728,6 +737,44 @@ export const isNewSettingsStoreEnabled = (): boolean => {
return getFeatureFlag("Use new settings store");
};

export const readAllLegacyFeatureFlags = (): Partial<FeatureFlags> => {
const flags: Partial<FeatureFlags> = {};
for (const [key, reader] of Object.entries(FEATURE_FLAG_LEGACY_MAP)) {
flags[key as keyof FeatureFlags] = reader();
}
flags["Reified relation triples"] = getSetting<boolean>(
USE_REIFIED_RELATIONS,
false,
);
flags["Use new settings store"] = false;
return flags;
};
Comment thread
sid597 marked this conversation as resolved.

export const readAllLegacyGlobalSettings = (): Record<string, unknown> => {
const result: Record<string, unknown> = {};
for (const key of Object.values(GLOBAL_KEYS)) {
result[key] = getLegacyGlobalSetting([key]);
}
return result;
};
Comment thread
sid597 marked this conversation as resolved.

export const readAllLegacyPersonalSettings = (): Record<string, unknown> => {
const result: Record<string, unknown> = {};
for (const key of Object.values(PERSONAL_KEYS)) {
result[key] = getLegacyPersonalSetting([key]);
}
return result;
};

export const readAllLegacyDiscourseNodeSettings = (
nodeType: string,
nodeTitle: string,
): Record<string, unknown> | undefined => {
const raw = getLegacyDiscourseNodeSetting(nodeType, []);
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
return { ...(raw as Record<string, unknown>), text: nodeTitle };
};

export const setFeatureFlag = (
key: keyof FeatureFlags,
value: boolean,
Expand Down
7 changes: 6 additions & 1 deletion apps/roam/src/components/settings/utils/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import type { json } from "~/utils/getBlockProps";
import INITIAL_NODE_VALUES from "~/data/defaultDiscourseNodes";
import DEFAULT_RELATIONS_BLOCK_PROPS from "~/components/settings/data/defaultRelationsBlockProps";
import { getAllDiscourseNodes } from "./accessors";
import {
migrateGraphLevel,
migratePersonalSettings,
} from "./migrateLegacyToBlockProps";
import {
DiscourseNodeSchema,
getTopLevelBlockPropsConfig,
Expand Down Expand Up @@ -147,7 +151,6 @@ const initSingleDiscourseNode = async (
tag: node.tag || "",
graphOverview: node.graphOverview ?? false,
canvasSettings: node.canvasSettings || {},
backedBy: "user",
});

setBlockProps(pageUid, nodeData, false);
Expand Down Expand Up @@ -256,6 +259,8 @@ export type InitSchemaResult = {

export const initSchema = async (): Promise<InitSchemaResult> => {
const blockUids = await initSettingsPageBlocks();
await migrateGraphLevel(blockUids);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs before initDiscourseNodePages() on purpose. The init check for “do we already have user discourse nodes?” only looks at block props, so legacy node pages without migrated props would be invisible there and the graph could be mistaken for an empty graph. Running migration first makes those existing legacy node pages visible to the new-store check before default node seeding happens.

const nodePageUids = await initDiscourseNodePages();
await migratePersonalSettings(blockUids);
return { blockUids, nodePageUids };
};
Loading
Loading