diff --git a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/DailySection.tsx b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/DailySection.tsx index 738167648..e21c151e4 100644 --- a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/DailySection.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/DailySection.tsx @@ -96,9 +96,11 @@ function getCurrentWeekDays(currentMonday: Date): Date[] { // ── Main Component ─────────────────────────────────────────── export default function DailySection({ - installationId + installationId, + onHasData }: { installationId: number; + onHasData?: (hasData: boolean) => void; }) { const intl = useIntl(); const currentMonday = useMemo(() => getCurrentMonday(), []); @@ -138,10 +140,12 @@ export default function DailySection({ const hourly = res.data?.hourlyRecords?.records ?? []; setAllRecords(Array.isArray(daily) ? daily : []); setAllHourlyRecords(Array.isArray(hourly) ? hourly : []); + onHasData?.(Array.isArray(daily) && daily.length > 0); }) .catch(() => { setAllRecords([]); setAllHourlyRecords([]); + onHasData?.(false); }) .finally(() => setLoadingWeek(false)); }, [installationId, weekDays]); diff --git a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/WeeklyReport.tsx b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/WeeklyReport.tsx index a80cc1022..326621352 100644 --- a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/WeeklyReport.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/WeeklyReport.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react'; +import { useEffect, useImperativeHandle, useRef, useState, forwardRef } from 'react'; import { useIntl, FormattedMessage } from 'react-intl'; import { Accordion, @@ -231,6 +231,12 @@ function WeeklyReport({ installationId }: WeeklyReportProps) { const [pendingMonths, setPendingMonths] = useState([]); const [pendingYears, setPendingYears] = useState([]); const [generating, setGenerating] = useState(null); + const [selectedMonthlyIdx, setSelectedMonthlyIdx] = useState(0); + const [selectedYearlyIdx, setSelectedYearlyIdx] = useState(0); + const [regenerating, setRegenerating] = useState(false); + const [dailyHasData, setDailyHasData] = useState(false); + const [weeklyHasData, setWeeklyHasData] = useState(false); + const weeklyRef = useRef(null); const fetchReportData = () => { const lang = intl.locale; @@ -287,6 +293,15 @@ function WeeklyReport({ installationId }: WeeklyReportProps) { const safeTab = Math.min(activeTab, tabs.length - 1); + const activeTabHasData = (() => { + const key = tabs[safeTab]?.key; + if (key === 'daily') return dailyHasData; + if (key === 'weekly') return weeklyHasData; + if (key === 'monthly') return monthlyReports.length > 0; + if (key === 'yearly') return yearlyReports.length > 0; + return false; + })(); + return (