-
Notifications
You must be signed in to change notification settings - Fork 378
feat(Toolbar): Add Toolbar and its components #150
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
Conversation
|
looking very promising @jeff-phillips-18 ! The recompose/context usage is very nice. I will dive in more soon! |
| toggleCurrentSortDirection() { | ||
| const { isSortAscending } = this.state; | ||
|
|
||
| this.setState({ isSortAscending: !isSortAscending }); |
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.
simple toggles like this can be simplified to:
this.setState(prevState => {
return { isSortAscending: !prevState.isSortAscending };
});
as setState also accepts a function ;)
https://medium.com/@shopsifter/using-a-function-in-setstate-instead-of-an-object-1f5cfd6e55d1
| import React from 'react'; | ||
| import { Sort, Toolbar } from '../../../index'; | ||
|
|
||
| const bindMethods = (context, methods) => { |
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.
should just be able to:
import { bindMethods } from '../../../common/helpers';
it seems to work here...
| /** Additional css classes */ | ||
| className: PropTypes.string, | ||
| /** Title for the list (ie. 'Active Filters:') */ | ||
| title: PropTypes.string.isRequired |
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 know that {title} is typically just a string... but {children} is more flexible. What if I want to put an emoji in there and a <b> tag... 😸
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.
another option is to just use PropTypes.node and leave it named {title}...
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.
title is bad anyhow, causes unwanted tooltips at times, I will update
src/components/Filter/FilterItem.js
Outdated
| /** additional filter item classes */ | ||
| className: PropTypes.string, | ||
| /** Label to show for the filter item */ | ||
| label: PropTypes.string.isRequired, |
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.
same as above... PropTypes.node preferred for label
| import { Grid, Col, Row, Filter } from '../../../index'; | ||
| import { Filter, Toolbar } from '../../../index'; | ||
|
|
||
| const bindMethods = (context, methods) => { |
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.
same with: import { bindMethods } from '../../../common/helpers';
| this.setState({ activeFilters: activeFilters }); | ||
| }; | ||
|
|
||
| selectFilterType(filterType) { |
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 missed this last time... but it's best to try to combine calls to setState when possible... as every call to setState forces a re-evaluation of the virtual dom in render() method. Maybe something like this can work here:
this.setState(prevState => {
return {
currentValue: '',
currentFilterType: filterType,
filterCategory:
filterType.filterType === 'complex-select'
? undefined
: prevState.filterCategory,
categoryValue:
filterType.filterType === 'complex-select'
? ''
: prevState.categoryValue
};
});
Not a big deal... just more of an awareness thing ;)
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.
Thanks. Fixed.
|
|
||
| toggleDropdownShown() { | ||
| const { dropdownShown } = this.state; | ||
| this.setState({ dropdownShown: !dropdownShown }); |
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.
same deal w/ toggles, you can use => prevState function
|
|
||
| if (currentValue && currentValue !== '') { | ||
| return [ | ||
| <span className="find-pf-nums"> |
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.
maybe the span and buttons can be combined into another stateless component ? Not sure how common it is...
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'd prefer to keep it all self contained unless you feel strongly.
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.
fine w/ me, just wasn't sure how common. ;)
|
As a first pass...very nice job with this @jeff-phillips-18 ! Also the ContextProvider pattern is beautiful here 👍 |
| import PropTypes from 'prop-types'; | ||
|
|
||
| const FilterItem = ({ className, label, onRemove, filterData, ...rest }) => { | ||
| const classes = cx(className); |
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.
For some reason I keep coming back to this bit...
FilterItem = ({ className, label, onRemove, filterData, ...rest })Not sure if we do this anywhere else within this repo, but label is a property on filterdata is that something we could combine to avoid passing the same data in while relating some of the context? Though saying that now I'm thinking we'd lose some flexibility.
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.
Yeah, we would have to force the filterData structure. And the label property is being removed in favor of children to allow users to show more than just a label here.
60fdce1 to
0fcaf92
Compare
src/components/Filter/Filter.test.js
Outdated
| filterTypes={mockFilterExampleFields} | ||
| currentFilterType={mockFilterExampleFields[0]} | ||
| /> | ||
| <input |
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.
we can use FormControl instead of inputs now that #131 has landed.
| @@ -0,0 +1,20 @@ | |||
| import React from 'react'; | |||
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.
can we rename this file to simply constants.js to match the other 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.
I actually find it confusing to have just constants.js which contain component specific constants.
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.
ok... no issues there then. I guess this is a bit more specific (as they are only specific to the Toolbar and not other sub-toolbar components). I guess typically I have been including those in the component itself in those cases, but fine with this convention. Is this the correct understanding? Or are you proposing that we rename all constants.js files?
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 just like to have the file named for what it is so if I have multiple open in my IDE I can see which is the Toolbar constants file vs the Button constants file.
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.
One could say, like a "constant" reminder...
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 would agree with this. So if it's the global change, I think we leave it ToolbarConstants.js and then apply the same to others in a separate PR... I just wanted to make sure I understood ;)
| import cx from 'classnames'; | ||
|
|
||
| const ToolbarViewSelector = ({ children, className, ...rest }) => { | ||
| const classes = cx('form-group toolbar-pf-view-selector', className); |
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.
do we want the ...rest passed through to the div?
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, added. thanks.
| import cx from 'classnames'; | ||
|
|
||
| const ToolbarRightContent = ({ children, className, ...rest }) => { | ||
| const classes = cx('toolbar-pf-action-right', className); |
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.
do we want the ...rest passed through to the div?
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, added. thanks.
|
the updates look good to me here... was chatting a bit with @cdcabrera, if you have extra time, it might be nice to pass down So something like this is the way to pass in actions Filter.stories.js... edit: updated example with decoratorAction |
0fcaf92 to
684ca8c
Compare
|
Updated per review comments. Added logging of actions into the toolbar action logger |
|
Added more logging of actions in the toolbar storybook |
1493bc0 to
6f48c8d
Compare
|
Rebased |
What:
Adding basic Filter component
Links to Storybooks:
Filter: https://jeff-phillips-18.github.io/patternfly-react/?selectedKind=Filter&selectedStory=Filter
Sort: https://jeff-phillips-18.github.io/patternfly-react/?selectedKind=Sort&selectedStory=Sort
Toolbar: https://jeff-phillips-18.github.io/patternfly-react/?selectedKind=Toolbar&selectedStory=Toolbar
closes #102
closes #124
FYI @serenamarie125 @ohadlevy