Skip to content

Commit 75b49dc

Browse files
authored
ENG-1520 Set reified relations to default for new graphs (#868)
* Refactor relation handling to use stored relations instead of reified relations across multiple components. Updated settings and migration documentation to reflect the transition from legacy pattern-based relations to stored relations. This includes changes in CreateRelationDialog, SuggestionsBody, DiscourseRelationUtil, ResultsTable, and various settings components. Adjusted user settings keys for better clarity and consistency. * Update INSTALL_CUTOFF date in storedRelations.ts and simplify getStoredRelationsEnabled logic by removing legacy setting handling. * Update documentation to reflect that new Discourse Graph installs use stored relations by default as of v0.18.0. Adjusted INSTALL_CUTOFF date in storedRelations.ts for consistency. * Corrected the terminology from "Refied relations" to "Reified relations" in storedRelations.ts. Updated documentation across multiple files to clarify the use of stored relations, including migration guidance and quick start instructions for users transitioning from legacy pattern-based relations. Enhanced clarity and consistency in the descriptions of stored relations and their benefits. * Updated documentation for extending and personalizing the Discourse Graph. Revised content to clarify the use of stored relations, added sections on legacy pattern relations, and included demo links for creating relation patterns. Adjusted navigation links for consistency across related documentation pages. * Refactor getInstallDefault to return a boolean value, ensuring a default of true when the config page is not found. Simplified logic in getStoredRelationsEnabled by removing unnecessary type checks for resolved defaults. * Changed section headers from "###" to "##"
1 parent d6ee840 commit 75b49dc

17 files changed

Lines changed: 176 additions & 190 deletions

apps/roam/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "roam",
3-
"version": "0.17.1",
3+
"version": "0.18.0",
44
"description": "Discourse Graph Plugin for roamresearch.com",
55
"scripts": {
66
"dev": "tsx scripts/dev.ts",

apps/roam/src/components/CreateRelationDialog.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ import { render as renderToast } from "roamjs-components/components/Toast";
1212
import MenuItemSelect from "roamjs-components/components/MenuItemSelect";
1313
import AutocompleteInput from "roamjs-components/components/AutocompleteInput";
1414
import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid";
15-
import { getSetting } from "~/utils/extensionSettings";
1615
import getDiscourseRelations, {
1716
type DiscourseRelation,
1817
} from "~/utils/getDiscourseRelations";
1918
import { createReifiedRelation } from "~/utils/createReifiedBlock";
19+
import { getStoredRelationsEnabled } from "~/utils/storedRelations";
2020
import findDiscourseNode from "~/utils/findDiscourseNode";
2121
import { getDiscourseNodeFormatInnerExpression } from "~/utils/getDiscourseNodeFormatExpression";
2222
import type { DiscourseNode } from "~/utils/getDiscourseNodes";
2323
import type { Result } from "~/utils/types";
2424
import internalError from "~/utils/internalError";
2525
import getDiscourseNodes from "~/utils/getDiscourseNodes";
26-
import { USE_REIFIED_RELATIONS } from "~/data/userSettings";
2726
import posthog from "posthog-js";
2827

2928
export type CreateRelationDialogProps = {
@@ -384,8 +383,8 @@ export const renderCreateRelationDialog = (
384383
export const CreateRelationButton = (
385384
props: CreateRelationDialogProps,
386385
): React.JSX.Element | null => {
387-
const showAddRelation = getSetting<boolean>(USE_REIFIED_RELATIONS, false);
388-
if (!showAddRelation) return null;
386+
const storedRelationsEnabled = getStoredRelationsEnabled();
387+
if (!storedRelationsEnabled) return null;
389388
let extProps: ExtendedCreateRelationDialogProps | null = null;
390389
try {
391390
extProps = extendProps(props);

apps/roam/src/components/SuggestionsBody.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ import normalizePageTitle from "roamjs-components/queries/normalizePageTitle";
2626
import { type RelationDetails } from "~/utils/hyde";
2727
import { getFormattedConfigTree } from "~/utils/discourseConfigRef";
2828
import { render as renderToast } from "roamjs-components/components/Toast";
29-
import { getSetting } from "~/utils/extensionSettings";
30-
import { USE_REIFIED_RELATIONS } from "~/data/userSettings";
3129
import { createReifiedRelation } from "~/utils/createReifiedBlock";
30+
import { getStoredRelationsEnabled } from "~/utils/storedRelations";
3231
import posthog from "posthog-js";
3332

3433
export type DiscourseData = {
@@ -310,7 +309,7 @@ const SuggestionsBody = ({
310309
};
311310

312311
const handleCreateBlock = async (node: SuggestedNode) => {
313-
if (getSetting<boolean>(USE_REIFIED_RELATIONS, false)) {
312+
if (getStoredRelationsEnabled()) {
314313
if (discourseNode === false) {
315314
renderToast({
316315
id: "suggestions-create-block-error",
@@ -374,7 +373,7 @@ const SuggestionsBody = ({
374373
tag,
375374
nodeType: node.type,
376375
nodeText: node.text,
377-
useReifiedRelations: getSetting<boolean>(USE_REIFIED_RELATIONS, false),
376+
useReifiedRelations: getStoredRelationsEnabled(),
378377
});
379378
setHydeFilteredNodes((prev) => prev.filter((n) => n.uid !== node.uid));
380379
};

apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ import {
6363
shapeAtTranslationStart,
6464
updateArrowTerminal,
6565
} from "./helpers";
66-
import { getSetting } from "~/utils/extensionSettings";
6766
import { createReifiedRelation } from "~/utils/createReifiedBlock";
67+
import { getStoredRelationsEnabled } from "~/utils/storedRelations";
6868
import { discourseContext, isPageUid } from "~/components/canvas/Tldraw";
6969
import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle";
7070

@@ -86,7 +86,10 @@ const getCanvasPageUidFromDOM = (): string | null => {
8686
// With multiple canvases, find the one that contains the currently focused element
8787
// or has been recently interacted with (has :focus-within)
8888
for (const container of containers) {
89-
if (container.matches(":focus-within") || container.contains(document.activeElement)) {
89+
if (
90+
container.matches(":focus-within") ||
91+
container.contains(document.activeElement)
92+
) {
9093
return container.getAttribute("data-page-uid");
9194
}
9295
}
@@ -107,7 +110,6 @@ import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageU
107110
import { AddReferencedNodeType } from "./DiscourseRelationTool";
108111
import { dispatchToastEvent } from "~/components/canvas/ToastListener";
109112
import internalError from "~/utils/internalError";
110-
import { USE_REIFIED_RELATIONS } from "~/data/userSettings";
111113

112114
const COLOR_ARRAY = Array.from(DefaultColorStyle.values)
113115
.filter((c) => !["red", "green", "grey"].includes(c))
@@ -638,7 +640,7 @@ export const createAllRelationShapeUtils = (
638640
if (arrow.type !== target.type) {
639641
editor.updateShapes([{ id: arrow.id, type: target.type }]);
640642
}
641-
if (getSetting<boolean>(USE_REIFIED_RELATIONS, false)) {
643+
if (getStoredRelationsEnabled()) {
642644
const sourceAsDNS = asDiscourseNodeShape(source, editor);
643645
const targetAsDNS = asDiscourseNodeShape(target, editor);
644646

apps/roam/src/components/results-view/ResultsTable.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import toCellValue from "~/utils/toCellValue";
2222
import { ContextContent } from "~/components/DiscourseContext";
2323
import DiscourseContextOverlay from "~/components/DiscourseContextOverlay";
2424
import { CONTEXT_OVERLAY_SUGGESTION } from "~/utils/predefinedSelections";
25-
import { USE_REIFIED_RELATIONS } from "~/data/userSettings";
26-
import { getSetting } from "~/utils/extensionSettings";
2725
import { strictQueryForReifiedBlocks } from "~/utils/createReifiedBlock";
26+
import { getStoredRelationsEnabled } from "~/utils/storedRelations";
27+
import internalError from "~/utils/internalError";
2828
import {
2929
RenderRoamBlock,
3030
RenderRoamPage,
@@ -201,7 +201,7 @@ const ResultRow = ({
201201
onDragEnd,
202202
onRefresh,
203203
}: ResultRowProps) => {
204-
const useReifiedRel = getSetting<boolean>(USE_REIFIED_RELATIONS, false);
204+
const storedRelationsEnabled = getStoredRelationsEnabled();
205205
const cell = (key: string) => {
206206
const value = toCellValue({
207207
value: r[`${key}-display`] || r[key] || "",
@@ -371,7 +371,7 @@ const ResultRow = ({
371371
) : (
372372
cell(key)
373373
)}
374-
{useReifiedRel &&
374+
{storedRelationsEnabled &&
375375
typeof r["ctxTargetUid"] === "string" &&
376376
typeof r["id"] === "string" &&
377377
typeof r["complement"] === "number" &&

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { getConditionLabels } from "~/utils/conditionToDatalog";
5050
import { formatHexColor } from "./DiscourseNodeCanvasSettings";
5151
import posthog from "posthog-js";
5252
import { getSetting, setSetting } from "~/utils/extensionSettings";
53-
import { USE_REIFIED_RELATIONS } from "~/data/userSettings";
53+
import { getStoredRelationsEnabled } from "~/utils/storedRelations";
5454
import {
5555
setGlobalSetting,
5656
getGlobalSettings,
@@ -91,7 +91,7 @@ export const RelationEditPanel = ({
9191
),
9292
[nodes],
9393
);
94-
const useReifiedRelations = getSetting<boolean>(USE_REIFIED_RELATIONS, false);
94+
const storedRelationsEnabled = getStoredRelationsEnabled();
9595
const containerRef = useRef<HTMLDivElement>(null);
9696
const idRef = useRef(0);
9797
const cyRef = useRef<cytoscape.Core>();
@@ -392,7 +392,7 @@ export const RelationEditPanel = ({
392392
);
393393

394394
const loadCytoscape = useCallback(async () => {
395-
if (useReifiedRelations) return;
395+
if (storedRelationsEnabled) return;
396396
cyRef.current?.destroy?.();
397397
const cytoscape = await window.RoamLazy?.Cytoscape();
398398
if (!cytoscape) return;
@@ -472,7 +472,7 @@ export const RelationEditPanel = ({
472472
setSelectedRelation,
473473
tab,
474474
unsavedChanges,
475-
useReifiedRelations,
475+
storedRelationsEnabled,
476476
]);
477477
useEffect(() => {
478478
loadCytoscape();
@@ -774,7 +774,7 @@ export const RelationEditPanel = ({
774774
/>
775775
</Label>
776776
</ControlGroup>
777-
{!useReifiedRelations && (
777+
{!storedRelationsEnabled && (
778778
<>
779779
<Tabs
780780
selectedTabId={tab}
@@ -1016,10 +1016,7 @@ const DiscourseRelationConfigPanel: CustomField["options"]["component"] = ({
10161016
const [deleteConfirmation, setDeleteConfirmation] = useState<string | null>(
10171017
null,
10181018
);
1019-
const shouldHideCanvasRelation = getSetting<boolean>(
1020-
USE_REIFIED_RELATIONS,
1021-
false,
1022-
);
1019+
const shouldHideCanvasRelation = getStoredRelationsEnabled();
10231020
const visibleRelations = useMemo(() => {
10241021
if (!shouldHideCanvasRelation) {
10251022
return relations;

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY,
2323
STREAMLINE_STYLING_KEY,
2424
DISALLOW_DIAGNOSTICS,
25-
USE_REIFIED_RELATIONS,
25+
USE_STORED_RELATIONS,
2626
} from "~/data/userSettings";
2727
import { getSetting, setSetting } from "~/utils/extensionSettings";
2828
import { enablePostHog, disablePostHog } from "~/utils/posthog";
@@ -35,6 +35,7 @@ import { countReifiedRelations } from "~/utils/createReifiedBlock";
3535
import posthog from "posthog-js";
3636
import internalError from "~/utils/internalError";
3737
import { setPersonalSetting } from "./utils/accessors";
38+
import { getStoredRelationsEnabled } from "~/utils/storedRelations";
3839

3940
const enum RelationMigrationDialog {
4041
"none",
@@ -52,10 +53,10 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
5253
const [numExistingRelations, setNumExistingRelations] = useState<number>(0);
5354
const [isOngoing, setIsOngoing] = useState<boolean>(false);
5455
const [storedRelations, setStoredRelationsState] = useState<boolean>(
55-
getSetting<boolean>(USE_REIFIED_RELATIONS, false),
56+
getStoredRelationsEnabled(),
5657
);
5758
const setStoredRelations = (value: boolean) => {
58-
setSetting<boolean>(USE_REIFIED_RELATIONS, value)
59+
setSetting<boolean>(USE_STORED_RELATIONS, value)
5960
.then(() => {
6061
setStoredRelationsState(value);
6162
setPersonalSetting(["Reified relation triples"], value);
@@ -67,11 +68,11 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
6768
const startMigration = async (): Promise<void> => {
6869
const before = numExistingRelations;
6970
try {
70-
posthog.capture("Reified Relations: Migration Started");
71+
posthog.capture("Stored Relations: Migration Started");
7172
const numProcessed = await migrateRelations();
7273
if (numProcessed === false) {
7374
renderToast({
74-
content: "Reified Relations: Migration Failed",
75+
content: "Stored Relations: Migration Failed",
7576
intent: Intent.DANGER,
7677
id: "migration-error",
7778
});
@@ -92,7 +93,7 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
9293
intent: Intent.SUCCESS,
9394
id: "migration-success",
9495
});
95-
posthog.capture("Reified Relations: Migration Completed", {
96+
posthog.capture("Stored Relations: Migration Completed", {
9697
processed: numProcessed,
9798
before,
9899
after,
@@ -102,7 +103,7 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
102103
} catch (error) {
103104
internalError({
104105
error,
105-
userMessage: "Reified Relations: Migration Failed",
106+
userMessage: "Stored Relations: Migration Failed",
106107
});
107108
setStoredRelations(false);
108109
} finally {
@@ -168,7 +169,7 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
168169

169170
<PersonalFlagPanel
170171
title="Enable stored relations"
171-
description="Transition to using stored relations instead of pattern-based relations"
172+
description="Use stored relations instead of legacy pattern-based relations"
172173
settingKeys={["Reified relation triples"]}
173174
value={storedRelations}
174175
onBeforeChange={async (checked) => {
@@ -299,12 +300,12 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
299300
) : (
300301
<>
301302
<p>
302-
Activating the faster relations system will migrate all
303-
previously created relations and newly created relations will
304-
use the new system. You can deactivate this setting to revert to
305-
the old system, and your newly created relations will not be
303+
Activating stored relations will migrate all previously created
304+
legacy pattern relations, and newly created relations will use
305+
stored relations. You can deactivate this setting to revert to
306+
the legacy system, and your newly created relations will not be
306307
deleted; however, they will not be accessible until you
307-
reactivate the faster relation system.
308+
reactivate stored relations.
308309
</p>
309310
{activeRelationMigration ===
310311
RelationMigrationDialog.reactivate ? (
@@ -366,11 +367,11 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
366367
>
367368
<div className={Classes.DIALOG_BODY}>
368369
<p>
369-
Deactivating the faster relations system will mean that any
370-
relations created using it will no longer be accessible. The
371-
discourse context overlay will still be usable with the previous
372-
relations system. Any relations created with the faster system will
373-
be accessible should you choose to reactivate.
370+
Deactivating stored relations means any relations created using them
371+
will no longer be accessible. The discourse context overlay will
372+
still be usable with the legacy pattern-based system. Any relations
373+
created with stored relations will be accessible should you choose
374+
to reactivate.
374375
</p>
375376
</div>
376377
<div className={Classes.DIALOG_FOOTER}>

apps/roam/src/data/userSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export const DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY =
99
"discourse-context-overlay-in-canvas";
1010
export const STREAMLINE_STYLING_KEY = "streamline-styling";
1111
export const DISALLOW_DIAGNOSTICS = "disallow-diagnostics";
12-
export const USE_REIFIED_RELATIONS = "use-reified-relations";
12+
export const USE_STORED_RELATIONS = "use-reified-relations"; // "use-reified-relations" is legacy terminology, but we keep it for backwards compatibility

apps/roam/src/utils/registerDiscourseDatalogTranslators.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import replaceDatalogVariables from "./replaceDatalogVariables";
1919
import parseQuery from "./parseQuery";
2020
import { fireQuerySync, getWhereClauses } from "./fireQuery";
2121
import { toVar } from "./compileDatalog";
22-
import { getSetting } from "./extensionSettings";
2322
import { getExistingRelationPageUid } from "./createReifiedBlock";
24-
import { USE_REIFIED_RELATIONS } from "~/data/userSettings";
23+
import { getStoredRelationsEnabled } from "./storedRelations";
2524

2625
const hasTag = (node: DiscourseNode): node is DiscourseNode & { tag: string } =>
2726
!!node.tag;
@@ -410,10 +409,7 @@ const registerDiscourseDatalogTranslators = () => {
410409
registerDatalogTranslator({
411410
key: label,
412411
callback: ({ source, target, uid }) => {
413-
const useReifiedRelations = getSetting<boolean>(
414-
USE_REIFIED_RELATIONS,
415-
false,
416-
);
412+
const storedRelationsEnabled = getStoredRelationsEnabled();
417413
const relationPageUid = getExistingRelationPageUid();
418414

419415
const filteredRelations = getFilteredRelations({
@@ -495,7 +491,7 @@ const registerDiscourseDatalogTranslators = () => {
495491
}
496492
};
497493

498-
if (useReifiedRelations && relationPageUid !== undefined) {
494+
if (storedRelationsEnabled && relationPageUid !== undefined) {
499495
const relClauseBasis: DatalogClause[] = [
500496
{
501497
type: "data-pattern",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// We made the decision to use "Store relations" terminology for the UI
2+
// But there is still some legacy code that uses "Reified relations" terminology.
3+
// ENG-1521: Update internal terminology to use "stored" instead of "reified"
4+
5+
import { USE_STORED_RELATIONS } from "~/data/userSettings";
6+
import { getSetting, setSetting } from "./extensionSettings";
7+
import { DISCOURSE_CONFIG_PAGE_TITLE } from "./renderNodeConfigPage";
8+
9+
const INSTALL_CUTOFF = Date.parse("2026-03-01T00:00:00.000Z");
10+
11+
const setResolvedDefault = (value: boolean): void => {
12+
void setSetting(USE_STORED_RELATIONS, value).catch(() => undefined);
13+
};
14+
15+
// Stored relations are the default for new DG installs. We use the config
16+
// page create date as the install cutoff because it reflects when DG was first
17+
// initialized in the graph.
18+
const getInstallDefault = (): boolean => {
19+
const page = window.roamAlphaAPI.pull(
20+
"[:create/time]",
21+
[":node/title", DISCOURSE_CONFIG_PAGE_TITLE],
22+
// eslint-disable-next-line @typescript-eslint/naming-convention
23+
) as { ":create/time"?: number } | null;
24+
if (!page) return true; // handle case where config page doesn't exist yet, assume new install
25+
26+
const createdAt = page[":create/time"];
27+
return typeof createdAt === "number" && createdAt >= INSTALL_CUTOFF;
28+
};
29+
30+
// Once the config page exists, persist the resolved default under the new
31+
// setting key so future reads can use the explicit setting path directly.
32+
export const getStoredRelationsEnabled = (): boolean => {
33+
const value = getSetting<boolean | undefined>(USE_STORED_RELATIONS);
34+
if (typeof value === "boolean") return value;
35+
36+
const resolvedDefault = getInstallDefault();
37+
setResolvedDefault(resolvedDefault);
38+
return resolvedDefault;
39+
};

0 commit comments

Comments
 (0)