Skip to content

Commit

Permalink
fix(MWPW-152338): handles &s in custom localized custom filters
Browse files Browse the repository at this point in the history
  • Loading branch information
cmiqueo committed Jun 17, 2024
1 parent ad472da commit 4f66c56
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion dist/app.css

Large diffs are not rendered by default.

34 changes: 20 additions & 14 deletions dist/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Chimera UI Libraries - Build 0.13.1 (6/11/2024, 19:35:09)
* Chimera UI Libraries - Build 0.13.1 (6/17/2024, 13:19:35)
*
*/
/******/ (function(modules) { // webpackBootstrap
Expand Down Expand Up @@ -6211,10 +6211,6 @@ var Container = function Container(props) {
var cardStyle = getConfig('collection', 'cardStyle');
var title = getConfig('collection', 'i18n.title');
var headers = getConfig('headers', '');
// eslint-disable-next-line no-use-before-define
var categories = getConfig('filterPanel', 'categories');
// eslint-disable-next-line no-use-before-define
var authoredCategories = getAuthoredCategories(authoredFilters, categories);

/**
**** Constants ****
Expand All @@ -6225,6 +6221,11 @@ var Container = function Container(props) {
var isStandardContainer = authoredLayoutContainer !== _constants.LAYOUT_CONTAINER.CAROUSEL;
var isCategoriesContainer = authoredLayoutContainer === _constants.LAYOUT_CONTAINER.CATEGORIES;

// eslint-disable-next-line no-use-before-define
var categories = getConfig('filterPanel', 'categories');
// eslint-disable-next-line no-use-before-define, max-len
var authoredCategories = isCategoriesContainer && getAuthoredCategories(authoredFilters, categories);

/**
**** Hooks ****
*/
Expand Down Expand Up @@ -6960,7 +6961,7 @@ var Container = function Container(props) {
return allFilters.map(function (filter) {
return _extends({}, filter, {
items: filter.items.filter(function (item) {
return tags.includes(item.id) || timingTags.includes(item.id);
return tags.includes(item.id) || tags.toString().includes('/' + item.id) || timingTags.includes(item.id);
})
});
}).filter(function (filter) {
Expand Down Expand Up @@ -7525,6 +7526,7 @@ var Container = function Container(props) {
* Prepends the "All products" label to the list of categories
*/
function getAllCategoryProducts() {
if (!authoredCategories) return [];
var allCategories = [];
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
Expand Down Expand Up @@ -7580,7 +7582,7 @@ var Container = function Container(props) {

return {
group: 'All products',
id: 'caas:products',
id: 'caas:all-products',
items: allCategories
};
}
Expand Down Expand Up @@ -7669,10 +7671,12 @@ var Container = function Container(props) {
});

(0, _react.useEffect)(function () {
setFilters(function (prevFilters) {
var nextFilters = prevFilters.concat(getAllCategoryProducts());
return nextFilters;
});
if (isCategoriesContainer) {
setFilters(function (prevFilters) {
var nextFilters = prevFilters.concat(getAllCategoryProducts());
return nextFilters;
});
}
}, []);

return _react2.default.createElement(
Expand Down Expand Up @@ -54078,6 +54082,8 @@ var LeftFilterPanel = (0, _react.forwardRef)(function (_ref, ref) {

var getConfig = (0, _hooks.useConfig)();

console.log('*** Panel.jsx: LeftFilterPanel: Filters:', filters);

/**
**** Authored Configs ****
*/
Expand Down Expand Up @@ -54473,7 +54479,7 @@ var Item = function Item(props) {
id: id + '-link',
onClick: handleClick,
tabIndex: '0' },
name,
name && name.replaceAll('&', '&'),
_react2.default.createElement(
'div',
{
Expand Down Expand Up @@ -54589,7 +54595,7 @@ var Items = function Items(props) {
'span',
{
className: 'consonant-LeftFilter-itemsItemName' },
item.label
item.label && item.label.replaceAll('&', '&')
)
)
);
Expand Down Expand Up @@ -54837,7 +54843,7 @@ var ChosenFilterItem = function ChosenFilterItem(props) {
'data-testid': 'consonant-ChosenFilter',
className: 'consonant-ChosenFilter',
tabIndex: '0' },
name
name.replaceAll('&', '&')
);
};

Expand Down
6 changes: 3 additions & 3 deletions dist/main.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/main.source.js

Large diffs are not rendered by default.

27 changes: 16 additions & 11 deletions react/src/js/components/Consonant/Container/Container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ const Container = (props) => {
const cardStyle = getConfig('collection', 'cardStyle');
const title = getConfig('collection', 'i18n.title');
const headers = getConfig('headers', '');
// eslint-disable-next-line no-use-before-define
const categories = getConfig('filterPanel', 'categories');
// eslint-disable-next-line no-use-before-define
const authoredCategories = getAuthoredCategories(authoredFilters, categories);

/**
**** Constants ****
Expand All @@ -168,6 +164,11 @@ const Container = (props) => {
const isStandardContainer = authoredLayoutContainer !== LAYOUT_CONTAINER.CAROUSEL;
const isCategoriesContainer = authoredLayoutContainer === LAYOUT_CONTAINER.CATEGORIES;

// eslint-disable-next-line no-use-before-define
const categories = getConfig('filterPanel', 'categories');
// eslint-disable-next-line no-use-before-define, max-len
const authoredCategories = isCategoriesContainer && getAuthoredCategories(authoredFilters, categories);

/**
**** Hooks ****
*/
Expand Down Expand Up @@ -743,8 +744,9 @@ const Container = (props) => {

return allFilters.map(filter => ({
...filter,
items: filter.items.filter(item => tags.includes(item.id) ||
timingTags.includes(item.id)),
items: filter.items.filter(item => tags.includes(item.id)
|| tags.toString().includes(`/${item.id}`)
|| timingTags.includes(item.id)),
})).filter(filter => filter.items.length > 0);
};

Expand Down Expand Up @@ -1236,6 +1238,7 @@ const Container = (props) => {
* Prepends the "All products" label to the list of categories
*/
function getAllCategoryProducts() {
if (!authoredCategories) return [];
let allCategories = [];
for (const category of authoredCategories) {
if (category && category.items) {
Expand All @@ -1247,7 +1250,7 @@ const Container = (props) => {
}
return {
group: 'All products',
id: 'caas:products',
id: 'caas:all-products',
items: allCategories,
};
}
Expand Down Expand Up @@ -1311,10 +1314,12 @@ const Container = (props) => {
});

useEffect(() => {
setFilters((prevFilters) => {
const nextFilters = prevFilters.concat(getAllCategoryProducts());
return nextFilters;
});
if (isCategoriesContainer) {
setFilters((prevFilters) => {
const nextFilters = prevFilters.concat(getAllCategoryProducts());
return nextFilters;
});
}
}, []);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const ChosenFilterItem = (props) => {
data-testid="consonant-ChosenFilter"
className="consonant-ChosenFilter"
tabIndex="0">
{name}
{name.replaceAll('&', '&')}
</button>
);
};
Expand Down
2 changes: 1 addition & 1 deletion react/src/js/components/Consonant/Filters/Left/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const Item = (props) => {
id={`${id}-link`}
onClick={handleClick}
tabIndex="0">
{name}
{name && name.replaceAll('&amp;', '&')}
<div
className="consonant-LeftFilter-selectedItemsQty"
data-qty={dataQtyTxt}>
Expand Down
2 changes: 1 addition & 1 deletion react/src/js/components/Consonant/Filters/Left/Items.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const Items = (props) => {
className="consonant-LeftFilter-itemsItemCheckmark" />
<span
className="consonant-LeftFilter-itemsItemName">
{item.label}
{item.label && item.label.replaceAll('&amp;', '&')}
</span>
</label>
</li>
Expand Down
2 changes: 2 additions & 0 deletions react/src/js/components/Consonant/Filters/Left/Panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ const LeftFilterPanel = forwardRef(({
}, ref) => {
const getConfig = useConfig();

console.log('*** Panel.jsx: LeftFilterPanel: Filters:', filters);

Check warning on line 92 in react/src/js/components/Consonant/Filters/Left/Panel.jsx

View workflow job for this annotation

GitHub Actions / check-build

Unexpected console statement

Check warning on line 92 in react/src/js/components/Consonant/Filters/Left/Panel.jsx

View workflow job for this annotation

GitHub Actions / check-build

Unexpected console statement

/**
**** Authored Configs ****
*/
Expand Down

0 comments on commit 4f66c56

Please sign in to comment.