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

Store: Update ProductSearch component for better variation support, multiple selections #19531

Merged
merged 28 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
766b65a
Remove existing `ProductSearch` component & style, copy over `Applies…
ryelle Nov 2, 2017
e02af8f
Split each product row into a new component, `ProductSearchRow`, whic…
ryelle Nov 2, 2017
4c79b30
Pull in product variations
ryelle Nov 3, 2017
d123a70
Style the variations form
ryelle Nov 3, 2017
7421d53
Clean up component, bring in the price display
ryelle Nov 3, 2017
7a8b10a
Update row display when a variation is selected
ryelle Nov 3, 2017
ead4472
Increase number of variations we can load
ryelle Nov 3, 2017
dd7df28
Move general functions into a helper utils file
ryelle Nov 3, 2017
1e04682
Clean up component
ryelle Nov 3, 2017
8f1f4b8
Add support for passing arrays to add/remove product IDs
ryelle Nov 4, 2017
988d6ac
Pull row-rendering into a separate function, so we can use the same t…
ryelle Nov 4, 2017
1dafc04
Handle selecting variations when the parent is unselected, delete uns…
ryelle Nov 4, 2017
c87bba0
Split up row-rendering function into smaller functions
ryelle Nov 6, 2017
74ee098
Add button to “Customize” variable products
ryelle Nov 6, 2017
3ecada0
Retain selected variations even if the components are hidden by search
ryelle Nov 6, 2017
aa5733b
Add attribute support into search by collapsing all attributes into a…
ryelle Nov 6, 2017
ecebc67
Fix singular display/interactions
ryelle Nov 6, 2017
ae3e2d9
Fix “Customize” button behavior
ryelle Nov 6, 2017
94a3b97
Update README
ryelle Nov 6, 2017
3a4188f
Fix props destructuring, use the correct name but map to the new/old …
ryelle Nov 7, 2017
c05afa8
Style the variation selector
jameskoster Nov 8, 2017
6e14d29
Bring back FormLabel for accessibility, update variation form button …
ryelle Nov 8, 2017
5528e92
Address PR feedback
ryelle Nov 8, 2017
24a6c25
Fix destructuring of new/old props
ryelle Nov 8, 2017
69a0cea
Fix issue where selecting an already-selected variation clears the re…
ryelle Nov 8, 2017
a3370f8
Update label text & the default select text.
ryelle Nov 8, 2017
d488f4b
Reset the form back to initial state after selecting a variation
ryelle Nov 8, 2017
fd909c2
Address PR feedback: don’t assign to this.state directly, update opti…
ryelle Nov 8, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean up component, bring in the price display
  • Loading branch information
ryelle committed Nov 8, 2017
commit 7421d53adbcb7b100e61c5ab9c0e58f65c2f3e2e
44 changes: 22 additions & 22 deletions client/extensions/woocommerce/components/product-search/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux';
import classNames from 'classnames';
import { connect } from 'react-redux';
import { noop } from 'lodash';
import { get, noop } from 'lodash';

/**
* Internal dependencies
*/
import { fetchProductVariations } from 'woocommerce/state/sites/product-variations/actions';
import formatCurrency from 'lib/format-currency';
import FormLabel from 'components/forms/form-label';
import FormRadio from 'components/forms/form-radio';
import FormCheckbox from 'components/forms/form-checkbox';
import { getPaymentCurrencySettings } from 'woocommerce/state/sites/settings/general/selectors';
import { getSelectedSiteWithFallback } from 'woocommerce/state/sites/selectors';
import { getVariationsForProduct } from 'woocommerce/state/sites/product-variations/selectors';
import ProductVariations from './variations';
Expand Down Expand Up @@ -72,39 +74,34 @@ class ProductSearchRow extends Component {
onChange( attributes, variations );
};

renderRow = ( component, rowText, rowValue, imageSrc, selected, onChange ) => {
const labelId = `applies-to-row-${ rowValue }-label`;
render() {
const { currency, product, isSelected } = this.props;
const { id, images, name, price } = product;
const nameWithPrice = name + ' - ' + formatCurrency( price, currency );
const imageSrc = get( images, '[0].src', false );
const labelId = `product-search-row-${ id }-label`;
const component = this.props.singular ? FormRadio : FormCheckbox;

const rowComponent = React.createElement( component, {
const inputComponent = React.createElement( component, {
htmlFor: labelId,
name: 'applies_to_select',
value: rowValue,
checked: selected,
onChange: onChange,
name: `product-search_select-${ id }`,
value: id,
checked: isSelected,
onChange: this.props.onChange,
} );

return (
<div className="product-search__row" key={ rowValue }>
<div className="product-search__row" key={ id }>
<FormLabel id={ labelId }>
{ rowComponent }
{ inputComponent }
{ renderImage( imageSrc ) }
<span>{ rowText }</span>
<span>{ nameWithPrice }</span>
</FormLabel>
{ selected && (
{ isSelected && (
<ProductVariations product={ this.props.product } onChange={ this.updateItem } />
) }
</div>
);
};

render() {
const { product, isSelected } = this.props;
const { name, id, images } = product;
const image = images && images[ 0 ];
const imageSrc = image && image.src;
const component = this.props.singular ? FormRadio : FormCheckbox;

return this.renderRow( component, name, id, imageSrc, isSelected, this.props.onChange );
}
}

Expand All @@ -114,8 +111,11 @@ export default connect(
const siteId = site ? site.ID : null;
const productId = props.product.id;
const variations = getVariationsForProduct( state, productId );
const currencySettings = getPaymentCurrencySettings( state, siteId );
const currency = currencySettings ? currencySettings.value : null;

return {
currency,
siteId,
productId,
variations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
.search {
margin-bottom: 0;
border: 1px solid lighten( $gray, 20% );
z-index: 0; // Keeps search from overlapping header above.
box-sizing: border-box;
z-index: 99;
z-index: 9;
}

.form-fieldset {
Expand Down