From ea7e89aaf920221fd1724ec3279d2ebf913716a3 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 12 Dec 2023 13:14:27 +0700 Subject: [PATCH 1/7] add selected category first --- src/libs/OptionsListUtils.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 95a8c52649d3..8ff45bc1761e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -846,28 +846,30 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt return categorySections; } - if (numberOfCategories < CONST.CATEGORY_LIST_THRESHOLD) { + if (!_.isEmpty(selectedOptions)) { categorySections.push({ - // "All" section when items amount less than the threshold + // "Selected" section title: '', - shouldShow: false, + shouldShow: true, indexOffset, - data: getIndentedOptionTree(enabledCategories), + data: getIndentedOptionTree(selectedOptions, true), }); - return categorySections; + indexOffset += selectedOptions.length; } - if (!_.isEmpty(selectedOptions)) { + const categoryListThreshold = !_.isEmpty(selectedOptions) ? CONST.CATEGORY_LIST_THRESHOLD - 1 : CONST.CATEGORY_LIST_THRESHOLD; + + if (numberOfCategories < categoryListThreshold) { categorySections.push({ - // "Selected" section + // "All" section when items amount less than the threshold title: '', - shouldShow: true, + shouldShow: false, indexOffset, - data: getIndentedOptionTree(selectedOptions, true), + data: getIndentedOptionTree(enabledCategories), }); - indexOffset += selectedOptions.length; + return categorySections; } const selectedOptionNames = _.map(selectedOptions, (selectedOption) => selectedOption.name); From a9bf6d6cde5f53aa5467a59e6786d15ed4303aec Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 12 Dec 2023 13:32:16 +0700 Subject: [PATCH 2/7] add selected category once --- src/libs/OptionsListUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 8ff45bc1761e..c35d07d2e4d6 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -859,6 +859,8 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt } const categoryListThreshold = !_.isEmpty(selectedOptions) ? CONST.CATEGORY_LIST_THRESHOLD - 1 : CONST.CATEGORY_LIST_THRESHOLD; + const selectedOptionNames = _.map(selectedOptions, (selectedOption) => selectedOption.name); + const filteredCategories = _.filter(enabledCategories, (category) => !_.includes(selectedOptionNames, category.name)); if (numberOfCategories < categoryListThreshold) { categorySections.push({ @@ -866,13 +868,12 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt title: '', shouldShow: false, indexOffset, - data: getIndentedOptionTree(enabledCategories), + data: getIndentedOptionTree(filteredCategories), }); return categorySections; } - const selectedOptionNames = _.map(selectedOptions, (selectedOption) => selectedOption.name); const filteredRecentlyUsedCategories = _.chain(recentlyUsedCategories) .filter((categoryName) => !_.includes(selectedOptionNames, categoryName) && lodashGet(categories, [categoryName, 'enabled'], false)) .map((categoryName) => ({ @@ -895,7 +896,6 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt indexOffset += filteredRecentlyUsedCategories.length; } - const filteredCategories = _.filter(enabledCategories, (category) => !_.includes(selectedOptionNames, category.name)); categorySections.push({ // "All" section when items amount more than the threshold From 61a83f445de2f55e748294e7844440fb27034246 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 12 Dec 2023 13:40:07 +0700 Subject: [PATCH 3/7] fix lint --- src/libs/OptionsListUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index c35d07d2e4d6..93730583c2f1 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -896,7 +896,6 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt indexOffset += filteredRecentlyUsedCategories.length; } - categorySections.push({ // "All" section when items amount more than the threshold title: Localize.translateLocal('common.all'), From 477c3a3166517c6366ef94ad1a2b116ed2d6210e Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 18 Dec 2023 14:07:27 +0700 Subject: [PATCH 4/7] fix lint --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index db7790983978..9375447db9ac 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -868,7 +868,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt title: '', shouldShow: false, indexOffset, - data: getIndentedOptionTree(filteredCategories), + data: getCategoryOptionTree(filteredCategories), }); return categorySections; From 7039ed9a577f3d1308db519e7c3e44ae0d801bd2 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 25 Dec 2023 15:30:26 +0700 Subject: [PATCH 5/7] fix margin bug --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index c199991122b8..db209371ab33 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -851,7 +851,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt categorySections.push({ // "Selected" section title: '', - shouldShow: true, + shouldShow: false, indexOffset, data: getCategoryOptionTree(selectedOptions, true), }); From 3abcdfb3b1d788f38769e0cc6aee23cf619d08e5 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 25 Dec 2023 15:44:41 +0700 Subject: [PATCH 6/7] fix margin bug --- src/libs/OptionsListUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index db209371ab33..d8c864027399 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -851,7 +851,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt categorySections.push({ // "Selected" section title: '', - shouldShow: false, + shouldShow: true, indexOffset, data: getCategoryOptionTree(selectedOptions, true), }); @@ -862,7 +862,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt const selectedOptionNames = _.map(selectedOptions, (selectedOption) => selectedOption.name); const filteredCategories = _.filter(enabledCategories, (category) => !_.includes(selectedOptionNames, category.name)); const numberOfVisibleCategories = selectedOptions.length + filteredCategories.length; - + if (numberOfVisibleCategories < CONST.CATEGORY_LIST_THRESHOLD) { categorySections.push({ // "All" section when items amount less than the threshold From 19891e10c204d5ffe0ced25f737b7e7177bf6327 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 25 Dec 2023 15:46:18 +0700 Subject: [PATCH 7/7] fix margin bug --- src/libs/OptionsListUtils.js | 2 +- tests/unit/OptionsListUtilsTest.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index d8c864027399..18a66b884e6c 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -851,7 +851,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt categorySections.push({ // "Selected" section title: '', - shouldShow: true, + shouldShow: false, indexOffset, data: getCategoryOptionTree(selectedOptions, true), }); diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 999107f0b3ae..eb8c02903d7e 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -817,7 +817,7 @@ describe('OptionsListUtils', () => { const largeResultList = [ { title: '', - shouldShow: true, + shouldShow: false, indexOffset: 0, data: [ {