11import React , { useEffect } from 'react' ;
22import { useDispatch , useSelector } from 'react-redux' ;
3- import { Table , Header , Popup } from 'semantic-ui-react' ;
3+ import { Breadcrumb } from 'semantic-ui-react' ;
44import { match , Link } from 'react-router-dom' ;
55import { History } from 'history' ;
6- import moment from 'moment' ;
76
87import { ApplicationState } from '../store' ;
9- import { Data } from '../client' ;
108import { fetchRequest , startSubscription , endSubscription } from '../store/data/actions' ;
9+ import { DataTable } from '../components/data/Table' ;
10+ import { DataChart } from '../components/data/Chart' ;
1111
1212interface RouteInfo {
1313 key : string ;
@@ -19,61 +19,35 @@ interface MainProps {
1919}
2020
2121export const DataPage : React . FC < MainProps > = props => {
22+ const { loading, columns, data, chart } = useSelector ( ( state : ApplicationState ) => state . data ) ;
23+ const dispatch = useDispatch ( ) ;
2224 const {
23- match : { params }
25+ history,
26+ match : {
27+ params : { key }
28+ }
2429 } = props ;
25- const { loading, data } = useSelector ( ( state : ApplicationState ) => state . data ) ;
26- const dispatch = useDispatch ( ) ;
2730
2831 useEffect ( ( ) => {
29- dispatch ( fetchRequest ( params . key ) ) ;
30- dispatch ( startSubscription ( params . key ) ) ;
32+ dispatch ( fetchRequest ( key ) ) ;
33+ dispatch ( startSubscription ( key ) ) ;
3134 return ( ) => {
32- dispatch ( endSubscription ( params . key ) ) ;
35+ dispatch ( endSubscription ( key ) ) ;
3336 } ;
34- } , [ dispatch ] ) ;
35-
36- // TODO tjt: move data formatting to store
37- const payloadColumnsSet = new Set ( data . map ( ( datum : Data ) => Object . keys ( datum . payload || { } ) ) . flat ( ) ) ;
38- const payloadColumns = [ ...payloadColumnsSet ] . sort ( ) ;
37+ } , [ dispatch , key ] ) ;
3938
4039 return (
4140 < >
42- < Header as = "h1" >
43- dlphn.< Link to = "/streams" > streams</ Link > .{ params . key }
44- </ Header >
41+ < Breadcrumb size = "big" >
42+ < Breadcrumb . Section as = { Link } link to = "/streams" >
43+ Streams
44+ </ Breadcrumb . Section >
45+ < Breadcrumb . Divider icon = "right chevron" />
46+ < Breadcrumb . Section > { key } </ Breadcrumb . Section >
47+ </ Breadcrumb >
4548 { ! loading && data . length === 0 && < div > not found.</ div > }
46- { data . length > 0 && (
47- < Table celled fixed >
48- < Table . Header >
49- < Table . Row >
50- < Table . HeaderCell > created</ Table . HeaderCell >
51- { payloadColumns . map ( ( column : string ) => (
52- < Table . HeaderCell > { column } </ Table . HeaderCell >
53- ) ) }
54- </ Table . Row >
55- </ Table . Header >
56-
57- < Table . Body >
58- { data . map ( ( datum : Data ) => (
59- < Table . Row key = { datum . id } onClick = { ( ) => props . history . push ( `/streams/${ params . key } /data` ) } >
60- < Table . Cell >
61- < Popup
62- size = "mini"
63- content = { datum . created }
64- trigger = { < div > { moment ( datum . created ) . fromNow ( ) } </ div > }
65- inverted
66- />
67- </ Table . Cell >
68- { payloadColumns . map ( ( column : string ) => {
69- const payload = datum . payload || { } ;
70- return < Table . Cell > { payload [ column ] || '' } </ Table . Cell > ;
71- } ) }
72- </ Table . Row >
73- ) ) }
74- </ Table . Body >
75- </ Table >
76- ) }
49+ { chart . length > 0 && < DataChart columns = { columns } chart = { chart } > </ DataChart > }
50+ { data . length > 0 && < DataTable streamKey = { key } columns = { columns } data = { data } history = { history } > </ DataTable > }
7751 </ >
7852 ) ;
7953} ;
0 commit comments