forked from asyncapi/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified getUniqueCategories to not show 0 expenses categories for a …
…selected month
- Loading branch information
1 parent
5fc837e
commit 894f705
Showing
2 changed files
with
19 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
import { loadYearData } from './loadYearData'; | ||
|
||
/** | ||
* Retrieves unique expense categories from the Expenses data. | ||
* Retrieves unique expense categories for a specific month and year. | ||
* @param {string} selectedYear - The year for which to retrieve the data. | ||
* @param {string} selectedMonth - The month for which to retrieve the data. | ||
* @returns {string[]} An array of unique expense categories. | ||
*/ | ||
export const getUniqueCategories = ({selectedYear} : {selectedYear: string}): string[] => { | ||
export const getUniqueCategories = ({selectedYear, selectedMonth} : {selectedYear: string; selectedMonth: string}): string[] => { | ||
const { expensesData } = loadYearData(selectedYear); | ||
const allCategories: string[] = []; | ||
for (const month in expensesData) { | ||
expensesData[month as keyof typeof expensesData].forEach((entry: { Category: string }) => { | ||
|
||
// If "All Months" is selected, return categories from all months | ||
if (selectedMonth === 'All Months') { | ||
for (const month in expensesData) { | ||
expensesData[month as keyof typeof expensesData].forEach((entry: { Category: string }) => { | ||
if (!allCategories.includes(entry.Category)) { | ||
allCategories.push(entry.Category); | ||
} | ||
}); | ||
} | ||
} else { | ||
// Return categories only for the selected month | ||
const monthData = expensesData[selectedMonth as keyof typeof expensesData] || []; | ||
monthData.forEach((entry: { Category: string }) => { | ||
if (!allCategories.includes(entry.Category)) { | ||
allCategories.push(entry.Category); | ||
} | ||
}); | ||
} | ||
|
||
return allCategories; | ||
}; |