woocommerce/plugins/woocommerce-blocks/assets/js/utils/attributes.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

Filter all products block by attribute (https://github.com/woocommerce/woocommerce-blocks/pull/1127) * Block setup * Working filtering and intersection of arrays * Implement block settings and no attribute placeholder * Correctly toggle counts * Implement filtering * Fix price slider constraints * Fix price slider constraints * Edit mode * Rename ProductAttributeControl to ProductAttributeTermControl * Attribute ID saving * fix incorrect test fixtures * fix incorrect regex for parsing model (or resource names) from the route. * Fix query classes for some endpoints * Style improvements * Update inline comments * use previous tests * Show attribute control in sidebar * Remove displayStyle option * Sort attributes by name * Show more/less toggle * Use renderFrontend * Only sort when adding values * Rename memo placeholder * More specific CSS for pointer * Update assets/js/base/hooks/use-query-state.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove always true taxonomy check * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove lodash join * native js for string casting * Move internal deps * hyphenate attributes * Correct data set names * Remove unwanted dependency * Moving imports * Missing deps * replace yoda conditonal * Missing deps * Missing deps * Check value exists * Remove undefined filter * renderedOptions usememo * Set defaults in checkbox list * Show more/less refactor * Use getAdminLink * Fix object length check * Correct AND query handling for counts * useQueryStateByContext * Add store rest endpoints * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Feedback * feedback * API readme * Fix API relation queries for multiple attributes * Prevent all options flashing visible during loads * null check * Improve loading state * Remove null options change - it's no longer needed
2019-11-11 10:32:56 +00:00
/**
* External dependencies
*/
Move Block Type Settings into Block Type Classes (https://github.com/woocommerce/woocommerce-blocks/pull/4059) * BLOCK SETTINGS: Remove unused constants/settings * AssetDataRegistry: Helpers to check for settings that exist, and registering page ID/permalinks * Move checkout and cart block settings to checkout and cart blocktypes * Move isShippingCalculatorEnabled to cart block * Remove HAS_DARK_EDITOR_STYLE_SUPPORT and IS_SHIPPING_CALCULATOR_ENABLED in favour of getSetting * Move displayCartPricesIncludingTax to blocktypes, and implement getSetting * Move block settings to core settings and blocktypes * Fix namespace usage * Move review settings * move tag settings * Keep productCount in core data * Move min and default height * Improve storePages code * Move attributes to attribute filter block type * Move $word_count_type outside of settings array * Remove unneeded setting in preview data (shippingCostRequiresAddress) * Move min/max settings dependency from GridLayoutControl to Blocks themselves and use getSettings * DEFAULT_COLUMNS and ROWS to settings * Move product columns/rows to block types * Add grid settings to AllProducts block * Correct default rows * correct min rows default * Move hasDarkEditorStyleSupport * Move hideOutOfStockItems to block type settings * Move build settings to inline script dependency * Pass data through asset api and move restApiRoutes * Export all core settings as constants * Remove WORD_COUNT_TYPE from core settings * Move some other core settings to assets * Update constants * Make settings use TypeScript * Update CURRENT_USER_IS_ADMIN usage * WORD_COUNT_TYPE * REST_API_ROUTES * REVIEW_RATINGS_ENABLED and SHOW_AVATARS * Remove REVIEW_RATINGS_ENABLED and SHOW_AVATARS constants * Remove MIN_HEIGHT * Remove DEFAULT_HEIGHT * PLACEHOLDER_IMG_SRC * LIMIT_TAGS * HAS_PRODUCTS * HOME_URL * HAS_TAGS * COUPONS_ENABLED * SHIPPING_ENABLED * TAXES_ENABLED * DISPLAY_ITEMIZED_TAXES * SHIPPING_COST_REQUIRES_ADDRESS * SHIPPING_STATES and SHIPPING_COUNTRIES * STORE_PAGES * ALLOWED_COUNTRIES * ALLOWED_STATES * SHIPPING_METHODS_EXIST * PAYMENT_GATEWAY_SORT_ORDER * CHECKOUT_SHOW_LOGIN_REMINDER * CHECKOUT_ALLOWS_GUEST and CHECKOUT_ALLOWS_SIGNUP * ATTRIBUTES * DISPLAY_CART_PRICES_INCLUDING_TAX * DISPLAY_CART_PRICES_INCLUDING_TAX * update build for TS files * fix build dir * Move blocks build config params * Move placeholderImgSrc to core settings * Move rest api hydration hoc to shared hocs and provide it restApiRoutes directly to avoid asset data registration * Move wordCountType to abstract block * Remove WORD_COUNT_TYPE in favour of getSetting * Move IS_LARGE_CATALOG and PRODUCT_COUNT to abstract block type and use getSetting inline * Add wcBlocksConfig * fix tests * Remove unused $asset_data_registry * remove console.log * Move build settings to abstract block * Trigger build again * Move hydration back to regular hocs for compatibility with trunk (merge conflict) * Removed wcSharedHocsConfig * esc home url * Update search fixture * Update search snap * 40000 timeout * hasProducts -> productCount * Product Count is part of blocks config * update mocks * Use version comparison to determine if batching is enabled * Change isWpVersion * scrollTo button
2021-04-22 11:37:27 +00:00
import { getSetting } from '@woocommerce/settings';
const ATTRIBUTES = getSetting( 'attributes', [] );
Filter all products block by attribute (https://github.com/woocommerce/woocommerce-blocks/pull/1127) * Block setup * Working filtering and intersection of arrays * Implement block settings and no attribute placeholder * Correctly toggle counts * Implement filtering * Fix price slider constraints * Fix price slider constraints * Edit mode * Rename ProductAttributeControl to ProductAttributeTermControl * Attribute ID saving * fix incorrect test fixtures * fix incorrect regex for parsing model (or resource names) from the route. * Fix query classes for some endpoints * Style improvements * Update inline comments * use previous tests * Show attribute control in sidebar * Remove displayStyle option * Sort attributes by name * Show more/less toggle * Use renderFrontend * Only sort when adding values * Rename memo placeholder * More specific CSS for pointer * Update assets/js/base/hooks/use-query-state.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove always true taxonomy check * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove lodash join * native js for string casting * Move internal deps * hyphenate attributes * Correct data set names * Remove unwanted dependency * Moving imports * Missing deps * replace yoda conditonal * Missing deps * Missing deps * Check value exists * Remove undefined filter * renderedOptions usememo * Set defaults in checkbox list * Show more/less refactor * Use getAdminLink * Fix object length check * Correct AND query handling for counts * useQueryStateByContext * Add store rest endpoints * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Feedback * feedback * API readme * Fix API relation queries for multiple attributes * Prevent all options flashing visible during loads * null check * Improve loading state * Remove null options change - it's no longer needed
2019-11-11 10:32:56 +00:00
/**
Active filters block (https://github.com/woocommerce/woocommerce-blocks/pull/1168) * Basic block construction * Register on PHP side * wc-active-filters script * Price utils * Refactor price slider so state reflects the query Moves some logic from the component to the block so that min and max price can change (via query) and be reflected by the price sliders. This allows the active filters block to change the query and have those new values reflected by the slider. * Fix type checking of numbers * Styles for filter block * Improved attribute helper for getting attribute taxonomy data from ID/taxonomy * Refactor attribute filter to use updateAttributeFilter helper * Disable checkboxes when loading to avoid multiple queries * Add todos - this is blocked * Remove checked state from Attribute Filter so it gets updated from the store (https://github.com/woocommerce/woocommerce-blocks/pull/1170) * isLoading check * active price filtering rendering * Block heading * Implement block options; chip display with clear button * Clear all should remove all attributes * Enable previews * Introduce a component to look up terms from slugs using collections (which are cached) * Correct all docblocks * activePriceFilters null return * renderRemovableListItem * Remove useMemo for hasFilters * Switch classnames notation * Ensure slug is array in removeAttributeFilterBySlug * null -> undefined return types for attributes * Remove fragment * Check we have a termObject in ActiveAttributeFilters * Refactor formatPriceRange return statements * Ensure query array index will exist * Only sort when adding a query * Remove aria-label with dupe text * hasFilters is function * Update useQueryStateByKey usage * More doc block fixes * Update getAttributeFromTaxonomy return and docblock * getAttributeFromID return/docblock
2019-11-15 14:41:23 +00:00
* Format an attribute from the settings into an object with standardized keys.
*
* @param {Object} attribute The attribute object.
Active filters block (https://github.com/woocommerce/woocommerce-blocks/pull/1168) * Basic block construction * Register on PHP side * wc-active-filters script * Price utils * Refactor price slider so state reflects the query Moves some logic from the component to the block so that min and max price can change (via query) and be reflected by the price sliders. This allows the active filters block to change the query and have those new values reflected by the slider. * Fix type checking of numbers * Styles for filter block * Improved attribute helper for getting attribute taxonomy data from ID/taxonomy * Refactor attribute filter to use updateAttributeFilter helper * Disable checkboxes when loading to avoid multiple queries * Add todos - this is blocked * Remove checked state from Attribute Filter so it gets updated from the store (https://github.com/woocommerce/woocommerce-blocks/pull/1170) * isLoading check * active price filtering rendering * Block heading * Implement block options; chip display with clear button * Clear all should remove all attributes * Enable previews * Introduce a component to look up terms from slugs using collections (which are cached) * Correct all docblocks * activePriceFilters null return * renderRemovableListItem * Remove useMemo for hasFilters * Switch classnames notation * Ensure slug is array in removeAttributeFilterBySlug * null -> undefined return types for attributes * Remove fragment * Check we have a termObject in ActiveAttributeFilters * Refactor formatPriceRange return statements * Ensure query array index will exist * Only sort when adding a query * Remove aria-label with dupe text * hasFilters is function * Update useQueryStateByKey usage * More doc block fixes * Update getAttributeFromTaxonomy return and docblock * getAttributeFromID return/docblock
2019-11-15 14:41:23 +00:00
*/
const attributeSettingToObject = ( attribute ) => {
if ( ! attribute || ! attribute.attribute_name ) {
return null;
}
return {
id: parseInt( attribute.attribute_id, 10 ),
name: attribute.attribute_name,
taxonomy: 'pa_' + attribute.attribute_name,
label: attribute.attribute_label,
};
};
/**
* Format all attribute settings into objects.
*/
const attributeObjects = ATTRIBUTES.reduce( ( acc, current ) => {
const attributeObject = attributeSettingToObject( current );
if ( attributeObject.id ) {
acc.push( attributeObject );
}
return acc;
}, [] );
/**
* Get attribute data by taxonomy.
Filter all products block by attribute (https://github.com/woocommerce/woocommerce-blocks/pull/1127) * Block setup * Working filtering and intersection of arrays * Implement block settings and no attribute placeholder * Correctly toggle counts * Implement filtering * Fix price slider constraints * Fix price slider constraints * Edit mode * Rename ProductAttributeControl to ProductAttributeTermControl * Attribute ID saving * fix incorrect test fixtures * fix incorrect regex for parsing model (or resource names) from the route. * Fix query classes for some endpoints * Style improvements * Update inline comments * use previous tests * Show attribute control in sidebar * Remove displayStyle option * Sort attributes by name * Show more/less toggle * Use renderFrontend * Only sort when adding values * Rename memo placeholder * More specific CSS for pointer * Update assets/js/base/hooks/use-query-state.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove always true taxonomy check * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove lodash join * native js for string casting * Move internal deps * hyphenate attributes * Correct data set names * Remove unwanted dependency * Moving imports * Missing deps * replace yoda conditonal * Missing deps * Missing deps * Check value exists * Remove undefined filter * renderedOptions usememo * Set defaults in checkbox list * Show more/less refactor * Use getAdminLink * Fix object length check * Correct AND query handling for counts * useQueryStateByContext * Add store rest endpoints * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Feedback * feedback * API readme * Fix API relation queries for multiple attributes * Prevent all options flashing visible during loads * null check * Improve loading state * Remove null options change - it's no longer needed
2019-11-11 10:32:56 +00:00
*
* @param {number} attributeId The attribute ID.
Active filters block (https://github.com/woocommerce/woocommerce-blocks/pull/1168) * Basic block construction * Register on PHP side * wc-active-filters script * Price utils * Refactor price slider so state reflects the query Moves some logic from the component to the block so that min and max price can change (via query) and be reflected by the price sliders. This allows the active filters block to change the query and have those new values reflected by the slider. * Fix type checking of numbers * Styles for filter block * Improved attribute helper for getting attribute taxonomy data from ID/taxonomy * Refactor attribute filter to use updateAttributeFilter helper * Disable checkboxes when loading to avoid multiple queries * Add todos - this is blocked * Remove checked state from Attribute Filter so it gets updated from the store (https://github.com/woocommerce/woocommerce-blocks/pull/1170) * isLoading check * active price filtering rendering * Block heading * Implement block options; chip display with clear button * Clear all should remove all attributes * Enable previews * Introduce a component to look up terms from slugs using collections (which are cached) * Correct all docblocks * activePriceFilters null return * renderRemovableListItem * Remove useMemo for hasFilters * Switch classnames notation * Ensure slug is array in removeAttributeFilterBySlug * null -> undefined return types for attributes * Remove fragment * Check we have a termObject in ActiveAttributeFilters * Refactor formatPriceRange return statements * Ensure query array index will exist * Only sort when adding a query * Remove aria-label with dupe text * hasFilters is function * Update useQueryStateByKey usage * More doc block fixes * Update getAttributeFromTaxonomy return and docblock * getAttributeFromID return/docblock
2019-11-15 14:41:23 +00:00
* @return {Object|undefined} The attribute object if it exists.
Filter all products block by attribute (https://github.com/woocommerce/woocommerce-blocks/pull/1127) * Block setup * Working filtering and intersection of arrays * Implement block settings and no attribute placeholder * Correctly toggle counts * Implement filtering * Fix price slider constraints * Fix price slider constraints * Edit mode * Rename ProductAttributeControl to ProductAttributeTermControl * Attribute ID saving * fix incorrect test fixtures * fix incorrect regex for parsing model (or resource names) from the route. * Fix query classes for some endpoints * Style improvements * Update inline comments * use previous tests * Show attribute control in sidebar * Remove displayStyle option * Sort attributes by name * Show more/less toggle * Use renderFrontend * Only sort when adding values * Rename memo placeholder * More specific CSS for pointer * Update assets/js/base/hooks/use-query-state.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove always true taxonomy check * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove lodash join * native js for string casting * Move internal deps * hyphenate attributes * Correct data set names * Remove unwanted dependency * Moving imports * Missing deps * replace yoda conditonal * Missing deps * Missing deps * Check value exists * Remove undefined filter * renderedOptions usememo * Set defaults in checkbox list * Show more/less refactor * Use getAdminLink * Fix object length check * Correct AND query handling for counts * useQueryStateByContext * Add store rest endpoints * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Feedback * feedback * API readme * Fix API relation queries for multiple attributes * Prevent all options flashing visible during loads * null check * Improve loading state * Remove null options change - it's no longer needed
2019-11-11 10:32:56 +00:00
*/
Active filters block (https://github.com/woocommerce/woocommerce-blocks/pull/1168) * Basic block construction * Register on PHP side * wc-active-filters script * Price utils * Refactor price slider so state reflects the query Moves some logic from the component to the block so that min and max price can change (via query) and be reflected by the price sliders. This allows the active filters block to change the query and have those new values reflected by the slider. * Fix type checking of numbers * Styles for filter block * Improved attribute helper for getting attribute taxonomy data from ID/taxonomy * Refactor attribute filter to use updateAttributeFilter helper * Disable checkboxes when loading to avoid multiple queries * Add todos - this is blocked * Remove checked state from Attribute Filter so it gets updated from the store (https://github.com/woocommerce/woocommerce-blocks/pull/1170) * isLoading check * active price filtering rendering * Block heading * Implement block options; chip display with clear button * Clear all should remove all attributes * Enable previews * Introduce a component to look up terms from slugs using collections (which are cached) * Correct all docblocks * activePriceFilters null return * renderRemovableListItem * Remove useMemo for hasFilters * Switch classnames notation * Ensure slug is array in removeAttributeFilterBySlug * null -> undefined return types for attributes * Remove fragment * Check we have a termObject in ActiveAttributeFilters * Refactor formatPriceRange return statements * Ensure query array index will exist * Only sort when adding a query * Remove aria-label with dupe text * hasFilters is function * Update useQueryStateByKey usage * More doc block fixes * Update getAttributeFromTaxonomy return and docblock * getAttributeFromID return/docblock
2019-11-15 14:41:23 +00:00
export const getAttributeFromID = ( attributeId ) => {
Filter all products block by attribute (https://github.com/woocommerce/woocommerce-blocks/pull/1127) * Block setup * Working filtering and intersection of arrays * Implement block settings and no attribute placeholder * Correctly toggle counts * Implement filtering * Fix price slider constraints * Fix price slider constraints * Edit mode * Rename ProductAttributeControl to ProductAttributeTermControl * Attribute ID saving * fix incorrect test fixtures * fix incorrect regex for parsing model (or resource names) from the route. * Fix query classes for some endpoints * Style improvements * Update inline comments * use previous tests * Show attribute control in sidebar * Remove displayStyle option * Sort attributes by name * Show more/less toggle * Use renderFrontend * Only sort when adding values * Rename memo placeholder * More specific CSS for pointer * Update assets/js/base/hooks/use-query-state.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove always true taxonomy check * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove lodash join * native js for string casting * Move internal deps * hyphenate attributes * Correct data set names * Remove unwanted dependency * Moving imports * Missing deps * replace yoda conditonal * Missing deps * Missing deps * Check value exists * Remove undefined filter * renderedOptions usememo * Set defaults in checkbox list * Show more/less refactor * Use getAdminLink * Fix object length check * Correct AND query handling for counts * useQueryStateByContext * Add store rest endpoints * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Feedback * feedback * API readme * Fix API relation queries for multiple attributes * Prevent all options flashing visible during loads * null check * Improve loading state * Remove null options change - it's no longer needed
2019-11-11 10:32:56 +00:00
if ( ! attributeId ) {
Active filters block (https://github.com/woocommerce/woocommerce-blocks/pull/1168) * Basic block construction * Register on PHP side * wc-active-filters script * Price utils * Refactor price slider so state reflects the query Moves some logic from the component to the block so that min and max price can change (via query) and be reflected by the price sliders. This allows the active filters block to change the query and have those new values reflected by the slider. * Fix type checking of numbers * Styles for filter block * Improved attribute helper for getting attribute taxonomy data from ID/taxonomy * Refactor attribute filter to use updateAttributeFilter helper * Disable checkboxes when loading to avoid multiple queries * Add todos - this is blocked * Remove checked state from Attribute Filter so it gets updated from the store (https://github.com/woocommerce/woocommerce-blocks/pull/1170) * isLoading check * active price filtering rendering * Block heading * Implement block options; chip display with clear button * Clear all should remove all attributes * Enable previews * Introduce a component to look up terms from slugs using collections (which are cached) * Correct all docblocks * activePriceFilters null return * renderRemovableListItem * Remove useMemo for hasFilters * Switch classnames notation * Ensure slug is array in removeAttributeFilterBySlug * null -> undefined return types for attributes * Remove fragment * Check we have a termObject in ActiveAttributeFilters * Refactor formatPriceRange return statements * Ensure query array index will exist * Only sort when adding a query * Remove aria-label with dupe text * hasFilters is function * Update useQueryStateByKey usage * More doc block fixes * Update getAttributeFromTaxonomy return and docblock * getAttributeFromID return/docblock
2019-11-15 14:41:23 +00:00
return;
Filter all products block by attribute (https://github.com/woocommerce/woocommerce-blocks/pull/1127) * Block setup * Working filtering and intersection of arrays * Implement block settings and no attribute placeholder * Correctly toggle counts * Implement filtering * Fix price slider constraints * Fix price slider constraints * Edit mode * Rename ProductAttributeControl to ProductAttributeTermControl * Attribute ID saving * fix incorrect test fixtures * fix incorrect regex for parsing model (or resource names) from the route. * Fix query classes for some endpoints * Style improvements * Update inline comments * use previous tests * Show attribute control in sidebar * Remove displayStyle option * Sort attributes by name * Show more/less toggle * Use renderFrontend * Only sort when adding values * Rename memo placeholder * More specific CSS for pointer * Update assets/js/base/hooks/use-query-state.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove always true taxonomy check * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove lodash join * native js for string casting * Move internal deps * hyphenate attributes * Correct data set names * Remove unwanted dependency * Moving imports * Missing deps * replace yoda conditonal * Missing deps * Missing deps * Check value exists * Remove undefined filter * renderedOptions usememo * Set defaults in checkbox list * Show more/less refactor * Use getAdminLink * Fix object length check * Correct AND query handling for counts * useQueryStateByContext * Add store rest endpoints * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Feedback * feedback * API readme * Fix API relation queries for multiple attributes * Prevent all options flashing visible during loads * null check * Improve loading state * Remove null options change - it's no longer needed
2019-11-11 10:32:56 +00:00
}
Active filters block (https://github.com/woocommerce/woocommerce-blocks/pull/1168) * Basic block construction * Register on PHP side * wc-active-filters script * Price utils * Refactor price slider so state reflects the query Moves some logic from the component to the block so that min and max price can change (via query) and be reflected by the price sliders. This allows the active filters block to change the query and have those new values reflected by the slider. * Fix type checking of numbers * Styles for filter block * Improved attribute helper for getting attribute taxonomy data from ID/taxonomy * Refactor attribute filter to use updateAttributeFilter helper * Disable checkboxes when loading to avoid multiple queries * Add todos - this is blocked * Remove checked state from Attribute Filter so it gets updated from the store (https://github.com/woocommerce/woocommerce-blocks/pull/1170) * isLoading check * active price filtering rendering * Block heading * Implement block options; chip display with clear button * Clear all should remove all attributes * Enable previews * Introduce a component to look up terms from slugs using collections (which are cached) * Correct all docblocks * activePriceFilters null return * renderRemovableListItem * Remove useMemo for hasFilters * Switch classnames notation * Ensure slug is array in removeAttributeFilterBySlug * null -> undefined return types for attributes * Remove fragment * Check we have a termObject in ActiveAttributeFilters * Refactor formatPriceRange return statements * Ensure query array index will exist * Only sort when adding a query * Remove aria-label with dupe text * hasFilters is function * Update useQueryStateByKey usage * More doc block fixes * Update getAttributeFromTaxonomy return and docblock * getAttributeFromID return/docblock
2019-11-15 14:41:23 +00:00
return attributeObjects.find( ( attribute ) => {
return attribute.id === attributeId;
} );
};
Filter all products block by attribute (https://github.com/woocommerce/woocommerce-blocks/pull/1127) * Block setup * Working filtering and intersection of arrays * Implement block settings and no attribute placeholder * Correctly toggle counts * Implement filtering * Fix price slider constraints * Fix price slider constraints * Edit mode * Rename ProductAttributeControl to ProductAttributeTermControl * Attribute ID saving * fix incorrect test fixtures * fix incorrect regex for parsing model (or resource names) from the route. * Fix query classes for some endpoints * Style improvements * Update inline comments * use previous tests * Show attribute control in sidebar * Remove displayStyle option * Sort attributes by name * Show more/less toggle * Use renderFrontend * Only sort when adding values * Rename memo placeholder * More specific CSS for pointer * Update assets/js/base/hooks/use-query-state.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove always true taxonomy check * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove lodash join * native js for string casting * Move internal deps * hyphenate attributes * Correct data set names * Remove unwanted dependency * Moving imports * Missing deps * replace yoda conditonal * Missing deps * Missing deps * Check value exists * Remove undefined filter * renderedOptions usememo * Set defaults in checkbox list * Show more/less refactor * Use getAdminLink * Fix object length check * Correct AND query handling for counts * useQueryStateByContext * Add store rest endpoints * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Feedback * feedback * API readme * Fix API relation queries for multiple attributes * Prevent all options flashing visible during loads * null check * Improve loading state * Remove null options change - it's no longer needed
2019-11-11 10:32:56 +00:00
Active filters block (https://github.com/woocommerce/woocommerce-blocks/pull/1168) * Basic block construction * Register on PHP side * wc-active-filters script * Price utils * Refactor price slider so state reflects the query Moves some logic from the component to the block so that min and max price can change (via query) and be reflected by the price sliders. This allows the active filters block to change the query and have those new values reflected by the slider. * Fix type checking of numbers * Styles for filter block * Improved attribute helper for getting attribute taxonomy data from ID/taxonomy * Refactor attribute filter to use updateAttributeFilter helper * Disable checkboxes when loading to avoid multiple queries * Add todos - this is blocked * Remove checked state from Attribute Filter so it gets updated from the store (https://github.com/woocommerce/woocommerce-blocks/pull/1170) * isLoading check * active price filtering rendering * Block heading * Implement block options; chip display with clear button * Clear all should remove all attributes * Enable previews * Introduce a component to look up terms from slugs using collections (which are cached) * Correct all docblocks * activePriceFilters null return * renderRemovableListItem * Remove useMemo for hasFilters * Switch classnames notation * Ensure slug is array in removeAttributeFilterBySlug * null -> undefined return types for attributes * Remove fragment * Check we have a termObject in ActiveAttributeFilters * Refactor formatPriceRange return statements * Ensure query array index will exist * Only sort when adding a query * Remove aria-label with dupe text * hasFilters is function * Update useQueryStateByKey usage * More doc block fixes * Update getAttributeFromTaxonomy return and docblock * getAttributeFromID return/docblock
2019-11-15 14:41:23 +00:00
/**
* Get attribute data by taxonomy.
*
* @param {string} taxonomy The attribute taxonomy name e.g. pa_color.
* @return {Object|undefined} The attribute object if it exists.
*/
export const getAttributeFromTaxonomy = ( taxonomy ) => {
if ( ! taxonomy ) {
return;
}
return attributeObjects.find( ( attribute ) => {
return attribute.taxonomy === taxonomy;
} );
};
Filter all products block by attribute (https://github.com/woocommerce/woocommerce-blocks/pull/1127) * Block setup * Working filtering and intersection of arrays * Implement block settings and no attribute placeholder * Correctly toggle counts * Implement filtering * Fix price slider constraints * Fix price slider constraints * Edit mode * Rename ProductAttributeControl to ProductAttributeTermControl * Attribute ID saving * fix incorrect test fixtures * fix incorrect regex for parsing model (or resource names) from the route. * Fix query classes for some endpoints * Style improvements * Update inline comments * use previous tests * Show attribute control in sidebar * Remove displayStyle option * Sort attributes by name * Show more/less toggle * Use renderFrontend * Only sort when adding values * Rename memo placeholder * More specific CSS for pointer * Update assets/js/base/hooks/use-query-state.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove always true taxonomy check * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Remove lodash join * native js for string casting * Move internal deps * hyphenate attributes * Correct data set names * Remove unwanted dependency * Moving imports * Missing deps * replace yoda conditonal * Missing deps * Missing deps * Check value exists * Remove undefined filter * renderedOptions usememo * Set defaults in checkbox list * Show more/less refactor * Use getAdminLink * Fix object length check * Correct AND query handling for counts * useQueryStateByContext * Add store rest endpoints * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/base/components/checkbox-list/index.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Update assets/js/blocks/attribute-filter/block.js Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com> * Feedback * feedback * API readme * Fix API relation queries for multiple attributes * Prevent all options flashing visible during loads * null check * Improve loading state * Remove null options change - it's no longer needed
2019-11-11 10:32:56 +00:00
Active filters block (https://github.com/woocommerce/woocommerce-blocks/pull/1168) * Basic block construction * Register on PHP side * wc-active-filters script * Price utils * Refactor price slider so state reflects the query Moves some logic from the component to the block so that min and max price can change (via query) and be reflected by the price sliders. This allows the active filters block to change the query and have those new values reflected by the slider. * Fix type checking of numbers * Styles for filter block * Improved attribute helper for getting attribute taxonomy data from ID/taxonomy * Refactor attribute filter to use updateAttributeFilter helper * Disable checkboxes when loading to avoid multiple queries * Add todos - this is blocked * Remove checked state from Attribute Filter so it gets updated from the store (https://github.com/woocommerce/woocommerce-blocks/pull/1170) * isLoading check * active price filtering rendering * Block heading * Implement block options; chip display with clear button * Clear all should remove all attributes * Enable previews * Introduce a component to look up terms from slugs using collections (which are cached) * Correct all docblocks * activePriceFilters null return * renderRemovableListItem * Remove useMemo for hasFilters * Switch classnames notation * Ensure slug is array in removeAttributeFilterBySlug * null -> undefined return types for attributes * Remove fragment * Check we have a termObject in ActiveAttributeFilters * Refactor formatPriceRange return statements * Ensure query array index will exist * Only sort when adding a query * Remove aria-label with dupe text * hasFilters is function * Update useQueryStateByKey usage * More doc block fixes * Update getAttributeFromTaxonomy return and docblock * getAttributeFromID return/docblock
2019-11-15 14:41:23 +00:00
/**
* Get the taxonomy of an attribute by Attribute ID.
*
* @param {number} attributeId The attribute ID.
* @return {string} The taxonomy name.
*/
export const getTaxonomyFromAttributeId = ( attributeId ) => {
if ( ! attributeId ) {
return null;
}
const attribute = getAttributeFromID( attributeId );
return attribute ? attribute.taxonomy : null;
};