Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions apps/roam/src/components/settings/DiscourseRelationConfigPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import { render as renderToast } from "roamjs-components/components/Toast";
import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid";
import updateBlock from "roamjs-components/writes/updateBlock";
import getTextByBlockUid from "roamjs-components/queries/getTextByBlockUid";
import getDiscourseNodes from "~/utils/getDiscourseNodes";
import getDiscourseNodes, {
excludeDefaultNodes,
} from "~/utils/getDiscourseNodes";
import { isRelationComplete } from "~/utils/isRelationComplete";
import { getConditionLabels } from "~/utils/conditionToDatalog";
import { formatHexColor } from "./DiscourseNodeCanvasSettings";
Expand Down Expand Up @@ -81,13 +83,15 @@ const edgeDisplayByUid = (uid: string) =>
export const RelationEditPanel = ({
editingRelationInfo,
nodes,
configuredNodeTypes,
back,
translatorKeys,
previewUid,
}: {
editingRelationInfo: TreeNode;
back: () => void;
nodes: Record<string, { label: string; format: string; color: string }>;
configuredNodeTypes: string[];
translatorKeys: string[];
previewUid: string;
}) => {
Expand Down Expand Up @@ -748,7 +752,7 @@ export const RelationEditPanel = ({
);
}
}}
items={Object.keys(nodes)}
items={configuredNodeTypes}
transformItem={transformItem}
/>
</Label>
Expand All @@ -765,7 +769,7 @@ export const RelationEditPanel = ({
).data("node", nodes[e]?.label);
}
}}
items={Object.keys(nodes)}
items={configuredNodeTypes}
transformItem={transformItem}
/>
</Label>
Expand Down Expand Up @@ -991,16 +995,20 @@ const DiscourseRelationConfigPanel = ({
})),
[],
);
const nodes = useMemo(() => {
const { nodes, configuredNodeTypes } = useMemo(() => {
const discourseNodes = getDiscourseNodes();
const nodes = Object.fromEntries(
getDiscourseNodes().map((n) => {
discourseNodes.map((n) => {
const color = formatHexColor(n.canvasSettings.color);
return [n.type, { label: n.text, format: n.format, color }];
}),
);
// TypeError: Iterator value * is not an entry object
nodes["*"] = { label: "Any", format: ".+", color: "#000" };
return nodes;
const configuredNodeTypes = discourseNodes
.filter(excludeDefaultNodes)
.map((n) => n.type);
Comment on lines +1008 to +1010

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add unit coverage for endpoint option filtering

This introduces new selector-filtering behavior without a unit test proving that default Page/Block nodes and synthetic Any are excluded while user-configured node types remain selectable. A regression in getDiscourseNodes or this filtering logic could silently restore invalid relation endpoints or remove valid ones, and the repository explicitly requires unit tests for new functionality.

AGENTS.md reference: AGENTS.md:L82-L85

Useful? React with 👍 / 👎.

return { nodes, configuredNodeTypes };
}, []);
const previewUid = useSubTree({ parentUid, key: "preview" }).uid;
const [translatorKeys, setTranslatorKeys] = useState(getConditionLabels);
Expand Down Expand Up @@ -1148,6 +1156,7 @@ const DiscourseRelationConfigPanel = ({
<div style={{ caretColor: "transparent" }}>
<RelationEditPanel
nodes={nodes}
configuredNodeTypes={configuredNodeTypes}
editingRelationInfo={editingRelationInfo}
back={handleBack}
translatorKeys={translatorKeys}
Expand Down