@@ -7,6 +7,7 @@ import React, {
77} from "react" ;
88import { Button , HTMLTable , Icon , IconName } from "@blueprintjs/core" ;
99import { IconNames } from "@blueprintjs/icons" ;
10+ import { render as renderToast } from "roamjs-components/components/Toast" ;
1011import { Column , Result } from "~/utils/types" ;
1112import type { FilterData , Sorts , Views } from "~/utils/parseResultSettings" ;
1213import Filter , { Filters } from "roamjs-components/components/Filter" ;
@@ -21,6 +22,9 @@ import toCellValue from "~/utils/toCellValue";
2122import { ContextContent } from "~/components/DiscourseContext" ;
2223import DiscourseContextOverlay from "~/components/DiscourseContextOverlay" ;
2324import { CONTEXT_OVERLAY_SUGGESTION } from "~/utils/predefinedSelections" ;
25+ import { getSetting } from "~/utils/extensionSettings" ;
26+ import { strictQueryForReifiedBlocks } from "~/utils/createReifiedBlock" ;
27+ import formatDistanceStrictWithOptions from "date-fns/esm/fp/formatDistanceStrictWithOptions/index.js" ;
2428
2529const EXTRA_ROW_TYPES = [ "context" , "discourse" ] as const ;
2630type ExtraRowType = ( typeof EXTRA_ROW_TYPES ) [ number ] | null ;
@@ -202,6 +206,7 @@ const ResultRow = ({
202206 onDragEnd,
203207 onRefresh,
204208} : ResultRowProps ) => {
209+ const useReifiedRel = getSetting < boolean > ( "use-reified-relations" ) ;
205210 const cell = ( key : string ) => {
206211 const value = toCellValue ( {
207212 value : r [ `${ key } -display` ] || r [ key ] || "" ,
@@ -264,6 +269,52 @@ const ResultRow = ({
264269 [ views ] ,
265270 ) ;
266271 const trRef = useRef < HTMLTableRowElement > ( null ) ;
272+ const onDelete = ( ) => {
273+ const data = {
274+ sourceUid : r [ "complement" ] === 1 ? r [ "uid" ] : r [ "ctxTargetUid" ] ,
275+ destinationUid : r [ "complement" ] === 1 ? r [ "ctxTargetUid" ] : r [ "uid" ] ,
276+ hasSchema : r [ "id" ] ,
277+ } as Record < string , string > ;
278+ strictQueryForReifiedBlocks ( data )
279+ . then ( ( blockUid ) => {
280+ if ( blockUid === null ) {
281+ renderToast ( {
282+ id : "delete-relation-error" ,
283+ content : "Could not find relation" ,
284+ intent : "warning" ,
285+ } ) ;
286+ return ;
287+ }
288+ deleteBlock ( blockUid )
289+ . then ( ( ) => {
290+ renderToast ( {
291+ id : "delete-relation-success" ,
292+ content : "Relation deleted" ,
293+ intent : "success" ,
294+ } ) ;
295+ onRefresh ( ) ;
296+ } )
297+ . catch ( ( e ) => {
298+ // this one should be an internalError
299+ console . error ( e ) ;
300+ renderToast ( {
301+ id : "delete-relation-error" ,
302+ content : "Could not delete relation" ,
303+ intent : "danger" ,
304+ } ) ;
305+ } ) ;
306+ } )
307+ . catch ( ( e ) => {
308+ // this one should be an internalError
309+ console . error ( e ) ;
310+ renderToast ( {
311+ id : "delete-relation-error" ,
312+ content : "Error searching for relation" ,
313+ intent : "danger" ,
314+ } ) ;
315+ } ) ;
316+ } ;
317+
267318 return (
268319 < >
269320 < tr ref = { trRef } data-uid = { r . uid } >
@@ -321,6 +372,15 @@ const ResultRow = ({
321372 ) : (
322373 cell ( key )
323374 ) }
375+ { useReifiedRel && r [ "ctxTargetUid" ] !== undefined && (
376+ < Button
377+ minimal
378+ icon = "delete"
379+ className = "float-right"
380+ title = "Delete relation"
381+ onClick = { onDelete }
382+ > </ Button >
383+ ) }
324384 { i < columns . length - 1 && (
325385 < div
326386 style = { {
0 commit comments