-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Simple user view #3244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Simple user view #3244
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { react2angular } from 'react2angular'; | ||
|
||
export const UserShow = ({ name, email, profileImageUrl }) => ( | ||
<div className="col-md-4 col-md-offset-4 profile__container"> | ||
<img | ||
alt="profile" | ||
src={profileImageUrl} | ||
className="profile__image" | ||
width="40" | ||
/> | ||
|
||
<h3 className="profile__h3">{name}</h3> | ||
|
||
<hr /> | ||
|
||
<dl className="profile__dl"> | ||
<dt>Name:</dt> | ||
<dd>{name}</dd> | ||
<dt>Email:</dt> | ||
<dd>{email}</dd> | ||
</dl> | ||
</div> | ||
); | ||
|
||
UserShow.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
email: PropTypes.string.isRequired, | ||
profileImageUrl: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default function init(ngModule) { | ||
ngModule.component('userShow', react2angular(UserShow)); | ||
} | ||
|
||
init.init = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { UserShow } from './UserShow'; | ||
|
||
test('renders correctly', () => { | ||
const component = renderer.create(<UserShow name="John Doe" email="[email protected]" profileImageUrl="http://www.images.com/llama.jpg" />); | ||
const tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders correctly 1`] = ` | ||
<div | ||
className="col-md-4 col-md-offset-4 profile__container" | ||
> | ||
<img | ||
alt="profile" | ||
className="profile__image" | ||
src="http://www.images.com/llama.jpg" | ||
width="40" | ||
/> | ||
<h3 | ||
className="profile__h3" | ||
> | ||
John Doe | ||
</h3> | ||
<hr /> | ||
<dl | ||
className="profile__dl" | ||
> | ||
<dt> | ||
Name: | ||
</dt> | ||
<dd> | ||
John Doe | ||
</dd> | ||
<dt> | ||
Email: | ||
</dt> | ||
<dd> | ||
[email protected] | ||
</dd> | ||
</dl> | ||
</div> | ||
`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it wouldn't be more "future proof" to pass the user object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda meaningless because we would want to describe the user object's shape using proptypes, and that's kind of the same effort when (read: "if") we choose to add anything in the future, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but then you'll need only change proptypes; currently you'll also need to update all the places where you use this component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kravets-levko kinda scratching my head with passing objects from Angular to React (as opposed to simple values). Do we have any examples of this happening in our code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What @kravets-levko said + you define the PropType shape of the User object one time and can reuse in multiple components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, static typing allows declaring props which can be used across the app with no import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's supposed to be
declare.ts
in your example, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume (never used TS but rather Flow)