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

Commit 3f562b8

Browse files
having onNavigate everywhere was annoying
1 parent 2fb69af commit 3f562b8

File tree

13 files changed

+64
-48
lines changed

13 files changed

+64
-48
lines changed

src/SqlStreamStoreBrowser.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
mount,
77
withAuthorization,
88
AuthorizationProvider,
9+
NavigationProvider,
910
Notifications,
1011
Loading,
1112
} from './components';
@@ -70,8 +71,10 @@ const SqlStreamStoreBrowser = withAuthorization()(
7071
<CssBaseline />
7172
<Hero />
7273
<Loading open={loading} />
73-
<Viewer {...props} onNavigate={onNavigate} />
74-
<Notifications />
74+
<NavigationProvider onNavigate={onNavigate}>
75+
<Viewer {...props} />
76+
<Notifications />
77+
</NavigationProvider>
7578
</div>
7679
</MuiThemeProvider>
7780
)),

src/components/HyperMediaControls/LinkButton.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React, { PureComponent } from 'react';
22
import { TextField } from '@material-ui/core';
33
import uriTemplate from 'uri-template';
4-
import { withAuthorization } from '../AuthorizationProvider';
4+
import { withNavigation } from '../NavigationProvider';
55
import Dialog from './Dialog';
66
import RelButton from './RelButton';
77
import { preventDefault } from '../../utils';
88

9-
const TemplatedLinkButton = withAuthorization()(
9+
const TemplatedLinkButton = withNavigation()(
1010
class TemplatedLinkButton extends PureComponent {
1111
state = {};
1212

@@ -50,7 +50,7 @@ const TemplatedLinkButton = withAuthorization()(
5050
},
5151
);
5252

53-
const NonTemplatedLinkButton = withAuthorization()(
53+
const NonTemplatedLinkButton = withNavigation()(
5454
({ link, rel, authorization, onNavigate }) => (
5555
<RelButton
5656
rel={rel}

src/components/HyperMediaControls/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const isNotSelf = (rel, links) =>
1111

1212
const state$ = createState(store.url$.map(href => ['href', () => href]));
1313

14-
const HyperMediaControls = ({ forms, href, actions, links, onNavigate }) => (
14+
const HyperMediaControls = ({ forms, href, actions, links }) => (
1515
<Card>
1616
<CardActions>
1717
<div>
@@ -23,7 +23,6 @@ const HyperMediaControls = ({ forms, href, actions, links, onNavigate }) => (
2323
key={rel}
2424
rel={rel}
2525
link={links[rel][0]}
26-
onNavigate={onNavigate}
2726
color={'active'}
2827
curies={links[rels.curies]}
2928
/>

src/components/Hyperlink.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { withStyles } from '@material-ui/core';
33
import { preventDefault } from '../utils';
4-
import { withAuthorization } from './AuthorizationProvider';
4+
import { withNavigation } from './NavigationProvider';
55
import theme from '../theme';
66

77
const color = theme.palette.action.active;
@@ -20,7 +20,7 @@ const styles = {
2020
},
2121
},
2222
};
23-
const Hyperlink = withAuthorization()(
23+
const Hyperlink = withNavigation()(
2424
withStyles(styles)(
2525
({ classes, link, children, authorization, onNavigate }) => (
2626
<a

src/components/NavigationLinks.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React, { PureComponent } from 'react';
22
import { IconButton } from '@material-ui/core';
33
import RelIcon from './RelIcon';
4-
import { withAuthorization } from './AuthorizationProvider';
4+
import { withNavigation } from './NavigationProvider';
55
import { navigation } from '../stream-store';
6-
import { preventDefault } from '../utils';
76

8-
const FeedNavigationLink = withAuthorization()(
9-
class FeedNavigationLink extends PureComponent {
7+
const FeedNavigationLink = withNavigation()(
8+
class What extends PureComponent {
109
_handleOnClick = e => {
1110
const { onNavigate, authorization, link } = this.props;
1211

@@ -34,13 +33,12 @@ const FeedNavigationLink = withAuthorization()(
3433
},
3534
);
3635

37-
const NavigationLinks = ({ onNavigate, links }) => (
36+
const NavigationLinks = ({ links }) => (
3837
<nav>
3938
{[...navigation].map(rel => (
4039
<FeedNavigationLink
4140
key={rel}
4241
link={(links[rel] || [])[0]}
43-
onNavigate={onNavigate}
4442
rel={rel}
4543
/>
4644
))}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import getDisplayName from './getDisplayName';
3+
const { Consumer, Provider } = React.createContext();
4+
5+
const NavigationProvider = ({ onNavigate, children }) => (
6+
<Provider value={onNavigate}>{children}</Provider>
7+
);
8+
9+
export default NavigationProvider;
10+
11+
const withNavigation = () => WrappedComponent => {
12+
const Component = props => (
13+
<Consumer>
14+
{onNavigate => (
15+
<WrappedComponent {...props} onNavigate={onNavigate} />
16+
)}
17+
</Consumer>
18+
);
19+
Component.displayName = getDisplayName(
20+
'WithNavigation',
21+
WrappedComponent,
22+
);
23+
return Component;
24+
};
25+
26+
export { withNavigation };

src/components/StreamBrowser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const StreamBrowser = withStyles(theme => ({
1313
browser: {
1414
padding: theme.spacing.unit * 2.5,
1515
},
16-
}))(({ streams, onNavigate, classes, loading }) => (
16+
}))(({ streams, classes, loading }) => (
1717
<div className={classes.browser}>
1818
<Typography variant={'title'}>Stream Browser</Typography>
1919
{loading ? (
@@ -23,7 +23,7 @@ const StreamBrowser = withStyles(theme => ({
2323
{streams.map(link => (
2424
<ListItem key={link.href}>
2525
<ListItemText>
26-
<Hyperlink link={link} onNavigate={onNavigate}>
26+
<Hyperlink link={link}>
2727
{link.title}
2828
</Hyperlink>
2929
</ListItemText>

src/components/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export { default as Hyperlink } from './Hyperlink';
66
export { default as HyperMediaControls } from './HyperMediaControls';
77
export { default as Loading } from './Loading';
88
export { default as NavigationLinks } from './NavigationLinks';
9+
export {
10+
default as NavigationProvider,
11+
withNavigation,
12+
} from './NavigationProvider';
913
export { default as Notifications } from './Notifications';
1014
export { default as StreamBrowser } from './StreamBrowser';
1115
export { default as mount } from './mount';

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,18 @@ const Message = ({
3737
streamVersion,
3838
type,
3939
links,
40-
onNavigate,
4140
}) => (
4241
<TableRow>
4342
<TableCell style={nowrap}>{messageId}</TableCell>
4443
<TableCell style={nowrap}>{createdUtc}</TableCell>
4544
<TableCell style={nowrap}>{type}</TableCell>
4645
<TableCell style={nowrap}>
47-
<Hyperlink link={links[rels.feed][0]} onNavigate={onNavigate}>
46+
<Hyperlink link={links[rels.feed][0]}>
4847
{streamId}
4948
</Hyperlink>
5049
</TableCell>
5150
<TableCell>
52-
<Hyperlink link={links.self[0]} onNavigate={onNavigate}>
51+
<Hyperlink link={links.self[0]}>
5352
{streamId}
5453
{'@'}
5554
{streamVersion}
@@ -59,7 +58,7 @@ const Message = ({
5958
</TableRow>
6059
);
6160

62-
const Messages = ({ messages, onNavigate }) => (
61+
const Messages = ({ messages }) => (
6362
<Table>
6463
<TableHead>
6564
<TableRow>
@@ -75,7 +74,6 @@ const Messages = ({ messages, onNavigate }) => (
7574
{messages.map(message => (
7675
<Message
7776
key={message.messageId}
78-
onNavigate={onNavigate}
7977
{...message}
8078
/>
8179
))}
@@ -87,9 +85,9 @@ Messages.defaultProps = {
8785
messages: [],
8886
};
8987

90-
const Stream = ({ messages, onNavigate }) => (
88+
const Stream = ({ messages }) => (
9189
<section>
92-
<Messages messages={messages} onNavigate={onNavigate} />
90+
<Messages messages={messages} />
9391
</section>
9492
);
9593

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,18 @@ const StreamMessageDetails = ({
6969
streamVersion,
7070
type,
7171
links,
72-
onNavigate,
7372
}) => (
7473
<TableRow>
7574
<TableCell style={nowrap}>
76-
<Hyperlink link={links[rels.feed][0]} onNavigate={onNavigate}>
75+
<Hyperlink link={links[rels.feed][0]}>
7776
{streamId}
7877
</Hyperlink>
7978
</TableCell>
8079
<TableCell style={nowrap}>{messageId}</TableCell>
8180
<TableCell style={nowrap}>{createdUtc}</TableCell>
8281
<TableCell style={nowrap}>{type}</TableCell>
8382
<TableCell style={{ width: '100%' }}>
84-
<Hyperlink link={links[rels.self][0]} onNavigate={onNavigate}>
83+
<Hyperlink link={links[rels.self][0]}>
8584
{streamId}
8685
{'@'}
8786
{streamVersion}
@@ -204,7 +203,7 @@ const StreamMessageJson = withStyles({
204203
);
205204

206205
render() {
207-
const { json, onNavigate, classes } = this.props;
206+
const { json, classes } = this.props;
208207
const { streams, loading, open } = this.state;
209208
return (
210209
<div>
@@ -224,7 +223,6 @@ const StreamMessageJson = withStyles({
224223
>
225224
<StreamBrowser
226225
streams={streams}
227-
onNavigate={onNavigate}
228226
loading={loading}
229227
/>
230228
</Drawer>
@@ -245,7 +243,6 @@ class StreamMessageTabs extends PureComponent {
245243
const {
246244
message: { payload, metadata },
247245
links,
248-
onNavigate,
249246
} = this.props;
250247
const { value } = this.state;
251248
return (
@@ -264,14 +261,12 @@ class StreamMessageTabs extends PureComponent {
264261
{value === 0 && (
265262
<StreamMessageJson
266263
json={payload}
267-
onNavigate={onNavigate}
268264
links={links}
269265
/>
270266
)}
271267
{value === 1 && (
272268
<StreamMessageJson
273269
json={metadata}
274-
onNavigate={onNavigate}
275270
links={links}
276271
/>
277272
)}
@@ -281,7 +276,7 @@ class StreamMessageTabs extends PureComponent {
281276
}
282277
}
283278

284-
const StreamMessage = ({ message, links, onNavigate }) => (
279+
const StreamMessage = ({ message, links }) => (
285280
<section>
286281
<Table style={{ tableLayout: 'auto' }}>
287282
<TableHead>
@@ -291,13 +286,11 @@ const StreamMessage = ({ message, links, onNavigate }) => (
291286
<StreamMessageDetails
292287
{...message}
293288
links={links}
294-
onNavigate={onNavigate}
295289
/>
296290
</TableBody>
297291
</Table>
298292
<StreamMessageTabs
299293
message={message}
300-
onNavigate={onNavigate}
301294
links={links}
302295
/>
303296
</section>

0 commit comments

Comments
 (0)