Skip to content

feat(Slider): Add Slider component, storybook and tests - #280

Merged
jeff-phillips-18 merged 5 commits into
patternfly:masterfrom
Ron-Lavi:feature/slider
Apr 17, 2018
Merged

jeff-phillips-18 merged 5 commits into
patternfly:masterfrom
Ron-Lavi:feature/slider

Conversation

@Ron-Lavi

@Ron-Lavi Ron-Lavi commented Mar 19, 2018 •

Copy link
Copy Markdown
Collaborator

jQuery is no longer an issue since I have published the npm module 'bootstrap-slider-without-jquery'.

Storybook

fix #183
re #263

@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 991

  • 48 of 70 (68.57%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.5%) to 71.068%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/components/Slider/Boundaries.js 15 17 88.24%
src/components/Slider/DropdownMenu.js 9 12 75.0%
src/components/Slider/Slider.js 14 21 66.67%
src/components/Slider/BootstrapSlider.js 10 20 50.0%
Totals Coverage Status
Change from base Build 988: -0.5%
Covered Lines: 1303
Relevant Lines: 1655

💛 - Coveralls

@coveralls

coveralls commented Mar 19, 2018 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 1200

  • 55 of 64 (85.94%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.08%) to 75.197%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/components/Slider/Slider.js 19 21 90.48%
src/components/Slider/Boundaries.js 13 15 86.67%
src/components/Slider/BootstrapSlider.js 15 20 75.0%
Totals Coverage Status
Change from base Build 1196: 0.08%
Covered Lines: 1529
Relevant Lines: 1850

💛 - Coveralls

@Ron-Lavi

Copy link
Copy Markdown
Collaborator Author

Hey @serenamarie125 and @jgiardino, I reopened this branch due to some issues with the old one,
please check the updated storybook

@Ron-Lavi
Ron-Lavi force-pushed the feature/slider branch 3 times, most recently from 3e2322b to dbf780b Compare March 19, 2018 22:13
serenamarie125
serenamarie125 previously approved these changes Mar 20, 2018

@serenamarie125 serenamarie125 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@LaViro this looks great! Thanks for your contribution!

Comment thread src/components/Slider/Slider.test.js Outdated
import React from 'react';
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import toJSON from 'enzyme-to-json';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No longer require tojson, snapshot serializer is built in 😋

Comment thread src/components/Slider/Slider.test.js Outdated
import { Slider } from './index';
import BootstrapSlider from './BootstrapSlider';

Enzyme.configure({ adapter: new Adapter() });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unsure if we need this also, I suspect not...

@dmiller9911 dmiller9911 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do have some concerns about the jQuery issues. It might be nice to either try to contribute to the lib or find another that does not have the jQuery workaround. From a consumer standpoint, I would not like to have to work around it. Additionally, this will be a breaking change and will require a major version since it will throw an error at import for any consumer without jQuery.

}
}

_onSlide = value => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Judging by other methods in this repo I do not believe we are prefixing "private" methods with a _ @michaelkro or @priley86 might have better insight into that though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that's correct - we have not been prefixing with _ here. I don't see that as necessary, but i'm open to ideas on this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dmiller @priley86 I think it is a good indication for function that will be used by other components rather than private ones.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed the private prefix

this._slider = new Slider(this.sliderDiv, {
...this.props
});
this._slider.on('slide', value => that._onSlide(value));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this can be written as this._slider.on('slide', this._onSlide) anything written like classMethod = () => {} are essentially be autobound to the instance.

@priley86 priley86 Mar 24, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sharvit can you remind me why we chose to use bindMethods syntax for binding class functions? It has been a long time since that was discussed...

to @dmiller9911 's point, I believe many communities have moved to the classMethod = () => {} syntax for auto binding...

}

componentDidMount() {
const that = this;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Arrow functions remove the need for doing this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dmiller9911 I am using it because the function is being called in bootstrap-slider's context.
this._slider.on('slide', value => that._onSlide(value));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dmiller9911,
I moved the onSlide function into componentDidMount

this._slider.setAttribute('formatter', nextProps.formatter);
// Adjust the tooltip to "sit" ontop of the slider's handle. #LibraryBug
// check
if (this.props.orientation === 'horizontal') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Creating constants for orientation similar to alerts and referencing the variable here will make it easier to maintain than using a string here.

// Instead of rendering the slider element again and again,
// we took advantage of the bootstrap-slider library
// and only update the new value or format when new props arrive.
componentWillUpdate(nextProps, nextState) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move this to componentDidUpdate. willUpdate will be deprecated in the next major react release, and the warning will be starting the next minor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

big +1 😸

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dmiller9911 Moved it to componentWillReceiveProps

Comment thread src/components/Slider/Boundaries.js Outdated
}
}

const slider = children[0];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it is usually bad practice to assume children's data structure in React. React exports tools for this. Wou will want to run children through this: https://reactjs.org/docs/react-api.html#reactchildrentoarray before referencing the array positions. That said for this scenario is might be better to have a slider Prop and a form Prop or slider and then use children for form.

<Bounderies slider={<BSSlider />} >form goes here</Bounderies>

Comment thread src/components/Slider/Slider.js Outdated
);
}

const inputElement = this.props.input ? (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be written as !!this.props.input && () React will render false the same as null.

Comment thread src/components/Slider/Slider.test.js Outdated
dropdownList: ['MB', 'GB'],
dropup: true
};
const wrapper = mount(<Slider {...props} />);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

any way to use shallow here and mock out bootstap-slider to return a mock instance/methods?

Comment thread src/components/Slider/Slider.test.js Outdated
'componentWillUpdate'
);
innerSlider.setProps({ value: 60 });
expect(componentWillUpdate).toHaveBeenCalled();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't really test much since it is kind of just exercising enzyme/react's lifecycle. A better test would be to verify the changes we make to slider after an update. You would need to get Slider mocked though. If you need help with that let me know. I can probably help out with that.

@Ron-Lavi Ron-Lavi Mar 27, 2018 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dmiller9911, I was also thinking about it, but it seems that Coverall's rate reduced when I didn't test it.

Comment thread src/components/Slider/Slider.test.js Outdated
dropup: true
};
const wrapper = mount(<Slider {...props} />);
expect(toJSON(wrapper)).toMatchSnapshot();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This snapshot is too big if we can't get shallow working. It would be better to verify values/method calls. It is best to try and keep snapshots around 20 lines or below.

@Ron-Lavi

Copy link
Copy Markdown
Collaborator Author

@dmiller9911 @priley86 @AllenBW Thank you for your review guys!

@mturley

mturley commented Mar 26, 2018

Copy link
Copy Markdown
Contributor

@LaViro this looks great! I do agree with @dmiller9911 however, about the jQuery issue... We definitely don't want consumers of this repo to have to think about jQuery whatsoever. Having to make an exception around jQuery or get a jQuery based warning... Both are no good. It would be nice to find a way to cut jQuery out of the picture entirely-- even if we need to target our own new fork of the slider or something.

@Ron-Lavi

Copy link
Copy Markdown
Collaborator Author

@mturley @dmiller9911 Thanks, I am going to try to figure this out.. Tell me if you got any idea

@Ron-Lavi

Ron-Lavi commented Apr 9, 2018

Copy link
Copy Markdown
Collaborator Author

@dmiller9911 @mturley I hacked the 'bootstrap-slider' package and published a new package called 'bootstrap-slider-without-jquery' which is jQuery-free.

@Ron-Lavi Ron-Lavi changed the title feat(Slider): Add Slider component, storybook and tests [W.I.P] feat(Slider): Add Slider component, storybook and tests Apr 9, 2018
@Ron-Lavi Ron-Lavi changed the title [W.I.P] feat(Slider): Add Slider component, storybook and tests feat(Slider): Add Slider component, storybook and tests Apr 11, 2018
@Ron-Lavi Ron-Lavi self-assigned this Apr 11, 2018
@jeff-phillips-18

Copy link
Copy Markdown
Member

Need to add export * from './components/Slider'; to src/index.js

@Ron-Lavi

Copy link
Copy Markdown
Collaborator Author

@jeff-phillips-18 It's the most important thing :)

…brary, add storybook and tests.

BREAKING CHANGE: Although jQuery is optional to this library, when it is not being used, an error
will be raised. In order to fix this error, we need to set jquery to null in webpack. Please check
the library repo on github for more information about this issue.

fix patternfly#183
-Delete constructor.
-Add orientation enums.
-Change moved onSlide into componentDidMount and change the syntax of
the binded call.
-Change componentWillUpdate, as it is deprecated, to
componentWillRecieveProps.
-Change the private _ convention.
-Add formatter props validation.
------------------------------------------------------------------------
Change Boundaries.js:
-Add slider prop.
-Delete avoid use of children index.
------------------------------------------------------------------------
Change Slider.js:
-Add implementation to Boundaries slider prop.
-Change moved BSSlider to const.
------------------------------------------------------------------------
Change Slider.test.js:
-Delete unnecessary imports and configurations.
-Change props to inline props.
- Change snapshot was decreased from 360 lines to 100.
- Add test for slide and slideStop
-Change the import source of Dropdown and MenuItem to '../../index'.
@jeff-phillips-18
jeff-phillips-18 merged commit c27866d into patternfly:master Apr 17, 2018
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.

Component : Slider

9 participants