Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Review suggestion changes
Browse files Browse the repository at this point in the history
  • Loading branch information
grogou committed Jul 14, 2021
1 parent 6b0f5d2 commit a63dbce
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 56 deletions.
2 changes: 1 addition & 1 deletion assets/js/blocks/attribute-filter/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { useCallback, useEffect, useState, useMemo } from '@wordpress/element';
import CheckboxList from '@woocommerce/base-components/checkbox-list';
import DropdownSelector from '@woocommerce/base-components/dropdown-selector';
import Label from '@woocommerce/base-components/filter-element-label';
import FilterSubmitButton from '@woocommerce/base-components/filter-submit-button';
import isShallowEqual from '@wordpress/is-shallow-equal';
import { decodeEntities } from '@wordpress/html-entities';
Expand All @@ -22,7 +23,6 @@ import { decodeEntities } from '@wordpress/html-entities';
*/
import { getAttributeFromID } from '../../utils/attributes';
import { updateAttributeFilter } from '../../utils/attributes-query';
import Label from './label';
import { previewAttributeObject, previewOptions } from './preview';
import './style.scss';

Expand Down
17 changes: 2 additions & 15 deletions assets/js/blocks/attribute-filter/style.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
.wc-block-attribute-filter {
margin-bottom: $gap-large;

.wc-block-attribute-filter-list-count {
&::before {
content: " (";
}
&::after {
content: ")";
}
}

.wc-block-attribute-filter-list {
margin: 0;

Expand All @@ -25,14 +16,10 @@
display: inline-block;
}
}

.wc-block-attribute-filter-list-count {
float: right;
}
}

.is-single .wc-block-attribute-filter-list-count,
.wc-block-dropdown-selector .wc-block-dropdown-selector__list .wc-block-attribute-filter-list-count {
.is-single,
.wc-block-dropdown-selector .wc-block-dropdown-selector__list {
opacity: 0.6;
}

Expand Down
39 changes: 16 additions & 23 deletions assets/js/blocks/stock-filter/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,29 @@ import { getSetting } from '@woocommerce/settings';
import { useCallback, useEffect, useState, useMemo } from '@wordpress/element';
import CheckboxList from '@woocommerce/base-components/checkbox-list';
import FilterSubmitButton from '@woocommerce/base-components/filter-submit-button';
import Label from '@woocommerce/base-components/filter-element-label';
import isShallowEqual from '@wordpress/is-shallow-equal';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import Label from './label';
import { previewOptions } from './preview';
import './style.scss';

const STOCK_STATUS_OPTIONS = getSetting( 'stockStatusOptions', [] );
const hideOutOfStockItems = getSetting( 'hideOutOfStockItems', false );
if ( hideOutOfStockItems ) {
delete STOCK_STATUS_OPTIONS.outofstock;
}
const initialOptions = Object.entries(
STOCK_STATUS_OPTIONS
).map( ( [ slug, name ] ) => ( { slug, name } ) );
const { outofstock, ...otherStockStatusOptions } = getSetting(
'stockStatusOptions',
{}
);
const STOCK_STATUS_OPTIONS = hideOutOfStockItems
? otherStockStatusOptions
: { outofstock, ...otherStockStatusOptions };
// filter added to handle if there are slugs without a corresponding name defined.
const initialOptions = Object.entries( STOCK_STATUS_OPTIONS )
.map( ( [ slug, name ] ) => ( { slug, name } ) )
.filter( ( status ) => !! status.name )
.sort( ( a, b ) => a.slug.localeCompare( b.slug ) );

/**
* Component displaying an stock status filter.
Expand Down Expand Up @@ -165,8 +170,8 @@ const StockStatusFilterBlock = ( {
// Track Stock query changes so the block reflects current filters.
useEffect( () => {
if (
! isShallowEqual( previousCheckedQuery, currentCheckedQuery ) && // checked query changed
! isShallowEqual( checked, currentCheckedQuery ) // checked query doesn't match the UI
! isShallowEqual( previousCheckedQuery, currentCheckedQuery ) && // Checked query changed.
! isShallowEqual( checked, currentCheckedQuery ) // Checked query doesn't match the UI.
) {
setChecked( currentCheckedQuery );
}
Expand All @@ -192,19 +197,7 @@ const StockStatusFilterBlock = ( {
const filterRemovedName = filterRemoved
? getFilterNameFromValue( filterRemoved )
: null;
if ( filterAddedName && filterRemovedName ) {
speak(
sprintf(
/* translators: %1$s and %2$s are stock statuses (for example: 'instock'...). */
__(
'%1$s filter replaced with %2$s.',
'woo-gutenberg-products-block'
),
filterAddedName,
filterRemovedName
)
);
} else if ( filterAddedName ) {
if ( filterAddedName ) {
speak(
sprintf(
/* translators: %s stock statuses (for example: 'instock'...) */
Expand Down
1 change: 0 additions & 1 deletion assets/js/blocks/stock-filter/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';

import { InspectorControls } from '@wordpress/block-editor';
import {
Disabled,
Expand Down
17 changes: 2 additions & 15 deletions assets/js/blocks/stock-filter/style.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
.wc-block-stock-filter {
margin-bottom: $gap-large;

.wc-block-stock-filter-list-count {
&::before {
content: " (";
}
&::after {
content: ")";
}
}

.wc-block-stock-filter-list {
margin: 0;

Expand All @@ -25,14 +16,10 @@
display: inline-block;
}
}

.wc-block-stock-filter-list-count {
float: right;
}
}

.is-single .wc-block-stock-filter-list-count,
.wc-block-dropdown-selector .wc-block-dropdown-selector__list .wc-block-stock-filter-list-count {
.is-single,
.wc-block-dropdown-selector .wc-block-dropdown-selector__list {
opacity: 0.6;
}

Expand Down
2 changes: 2 additions & 0 deletions src/BlockTypes/StockFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ class StockFilter extends AbstractBlock {
protected function enqueue_data( array $stock_statuses = [] ) {
parent::enqueue_data( $stock_statuses );
$this->asset_data_registry->add( 'stockStatusOptions', wc_get_product_stock_status_options(), true );
$this->asset_data_registry->add( 'hideOutOfStockItems', 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ), true );

}
}
2 changes: 1 addition & 1 deletion src/StoreApi/Schemas/ProductCollectionDataSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function get_properties() {
'properties' => [
'status' => [
'description' => __( 'Status', 'woo-gutenberg-products-block' ),
'type' => 'integer',
'type' => 'string',
'context' => [ 'view', 'edit' ],
'readonly' => true,
],
Expand Down

0 comments on commit a63dbce

Please sign in to comment.