-
Notifications
You must be signed in to change notification settings - Fork 9
Assignment from UVdata #4
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
Open
CamillaHorne
wants to merge
7
commits into
uvdata:master
Choose a base branch
from
CamillaHorne:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
39911ba
Finished the challenges and added some additional changes:
Kmulla d4c6cb6
Added locale and sensitivity to localeCompare and a fallback in case …
Kmulla 76d6319
Converted functions to const
Kmulla 514e60c
Converted string concatenations to template literals
Kmulla 674bd38
Removed arrow functions in JSX
Kmulla 4ac216f
Load schema while loading data.
Kmulla 35e49a5
Updated the Dockerfile
Kmulla 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,12 @@ | ||
| FROM node:11 | ||
|
|
||
| RUN mkdir /usr/src/app | ||
| WORKDIR /usr/src/app | ||
|
|
||
| COPY . /usr/src/app | ||
|
|
||
| RUN yarn | ||
|
|
||
| CMD ["npm", "start"] | ||
|
|
||
| EXPOSE 3000 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { bindActionCreators} from 'redux'; | ||
| import { connect } from 'react-redux'; | ||
| import CategoryDisplay from '../components/category-display'; | ||
|
|
||
| import { onChooseEndpoint } from '../actions'; | ||
|
|
||
| const mapStateToProps = (state, categoryDisplay) => { | ||
| return { | ||
| loading: state.operations > 0, | ||
| endpoint: state.endpoint | ||
| } | ||
| }; | ||
|
|
||
| const mapDispatchToProps = (dispatch) => { | ||
| return bindActionCreators({ | ||
| onChooseEndpoint, | ||
| }, dispatch); | ||
| }; | ||
|
|
||
| export default connect(mapStateToProps, mapDispatchToProps)(CategoryDisplay); |
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,29 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import classNames from 'classnames'; | ||
|
|
||
| export default class CategoryDisplay extends React.PureComponent { | ||
|
|
||
| static propTypes = { | ||
| onChooseEndpoint: PropTypes.func.isRequired, | ||
| children: PropTypes.shape({ | ||
| key: PropTypes.string.isRequired, | ||
| name: PropTypes.string.isRequired, | ||
| }).isRequired, | ||
| endpoint: PropTypes.string, | ||
| loading: PropTypes.bool.isRequired, | ||
| }; | ||
|
|
||
| handleChooseEndpoint = () => this.props.onChooseEndpoint(this.props.children.key); | ||
|
|
||
| render() { | ||
| const { children: { key, name }, loading, endpoint } = this.props; | ||
|
|
||
| const getEndpointButtonClassNames = classNames('btn', { | ||
| 'btn-default': key !== endpoint, | ||
| 'btn-success': key === endpoint | ||
| }); | ||
|
|
||
| return (<button disabled={loading} onClick={this.handleChooseEndpoint} className={getEndpointButtonClassNames}>{name}</button>); | ||
| } | ||
| } |
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,48 @@ | ||
| import { bindActionCreators} from 'redux'; | ||
| import { connect } from 'react-redux'; | ||
| import ItemDisplay from '../components/item-display'; | ||
|
|
||
| import { onExpandToggle } from '../actions'; | ||
|
|
||
| const getIconName = (data) => { | ||
| switch (data.kind) { | ||
| case 'people': | ||
| if (data.gender == 'female') | ||
| return 'fa-female' | ||
| else if (data.gender == 'male') | ||
| return 'fa-male' | ||
| else | ||
| return 'fa-android' | ||
| case 'films': | ||
| return 'fa-film' | ||
| case 'planets': | ||
| return 'fa-globe' | ||
| case 'species': | ||
| return 'fa-user' | ||
| case 'starships': | ||
| return 'fa-plane' | ||
| case 'vehicles': | ||
| return 'fa-bus' | ||
| } | ||
| } | ||
|
|
||
| const mapStateToProps = (state, itemDisplay) => { | ||
| const data = Object.assign({}, itemDisplay.children); | ||
| const isExpanded = data.isExpanded; | ||
| delete data.isExpanded; | ||
|
|
||
| return { | ||
| data, | ||
| isExpanded, | ||
| loading: state.operations > 0, | ||
| getIconName | ||
| } | ||
| }; | ||
|
|
||
| const mapDispatchToProps = (dispatch) => { | ||
| return bindActionCreators({ | ||
| onExpandToggle, | ||
| }, dispatch); | ||
| }; | ||
|
|
||
| export default connect(mapStateToProps, mapDispatchToProps)(ItemDisplay); |
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 |
|---|---|---|
| @@ -1,37 +1,38 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import classNames from 'classnames'; | ||
|
|
||
| export default class ItemDisplay extends React.PureComponent { | ||
|
|
||
| static propTypes = { | ||
| onExpandToggle: PropTypes.func.isRequired, | ||
| children: PropTypes.shape({ | ||
| url: PropTypes.string.isRequired, | ||
| name: PropTypes.string.isRequired, | ||
| kind: PropTypes.string.isRequired, | ||
| }) | ||
| }), | ||
| isExpanded: PropTypes.bool, | ||
| loading: PropTypes.bool.isRequired, | ||
| getIconName: PropTypes.func.isRequired, | ||
| }; | ||
|
|
||
| state = { | ||
| isExpanded: false, | ||
| }; | ||
|
|
||
| handleExpandToggle = () => { | ||
| this.setState((state) => ({ isExpanded: !state.isExpanded })); | ||
| }; | ||
| handleExpandToggle = () => this.props.onExpandToggle(this.props.children.url); | ||
|
|
||
| render() { | ||
| const { children: { name }, onExpandToggle} = this.props; | ||
| const { isExpanded } = this.state; | ||
| const { data, onExpandToggle, isExpanded, loading, getIconName } = this.props; | ||
|
|
||
| return (<span> | ||
| <button className="btn btn-xs btn-default" onClick={this.handleExpandToggle} aria-label={isExpanded ? 'Collapse' : 'Expand'}> | ||
| <button disabled={loading} className="btn btn-xs btn-default" onClick={this.handleExpandToggle} aria-label={isExpanded ? 'Collapse' : 'Expand'}> | ||
| {isExpanded | ||
| ? <i className="fa fa-chevron-circle-up" /> | ||
| : <i className="fa fa-chevron-circle-down" />} | ||
| </button> | ||
| {' '} | ||
| {name} | ||
| { isExpanded ? <pre>{JSON.stringify(this.props.children, null, 4)}</pre> : null} | ||
| <i className={classNames('fa', getIconName(data))} /> | ||
| {' '} | ||
| {data.kind === 'films' ? `Episode ${data.episode_id}: ` : null} | ||
| {data.name} | ||
| {isExpanded ? <pre>{JSON.stringify(data, null, 4)}</pre> : null} | ||
| </span>); | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -2,23 +2,52 @@ import { bindActionCreators} from 'redux'; | |
| import { connect } from 'react-redux'; | ||
| import MillenniumFalcon from '../components/millennium-falcon'; | ||
|
|
||
| import { onChooseEndpoint } from '../actions'; | ||
| import { onChooseEndpoint, onOrderList, onExpandAll } from '../actions'; | ||
|
|
||
| const getSchemaProperties = (schema, endpoint) => { | ||
| return (schema && schema[endpoint] && schema[endpoint].properties) || []; | ||
| } | ||
|
|
||
| const getOrderableSchemaProperties = (schema, endpoint) => { | ||
| var schemaProperties = getSchemaProperties(schema, endpoint); | ||
| return Object.keys(schemaProperties) | ||
| .map((propertyKey) => { | ||
| var value = schemaProperties[propertyKey]; | ||
| value['key'] = propertyKey; | ||
| return value; | ||
| }) | ||
| .filter((property) => (property.type === 'string' || property.type === 'integer') && property.format === undefined); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Har du overvejet om man kunne sortere på array typer? Måske på |
||
| } | ||
|
|
||
| const mapStateToProps = (state) => { | ||
| const { endpoint, data } = state; | ||
| const { endpoint, data, schema } = state; | ||
|
|
||
| const list = (data && data[endpoint]) || []; | ||
| console.log(state.operations); | ||
|
|
||
| const categoryList = [ | ||
| {key: 'people', name: 'People'}, | ||
| {key: 'films', name: 'Films'}, | ||
| {key: 'planets', name: 'Planets'}, | ||
| {key: 'species', name: 'Species'}, | ||
| {key: 'starships', name: 'Starships'}, | ||
| {key: 'vehicles', name: 'Vehicles'} | ||
| ]; | ||
|
|
||
| return { | ||
| list, | ||
| categoryList, | ||
| endpoint, | ||
| loading: state.operations > 0, | ||
| hasData: list.length > 0, | ||
| orderOptions: getOrderableSchemaProperties(schema, endpoint), | ||
| } | ||
| }; | ||
|
|
||
| const mapDispatchToProps = (dispatch) => { | ||
| return bindActionCreators({ | ||
| onChooseEndpoint: onChooseEndpoint, | ||
| onChooseEndpoint, | ||
| onOrderList, | ||
| onExpandAll, | ||
| }, dispatch); | ||
| }; | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
Har du overvejet at bruge
const?