Skip to content
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

Country selector component integrated with country performance graphs #17

Merged
merged 13 commits into from Feb 6, 2017

Conversation

zelima
Copy link
Contributor

@zelima zelima commented Feb 5, 2017

This PR makes it possible for graphs to select country from 3 different drop down menus and add or remove data for selected country.

Thought selecting/removing is done IMHO in a quite hacky way, this is the only way we found solution to handle changing countries from 3 different dropdowns and not mass with each other.

This PR is introducing the Redux store in application and using mocked up action and reducer to handle inserting and removing lines from graph. This is happening in CountryPerformanceOnRisk component

As CountryPerformanceOnRisk has become "smart" component and is handling graph modification, testing this becomes harder. This PR does include thorough (partially) tests checking weather onchange methods are called and state is updated. (meaning line is added to the graph)
Testing smart component seems harder then expected. This may be helpful - reduxjs/redux#588

Besides this PR includes:

  • 5 selctors available under graph. Using react-select library
  • Test using snapshot testing
  • 2 non-editable selectors and 3 other, listing countries passed from redux store.
  • Mocked up redux store inside main index.js file with mocked up reducer (responsible for adding/removing)
  • Test for onchange methods and store udpates

}
this.updateValue1 = this.updateValue1.bind(this)
this.updateValue2 = this.updateValue2.bind(this)
this.updateValue3 = this.updateValue3.bind(this)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Really doubt having separate function for each selector handling dropdown changes is the right approach. Especially when there will be multiple graphs.
We need to explore more how this may be done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zelima when there will be multiple graphs they will be instantiated from different containers in parallel, so they are independent of each other.
To be able to have a single function we need to pass some indicator from onChange event - which must be passed from the container as our CountrySelect component is generic. I think in the end we will have more not DRY code than we have now.

Copy link
Contributor

@anuveyatsu anuveyatsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes

import { CountryPerformanceOnRisk, CountrySelect }
from '../src/components/CountryPerformanceOnRisk.js';
import React from 'react';
import { Provider } from 'react-redux';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not using Provider in this test. I forgot to remove it previously.

}

it('Dropdown is there', () => {
const wrapper = shallow(< CountrySelect selectOptions={[]}/>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably now, it would be better to use setup() function for wrapper:

const { enzymeWrapper } = setup()
expect(toJson(enzymeWrapper)).toMatchSnapshot();

< CountrySelect
selectOptions={this.state.countries}
onChange={this.updateValue1}
selectedCountries={this.state.selected1}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets change the name to selectedCountry as it should be singular.

@rufuspollock
Copy link
Contributor

I've reviewed and this is excellent. Good things:

  • Perfectly working in demo
  • Each commit was well described and very easy to review
  • Overall description of the PR had excellent detail.

@anuveyatsu
Copy link
Contributor

LGMT

@zelima
Copy link
Contributor Author

zelima commented Feb 6, 2017

Merging. Closes #15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants