Skip to content

Commit 4843dfb

Browse files
committed
ENG-1456: Migrate personal boolean flag consumers (getSetting → getPersonalSetting)
1 parent c90e2c8 commit 4843dfb

13 files changed

Lines changed: 52 additions & 72 deletions

apps/roam/src/components/DiscourseFloatingMenu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { FeedbackWidget } from "./BirdEatsBugs";
1414
import { render as renderSettings } from "~/components/settings/Settings";
1515
import posthog from "posthog-js";
16+
import { getPersonalSetting } from "./settings/utils/accessors";
1617

1718
type DiscourseFloatingMenuProps = {
1819
// CSS placement class
@@ -128,7 +129,7 @@ export const installDiscourseFloatingMenu = (
128129
floatingMenuAnchor.id = ANCHOR_ID;
129130
document.getElementById("app")?.appendChild(floatingMenuAnchor);
130131
}
131-
if (onLoadArgs.extensionAPI.settings.get("hide-feedback-button") as boolean) {
132+
if (getPersonalSetting<boolean>(["Hide feedback button"])) {
132133
floatingMenuAnchor.classList.add("hidden");
133134
}
134135
ReactDOM.render(

apps/roam/src/components/canvas/DiscourseNodeUtil.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ import calcCanvasNodeSizeAndImg from "~/utils/calcCanvasNodeSizeAndImg";
3535
import { createTextJsxFromSpans } from "./DiscourseRelationShape/helpers";
3636
import { loadImage } from "~/utils/loadImage";
3737
import { getRelationColor } from "./DiscourseRelationShape/DiscourseRelationUtil";
38-
import {
39-
AUTO_CANVAS_RELATIONS_KEY,
40-
DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY,
41-
} from "~/data/userSettings";
42-
import { getSetting } from "~/utils/extensionSettings";
38+
import { getPersonalSetting } from "~/components/settings/utils/accessors";
4339
import DiscourseContextOverlay from "~/components/DiscourseContextOverlay";
4440
import { getDiscourseNodeColors } from "~/utils/getDiscourseNodeColors";
4541
import { render as renderToast } from "roamjs-components/components/Toast";
@@ -435,7 +431,7 @@ export class BaseDiscourseNodeUtil extends BaseBoxShapeUtil<DiscourseNodeShape>
435431
} = discourseContext.nodes[shape.type] || {};
436432
// eslint-disable-next-line react-hooks/rules-of-hooks
437433
const isOverlayEnabled = useMemo(
438-
() => getSetting(DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY, false),
434+
() => getPersonalSetting<boolean>(["Overlay in canvas"]),
439435
[],
440436
);
441437

@@ -516,10 +512,9 @@ export class BaseDiscourseNodeUtil extends BaseBoxShapeUtil<DiscourseNodeShape>
516512
uid,
517513
});
518514

519-
const autoCanvasRelations = getSetting<boolean>(
520-
AUTO_CANVAS_RELATIONS_KEY,
521-
false,
522-
);
515+
const autoCanvasRelations = getPersonalSetting<boolean>([
516+
"Auto canvas relations",
517+
]);
523518
if (autoCanvasRelations) {
524519
try {
525520
const relationIds = getRelationIds();

apps/roam/src/components/canvas/Tldraw.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,14 @@ import ToastListener, { dispatchToastEvent } from "./ToastListener";
9696
import { CanvasDrawerPanel } from "./CanvasDrawer";
9797
import { ClipboardPanel, ClipboardProvider } from "./Clipboard";
9898
import internalError from "~/utils/internalError";
99-
import { AUTO_CANVAS_RELATIONS_KEY } from "~/data/userSettings";
100-
import { getSetting } from "~/utils/extensionSettings";
10199
import { isPluginTimerReady, waitForPluginTimer } from "~/utils/pluginTimer";
102100
import { HistoryEntry } from "@tldraw/store";
103101
import { TLRecord } from "@tldraw/tlschema";
104102
import { WHITE_LOGO_SVG } from "~/icons";
105103
import { BLOCK_REF_REGEX } from "roamjs-components/dom";
106104
import { defaultHandleExternalTextContent } from "./defaultHandleExternalTextContent";
107105
import posthog from "posthog-js";
106+
import { getPersonalSetting } from "~/components/settings/utils/accessors";
108107

109108
declare global {
110109
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
@@ -1132,10 +1131,9 @@ const InsideEditorAndUiContext = ({
11321131
editor.sideEffects.registerAfterCreateHandler("shape", (shape) => {
11331132
const util = editor.getShapeUtil(shape);
11341133
if (util instanceof BaseDiscourseNodeUtil) {
1135-
const autoCanvasRelations = getSetting<boolean>(
1136-
AUTO_CANVAS_RELATIONS_KEY,
1137-
false,
1138-
);
1134+
const autoCanvasRelations = getPersonalSetting<boolean>([
1135+
"Auto canvas relations",
1136+
]);
11391137
if (autoCanvasRelations) {
11401138
void util.createExistingRelations({
11411139
shape: shape as DiscourseNodeShape,

apps/roam/src/components/canvas/uiOverrides.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ import calcCanvasNodeSizeAndImg from "~/utils/calcCanvasNodeSizeAndImg";
4242
import { AddReferencedNodeType } from "./DiscourseRelationShape/DiscourseRelationTool";
4343
import { getRelationColor } from "./DiscourseRelationShape/DiscourseRelationUtil";
4444
import DiscourseGraphPanel from "./DiscourseToolPanel";
45-
import { DISCOURSE_TOOL_SHORTCUT_KEY } from "~/data/userSettings";
46-
import { getSetting } from "~/utils/extensionSettings";
4745
import { CustomDefaultToolbar } from "./CustomDefaultToolbar";
4846
import { renderModifyNodeDialog } from "~/components/ModifyNodeDialog";
47+
import { getPersonalSetting } from "~/components/settings/utils/accessors";
4948

5049
export const getOnSelectForShape = ({
5150
shape,
@@ -271,10 +270,12 @@ export const createUiOverrides = ({
271270
}): TLUiOverrides => ({
272271
tools: (editor, tools) => {
273272
// Get the custom keyboard shortcut for the discourse tool
274-
const discourseToolCombo = getSetting(DISCOURSE_TOOL_SHORTCUT_KEY, {
273+
const discourseToolCombo = getPersonalSetting<IKeyCombo>([
274+
"Discourse tool shortcut",
275+
]) || {
275276
key: "",
276277
modifiers: 0,
277-
}) as IKeyCombo;
278+
};
278279

279280
// For discourse tool, just use the key directly since we don't allow modifiers
280281
const discourseToolShortcut = discourseToolCombo?.key?.toUpperCase() || "";

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
STREAMLINE_STYLING_KEY,
2323
DISALLOW_DIAGNOSTICS,
2424
} from "~/data/userSettings";
25-
import { getSetting, setSetting } from "~/utils/extensionSettings";
25+
import { setSetting } from "~/utils/extensionSettings";
2626
import { enablePostHog, disablePostHog } from "~/utils/posthog";
2727
import KeyboardShortcutInput from "./KeyboardShortcutInput";
2828
import streamlineStyling from "~/styles/streamlineStyling";
@@ -66,7 +66,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
6666
title="Overlay"
6767
description="Whether or not to overlay discourse context information over discourse node references."
6868
settingKeys={["Discourse context overlay"]}
69-
initialValue={getSetting<boolean>("discourse-context-overlay", false)}
7069
onChange={(checked) => {
7170
void setSetting("discourse-context-overlay", checked);
7271
onPageRefObserverChange(overlayHandler)(checked);
@@ -80,7 +79,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
8079
title="Suggestive mode overlay"
8180
description="Whether or not to overlay suggestive mode button over discourse node references."
8281
settingKeys={["Suggestive mode overlay"]}
83-
initialValue={getSetting<boolean>("suggestive-mode-overlay", false)}
8482
onChange={(checked) => {
8583
void setSetting("suggestive-mode-overlay", checked);
8684
onPageRefObserverChange(getSuggestiveOverlayHandler(onloadArgs))(
@@ -93,7 +91,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
9391
title="Text selection popup"
9492
description="Whether or not to show the discourse node menu when selecting text."
9593
settingKeys={["Text selection popup"]}
96-
initialValue={getSetting("text-selection-popup", true)}
9794
onChange={(checked) => {
9895
void setSetting("text-selection-popup", checked);
9996
}}
@@ -102,7 +99,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
10299
title="Disable sidebar open"
103100
description="Disable opening new nodes in the sidebar when created"
104101
settingKeys={["Disable sidebar open"]}
105-
initialValue={getSetting<boolean>("disable-sidebar-open", false)}
106102
onChange={(checked) => {
107103
void setSetting("disable-sidebar-open", checked);
108104
}}
@@ -111,7 +107,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
111107
title="Page preview"
112108
description="Whether or not to display page previews when hovering over page refs"
113109
settingKeys={["Page preview"]}
114-
initialValue={getSetting<boolean>("page-preview", false)}
115110
onChange={(checked) => {
116111
void setSetting("page-preview", checked);
117112
onPageRefObserverChange(previewPageRefHandler)(checked);
@@ -121,7 +116,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
121116
title="Hide feedback button"
122117
description="Hide the 'Send feedback' button at the bottom right of the screen."
123118
settingKeys={["Hide feedback button"]}
124-
initialValue={getSetting<boolean>("hide-feedback-button", false)}
125119
onChange={(checked) => {
126120
void setSetting("hide-feedback-button", checked);
127121
if (checked) {
@@ -135,7 +129,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
135129
title="Auto canvas relations"
136130
description="Automatically add discourse relations to canvas when a node is added"
137131
settingKeys={["Auto canvas relations"]}
138-
initialValue={getSetting<boolean>(AUTO_CANVAS_RELATIONS_KEY, false)}
139132
onChange={(checked) => {
140133
void setSetting(AUTO_CANVAS_RELATIONS_KEY, checked);
141134
}}
@@ -145,10 +138,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
145138
title="(BETA) Overlay in canvas"
146139
description="Whether or not to overlay discourse context information over canvas nodes."
147140
settingKeys={["Overlay in canvas"]}
148-
initialValue={getSetting<boolean>(
149-
DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY,
150-
false,
151-
)}
152141
onChange={(checked) => {
153142
void setSetting(DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY, checked);
154143
}}
@@ -157,7 +146,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
157146
title="Streamline styling"
158147
description="Apply streamlined styling to your personal graph for a cleaner appearance."
159148
settingKeys={["Streamline styling"]}
160-
initialValue={getSetting<boolean>(STREAMLINE_STYLING_KEY, false)}
161149
onChange={(checked) => {
162150
void setSetting(STREAMLINE_STYLING_KEY, checked);
163151
const existingStyleElement =
@@ -175,7 +163,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
175163
title="Disable product diagnostics"
176164
description="Disable sending usage signals and error reports that help us improve the product."
177165
settingKeys={["Disable product diagnostics"]}
178-
initialValue={getSetting<boolean>(DISALLOW_DIAGNOSTICS, false)}
179166
onChange={(checked) => {
180167
void setSetting(DISALLOW_DIAGNOSTICS, checked);
181168
if (checked) {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ const QuerySettings = ({
2323
title="Hide query metadata"
2424
description="Hide the Roam blocks that are used to power each query"
2525
settingKeys={["Query", "Hide query metadata"]}
26-
initialValue={
27-
(extensionAPI.settings.get(HIDE_METADATA_KEY) as boolean) ?? true
28-
}
2926
onChange={(checked) => {
3027
void extensionAPI.settings.set(HIDE_METADATA_KEY, checked);
3128
posthog.capture("Query Settings: Hide Metadata Toggled", {

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ const PERSONAL_OLD_KEY_MAP = new Map<string, string>([
194194
[pathKey(["Query", "Default filters"]), "default-filters"],
195195
]);
196196

197-
const PERSONAL_OLD_DEFAULT_OVERRIDES = new Map<string, unknown>([
198-
[pathKey(["Query", "Hide query metadata"]), true],
199-
]);
200-
201197
const getLegacyPersonalLeftSidebarSetting = (): Record<string, unknown> => {
202198
const settings = getFormattedConfigTree();
203199

@@ -223,12 +219,9 @@ const getLegacyPersonalLeftSidebarSetting = (): Record<string, unknown> => {
223219
const getLegacyPersonalSetting = (keys: string[]): unknown => {
224220
const mappedOldKey = PERSONAL_OLD_KEY_MAP.get(pathKey(keys));
225221
if (mappedOldKey) {
226-
const path = pathKey(keys);
227222
return getSetting<unknown>(
228223
mappedOldKey,
229-
PERSONAL_OLD_DEFAULT_OVERRIDES.has(path)
230-
? PERSONAL_OLD_DEFAULT_OVERRIDES.get(path)
231-
: readPathValue(DEFAULT_PERSONAL_SETTINGS, keys),
224+
readPathValue(DEFAULT_PERSONAL_SETTINGS, keys),
232225
);
233226
}
234227

apps/roam/src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,18 @@ import { getUidAndBooleanSetting } from "./utils/getExportSettings";
3535
import getBasicTreeByParentUid from "roamjs-components/queries/getBasicTreeByParentUid";
3636
import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle";
3737
import { DISCOURSE_CONFIG_PAGE_TITLE } from "./utils/renderNodeConfigPage";
38-
import { getSetting } from "./utils/extensionSettings";
3938
import { initPostHog } from "./utils/posthog";
40-
import {
41-
STREAMLINE_STYLING_KEY,
42-
DISALLOW_DIAGNOSTICS,
43-
} from "./data/userSettings";
4439
import { initSchema } from "./components/settings/utils/init";
4540
import { setupPullWatchOnSettingsPage } from "./components/settings/utils/pullWatchers";
41+
import { getPersonalSetting } from "./components/settings/utils/accessors";
4642
export const DEFAULT_CANVAS_PAGE_FORMAT = "Canvas/*";
4743

4844
export default runExtension(async (onloadArgs) => {
4945
const isEncrypted = window.roamAlphaAPI.graph.isEncrypted;
5046
const isOffline = window.roamAlphaAPI.graph.type === "offline";
51-
const disallowDiagnostics = getSetting(DISALLOW_DIAGNOSTICS, false);
47+
const disallowDiagnostics = getPersonalSetting<boolean>([
48+
"Disable product diagnostics",
49+
]);
5250
if (!isEncrypted && !isOffline && !disallowDiagnostics) {
5351
initPostHog();
5452
}
@@ -91,7 +89,9 @@ export default runExtension(async (onloadArgs) => {
9189
const discourseFloatingMenuStyle = addStyle(discourseFloatingMenuStyles);
9290

9391
// Add streamline styling only if enabled
94-
const isStreamlineStylingEnabled = getSetting(STREAMLINE_STYLING_KEY, false);
92+
const isStreamlineStylingEnabled = getPersonalSetting<boolean>([
93+
"Streamline styling",
94+
]);
9595
let streamlineStyleElement: HTMLStyleElement | null = null;
9696
if (isStreamlineStylingEnabled) {
9797
streamlineStyleElement = addStyle(streamlineStyling);

apps/roam/src/utils/createDiscourseNode.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { OnloadArgs, RoamBasicNode } from "roamjs-components/types";
1212
import runQuery from "./runQuery";
1313
import updateBlock from "roamjs-components/writes/updateBlock";
1414
import posthog from "posthog-js";
15+
import { getPersonalSetting } from "~/components/settings/utils/accessors";
1516

1617
type Props = {
1718
text: string;
@@ -32,8 +33,8 @@ const createDiscourseNode = async ({
3233
text: text,
3334
});
3435
const handleOpenInSidebar = (uid: string) => {
35-
if (extensionAPI?.settings.get("disable-sidebar-open")) return;
36-
openBlockInSidebar(uid);
36+
if (getPersonalSetting<boolean>(["Disable sidebar open"])) return;
37+
void openBlockInSidebar(uid);
3738
setTimeout(() => {
3839
const sidebarTitle = document.querySelector(
3940
".rm-sidebar-outline .rm-title-display",

apps/roam/src/utils/initializeObserversAndListeners.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { renderPossibleDuplicates } from "~/components/VectorDuplicateMatches";
6161
import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle";
6262
import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid";
6363
import findDiscourseNode from "./findDiscourseNode";
64+
import { getPersonalSetting } from "~/components/settings/utils/accessors";
6465

6566
const debounce = (fn: () => void, delay = 250) => {
6667
let timeout: number;
@@ -191,19 +192,19 @@ export const initObservers = async ({
191192
}>,
192193
) => {
193194
if (!/page/i.test(e.detail.action)) return;
194-
window.roamAlphaAPI.ui.mainWindow
195+
void window.roamAlphaAPI.ui.mainWindow
195196
.getOpenPageOrBlockUid()
196197
.then((u) => u || window.roamAlphaAPI.util.dateToPageUid(new Date()))
197198
.then((parentUid) => {
198-
createBlock({
199+
return createBlock({
199200
parentUid,
200201
order: Number.MAX_VALUE,
201202
node: { text: `[[${e.detail.val}]]` },
202203
});
203204
});
204205
}) as EventListener;
205206

206-
if (onloadArgs.extensionAPI.settings.get("suggestive-mode-overlay")) {
207+
if (getPersonalSetting<boolean>(["Suggestive mode overlay"])) {
207208
addPageRefObserver(getSuggestiveOverlayHandler(onloadArgs));
208209
}
209210

@@ -226,9 +227,9 @@ export const initObservers = async ({
226227
},
227228
});
228229

229-
if (onloadArgs.extensionAPI.settings.get("page-preview"))
230+
if (getPersonalSetting<boolean>(["Page preview"]))
230231
addPageRefObserver(previewPageRefHandler);
231-
if (onloadArgs.extensionAPI.settings.get("discourse-context-overlay")) {
232+
if (getPersonalSetting<boolean>(["Discourse context overlay"])) {
232233
const overlayHandler = getOverlayHandler(onloadArgs);
233234
onPageRefObserverChange(overlayHandler)(true);
234235
}
@@ -383,7 +384,7 @@ export const initObservers = async ({
383384

384385
const nodeCreationPopoverListener = debounce(() => {
385386
const isTextSelectionPopupEnabled =
386-
onloadArgs.extensionAPI.settings.get("text-selection-popup") !== false;
387+
getPersonalSetting<boolean>(["Text selection popup"]) !== false;
387388

388389
if (!isTextSelectionPopupEnabled) return;
389390

0 commit comments

Comments
 (0)