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

Commit

Permalink
Pre pull request clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
grogou committed Apr 28, 2021
1 parent 105b3f7 commit 5e0c7f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
8 changes: 3 additions & 5 deletions assets/js/base/components/product-list/product-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,16 @@ const generateQuery = ( {
'stock_status',
[]
);
// @todo Find way to exclude "outofstock" from existing product filters.
if ( hideOutOfStockItems ) {
let newStockStatus = [];
let newStockStatus = [ 'instock', 'onbackorder' ];
if ( productStockStatus.length > 0 ) {
newStockStatus = productStockStatus;
if ( productStockStatus.includes( 'outofstock' ) ) {
newStockStatus = productStockStatus.filter(
( slug ) => slug !== 'outofstock'
);
} else {
newStockStatus = productStockStatus;
}
} else {
newStockStatus = [ 'instock', 'onbackorder' ];
}
setProductStockStatus( newStockStatus );
}
Expand Down
26 changes: 13 additions & 13 deletions assets/js/blocks/stock-filter/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const StockStatusFilterBlock = ( {
);

/**
* Compare intersection of all stock stauses and filtered counts to get a list of options to display.
* Compare intersection of all stock statuses and filtered counts to get a list of options to display.
*/
useEffect( () => {
/**
Expand Down Expand Up @@ -137,6 +137,18 @@ const StockStatusFilterBlock = ( {
queryState.stock_status,
] );

const onSubmit = useCallback(
( isChecked ) => {
if ( isEditor ) {
return;
}
if ( isChecked ) {
setProductStockStatusQuery( checked );
}
},
[ isEditor, setProductStockStatusQuery, checked ]
);

// Track checked STATE changes - if state changes, update the query.
useEffect( () => {
if ( ! blockAttributes.showFilterButton ) {
Expand All @@ -160,18 +172,6 @@ const StockStatusFilterBlock = ( {
}
}, [ checked, currentCheckedQuery, previousCheckedQuery ] );

const onSubmit = useCallback(
( isChecked ) => {
if ( isEditor ) {
return;
}
if ( isChecked ) {
setProductStockStatusQuery( checked );
}
},
[ isEditor, setProductStockStatusQuery, checked ]
);

/**
* When a checkbox in the list changes, update state.
*/
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 @@ -12,7 +12,6 @@ import {
} from '@wordpress/components';
import HeadingToolbar from '@woocommerce/editor-components/heading-toolbar';
import BlockTitle from '@woocommerce/editor-components/block-title';
// import { useState } from '@wordpress/element';

/**
* Internal dependencies
Expand Down

0 comments on commit 5e0c7f9

Please sign in to comment.