Skip to content

Commit ce7e7d7

Browse files
committed
ENG-1660 Dual-write canvas node shortcuts and flag-gate the read
1 parent 42cae58 commit ce7e7d7

5 files changed

Lines changed: 24 additions & 22 deletions

File tree

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ import calcCanvasNodeSizeAndImg from "~/utils/calcCanvasNodeSizeAndImg";
5151
import { AddReferencedNodeType } from "./DiscourseRelationShape/DiscourseRelationTool";
5252
import { getRelationColor } from "./DiscourseRelationShape/DiscourseRelationUtil";
5353
import DiscourseGraphPanel from "./DiscourseToolPanel";
54-
import { CANVAS_NODE_SHORTCUTS_KEY } from "~/data/userSettings";
55-
import { getSetting } from "~/utils/extensionSettings";
5654
import type { CanvasNodeShortcuts } from "~/components/settings/utils/zodSchema";
5755
import { CustomDefaultToolbar } from "./CustomDefaultToolbar";
5856
import { renderModifyNodeDialog } from "~/components/ModifyNodeDialog";
@@ -401,10 +399,10 @@ export const createUiOverrides = ({
401399
editor.setCurrentTool("discourse-tool");
402400
},
403401
};
404-
const canvasNodeShortcuts = getSetting<CanvasNodeShortcuts>(
405-
CANVAS_NODE_SHORTCUTS_KEY,
406-
{},
407-
);
402+
const canvasNodeShortcuts =
403+
getPersonalSetting<CanvasNodeShortcuts>([
404+
PERSONAL_KEYS.canvasNodeShortcuts,
405+
]) ?? {};
408406

409407
allNodes.forEach((node, index) => {
410408
const nodeId = node.type;

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import getDiscourseNodes, {
55
excludeDefaultNodes,
66
} from "~/utils/getDiscourseNodes";
77
import { setPersonalSetting } from "~/components/settings/utils/accessors";
8-
import { getSetting, setSetting } from "~/utils/extensionSettings";
8+
import { PERSONAL_KEYS } from "~/components/settings/utils/settingKeys";
9+
import { setSetting } from "~/utils/extensionSettings";
910
import { CANVAS_NODE_SHORTCUTS_KEY } from "~/data/userSettings";
10-
import type { CanvasNodeShortcuts } from "./utils/zodSchema";
11-
12-
const BLOCK_PROP_KEY = "Canvas node shortcuts";
11+
import type { CanvasNodeShortcuts, PersonalSettings } from "./utils/zodSchema";
1312

1413
type ShortcutRowProps = {
15-
nodeType: string;
1614
nodeText: string;
1715
defaultShortcut: string;
1816
initialEnabled: boolean;
@@ -22,30 +20,24 @@ type ShortcutRowProps = {
2220
};
2321

2422
const ShortcutRow = ({
25-
nodeType,
2623
nodeText,
2724
defaultShortcut,
2825
initialEnabled,
2926
initialValue,
3027
onEnabledChange,
3128
onValueChange,
3229
}: ShortcutRowProps) => {
33-
const enabledKey = [BLOCK_PROP_KEY, nodeType, "enabled"];
34-
const valueKey = [BLOCK_PROP_KEY, nodeType, "value"];
35-
3630
const [enabled, setEnabled] = useState(initialEnabled);
3731
const [storedValue, setStoredValue] = useState(initialValue);
3832

3933
const persistValue = (value: string) => {
4034
setStoredValue(value);
41-
setPersonalSetting(valueKey, value);
4235
onValueChange(value);
4336
};
4437

4538
const handleEnabledChange = (e: React.FormEvent<HTMLInputElement>) => {
4639
const checked = e.currentTarget.checked;
4740
setEnabled(checked);
48-
setPersonalSetting(enabledKey, checked);
4941
if (!checked) {
5042
persistValue("");
5143
}
@@ -89,10 +81,16 @@ const ShortcutRow = ({
8981
);
9082
};
9183

92-
const CanvasShortcutSettings = () => {
84+
type CanvasShortcutSettingsProps = {
85+
personalSettings: PersonalSettings;
86+
};
87+
88+
const CanvasShortcutSettings = ({
89+
personalSettings,
90+
}: CanvasShortcutSettingsProps) => {
9391
const nodes = getDiscourseNodes().filter(excludeDefaultNodes);
94-
const [shortcuts, setShortcuts] = useState<CanvasNodeShortcuts>(() =>
95-
getSetting<CanvasNodeShortcuts>(CANVAS_NODE_SHORTCUTS_KEY, {}),
92+
const [shortcuts, setShortcuts] = useState<CanvasNodeShortcuts>(
93+
() => personalSettings[PERSONAL_KEYS.canvasNodeShortcuts],
9694
);
9795

9896
const updateShortcut = (
@@ -102,6 +100,7 @@ const CanvasShortcutSettings = () => {
102100
const current = shortcuts[nodeType] ?? { value: "", enabled: false };
103101
const next = { ...shortcuts, [nodeType]: { ...current, ...update } };
104102
void setSetting(CANVAS_NODE_SHORTCUTS_KEY, next);
103+
setPersonalSetting([PERSONAL_KEYS.canvasNodeShortcuts], next);
105104
setShortcuts(next);
106105
};
107106

@@ -125,7 +124,6 @@ const CanvasShortcutSettings = () => {
125124
return (
126125
<ShortcutRow
127126
key={node.type}
128-
nodeType={node.type}
129127
nodeText={node.text}
130128
defaultShortcut={node.shortcut}
131129
initialEnabled={override?.enabled ?? false}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ export const SettingsDialog = ({
194194
id="canvas-shortcuts-personal-settings"
195195
title="Canvas"
196196
className="overflow-y-auto"
197-
panel={<CanvasShortcutSettings />}
197+
panel={
198+
<CanvasShortcutSettings
199+
personalSettings={settings.personalSettings}
200+
/>
201+
}
198202
/>
199203
<Tab
200204
id="left-sidebar-personal-settings"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ const PERSONAL_SCHEMA_PATH_TO_LEGACY_KEY = new Map<string, string>([
238238
"default-filters",
239239
],
240240
[pathKey([PERSONAL_KEYS.reifiedRelationTriples]), "use-reified-relations"],
241+
[pathKey([PERSONAL_KEYS.canvasNodeShortcuts]), "canvas-node-shortcuts"],
241242
]);
242243

243244
const getLegacyPersonalLeftSidebarSetting = (): unknown[] => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const PERSONAL_KEYS = {
2626
leftSidebar: "Left sidebar",
2727
query: "Query",
2828
reifiedRelationTriples: "Reified relation triples",
29+
canvasNodeShortcuts: "Canvas node shortcuts",
2930
} as const satisfies Record<string, keyof PersonalSettings>;
3031

3132
export const QUERY_KEYS = {

0 commit comments

Comments
 (0)