only show categories with specified type in category filter dialog / page

This commit is contained in:
MaysWind
2024-07-07 11:47:48 +08:00
parent e5a04596e1
commit 7b70b2db29
6 changed files with 52 additions and 7 deletions
+9 -1
View File
@@ -62,8 +62,12 @@ export function getTransactionSecondaryCategoryName(categoryId, allCategories) {
return '';
}
export function allVisibleTransactionCategories(allTransactionCategories) {
export function allVisibleTransactionCategories(allTransactionCategories, allowCategoryTypes) {
const ret = {};
const hasAllowCategoryTypes = allowCategoryTypes
&& (allowCategoryTypes[categoryConstants.allCategoryTypes.Income.toString()]
|| allowCategoryTypes[categoryConstants.allCategoryTypes.Expense.toString()]
|| allowCategoryTypes[categoryConstants.allCategoryTypes.Transfer.toString()]);
for (let key in categoryConstants.allCategoryTypes) {
if (!Object.prototype.hasOwnProperty.call(categoryConstants.allCategoryTypes, key)) {
@@ -76,6 +80,10 @@ export function allVisibleTransactionCategories(allTransactionCategories) {
continue;
}
if (hasAllowCategoryTypes && !allowCategoryTypes[categoryType]) {
continue;
}
const allCategories = allTransactionCategories[categoryType];
const visibleCategories = [];
const allVisibleSubCategories = {};
+10
View File
@@ -373,6 +373,16 @@ export function objectToArray(object) {
return ret;
}
export function arrayItemToObjectField(array, value) {
const ret = {};
for (let i = 0; i < array.length; i++) {
ret[array[i]] = value;
}
return ret;
}
export function categorizedArrayToPlainArray(object) {
const ret = [];