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..4a980a644 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,8 @@ 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"; const EXTRA_ROW_TYPES = ["context", "discourse"] as const; type ExtraRowType = (typeof EXTRA_ROW_TYPES)[number] | null; @@ -202,6 +205,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 +268,53 @@ 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; + // types got checked as a condition for displaying the button + 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,19 @@ const ResultRow = ({ ) : ( cell(key) )} + {useReifiedRel && + typeof r["ctxTargetUid"] === "string" && + typeof r["id"] === "string" && + typeof r["complement"] === "number" && + i === columns.length - 1 && ( + + )} {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,