Skip to content

Commit d4bb8a1

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

13 files changed

Lines changed: 52 additions & 73 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";
@@ -67,7 +67,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
6767
title="Overlay"
6868
description="Whether or not to overlay discourse context information over discourse node references."
6969
settingKeys={["Discourse context overlay"]}
70-
initialValue={getSetting<boolean>("discourse-context-overlay", false)}
7170
onChange={(checked) => {
7271
void setSetting("discourse-context-overlay", checked);
7372
onPageRefObserverChange(overlayHandler)(checked);
@@ -81,7 +80,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
8180
title="Suggestive mode overlay"
8281
description="Whether or not to overlay suggestive mode button over discourse node references."
8382
settingKeys={["Suggestive mode overlay"]}
84-
initialValue={getSetting<boolean>("suggestive-mode-overlay", false)}
8583
onChange={(checked) => {
8684
void setSetting("suggestive-mode-overlay", checked);
8785
onPageRefObserverChange(getSuggestiveOverlayHandler(onloadArgs))(
@@ -94,7 +92,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
9492
title="Text selection popup"
9593
description="Whether or not to show the discourse node menu when selecting text."
9694
settingKeys={["Text selection popup"]}
97-
initialValue={getSetting("text-selection-popup", true)}
9895
onChange={(checked) => {
9996
void setSetting("text-selection-popup", checked);
10097
}}
@@ -103,7 +100,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
103100
title="Disable sidebar open"
104101
description="Disable opening new nodes in the sidebar when created"
105102
settingKeys={["Disable sidebar open"]}
106-
initialValue={getSetting<boolean>("disable-sidebar-open", false)}
107103
onChange={(checked) => {
108104
void setSetting("disable-sidebar-open", checked);
109105
}}
@@ -112,7 +108,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
112108
title="Page preview"
113109
description="Whether or not to display page previews when hovering over page refs"
114110
settingKeys={["Page preview"]}
115-
initialValue={getSetting<boolean>("page-preview", false)}
116111
onChange={(checked) => {
117112
void setSetting("page-preview", checked);
118113
onPageRefObserverChange(previewPageRefHandler)(checked);
@@ -122,7 +117,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
122117
title="Hide feedback button"
123118
description="Hide the 'Send feedback' button at the bottom right of the screen."
124119
settingKeys={["Hide feedback button"]}
125-
initialValue={getSetting<boolean>("hide-feedback-button", false)}
126120
onChange={(checked) => {
127121
void setSetting("hide-feedback-button", checked);
128122
if (checked) {
@@ -136,7 +130,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
136130
title="Auto canvas relations"
137131
description="Automatically add discourse relations to canvas when a node is added"
138132
settingKeys={["Auto canvas relations"]}
139-
initialValue={getSetting<boolean>(AUTO_CANVAS_RELATIONS_KEY, false)}
140133
onChange={(checked) => {
141134
void setSetting(AUTO_CANVAS_RELATIONS_KEY, checked);
142135
}}
@@ -146,10 +139,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
146139
title="(BETA) Overlay in canvas"
147140
description="Whether or not to overlay discourse context information over canvas nodes."
148141
settingKeys={["Overlay in canvas"]}
149-
initialValue={getSetting<boolean>(
150-
DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY,
151-
false,
152-
)}
153142
onChange={(checked) => {
154143
void setSetting(DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY, checked);
155144
}}
@@ -158,7 +147,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
158147
title="Streamline styling"
159148
description="Apply streamlined styling to your personal graph for a cleaner appearance."
160149
settingKeys={["Streamline styling"]}
161-
initialValue={getSetting<boolean>(STREAMLINE_STYLING_KEY, false)}
162150
onChange={(checked) => {
163151
void setSetting(STREAMLINE_STYLING_KEY, checked);
164152
const existingStyleElement =
@@ -176,7 +164,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
176164
title="Disable product diagnostics"
177165
description="Disable sending usage signals and error reports that help us improve the product."
178166
settingKeys={["Disable product diagnostics"]}
179-
initialValue={getSetting<boolean>(DISALLOW_DIAGNOSTICS, false)}
180167
onChange={(checked) => {
181168
void setSetting(DISALLOW_DIAGNOSTICS, checked);
182169
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,19 @@ 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";
46-
41+
import { getPersonalSetting } from "./components/settings/utils/accessors";
4742

4843
export const DEFAULT_CANVAS_PAGE_FORMAT = "Canvas/*";
4944

5045
export default runExtension(async (onloadArgs) => {
5146
const isEncrypted = window.roamAlphaAPI.graph.isEncrypted;
5247
const isOffline = window.roamAlphaAPI.graph.type === "offline";
53-
const disallowDiagnostics = getSetting(DISALLOW_DIAGNOSTICS, false);
48+
const disallowDiagnostics = getPersonalSetting<boolean>([
49+
"Disable product diagnostics",
50+
]);
5451
if (!isEncrypted && !isOffline && !disallowDiagnostics) {
5552
initPostHog();
5653
}
@@ -93,7 +90,9 @@ export default runExtension(async (onloadArgs) => {
9390
const discourseFloatingMenuStyle = addStyle(discourseFloatingMenuStyles);
9491

9592
// Add streamline styling only if enabled
96-
const isStreamlineStylingEnabled = getSetting(STREAMLINE_STYLING_KEY, false);
93+
const isStreamlineStylingEnabled = getPersonalSetting<boolean>([
94+
"Streamline styling",
95+
]);
9796
let streamlineStyleElement: HTMLStyleElement | null = null;
9897
if (isStreamlineStylingEnabled) {
9998
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)