Skip to content

Commit

Permalink
handle a case with dots in category name
Browse files Browse the repository at this point in the history
  • Loading branch information
rezkiy37 committed Oct 18, 2023
1 parent 9fa9bca commit 21a25fa
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2726,6 +2726,8 @@ const CONST = {
},
INDENTS: ' ',
PARENT_CHILD_SEPARATOR: ': ',
PATH_DOT: '.',
PATH_DOT_REPLACER: 'TEMPORARY_REPLACEMENT_FOR_DOT',
CATEGORY_LIST_THRESHOLD: 8,
TAG_LIST_THRESHOLD: 8,
DEMO_PAGES: {
Expand Down
5 changes: 3 additions & 2 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,8 @@ function sortCategories(categories) {
* }
*/
_.each(categories, (category) => {
const path = category.name.replaceAll(CONST.PARENT_CHILD_SEPARATOR, '.');
const safeCategoryName = category.name.replaceAll(CONST.PATH_DOT, CONST.PATH_DOT_REPLACER);
const path = safeCategoryName.replaceAll(CONST.PARENT_CHILD_SEPARATOR, CONST.PATH_DOT);
const existedValue = lodashGet(hierarchy, path, {});

lodashSet(hierarchy, path, {
Expand All @@ -693,7 +694,7 @@ function sortCategories(categories) {
if (!_.isEmpty(name)) {
const categoryObject = {
name,
enabled: lodashGet(categories, `${name}.enabled`, false),
enabled: lodashGet(categories, [name, 'enabled'], false),
};

acc.push(categoryObject);
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1928,9 +1928,54 @@ describe('OptionsListUtils', () => {
name: 'Taxi',
},
];
const categoriesIncorrectOrdering3 = {
'Movies: Mr. Nobody': {
enabled: true,
name: 'Movies: Mr. Nobody',
},
Movies: {
enabled: true,
name: 'Movies',
},
'Dr. House': {
enabled: true,
name: 'Dr. House',
},
'Many.dots.on.the.way.': {
enabled: true,
name: 'Many.dots.on.the.way.',
},
'More.Many.dots.on.the.way.': {
enabled: false,
name: 'More.Many.dots.on.the.way.',
},
};
const result3 = [
{
enabled: true,
name: 'Movies',
},
{
enabled: true,
name: 'Movies: Mr. Nobody',
},
{
enabled: true,
name: 'Dr. House',
},
{
enabled: true,
name: 'Many.dots.on.the.way.',
},
{
enabled: false,
name: 'More.Many.dots.on.the.way.',
},
];

expect(OptionsListUtils.sortCategories(categoriesIncorrectOrdering)).toStrictEqual(result);
expect(OptionsListUtils.sortCategories(categoriesIncorrectOrdering2)).toStrictEqual(result2);
expect(OptionsListUtils.sortCategories(categoriesIncorrectOrdering3)).toStrictEqual(result3);
});

it('formatMemberForList()', () => {
Expand Down

0 comments on commit 21a25fa

Please sign in to comment.