1- import {
2- Button ,
3- Icon ,
4- Portal ,
5- Switch ,
6- Tabs ,
7- Tab ,
8- Tooltip ,
9- Spinner ,
10- } from "@blueprintjs/core" ;
11- import React , {
12- useCallback ,
13- useEffect ,
14- useMemo ,
15- useState ,
16- useRef ,
17- } from "react" ;
18- import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid" ;
19- import getShallowTreeByParentUid from "roamjs-components/queries/getShallowTreeByParentUid" ;
1+ import { Switch , Tabs , Tab , Spinner } from "@blueprintjs/core" ;
2+ import React , { useCallback , useEffect , useMemo , useState } from "react" ;
203import { Result } from "roamjs-components/types/query-builder" ;
21- import nanoId from "nanoid" ;
224import getDiscourseContextResults from "~/utils/getDiscourseContextResults" ;
235import ResultsView from "./results-view/ResultsView" ;
246import posthog from "posthog-js" ;
@@ -34,188 +16,12 @@ type Props = {
3416 overlayRefresh ?: ( ) => void ;
3517} ;
3618
37- const ExtraColumnRow = ( r : Result ) => {
38- const [ contextOpen , setContextOpen ] = useState ( false ) ;
39- const [ contextRowReady , setContextRowReady ] = useState ( false ) ;
40- const contextId = useMemo ( ( ) => `td-${ nanoId ( ) } ` , [ ] ) ;
41- const anchorId = useMemo ( ( ) => `td-${ nanoId ( ) } ` , [ ] ) ;
42- const [ anchorOpen , setAnchorOpen ] = useState ( false ) ;
43- const [ anchorRowReady , setAnchorRowReady ] = useState ( false ) ;
44- const containerRef = useRef < HTMLSpanElement > ( null ) ;
45- const contextPageTitle = useMemo (
46- ( ) =>
47- r [ "context-uid" ] && getPageTitleByPageUid ( r [ "context-uid" ] . toString ( ) ) ,
48- [ r [ "context-uid" ] ] ,
49- ) ;
50- const contextBreadCrumbs = useMemo (
51- ( ) =>
52- r [ "context-uid" ]
53- ? window . roamAlphaAPI
54- . q (
55- `[:find (pull ?p [:node/title :block/string :block/uid]) :where
56- [?b :block/uid "${ r [ "context-uid" ] } "]
57- [?b :block/parents ?p]
58- ]` ,
59- )
60- . map (
61- ( a ) => a [ 0 ] as { string ?: string ; title ?: string ; uid : string } ,
62- )
63- . map ( ( a ) => ( { uid : a . uid , text : a . string || a . title || "" } ) )
64- : [ ] ,
65- [ r [ "context-uid" ] ] ,
66- ) ;
67- const contextChildren = useMemo (
68- ( ) =>
69- r [ "context-uid" ] && contextPageTitle
70- ? getShallowTreeByParentUid ( r [ "context-uid" ] . toString ( ) ) . map (
71- ( { uid } ) => uid ,
72- )
73- : [ r [ "context-uid" ] . toString ( ) ] ,
74- [ r [ "context-uid" ] , contextPageTitle , r . uid ] ,
75- ) ;
76- useEffect ( ( ) => {
77- if ( contextOpen && containerRef . current ) {
78- const row = containerRef . current . closest ( "tr" ) ;
79- const contextElement = document . createElement ( "tr" ) ;
80- const contextTd = document . createElement ( "td" ) ;
81- contextTd . colSpan = row ?. childElementCount || 0 ;
82- contextElement . id = contextId ;
83- row ?. parentElement ?. insertBefore ( contextElement , row . nextElementSibling ) ;
84- contextElement . append ( contextTd ) ;
85- setContextRowReady ( true ) ;
86- } else {
87- setContextRowReady ( false ) ;
88- document . getElementById ( contextId ) ?. remove ( ) ;
89- }
90- } , [ contextOpen , setContextRowReady , contextId ] ) ;
91- useEffect ( ( ) => {
92- if ( contextRowReady ) {
93- setTimeout ( ( ) => {
94- contextChildren . forEach ( ( uid ) => {
95- const el = document . querySelector < HTMLElement > (
96- `tr#${ contextId } div[data-uid="${ uid } "]` ,
97- ) ;
98- if ( el )
99- window . roamAlphaAPI . ui . components . renderBlock ( {
100- uid,
101- el,
102- } ) ;
103- } ) ;
104- } , 1 ) ;
105- }
106- } , [ contextRowReady ] ) ;
107- useEffect ( ( ) => {
108- if ( anchorOpen ) {
109- const row = containerRef . current ?. closest ( "tr" ) ;
110- const anchorElement = document . createElement ( "tr" ) ;
111- const anchorTd = document . createElement ( "td" ) ;
112- anchorTd . colSpan = row ?. childElementCount || 0 ;
113- anchorElement . id = anchorId ;
114- row ?. parentElement ?. insertBefore ( anchorElement , row . nextElementSibling ) ;
115- anchorElement . append ( anchorTd ) ;
116- setAnchorRowReady ( true ) ;
117- } else {
118- setAnchorRowReady ( false ) ;
119- document . getElementById ( anchorId ) ?. remove ( ) ;
120- }
121- } , [ anchorOpen , setAnchorRowReady , anchorId ] ) ;
122- return (
123- < span ref = { containerRef } >
124- { r [ "context-uid" ] && (
125- < Tooltip content = { "Context" } >
126- < Button
127- onClick = { ( ) => setContextOpen ( ! contextOpen ) }
128- small
129- active = { contextOpen }
130- style = { {
131- opacity : 0.5 ,
132- fontSize : "0.8em" ,
133- ...( contextOpen
134- ? {
135- opacity : 1 ,
136- color : "#8A9BA8" ,
137- backgroundColor : "#F5F8FA" ,
138- }
139- : { } ) ,
140- } }
141- minimal
142- icon = "info-sign"
143- />
144- </ Tooltip >
145- ) }
146- < style >
147- { `#${ contextId } td,
148- #${ anchorId } td {
149- position: relative;
150- background-color: #F5F8FA;
151- padding: 16px;
152- max-height: 240px;
153- overflow-y: scroll;
154- }
155- #${ contextId } .bp3-portal,
156- #${ anchorId } .bp3-portal {
157- position: relative;
158- }` }
159- </ style >
160- { contextRowReady && (
161- < Portal
162- container = {
163- document . getElementById ( contextId )
164- ?. firstElementChild as HTMLDataElement
165- }
166- className = { "relative" }
167- >
168- { contextPageTitle ? (
169- < h3 style = { { margin : 0 } } > { contextPageTitle } </ h3 >
170- ) : (
171- < div className = "rm-zoom" >
172- { contextBreadCrumbs . map ( ( bc ) => (
173- < div key = { bc . uid } className = "rm-zoom-item" >
174- < span className = "rm-zoom-item-content" > { bc . text } </ span >
175- < Icon icon = { "chevron-right" } />
176- </ div >
177- ) ) }
178- </ div >
179- ) }
180- { contextChildren . map ( ( uid ) => (
181- < div data-uid = { uid } key = { uid } > </ div >
182- ) ) }
183- </ Portal >
184- ) }
185- { r . anchor && (
186- < Tooltip content = { "See Related Relations" } >
187- < Button
188- onClick = { ( ) => setAnchorOpen ( ! anchorOpen ) }
189- active = { anchorOpen }
190- small
191- style = { {
192- opacity : 0.5 ,
193- fontSize : "0.8em" ,
194- ...( anchorOpen
195- ? {
196- opacity : 1 ,
197- color : "#8A9BA8" ,
198- backgroundColor : "#F5F8FA" ,
199- }
200- : { } ) ,
201- } }
202- minimal
203- icon = { "resolve" }
204- />
205- </ Tooltip >
206- ) }
207- { anchorRowReady && (
208- < Portal
209- container = {
210- document . getElementById ( anchorId )
211- ?. firstElementChild as HTMLDataElement
212- }
213- >
214- < ContextContent uid = { r [ "anchor-uid" ] } results = { [ ] } />
215- </ Portal >
216- ) }
217- </ span >
218- ) ;
19+ const removeTargetFromResult = (
20+ result : Partial < Result & { target : string } > ,
21+ ) : Result => {
22+ const tableResult = { ...result } ;
23+ delete tableResult . target ;
24+ return tableResult as Result ;
21925} ;
22026
22127const ContextTab = ( {
@@ -270,7 +76,7 @@ const ContextTab = ({
27076 // TODO - always save settings, but maybe separate from root `parentUid`?
27177 preventSavingSettings
27278 parentUid = { parentUid }
273- results = { Object . values ( results ) . map ( ( { target , ... a } ) => a as Result ) }
79+ results = { Object . values ( results ) . map ( removeTargetFromResult ) }
27480 columns = { columns }
27581 onRefresh = { onRefresh }
27682 header = {
0 commit comments