11import React , { PureComponent } from 'react' ;
22import { Observable as obs } from 'rxjs' ;
33import {
4- List ,
5- ListItem ,
64 Popover ,
75 Typography ,
86 ExpansionPanel ,
97 ExpansionPanelSummary ,
108 ExpansionPanelDetails ,
11- withStyles ,
129} from '@material-ui/core' ;
1310import Inspector , {
1411 ObjectLabel ,
@@ -24,7 +21,7 @@ import {
2421 TableHead ,
2522 TableCell ,
2623} from '../../components/StripeyTable' ;
27- import { Hyperlink } from '../../components' ;
24+ import { Hyperlink , StreamBrowser } from '../../components' ;
2825import { createState , connect } from '../../reactive' ;
2926import rels from '../rels' ;
3027import { http } from '../../utils' ;
@@ -38,14 +35,14 @@ const tryParseJson = payload => {
3835 }
3936} ;
4037
41- const message$ = store . body$ . map ( ( { payload, metadata, ...body } ) => ( ) => ( {
38+ const message$ = store . body$ . map ( ( { payload, metadata, ...body } ) => ( {
4239 ...body ,
4340 payload : tryParseJson ( payload ) ,
4441 metadata : tryParseJson ( metadata ) ,
4542} ) ) ;
4643
4744const state$ = createState (
48- message$ . map ( message => [ 'message' , message ] ) ,
45+ message$ . map ( message => [ 'message' , ( ) => message ] ) ,
4946 obs . of ( { message : { } } ) ,
5047) ;
5148
@@ -102,45 +99,10 @@ const getStreamIds = ({ _embedded = {} }) =>
10299 . map ( ( { _links = { } } ) => _links [ rels . feed ] )
103100 . filter ( link => link ) ;
104101
105- const MatchingStreamIds = withStyles ( theme => ( {
106- paper : {
107- padding : theme . spacing . unit * 2.5 ,
108- } ,
109- } ) ) ( ( { matches, onNavigate, ...props } ) => (
110- < Popover
111- transformOrigin = { {
112- vertical : 'bottom' ,
113- horizontal : 'center' ,
114- } }
115- anchorOrigin = { {
116- vertical : 'top' ,
117- horizontal : 'center' ,
118- } }
119- { ...props }
120- >
121- < Typography variant = { 'subheading' } > Matching Stream Ids</ Typography >
122- { matches . length ? (
123- < List >
124- { matches . map ( ( { title, href } ) => (
125- < ListItem button key = { href } >
126- < Hyperlink href = { href } onNavigate = { onNavigate } >
127- { title }
128- </ Hyperlink >
129- </ ListItem >
130- ) ) }
131- </ List >
132- ) : (
133- < Typography variant = { 'body1' } >
134- No matching streams found.
135- </ Typography >
136- ) }
137- </ Popover >
138- ) ) ;
139-
140102class StreamMessageJson extends PureComponent {
141103 state = {
142104 anchorElement : undefined ,
143- matches : [ ] ,
105+ streams : [ ] ,
144106 } ;
145107
146108 _handlePotentialStreamIdClick = async (
@@ -153,23 +115,19 @@ class StreamMessageJson extends PureComponent {
153115 anchorElement,
154116 } ) ;
155117
156- const template = uriTemplate . parse (
157- decodeURI ( links [ rels . browse ] . href ) ,
158- ) ;
159-
160- const url = template . expand ( { p, t : 'e' } ) ;
118+ const template = uriTemplate . parse ( decodeURI ( links [ rels . browse ] . href ) ) ;
161119
162120 const responses = await Promise . all (
163121 [ ...new Set ( [ p , String ( p ) . replace ( '-' , '' ) ] ) ] . map ( p =>
164122 http . get ( {
165- url,
123+ url : template . expand ( { p , t : 'e' } ) ,
166124 headers : { authorization } ,
167125 } ) ,
168126 ) ,
169127 ) ;
170128
171129 this . setState ( {
172- matches : Object . values (
130+ streams : Object . values (
173131 responses . flatMap ( ( { body } ) => getStreamIds ( body ) ) . reduce (
174132 ( akk , { href, title } ) => ( {
175133 ...akk ,
@@ -217,7 +175,7 @@ class StreamMessageJson extends PureComponent {
217175
218176 render ( ) {
219177 const { json, title, onNavigate } = this . props ;
220- const { anchorElement, matches } = this . state ;
178+ const { anchorElement, streams } = this . state ;
221179 return (
222180 < ExpansionPanel expanded >
223181 < ExpansionPanelSummary expandIcon = { < Code /> } >
@@ -229,13 +187,24 @@ class StreamMessageJson extends PureComponent {
229187 expandLevel = { 32 }
230188 nodeRenderer = { this . _renderNode }
231189 />
232- < MatchingStreamIds
190+ < Popover
233191 open = { ! ! anchorElement }
234192 anchorEl = { anchorElement }
235193 onClose = { this . _handlePotentialStreamIdClose }
236- matches = { matches }
237- onNavigate = { onNavigate }
238- />
194+ transformOrigin = { {
195+ vertical : 'bottom' ,
196+ horizontal : 'center' ,
197+ } }
198+ anchorOrigin = { {
199+ vertical : 'top' ,
200+ horizontal : 'center' ,
201+ } }
202+ >
203+ < StreamBrowser
204+ streams = { streams }
205+ onNavigate = { onNavigate }
206+ />
207+ </ Popover >
239208 </ ExpansionPanelDetails >
240209 </ ExpansionPanel >
241210 ) ;
0 commit comments