Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update financial data for current year #2687

Merged
merged 22 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e31f020
Auto update financial data
JeelRajodiya Jul 23, 2024
676ccab
update indention
JeelRajodiya Jul 23, 2024
1d98305
remove comment
JeelRajodiya Jul 24, 2024
2fdf27b
Move the current year inside the components
JeelRajodiya Jul 24, 2024
929a814
Merge branch 'master' into auto-year-detection
JeelRajodiya Jul 24, 2024
72b7190
Merge branch 'master' into auto-year-detection
JeelRajodiya Aug 23, 2024
9063550
Merge branch 'master' into auto-year-detection
JeelRajodiya Aug 26, 2024
a21b8dc
chore: add logic to find the foldername with latest year
JeelRajodiya Aug 27, 2024
e346334
chore: add error handling when the finance files are not present
JeelRajodiya Aug 29, 2024
f31af6a
new method to detect latest year
JeelRajodiya Aug 29, 2024
124209f
update indention
JeelRajodiya Aug 29, 2024
5f4ecd1
update path in the test
JeelRajodiya Aug 29, 2024
80b1702
remove unused import
JeelRajodiya Aug 29, 2024
1179dd7
fix formatting
JeelRajodiya Aug 29, 2024
28ea995
fix formatting
JeelRajodiya Aug 29, 2024
09ad54f
Merge branch 'master' into auto-year-detection
JeelRajodiya Aug 30, 2024
fddb7d6
Merge branch 'master' into auto-year-detection
JeelRajodiya Aug 30, 2024
4ea0a2e
Merge branch 'master' into auto-year-detection
JeelRajodiya Sep 7, 2024
ef8e8c8
Merge branch 'master' into auto-year-detection
JeelRajodiya Sep 9, 2024
b8c692b
Merge branch 'master' into auto-year-detection
JeelRajodiya Sep 10, 2024
555b5e5
Merge branch 'master' into auto-year-detection
JeelRajodiya Sep 14, 2024
be79285
Merge branch 'master' into auto-year-detection
akshatnema Sep 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions components/FinancialSummary/BarChartComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Bar, BarChart, CartesianGrid, Legend, Tooltip, YAxis } from 'recharts';

import type { ExpenseItem, ExpensesLinkItem } from '@/types/FinancialSummary/BarChartComponent';

import ExpensesData from '../../config/finance/json-data/2024/Expenses.json';
import ExpensesLinkData from '../../config/finance/json-data/2024/ExpensesLink.json';
import { getUniqueCategories } from '../../utils/getUniqueCategories';
import CustomTooltip from './CustomTooltip';
import ExpensesCard from './ExpensesCard';
Expand All @@ -19,8 +17,11 @@ export default function BarChartComponent() {
const [windowWidth, setWindowWidth] = useState<number>(0);

// Extracting unique categories and months from the data
const categories: string[] = getUniqueCategories();
const [categories, setCategories] = useState<string[]>([]);
const [ExpensesData, setExpensesData] = useState<{ [month: string]: ExpenseItem[] }>({});

const months: string[] = Object.keys(ExpensesData);
const [ExpensesLinkData, setExpensesLinkData] = useState<ExpensesLinkItem[]>([]);

// Effect hook to update windowWidth state on resize
useEffect(() => {
Expand All @@ -30,7 +31,14 @@ export default function BarChartComponent() {

// Initial setup and event listener
handleResize();
const currentYear = new Date().getFullYear();

window.addEventListener('resize', handleResize);
import(`../../config/finance/json-data/${currentYear}/ExpensesLink.json`).then((data) =>
setExpensesLinkData(data.default)
);
getUniqueCategories().then((data) => setCategories(data));
import(`../../config/finance/json-data/${currentYear}/Expenses.json`).then((data) => setExpensesData(data.default));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if Expenses Files of current are not present? In that case this import will lead to error and a deadlock situation will be created. Provide some fallback for these imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some logic for checking whether we have any financial data or not, please view scripts/index.js. If we do not have any financial data, it will throw an error on the build. Also, I have moved those imports on the top level now.


// Cleanup function to remove event listener
return () => {
Expand Down
18 changes: 5 additions & 13 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
const { resolve } = require('path');
const rssFeed = require('./build-rss');
const buildPostList = require('./build-post-list');
const buildCaseStudiesList = require('./casestudies');
const buildAdoptersList = require('./adopters')
const buildAdoptersList = require('./adopters');
const buildFinanceInfoList = require('./finance');
const { resolve } = require('path');

async function start() {
await buildPostList();
rssFeed(
'blog',
'AsyncAPI Initiative Blog RSS Feed',
'AsyncAPI Initiative Blog',
'rss.xml'
);
await buildCaseStudiesList(
'config/casestudies',
resolve(__dirname, '../config', 'case-studies.json')
);
rssFeed('blog', 'AsyncAPI Initiative Blog RSS Feed', 'AsyncAPI Initiative Blog', 'rss.xml');
await buildCaseStudiesList('config/casestudies', resolve(__dirname, '../config', 'case-studies.json'));
await buildAdoptersList();
await buildFinanceInfoList({
currentDir: '.',
configDir: 'config',
financeDir: 'finance',
year: '2024',
year: String(new Date().getFullYear()),
JeelRajodiya marked this conversation as resolved.
Show resolved Hide resolved
jsonDataDir: 'json-data'
});
}
Expand Down
8 changes: 5 additions & 3 deletions utils/getUniqueCategories.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import Expenses from '../config/finance/json-data/2024/Expenses.json';

/**
* Retrieves unique expense categories from the Expenses data.
*
* @param {Object} expenses - The expenses data.
* @returns {string[]} An array of unique expense categories.
*/
export const getUniqueCategories = (): string[] => {
export const getUniqueCategories = async (): Promise<string[]> => {
const currentYear = new Date().getFullYear();
const allCategories: string[] = [];
const Expenses = (await import(`../config/finance/json-data/${currentYear}/Expenses.json`)).default;

JeelRajodiya marked this conversation as resolved.
Show resolved Hide resolved
for (const month in Expenses) {
Expenses[month as keyof typeof Expenses].forEach((entry: { Category: string }) => {
if (!allCategories.includes(entry.Category)) {
allCategories.push(entry.Category);
}
});
}

return allCategories;
};
Loading