Skip to content

Commit c8e7280

Browse files
ENG-1896 Remove legacy anchor-backed discourse node type support (#1135)
* Remove legacy anchor-backed discourse node type support - Remove anchor-backed discourse node creation from getDiscourseNodes - Remove anchor selection logic from getDiscourseContextResults - Preserve existing context selection behavior This removes unused legacy functionality where relations with 'anchor' in their triples would generate discourse nodes. Per the issue, this feature is no longer used and has no place to surface in the current discourse context UI. * Refactor getDiscourseNodes to remove legacy relations parameter - Updated getDiscourseNodes to only accept settingsSnapshot, removing the relations parameter. - Adjusted multiple components and utility functions to align with the new getDiscourseNodes signature. - Ensured consistent behavior across the application by standardizing how discourse nodes are retrieved. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 6f3a22c commit c8e7280

16 files changed

Lines changed: 73 additions & 316 deletions

apps/roam/src/components/DiscourseContext.tsx

Lines changed: 9 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
import {
2-
Button,
3-
Icon,
4-
Portal,
5-
Switch,
6-
Tabs,
7-
Tab,
8-
Tooltip,
9-
Spinner,
10-
} from "@blueprintjs/core";
11-
import React, {
12-
useCallback,
13-
useEffect,
14-
useMemo,
15-
useState,
16-
useRef,
17-
} from "react";
18-
import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid";
19-
import getShallowTreeByParentUid from "roamjs-components/queries/getShallowTreeByParentUid";
1+
import { Switch, Tabs, Tab, Spinner } from "@blueprintjs/core";
2+
import React, { useCallback, useEffect, useMemo, useState } from "react";
203
import { Result } from "roamjs-components/types/query-builder";
21-
import nanoId from "nanoid";
224
import getDiscourseContextResults from "~/utils/getDiscourseContextResults";
235
import ResultsView from "./results-view/ResultsView";
246
import posthog from "posthog-js";
@@ -34,188 +16,12 @@ type Props = {
3416
overlayRefresh?: () => void;
3517
};
3618

37-
const ExtraColumnRow = (r: Result) => {
38-
const [contextOpen, setContextOpen] = useState(false);
39-
const [contextRowReady, setContextRowReady] = useState(false);
40-
const contextId = useMemo(() => `td-${nanoId()}`, []);
41-
const anchorId = useMemo(() => `td-${nanoId()}`, []);
42-
const [anchorOpen, setAnchorOpen] = useState(false);
43-
const [anchorRowReady, setAnchorRowReady] = useState(false);
44-
const containerRef = useRef<HTMLSpanElement>(null);
45-
const contextPageTitle = useMemo(
46-
() =>
47-
r["context-uid"] && getPageTitleByPageUid(r["context-uid"].toString()),
48-
[r["context-uid"]],
49-
);
50-
const contextBreadCrumbs = useMemo(
51-
() =>
52-
r["context-uid"]
53-
? window.roamAlphaAPI
54-
.q(
55-
`[:find (pull ?p [:node/title :block/string :block/uid]) :where
56-
[?b :block/uid "${r["context-uid"]}"]
57-
[?b :block/parents ?p]
58-
]`,
59-
)
60-
.map(
61-
(a) => a[0] as { string?: string; title?: string; uid: string },
62-
)
63-
.map((a) => ({ uid: a.uid, text: a.string || a.title || "" }))
64-
: [],
65-
[r["context-uid"]],
66-
);
67-
const contextChildren = useMemo(
68-
() =>
69-
r["context-uid"] && contextPageTitle
70-
? getShallowTreeByParentUid(r["context-uid"].toString()).map(
71-
({ uid }) => uid,
72-
)
73-
: [r["context-uid"].toString()],
74-
[r["context-uid"], contextPageTitle, r.uid],
75-
);
76-
useEffect(() => {
77-
if (contextOpen && containerRef.current) {
78-
const row = containerRef.current.closest("tr");
79-
const contextElement = document.createElement("tr");
80-
const contextTd = document.createElement("td");
81-
contextTd.colSpan = row?.childElementCount || 0;
82-
contextElement.id = contextId;
83-
row?.parentElement?.insertBefore(contextElement, row.nextElementSibling);
84-
contextElement.append(contextTd);
85-
setContextRowReady(true);
86-
} else {
87-
setContextRowReady(false);
88-
document.getElementById(contextId)?.remove();
89-
}
90-
}, [contextOpen, setContextRowReady, contextId]);
91-
useEffect(() => {
92-
if (contextRowReady) {
93-
setTimeout(() => {
94-
contextChildren.forEach((uid) => {
95-
const el = document.querySelector<HTMLElement>(
96-
`tr#${contextId} div[data-uid="${uid}"]`,
97-
);
98-
if (el)
99-
window.roamAlphaAPI.ui.components.renderBlock({
100-
uid,
101-
el,
102-
});
103-
});
104-
}, 1);
105-
}
106-
}, [contextRowReady]);
107-
useEffect(() => {
108-
if (anchorOpen) {
109-
const row = containerRef.current?.closest("tr");
110-
const anchorElement = document.createElement("tr");
111-
const anchorTd = document.createElement("td");
112-
anchorTd.colSpan = row?.childElementCount || 0;
113-
anchorElement.id = anchorId;
114-
row?.parentElement?.insertBefore(anchorElement, row.nextElementSibling);
115-
anchorElement.append(anchorTd);
116-
setAnchorRowReady(true);
117-
} else {
118-
setAnchorRowReady(false);
119-
document.getElementById(anchorId)?.remove();
120-
}
121-
}, [anchorOpen, setAnchorRowReady, anchorId]);
122-
return (
123-
<span ref={containerRef}>
124-
{r["context-uid"] && (
125-
<Tooltip content={"Context"}>
126-
<Button
127-
onClick={() => setContextOpen(!contextOpen)}
128-
small
129-
active={contextOpen}
130-
style={{
131-
opacity: 0.5,
132-
fontSize: "0.8em",
133-
...(contextOpen
134-
? {
135-
opacity: 1,
136-
color: "#8A9BA8",
137-
backgroundColor: "#F5F8FA",
138-
}
139-
: {}),
140-
}}
141-
minimal
142-
icon="info-sign"
143-
/>
144-
</Tooltip>
145-
)}
146-
<style>
147-
{`#${contextId} td,
148-
#${anchorId} td {
149-
position: relative;
150-
background-color: #F5F8FA;
151-
padding: 16px;
152-
max-height: 240px;
153-
overflow-y: scroll;
154-
}
155-
#${contextId} .bp3-portal,
156-
#${anchorId} .bp3-portal {
157-
position: relative;
158-
}`}
159-
</style>
160-
{contextRowReady && (
161-
<Portal
162-
container={
163-
document.getElementById(contextId)
164-
?.firstElementChild as HTMLDataElement
165-
}
166-
className={"relative"}
167-
>
168-
{contextPageTitle ? (
169-
<h3 style={{ margin: 0 }}>{contextPageTitle}</h3>
170-
) : (
171-
<div className="rm-zoom">
172-
{contextBreadCrumbs.map((bc) => (
173-
<div key={bc.uid} className="rm-zoom-item">
174-
<span className="rm-zoom-item-content">{bc.text}</span>
175-
<Icon icon={"chevron-right"} />
176-
</div>
177-
))}
178-
</div>
179-
)}
180-
{contextChildren.map((uid) => (
181-
<div data-uid={uid} key={uid}></div>
182-
))}
183-
</Portal>
184-
)}
185-
{r.anchor && (
186-
<Tooltip content={"See Related Relations"}>
187-
<Button
188-
onClick={() => setAnchorOpen(!anchorOpen)}
189-
active={anchorOpen}
190-
small
191-
style={{
192-
opacity: 0.5,
193-
fontSize: "0.8em",
194-
...(anchorOpen
195-
? {
196-
opacity: 1,
197-
color: "#8A9BA8",
198-
backgroundColor: "#F5F8FA",
199-
}
200-
: {}),
201-
}}
202-
minimal
203-
icon={"resolve"}
204-
/>
205-
</Tooltip>
206-
)}
207-
{anchorRowReady && (
208-
<Portal
209-
container={
210-
document.getElementById(anchorId)
211-
?.firstElementChild as HTMLDataElement
212-
}
213-
>
214-
<ContextContent uid={r["anchor-uid"]} results={[]} />
215-
</Portal>
216-
)}
217-
</span>
218-
);
19+
const removeTargetFromResult = (
20+
result: Partial<Result & { target: string }>,
21+
): Result => {
22+
const tableResult = { ...result };
23+
delete tableResult.target;
24+
return tableResult as Result;
21925
};
22026

22127
const ContextTab = ({
@@ -270,7 +76,7 @@ const ContextTab = ({
27076
// TODO - always save settings, but maybe separate from root `parentUid`?
27177
preventSavingSettings
27278
parentUid={parentUid}
273-
results={Object.values(results).map(({ target, ...a }) => a as Result)}
79+
results={Object.values(results).map(removeTargetFromResult)}
27480
columns={columns}
27581
onRefresh={onRefresh}
27682
header={

apps/roam/src/components/DiscourseContextOverlay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const getOverlayInfo = async (
3838
): Promise<DiscourseData> => {
3939
try {
4040
const relations = getDiscourseRelations();
41-
const nodes = getDiscourseNodes(relations);
41+
const nodes = getDiscourseNodes();
4242

4343
const [results, refs] = await Promise.all([
4444
getDiscourseContextResults({

apps/roam/src/components/DiscourseNodeMenu.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ const NodeMenu = ({
6262
);
6363
const userDiscourseNodes = useMemo(
6464
() =>
65-
getDiscourseNodes(undefined, settingsSnapshot).filter(
66-
(n) => n.backedBy === "user",
67-
),
65+
getDiscourseNodes(settingsSnapshot).filter((n) => n.backedBy === "user"),
6866
[settingsSnapshot],
6967
);
7068
const discourseNodes = userDiscourseNodes.filter(

apps/roam/src/components/Export.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ const ExportDialog: ExportDialogComponent = ({
327327
);
328328
const allRelations = relations;
329329
const allRelationIds = allRelations.map((r) => r.id);
330-
const allNodes = getDiscourseNodes(allRelations);
330+
const allNodes = getDiscourseNodes();
331331
const allAddReferencedNodeByAction = (() => {
332332
const obj: AddReferencedNodeType = {};
333333

apps/roam/src/components/SuggestionsBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const getOverlayInfo = async (
5151
try {
5252
if (cache[tag]) return cache[tag];
5353

54-
const nodes = getDiscourseNodes(relations);
54+
const nodes = getDiscourseNodes();
5555

5656
const [results, refs] = await Promise.all([
5757
getDiscourseContextResults({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,12 @@ const TldrawCanvasShared = ({
486486
return Object.keys(discourseContext.relations);
487487
}, []);
488488
const allNodes = useMemo(() => {
489-
const allNodes = getDiscourseNodes(allRelations);
489+
const allNodes = getDiscourseNodes();
490490
discourseContext.nodes = Object.fromEntries(
491491
allNodes.map((n, index) => [n.type, { ...n, index }]),
492492
);
493493
return allNodes;
494-
}, [allRelations]);
494+
}, []);
495495

496496
const allAddReferencedNodeByAction = useMemo(() => {
497497
const obj: AddReferencedNodeType = {};

apps/roam/src/utils/deriveDiscourseNodeAttribute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const deriveNodeAttribute = async ({
4747
uid: string;
4848
}): Promise<string | number> => {
4949
const relations = getDiscourseRelations();
50-
const nodes = getDiscourseNodes(relations);
50+
const nodes = getDiscourseNodes();
5151
const discourseNode = findDiscourseNode({ uid, nodes });
5252
if (!discourseNode) return 0;
5353
const nodeType = discourseNode.type;

apps/roam/src/utils/findDiscourseNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const findDiscourseNode = ({
2727
return discourseNodeTypeCache[uid];
2828
}
2929

30-
const resolvedNodes = nodes ?? getDiscourseNodes(undefined, snapshot);
30+
const resolvedNodes = nodes ?? getDiscourseNodes(snapshot);
3131
const matchingNode =
3232
resolvedNodes.find((node) =>
3333
title === undefined

apps/roam/src/utils/getDiscourseContextResults.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ const buildSelections = ({
5050
label: "context",
5151
text: `node:${conditionUid}-Context`,
5252
});
53-
} else if (r.triples.some((t) => t.some((a) => /anchor/i.test(a)))) {
54-
selections.push({
55-
uid: window.roamAlphaAPI.util.generateUID(),
56-
label: "anchor",
57-
text: `node:${conditionUid}-Anchor`,
58-
});
5953
}
6054

6155
return selections;
@@ -172,7 +166,7 @@ const buildQueryConfig = ({
172166
const getDiscourseContextResults = async ({
173167
uid: targetUid,
174168
relations = getDiscourseRelations(),
175-
nodes = getDiscourseNodes(relations),
169+
nodes = getDiscourseNodes(),
176170
ignoreCache,
177171
onResult,
178172
}: {

0 commit comments

Comments
 (0)