Skip to content

Conversation

@jeff-phillips-18
Copy link
Member

@priley86
Copy link
Member

priley86 commented Jan 4, 2018

looking very promising @jeff-phillips-18 ! The recompose/context usage is very nice. I will dive in more soon!

@jeff-phillips-18
Copy link
Member Author

@priley86 Thanks, the recompose/context usage credit goes to @mturley !

toggleCurrentSortDirection() {
const { isSortAscending } = this.state;

this.setState({ isSortAscending: !isSortAscending });
Copy link
Member

@priley86 priley86 Jan 5, 2018

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) => {
Copy link
Member

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
Copy link
Member

@priley86 priley86 Jan 5, 2018

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... 😸

Copy link
Member

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}...

Copy link
Member Author

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

/** additional filter item classes */
className: PropTypes.string,
/** Label to show for the filter item */
label: PropTypes.string.isRequired,
Copy link
Member

@priley86 priley86 Jan 5, 2018

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) => {
Copy link
Member

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) {
Copy link
Member

@priley86 priley86 Jan 5, 2018

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 ;)

Copy link
Member Author

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 });
Copy link
Member

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">
Copy link
Member

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...

Copy link
Member Author

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.

Copy link
Member

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. ;)

@priley86
Copy link
Member

priley86 commented Jan 5, 2018

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);
Copy link
Member

@cdcabrera cdcabrera Jan 5, 2018

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.

Copy link
Member Author

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.

filterTypes={mockFilterExampleFields}
currentFilterType={mockFilterExampleFields[0]}
/>
<input
Copy link
Member

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';
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@priley86 priley86 Jan 9, 2018

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?

Copy link
Member Author

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.

Copy link
Member

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...

Copy link
Member

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);
Copy link
Member

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?

Copy link
Member Author

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);
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, added. thanks.

@priley86
Copy link
Member

priley86 commented Jan 9, 2018

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 actions as props into the Filters example and log the filter values as they change in the storybook Actions console. I think it just helps clarify the examples more for developers but is definitely a "nice-to-have".

So something like this is the way to pass in actions Filter.stories.js...
priley86@1be9253#diff-af9477690520614260c8b88ebe909580

edit: updated example with decoratorAction
priley86@a914026

@jeff-phillips-18
Copy link
Member Author

Updated per review comments. Added logging of actions into the toolbar action logger

@jeff-phillips-18
Copy link
Member Author

Added more logging of actions in the toolbar storybook

@jeff-phillips-18
Copy link
Member Author

Rebased

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.

Change View Support in Toolbar Component - Toolbar

4 participants