11import { AppBar , CssBaseline , Toolbar , Typography } from '@material-ui/core' ;
22import { MuiThemeProvider } from '@material-ui/core/styles' ;
3+ import { JSONSchema7 } from 'json-schema' ;
34import React , { ComponentType } from 'react' ;
45import { Observable as obs } from 'rxjs' ;
56import {
@@ -14,13 +15,13 @@ import { SqlStreamStore } from './components/Icons';
1415import { connect , createState } from './reactive' ;
1516import { actions , store , Viewer } from './stream-store' ;
1617import theme from './theme' ;
17- import { HalLink , HalLinks } from './types' ;
18+ import { AuthorizationProps , HalLink , HalLinks } from './types' ;
1819import { mediaTypes } from './utils' ;
1920
20- const getSelfAlias = links =>
21+ const getSelfAlias = ( links : HalLinks ) =>
2122 Object . keys ( links )
2223 . flatMap ( rel => links [ rel ] )
23- . filter ( ( { rel } ) => rel . indexOf ( 'streamStore:' ) === 0 )
24+ . filter ( ( { rel } ) => rel && rel . indexOf ( 'streamStore:' ) === 0 )
2425 . filter (
2526 ( { rel, href } ) =>
2627 ! ! links . self . filter ( link => link . href === href ) . length ,
@@ -36,20 +37,21 @@ const self$ = store.hal$.links$
3637interface SqlStreamStoreBrowserState {
3738 loading : boolean ;
3839 mediaType : string ;
39- links : HalLinks ;
40+ _links : HalLinks ;
4041 self : HalLink ;
42+ forms : { [ rel : string ] : JSONSchema7 } ;
4143}
4244const state$ = createState < SqlStreamStoreBrowserState > (
4345 obs . merge (
4446 self$ . map ( self => [ 'self' , ( ) => self ] ) ,
45- store . hal$ . links$ . map ( links => [ 'links ' , ( ) => links ] ) ,
47+ store . hal$ . links$ . map ( links => [ '_links ' , ( ) => links ] ) ,
4648 store . hal$ . forms$ . map ( forms => [ 'forms' , ( ) => forms ] ) ,
4749 store . hal$ . loading$ . map ( loading => [ 'loading' , ( ) => loading ] ) ,
4850 store . hal$ . mediaType$ . map ( mediaType => [ 'mediaType' , ( ) => mediaType ] ) ,
4951 ) ,
5052 obs . of ( {
53+ _links : { } ,
5154 forms : { } ,
52- links : { } ,
5355 loading : false ,
5456 mediaType : mediaTypes . hal ,
5557 self : {
@@ -62,7 +64,7 @@ const onNavigate = (link: HalLink, authorization: string | undefined) =>
6264 link . href . indexOf ( '#' ) === - 1 &&
6365 actions . get . request . next ( { link, headers : { authorization } } ) ;
6466
65- const initialNavigation = ( { authorization } ) =>
67+ const initialNavigation = ( { authorization } : AuthorizationProps ) =>
6668 onNavigate (
6769 { href : window . location . href , type : mediaTypes . any } ,
6870 authorization ,
@@ -82,29 +84,31 @@ const Hero = () => (
8284const SqlStreamStoreBrowser : ComponentType <
8385 SqlStreamStoreBrowserState
8486> = withAuthorization ( ) (
85- mount < SqlStreamStoreBrowserState & { authorization : string | undefined } > (
86- initialNavigation ,
87- ) ( ( { loading , ... props } ) => (
88- < MuiThemeProvider theme = { theme } >
89- < div >
90- < CssBaseline />
91- < Hero />
92- < Loading open = { loading } / >
93- < NavigationProvider onNavigate = { onNavigate } >
94- < Viewer { ... props } />
95- < Notifications / >
96- </ NavigationProvider >
97- </ div >
98- </ MuiThemeProvider >
99- ) ) ,
87+ mount < SqlStreamStoreBrowserState & AuthorizationProps > ( initialNavigation ) (
88+ ( { loading , ... props } ) => (
89+ < MuiThemeProvider theme = { theme } >
90+ < div >
91+ < CssBaseline / >
92+ < Hero />
93+ < Loading open = { loading } />
94+ < NavigationProvider onNavigate = { onNavigate } >
95+ < Viewer { ... props } / >
96+ < Notifications />
97+ </ NavigationProvider >
98+ </ div >
99+ </ MuiThemeProvider >
100+ ) ,
101+ ) ,
100102) ;
101103
102104const AuthorizedSqlStreamStoreBrowser : ComponentType <
103- SqlStreamStoreBrowserState & { authorization : string | undefined }
105+ SqlStreamStoreBrowserState & AuthorizationProps
104106> = ( { authorization, ...props } ) => (
105107 < AuthorizationProvider authorization = { authorization } >
106108 < SqlStreamStoreBrowser { ...props } />
107109 </ AuthorizationProvider >
108110) ;
109111
110- export default connect ( state$ ) ( AuthorizedSqlStreamStoreBrowser ) ;
112+ export default connect < SqlStreamStoreBrowserState , AuthorizationProps > ( state$ ) (
113+ AuthorizedSqlStreamStoreBrowser ,
114+ ) ;
0 commit comments