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

Add functionality for download button #814

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"react-calendar-heatmap": "^1.9.0",
"react-chartjs-2": "^5.2.0",
"react-chatbot-kit": "^2.2.2",
"react-csv": "^2.2.2",
"react-day-picker": "^8.10.1",
"react-dom": "^18.3.1",
"react-dropzone": "^14.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ import {
TopSectionCaptionCTABtnBig,
TopSectionCaptionCTABtnBigInnerSection,
TopSectionMainContent,
TopSectionDownloadText,
} from "./AnalyticsPageTopSectionMainContentElements";
import { FiInfoIcon, SlCalenderIcon, TbFileDownloadIcon } from "./AnalyticsIconElements";
import { lastAmountOfDays } from "./AnalyticsUtils";
import { getAnalyticsFileData, lastAmountOfDays } from "./AnalyticsUtils";
import { AnalyticsTopInnerCards } from "./AnalyticsTopInnerCards";
import { AnalyticsBarChart } from "./AnalyticsBarChart";
import { AnalyticsDoughnutChart } from "./AnalyticsDoughnutChart";
import visitors from "./AnalyticsVisitorsData.json";
import AnalyticsHorizontalBarCharts from "./AnalyticsHorizontalBarCharts";
import { CSVLink } from "react-csv";

export const AnalyticsPageTopSectionMainContent = () => {
const { headers, data } = getAnalyticsFileData();

return (
<TopSection>
<Caption>
Expand All @@ -33,10 +37,12 @@ export const AnalyticsPageTopSectionMainContent = () => {
</TopSectionCaptionCTABtnBigInnerSection>
</TopSectionCaptionCTABtnBig>
<TopSectionCaptionCTABtnBig>
<TopSectionCaptionCTABtnBigInnerSection>
Download
<TbFileDownloadIcon />
</TopSectionCaptionCTABtnBigInnerSection>
<CSVLink data={data} headers={headers} filename="Analytics_Data.csv">
<TopSectionCaptionCTABtnBigInnerSection>
<TopSectionDownloadText>Download</TopSectionDownloadText>
<TbFileDownloadIcon />
</TopSectionCaptionCTABtnBigInnerSection>
</CSVLink>
</TopSectionCaptionCTABtnBig>
</CTABtn>
</Caption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export const TopSectionCaptionCTABtnBig = styled.div`
}
`;

export const TopSectionDownloadText = styled.p`
color: #e77b0f;
`;

export const TopSectionCaptionCTABtnBigInnerSection = styled.div`
display: flex;
justify-content: space-between;
Expand Down
23 changes: 23 additions & 0 deletions src/components/Dashboard/Analytics/AnalyticsUtils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { datasets as monthsDatasets, xDataSet as xDataSetMonths } from "./MainBarChartDataMonths.json";
import { datasets as hoursDatasets, xDataSet as xDataSetHours } from "./MainBarChartDataHours.json";

export const lastAmountOfDays = 30;
export const lastAmountOfMinAgo = 14;

Expand Down Expand Up @@ -142,3 +145,23 @@ export const allOptions = [
responsive: true,
},
];

export const getAnalyticsFileData = () => {
const monthsDataset = monthsDatasets[0];
const hoursDataset = hoursDatasets[0];

const headers = [
{ label: "Contributions Hours", key: "hours" },
{ label: "Months Contribution", key: "months" },
];

const data = [];

for (let i = 0; i < xDataSetHours.length; i++) {
const hoursData = `${xDataSetHours[i]} - ${hoursDataset.data[i]}`;
const monthsData = `${xDataSetMonths[i]} - ${monthsDataset.data[i]}`;
data.push({ hours: hoursData, months: monthsData });
}

return { headers, data };
};