Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions apps/roam/src/components/DiscourseContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down
64 changes: 64 additions & 0 deletions apps/roam/src/components/results-view/ResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -202,6 +205,7 @@ const ResultRow = ({
onDragEnd,
onRefresh,
}: ResultRowProps) => {
const useReifiedRel = getSetting<boolean>("use-reified-relations");
const cell = (key: string) => {
const value = toCellValue({
value: r[`${key}-display`] || r[key] || "",
Expand Down Expand Up @@ -264,6 +268,53 @@ const ResultRow = ({
[views],
);
const trRef = useRef<HTMLTableRowElement>(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<string, string>;
// 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 (
<>
<tr ref={trRef} data-uid={r.uid}>
Expand Down Expand Up @@ -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 && (
<Button
minimal
icon="delete"
className="float-right"
title="Delete relation"
onClick={onDelete}
></Button>
)}
{i < columns.length - 1 && (
<div
style={{
Expand Down
2 changes: 1 addition & 1 deletion apps/roam/src/utils/createReifiedBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const DISCOURSE_GRAPH_PROP_NAME = "discourse-graph";

const SANE_ROLE_NAME_RE = new RegExp(/^[\w\-]*$/);

const strictQueryForReifiedBlocks = async (
export const strictQueryForReifiedBlocks = async (
parameterUids: Record<string, string>,
): Promise<string | null> => {
const paramsAsSeq = Object.entries(parameterUids);
Expand Down
3 changes: 2 additions & 1 deletion apps/roam/src/utils/getDiscourseContextResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down