Skip to content

Commit 6a76a03

Browse files
authored
ENG-984 Add DiscourseContextOverlay support in ResultsTable (#505)
* feat: Add DiscourseContextOverlay support in ResultsTable - Integrated DiscourseContextOverlay to display context suggestions in ResultRow. - Updated uid handling for actions to ensure proper functionality. - Introduced CONTEXT_OVERLAY_SUGGESTION constant for better maintainability in predefined selections. * refactor: Clean up imports and enhance uid handling in ResultsTable - Removed unnecessary imports for improved code clarity. - Simplified uid generation for DiscourseContextOverlay to ensure consistent behavior. - Updated conditional logic for better readability and maintainability.
1 parent e386761 commit 6a76a03

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

apps/roam/src/components/results-view/ResultsTable.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import React, {
55
useState,
66
useCallback,
77
} from "react";
8-
import {
9-
Button,
10-
HTMLTable,
11-
Icon,
12-
IconName,
13-
} from "@blueprintjs/core";
8+
import { Button, HTMLTable, Icon, IconName } from "@blueprintjs/core";
149
import { IconNames } from "@blueprintjs/icons";
1510
import { Column, Result } from "~/utils/types";
1611
import type { FilterData, Sorts, Views } from "~/utils/parseResultSettings";
@@ -24,6 +19,8 @@ import openBlockInSidebar from "roamjs-components/writes/openBlockInSidebar";
2419
import setInputSettings from "roamjs-components/util/setInputSettings";
2520
import toCellValue from "~/utils/toCellValue";
2621
import { ContextContent } from "~/components/DiscourseContext";
22+
import DiscourseContextOverlay from "~/components/DiscourseContextOverlay";
23+
import { CONTEXT_OVERLAY_SUGGESTION } from "~/utils/predefinedSelections";
2724

2825
const EXTRA_ROW_TYPES = ["context", "discourse"] as const;
2926
type ExtraRowType = (typeof EXTRA_ROW_TYPES)[number] | null;
@@ -211,14 +208,28 @@ const ResultRow = ({
211208
const cell = (key: string) => {
212209
const value = toCellValue({
213210
value: r[`${key}-display`] || r[key] || "",
214-
uid: (r[`${key}-uid`] as string) || "",
211+
uid: r[`${key}-uid`] || "",
215212
});
216213
const action = r[`${key}-action`];
217214
if (typeof action === "string") {
218215
const buttonProps =
219216
value.toUpperCase().replace(/\s/g, "_") in IconNames
220217
? { icon: value as IconName, minimal: true }
221218
: { text: value };
219+
const actionUid = r[`${key}-uid`];
220+
221+
if (
222+
action === "discourse" &&
223+
value === CONTEXT_OVERLAY_SUGGESTION &&
224+
actionUid
225+
) {
226+
return (
227+
<DiscourseContextOverlay
228+
uid={actionUid}
229+
id={`discourse-overlay-${parentUid}-${actionUid}`}
230+
/>
231+
);
232+
}
222233
return (
223234
<Button
224235
{...buttonProps}
@@ -227,7 +238,7 @@ const ResultRow = ({
227238
new CustomEvent("roamjs:query-builder:action", {
228239
detail: {
229240
action,
230-
uid: r[`${key}-uid`],
241+
uid: actionUid,
231242
val: r["text"],
232243
onRefresh,
233244
queryUid: parentUid,

apps/roam/src/utils/predefinedSelections.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ const LEAF_SUGGESTIONS: SelectionSuggestion[] = CREATE_DATE_SUGGESTIONS.concat(
242242
.concat(EDIT_BY_SUGGESTIONS);
243243
// .concat(ATTR_SUGGESTIONS);
244244

245+
export const CONTEXT_OVERLAY_SUGGESTION = "overlay";
246+
245247
const predefinedSelections: PredefinedSelection[] = [
246248
{
247249
test: CREATE_DATE_TEST,
@@ -522,6 +524,7 @@ const predefinedSelections: PredefinedSelection[] = [
522524
{ text: "flows" },
523525
{ text: "graph" },
524526
{ text: "layout" }, // replace with { text: "search-around" }, not supported yet
527+
{ text: CONTEXT_OVERLAY_SUGGESTION },
525528
],
526529
},
527530
],

0 commit comments

Comments
 (0)