Skip to content

Commit f5ea58e

Browse files
committed
Stopped authorized section from spreading own props to children and made adjustments in line with comments that came up during review
1 parent 94eb031 commit f5ea58e

File tree

8 files changed

+14
-37
lines changed

8 files changed

+14
-37
lines changed

packages/react-router-pagination/src/react-router-pagination.types.js.flow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import type { Location, RouterHistory } from 'react-router-dom';
2+
import type { Location, RouterHistory } from 'react-router';
33

44
export type ConfigOptions = {
55
currentPageKey: string,
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
es
2-
/*.js
3-
authorization-strategy
4-
authorized-route
5-
authorized-section
6-
permissions-context
7-
permissions-provider
2+
/*.js

packages/react-router-permissions/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ There are some strategies provided with the package out of the box. Those are:
103103
- Role based strategy
104104

105105
```js
106-
const strategy = ['MODERATOR', 'PREMIUM_USER'];
106+
const permissions = ['MODERATOR', 'PREMIUM_USER'];
107107

108108
...
109109
// authorization will pass
@@ -125,7 +125,7 @@ There are some strategies provided with the package out of the box. Those are:
125125
* Permissions based strategy
126126

127127
```js
128-
const strategy = {
128+
const permissions = {
129129
canReadPosts: true,
130130
canManagePosts: true,
131131
canManageUsers: false,
@@ -151,7 +151,7 @@ There are some strategies provided with the package out of the box. Those are:
151151
* At least one strategy
152152

153153
```js
154-
const strategy = {
154+
const permissions = {
155155
canReadPosts: true,
156156
canManagePosts: false,
157157
canManageUsers: false,

packages/react-router-permissions/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
],
1616
"peerDependencies": {
1717
"react": "^16.6.0",
18-
"react-dom": "^16.6.0",
19-
"react-router": "^4.3.1",
20-
"react-router-dom": "^4.3.1"
18+
"react-router": "^4.3.1"
2119
},
2220
"scripts": {
2321
"build": "node scripts/build.js",
@@ -36,10 +34,10 @@
3634
"babel-core": "^7.0.0-0",
3735
"babel-jest": "^23.6.0",
3836
"codecov": "^3.1.0",
39-
"flow-bin": "^0.81.0",
40-
"jest": "^23.6.0",
4137
"enzyme": "^3.7.0",
42-
"enzyme-adapter-react-16": "^1.7.0"
38+
"enzyme-adapter-react-16": "^1.7.0",
39+
"flow-bin": "^0.81.0",
40+
"jest": "^23.6.0"
4341
},
4442
"jest": {
4543
"collectCoverageFrom": [

packages/react-router-permissions/src/authorized-route/authorized-route.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ export class AuthorizedRoute extends React.Component<AuthorizedRouteProps> {
2020
children={(routerProps: ContextRouter) =>
2121
routerProps.match ? (
2222
<AuthorizedSection
23-
{...routerProps}
2423
requires={requires}
2524
authorizationStrategy={authorizationStrategy}
26-
children={children}
25+
children={({ isAuthorized }: { isAuthorized: * }) => children({ ...routerProps, isAuthorized })}
2726
/>
2827
) : null
2928
}

packages/react-router-permissions/src/authorized-route/authorized-route.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import Enzyme, { mount } from 'enzyme';
33
import Adapter from 'enzyme-adapter-react-16';
44

5-
import { MemoryRouter, Switch } from 'react-router-dom';
5+
import { MemoryRouter, Switch } from 'react-router';
66

77
import AuthorizedRoute from './authorized-route';
88
import PermissionsProvider from '../permissions-provider/permissions-provider';

packages/react-router-permissions/src/authorized-section/authorized-section.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import { PermissionsContext } from '../permissions-context/permissions.context';
55

66
export type AuthorizedSectionProps = {
77
requires: *,
8-
authorizationStrategy?: (*, *) => *,
8+
authorizationStrategy?: (permissions: *, requirement: *) => *,
99
children: ({
10-
isAuthorized: boolean,
10+
isAuthorized: *,
1111
}) => React.Node,
12-
[string]: *,
1312
};
1413

1514
export class AuthorizedSection extends React.Component<AuthorizedSectionProps> {
1615
render() {
17-
const { requires, authorizationStrategy: overrideStrategy, children, ...rest } = this.props;
16+
const { requires, authorizationStrategy: overrideStrategy, children } = this.props;
1817

1918
return (
2019
<PermissionsContext.Consumer>
@@ -23,7 +22,6 @@ export class AuthorizedSection extends React.Component<AuthorizedSectionProps> {
2322
? overrideStrategy(permissions, requires)
2423
: authorizationStrategy(permissions, requires);
2524
return children({
26-
...rest,
2725
isAuthorized,
2826
});
2927
}}

packages/react-router-permissions/src/authorized-section/authorized-section.spec.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,4 @@ describe('Authorized Section', () => {
5050

5151
expect(authorization).toBeCalledWith(false);
5252
});
53-
54-
it('passes cuctom props along isAuthorized', () => {
55-
const trapForFoo = jest.fn();
56-
mount(
57-
<PermissionsProvider permissions={{ isLogged: true }} authorizationStrategy={strategy}>
58-
<AuthorizedSection requires="isLogged" foo="bar">
59-
{({ foo }) => trapForFoo(foo)}
60-
</AuthorizedSection>
61-
</PermissionsProvider>,
62-
);
63-
64-
expect(trapForFoo).toBeCalledWith('bar');
65-
});
6653
});

0 commit comments

Comments
 (0)