From 7ef9d8840c2ea68dd3be5f9d73470fe37ffbf11a Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Sun, 14 Dec 2025 18:28:52 -0500 Subject: [PATCH 1/3] ENG-1088: An affordance to delete relations. Sending necessary data through the result. --- apps/roam/src/components/DiscourseContext.tsx | 4 +- .../components/results-view/ResultsTable.tsx | 60 +++++++++++++++++++ apps/roam/src/utils/createReifiedBlock.ts | 2 +- .../src/utils/getDiscourseContextResults.ts | 3 +- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/apps/roam/src/components/DiscourseContext.tsx b/apps/roam/src/components/DiscourseContext.tsx index 3a058747e..cbd97ef73 100644 --- a/apps/roam/src/components/DiscourseContext.tsx +++ b/apps/roam/src/components/DiscourseContext.tsx @@ -269,9 +269,7 @@ const ContextTab = ({ // TODO - always save settings, but maybe separate from root `parentUid`? preventSavingSettings parentUid={parentUid} - results={Object.values(results).map( - ({ target, complement, id, ...a }) => a as Result, - )} + results={Object.values(results).map(({ target, ...a }) => a as Result)} columns={columns} onRefresh={onRefresh} header={ diff --git a/apps/roam/src/components/results-view/ResultsTable.tsx b/apps/roam/src/components/results-view/ResultsTable.tsx index 74af4956d..15d935541 100644 --- a/apps/roam/src/components/results-view/ResultsTable.tsx +++ b/apps/roam/src/components/results-view/ResultsTable.tsx @@ -7,6 +7,7 @@ import React, { } from "react"; import { Button, HTMLTable, Icon, IconName } from "@blueprintjs/core"; import { IconNames } from "@blueprintjs/icons"; +import { render as renderToast } from "roamjs-components/components/Toast"; import { Column, Result } from "~/utils/types"; import type { FilterData, Sorts, Views } from "~/utils/parseResultSettings"; import Filter, { Filters } from "roamjs-components/components/Filter"; @@ -21,6 +22,9 @@ import toCellValue from "~/utils/toCellValue"; import { ContextContent } from "~/components/DiscourseContext"; import DiscourseContextOverlay from "~/components/DiscourseContextOverlay"; import { CONTEXT_OVERLAY_SUGGESTION } from "~/utils/predefinedSelections"; +import { getSetting } from "~/utils/extensionSettings"; +import { strictQueryForReifiedBlocks } from "~/utils/createReifiedBlock"; +import formatDistanceStrictWithOptions from "date-fns/esm/fp/formatDistanceStrictWithOptions/index.js"; const EXTRA_ROW_TYPES = ["context", "discourse"] as const; type ExtraRowType = (typeof EXTRA_ROW_TYPES)[number] | null; @@ -202,6 +206,7 @@ const ResultRow = ({ onDragEnd, onRefresh, }: ResultRowProps) => { + const useReifiedRel = getSetting("use-reified-relations"); const cell = (key: string) => { const value = toCellValue({ value: r[`${key}-display`] || r[key] || "", @@ -264,6 +269,52 @@ const ResultRow = ({ [views], ); const trRef = useRef(null); + const onDelete = () => { + const data = { + sourceUid: r["complement"] === 1 ? r["uid"] : r["ctxTargetUid"], + destinationUid: r["complement"] === 1 ? r["ctxTargetUid"] : r["uid"], + hasSchema: r["id"], + } as Record; + strictQueryForReifiedBlocks(data) + .then((blockUid) => { + if (blockUid === null) { + renderToast({ + id: "delete-relation-error", + content: "Could not find relation", + intent: "warning", + }); + return; + } + deleteBlock(blockUid) + .then(() => { + renderToast({ + id: "delete-relation-success", + content: "Relation deleted", + intent: "success", + }); + onRefresh(); + }) + .catch((e) => { + // this one should be an internalError + console.error(e); + renderToast({ + id: "delete-relation-error", + content: "Could not delete relation", + intent: "danger", + }); + }); + }) + .catch((e) => { + // this one should be an internalError + console.error(e); + renderToast({ + id: "delete-relation-error", + content: "Error searching for relation", + intent: "danger", + }); + }); + }; + return ( <> @@ -321,6 +372,15 @@ const ResultRow = ({ ) : ( cell(key) )} + {useReifiedRel && r["ctxTargetUid"] !== undefined && ( + + )} {i < columns.length - 1 && (
, ): Promise => { const paramsAsSeq = Object.entries(parameterUids); diff --git a/apps/roam/src/utils/getDiscourseContextResults.ts b/apps/roam/src/utils/getDiscourseContextResults.ts index 2bc2df3a8..48a76220b 100644 --- a/apps/roam/src/utils/getDiscourseContextResults.ts +++ b/apps/roam/src/utils/getDiscourseContextResults.ts @@ -76,7 +76,8 @@ const executeQueries = async ( onResult?: onResult, ) => { const promises = queryConfigs.map(async ({ relation, queryPromise }) => { - const results = await queryPromise(); + let results = await queryPromise(); + results = results.map((r) => ({ ...r, ctxTargetUid: targetUid })); if (onResult) { const groupedResult = { label: relation.text, From 1067a9210878bc4e92d3a30a85c659de1ffc4fd5 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Thu, 18 Dec 2025 10:14:04 -0500 Subject: [PATCH 2/3] coderabbit correction: delete button only on last column, more type checks --- .../components/results-view/ResultsTable.tsx | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/roam/src/components/results-view/ResultsTable.tsx b/apps/roam/src/components/results-view/ResultsTable.tsx index 15d935541..e7b040d55 100644 --- a/apps/roam/src/components/results-view/ResultsTable.tsx +++ b/apps/roam/src/components/results-view/ResultsTable.tsx @@ -24,7 +24,6 @@ import DiscourseContextOverlay from "~/components/DiscourseContextOverlay"; import { CONTEXT_OVERLAY_SUGGESTION } from "~/utils/predefinedSelections"; import { getSetting } from "~/utils/extensionSettings"; import { strictQueryForReifiedBlocks } from "~/utils/createReifiedBlock"; -import formatDistanceStrictWithOptions from "date-fns/esm/fp/formatDistanceStrictWithOptions/index.js"; const EXTRA_ROW_TYPES = ["context", "discourse"] as const; type ExtraRowType = (typeof EXTRA_ROW_TYPES)[number] | null; @@ -372,15 +371,19 @@ const ResultRow = ({ ) : ( cell(key) )} - {useReifiedRel && r["ctxTargetUid"] !== undefined && ( - - )} + {useReifiedRel && + typeof r["ctxTargetUid"] === "string" && + typeof r["id"] === "string" && + typeof r["complement"] === "number" && + i === columns.length - 1 && ( + + )} {i < columns.length - 1 && (
Date: Thu, 18 Dec 2025 10:15:20 -0500 Subject: [PATCH 3/3] comment re cast --- apps/roam/src/components/results-view/ResultsTable.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/roam/src/components/results-view/ResultsTable.tsx b/apps/roam/src/components/results-view/ResultsTable.tsx index e7b040d55..4a980a644 100644 --- a/apps/roam/src/components/results-view/ResultsTable.tsx +++ b/apps/roam/src/components/results-view/ResultsTable.tsx @@ -274,6 +274,7 @@ const ResultRow = ({ destinationUid: r["complement"] === 1 ? r["ctxTargetUid"] : r["uid"], hasSchema: r["id"], } as Record; + // types got checked as a condition for displaying the button strictQueryForReifiedBlocks(data) .then((blockUid) => { if (blockUid === null) {