Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 5a6ffd5

Browse files
migrated all the viewers
views that view a single resource are broken atm
1 parent 9061274 commit 5a6ffd5

27 files changed

+755
-493
lines changed

src/components/HyperMediaControls/Dialog.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import {
88
withStyles,
99
WithStyles,
1010
} from '@material-ui/core';
11-
import React, {
12-
FormEventHandler,
13-
PureComponent,
14-
StatelessComponent,
15-
} from 'react';
11+
import React, { PureComponent, StatelessComponent } from 'react';
1612

1713
import { SlideProps } from '@material-ui/core/Slide';
1814
import { HalLink } from '../../types';

src/components/HyperMediaControls/HelpButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
WithStyles,
66
withStyles,
77
} from '@material-ui/core';
8-
import React, { PureComponent, ReactNode } from 'react';
8+
import React, { ComponentType, PureComponent, ReactNode } from 'react';
99
import Remarkable from 'react-remarkable';
1010
import uriTemplate from 'uri-template';
1111
import { HalLink } from '../../types';
@@ -33,7 +33,7 @@ interface DocumentationProps {
3333
readonly onClose: () => void;
3434
}
3535

36-
const Documentation = withStyles(theme => ({
36+
const Documentation: ComponentType<DocumentationProps> = withStyles(theme => ({
3737
drawerPaper: {
3838
padding: theme.spacing.unit * 2,
3939
width: '45%',

src/components/HyperMediaControls/index.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
import { Card, CardActions } from '@material-ui/core';
2-
import React, { StatelessComponent } from 'react';
2+
import { JSONSchema7 } from 'json-schema';
3+
import React, { ComponentType, StatelessComponent } from 'react';
4+
import { Observable } from 'rxjs';
35
import { connect, createState } from '../../reactive';
46
import { navigation, rels, store } from '../../stream-store';
5-
import { HalLinks } from '../../types';
7+
import { HalLinks, HalResource } from '../../types';
68
import FormButton from './FormButton';
79
import LinkButton from './LinkButton';
810

911
const isNotSelf = (rel: string, links: HalLinks): boolean =>
1012
links[rels.self] && links[rel][0].href !== links[rels.self][0].href;
1113

12-
const state$ = createState(store.url$.map(href => ['href', () => href]));
14+
interface HyperMediaControlsState {
15+
href: string;
16+
}
17+
18+
const state$ = createState<HyperMediaControlsState>(
19+
store.url$.map(href => ['href', () => href]),
20+
Observable.of<HyperMediaControlsState>({ href: '' }),
21+
);
1322

1423
interface HyperMediaControlsProps {
1524
actions: any;
16-
href: string;
1725
links: HalLinks;
18-
forms: { [rel: string]: any };
26+
forms: { [rel: string]: HalResource & JSONSchema7 };
1927
}
2028

21-
const HyperMediaControls: StatelessComponent<HyperMediaControlsProps> = ({
22-
forms,
23-
href,
24-
actions,
25-
links,
26-
}) => (
29+
const HyperMediaControls: StatelessComponent<
30+
HyperMediaControlsProps & HyperMediaControlsState
31+
> = ({ actions, forms, href, links }) => (
2732
<Card>
2833
<CardActions>
2934
<div>
@@ -54,4 +59,6 @@ const HyperMediaControls: StatelessComponent<HyperMediaControlsProps> = ({
5459
</Card>
5560
);
5661

57-
export default connect(state$)(HyperMediaControls);
62+
export default connect(state$)(HyperMediaControls) as ComponentType<
63+
HyperMediaControlsProps
64+
>;

src/components/Notifications.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,4 @@ const Notifications: StatelessComponent<NotificationsState> = ({
214214
</div>
215215
);
216216

217-
export default connect(state$)(Notifications);
217+
export default connect<{}, NotificationsState>(state$)(Notifications);

src/components/RelIcon.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SvgIconProps } from '@material-ui/core/SvgIcon';
2-
import { createElement, ReactElement } from 'react';
2+
import { createElement, ReactElement, StatelessComponent } from 'react';
33
import { rels } from '../stream-store';
44
import {
55
ChevronLeft,
@@ -33,11 +33,13 @@ const fontIconByRel = {
3333
[rels.curies]: Help,
3434
};
3535

36-
interface RelIconProps extends SvgIconProps {
36+
interface RelIconProps {
3737
rel: string;
3838
}
3939

40-
const RelIcon = ({ rel, ...props }: RelIconProps): ReactElement<SvgIconProps> =>
41-
createElement(fontIconByRel[rel] || SqlStreamStore, props);
40+
const RelIcon: StatelessComponent<RelIconProps & SvgIconProps> = ({
41+
rel,
42+
...props
43+
}) => createElement(fontIconByRel[rel] || SqlStreamStore, props);
4244

4345
export default RelIcon;

src/components/StreamBrowser.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ const StreamBrowser: ComponentType<StreamBrowserProps> = withStyles(styles)(
5151
),
5252
);
5353

54-
export default StreamBrowser;
54+
export default StreamBrowser as ComponentType<StreamBrowserProps>;

src/components/StripeyTable/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ import {
88
WithStyles,
99
withStyles,
1010
} from '@material-ui/core';
11+
import { TableCellProps } from '@material-ui/core/TableCell';
1112
import { TableRowProps } from '@material-ui/core/TableRow';
12-
import React from 'react';
13+
import React, { ComponentType } from 'react';
1314

1415
const TableCell = withStyles(theme => ({
1516
head: {
1617
backgroundColor: theme.palette.primary.dark,
1718
color: theme.palette.common.white,
1819
},
19-
}))(MaterialTableCell);
20+
}))(MaterialTableCell) as ComponentType<TableCellProps>;
2021

2122
const tableRowStyles = theme => ({
2223
row: {
@@ -33,6 +34,6 @@ const TableRow = withStyles(tableRowStyles)(
3334
}: TableRowProps & WithStyles<typeof tableRowStyles>) => (
3435
<MaterialTableRow {...props} className={classes.row} />
3536
),
36-
);
37+
) as ComponentType<TableRowProps>;
3738

3839
export { Table, TableBody, TableHead, TableCell, TableRow, TableFooter };

src/index.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import SqlStreamStoreBrowser from './SqlStreamStoreBrowser';
44

5-
const anyWindow = window as any;
6-
anyWindow.SqlStreamStoreBrowser = SqlStreamStoreBrowser;
7-
anyWindow.ReactDOM = ReactDOM;
8-
anyWindow.React = React;
5+
declare global {
6+
interface Window {
7+
React: typeof React;
8+
ReactDOM: typeof ReactDOM;
9+
SqlStreamStoreBrowser: typeof SqlStreamStoreBrowser;
10+
}
11+
}
12+
13+
window.SqlStreamStoreBrowser = SqlStreamStoreBrowser;
14+
window.ReactDOM = ReactDOM;
15+
window.React = React;
916

1017
export default SqlStreamStoreBrowser;

src/reactive/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { Observable, ReplaySubject, Subscription } from 'rxjs';
44

55
export const createAction = <T>() => new ReplaySubject<T>(1);
66

7-
export const createState = <TState>(
7+
export const createState = <TState extends object>(
88
reducer$,
9-
initialState$ = Observable.of({}),
9+
initialState$: Observable<TState>,
1010
): Observable<TState> =>
1111
initialState$
1212
.merge(reducer$)
@@ -20,7 +20,11 @@ export const createState = <TState>(
2020
} as TState),
2121
)
2222
.publishReplay(1)
23-
.refCount() as Observable<TState>;
23+
.refCount();
24+
25+
const createLogger = <TState>() => (state: TState) =>
26+
// tslint:disable-next-line:no-console
27+
console.debug(state, typeof state);
2428

2529
export const connect = <TProps extends object, TState extends object>(
2630
state$: Observable<TState>,
@@ -31,8 +35,9 @@ export const connect = <TProps extends object, TState extends object>(
3135
subscription: Subscription;
3236

3337
componentWillMount() {
34-
this.subscription = state$.subscribe(s => {
35-
this.setState(s || {});
38+
const log = createLogger<TState>();
39+
this.subscription = state$.do(log).subscribe(s => {
40+
this.setState(s);
3641
});
3742
}
3843

src/stream-store/Viewer/HalViewer/Home.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)