Skip to content

Commit 63856a1

Browse files
committed
ENG-1456: Migrate personal boolean flag consumers (getSetting → getPersonalSetting)
1 parent 11a99fe commit 63856a1

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
@@ -12,6 +12,7 @@ import {
1212
} from "@blueprintjs/core";
1313
import { FeedbackWidget } from "./BirdEatsBugs";
1414
import { render as renderSettings } from "~/components/settings/Settings";
15+
import { getPersonalSetting } from "./settings/utils/accessors";
1516

1617
type DiscourseFloatingMenuProps = {
1718
// CSS placement class
@@ -118,7 +119,7 @@ export const installDiscourseFloatingMenu = (
118119
floatingMenuAnchor.id = ANCHOR_ID;
119120
document.getElementById("app")?.appendChild(floatingMenuAnchor);
120121
}
121-
if (onLoadArgs.extensionAPI.settings.get("hide-feedback-button") as boolean) {
122+
if (getPersonalSetting<boolean>(["Hide feedback button"])) {
122123
floatingMenuAnchor.classList.add("hidden");
123124
}
124125
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
@@ -90,14 +90,13 @@ import ToastListener, { dispatchToastEvent } from "./ToastListener";
9090
import { CanvasDrawerPanel } from "./CanvasDrawer";
9191
import { ClipboardPanel, ClipboardProvider } from "./Clipboard";
9292
import internalError from "~/utils/internalError";
93-
import { AUTO_CANVAS_RELATIONS_KEY } from "~/data/userSettings";
94-
import { getSetting } from "~/utils/extensionSettings";
9593
import { isPluginTimerReady, waitForPluginTimer } from "~/utils/pluginTimer";
9694
import { HistoryEntry } from "@tldraw/store";
9795
import { TLRecord } from "@tldraw/tlschema";
9896
import { WHITE_LOGO_SVG } from "~/icons";
9997
import { BLOCK_REF_REGEX } from "roamjs-components/dom";
10098
import { defaultHandleExternalTextContent } from "./defaultHandleExternalTextContent";
99+
import { getPersonalSetting } from "~/components/settings/utils/accessors";
101100

102101
declare global {
103102
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
@@ -1091,10 +1090,9 @@ const InsideEditorAndUiContext = ({
10911090
editor.sideEffects.registerAfterCreateHandler("shape", (shape) => {
10921091
const util = editor.getShapeUtil(shape);
10931092
if (util instanceof BaseDiscourseNodeUtil) {
1094-
const autoCanvasRelations = getSetting<boolean>(
1095-
AUTO_CANVAS_RELATIONS_KEY,
1096-
false,
1097-
);
1093+
const autoCanvasRelations = getPersonalSetting<boolean>([
1094+
"Auto canvas relations",
1095+
]);
10981096
if (autoCanvasRelations) {
10991097
void util.createExistingRelations({
11001098
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";
@@ -65,7 +65,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
6565
title="Overlay"
6666
description="Whether or not to overlay discourse context information over discourse node references."
6767
settingKeys={["Discourse context overlay"]}
68-
initialValue={getSetting<boolean>("discourse-context-overlay", false)}
6968
onChange={(checked) => {
7069
void setSetting("discourse-context-overlay", checked);
7170
onPageRefObserverChange(overlayHandler)(checked);
@@ -76,7 +75,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
7675
title="Suggestive mode overlay"
7776
description="Whether or not to overlay suggestive mode button over discourse node references."
7877
settingKeys={["Suggestive mode overlay"]}
79-
initialValue={getSetting<boolean>("suggestive-mode-overlay", false)}
8078
onChange={(checked) => {
8179
void setSetting("suggestive-mode-overlay", checked);
8280
onPageRefObserverChange(getSuggestiveOverlayHandler(onloadArgs))(
@@ -89,7 +87,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
8987
title="Text selection popup"
9088
description="Whether or not to show the discourse node menu when selecting text."
9189
settingKeys={["Text selection popup"]}
92-
initialValue={getSetting("text-selection-popup", true)}
9390
onChange={(checked) => {
9491
void setSetting("text-selection-popup", checked);
9592
}}
@@ -98,7 +95,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
9895
title="Disable sidebar open"
9996
description="Disable opening new nodes in the sidebar when created"
10097
settingKeys={["Disable sidebar open"]}
101-
initialValue={getSetting<boolean>("disable-sidebar-open", false)}
10298
onChange={(checked) => {
10399
void setSetting("disable-sidebar-open", checked);
104100
}}
@@ -107,7 +103,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
107103
title="Page preview"
108104
description="Whether or not to display page previews when hovering over page refs"
109105
settingKeys={["Page preview"]}
110-
initialValue={getSetting<boolean>("page-preview", false)}
111106
onChange={(checked) => {
112107
void setSetting("page-preview", checked);
113108
onPageRefObserverChange(previewPageRefHandler)(checked);
@@ -117,7 +112,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
117112
title="Hide feedback button"
118113
description="Hide the 'Send feedback' button at the bottom right of the screen."
119114
settingKeys={["Hide feedback button"]}
120-
initialValue={getSetting<boolean>("hide-feedback-button", false)}
121115
onChange={(checked) => {
122116
void setSetting("hide-feedback-button", checked);
123117
if (checked) {
@@ -131,7 +125,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
131125
title="Auto canvas relations"
132126
description="Automatically add discourse relations to canvas when a node is added"
133127
settingKeys={["Auto canvas relations"]}
134-
initialValue={getSetting<boolean>(AUTO_CANVAS_RELATIONS_KEY, false)}
135128
onChange={(checked) => {
136129
void setSetting(AUTO_CANVAS_RELATIONS_KEY, checked);
137130
}}
@@ -141,10 +134,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
141134
title="(BETA) Overlay in canvas"
142135
description="Whether or not to overlay discourse context information over canvas nodes."
143136
settingKeys={["Overlay in canvas"]}
144-
initialValue={getSetting<boolean>(
145-
DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY,
146-
false,
147-
)}
148137
onChange={(checked) => {
149138
void setSetting(DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY, checked);
150139
}}
@@ -153,7 +142,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
153142
title="Streamline styling"
154143
description="Apply streamlined styling to your personal graph for a cleaner appearance."
155144
settingKeys={["Streamline styling"]}
156-
initialValue={getSetting<boolean>(STREAMLINE_STYLING_KEY, false)}
157145
onChange={(checked) => {
158146
void setSetting(STREAMLINE_STYLING_KEY, checked);
159147
const existingStyleElement =
@@ -171,7 +159,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
171159
title="Disable product diagnostics"
172160
description="Disable sending usage signals and error reports that help us improve the product."
173161
settingKeys={["Disable product diagnostics"]}
174-
initialValue={getSetting<boolean>(DISALLOW_DIAGNOSTICS, false)}
175162
onChange={(checked) => {
176163
void setSetting(DISALLOW_DIAGNOSTICS, checked);
177164
if (checked) {

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

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

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)