Skip to content

feat: Enhance AnalysisPage with recent events summary and API integration - #98

Merged
geeth24 merged 1 commit into
mainfrom
geeth/br-143-frontend-add-quick-event-summaries-to-analysis-page
Dec 1, 2025
Merged

feat: Enhance AnalysisPage with recent events summary and API integration#98
geeth24 merged 1 commit into
mainfrom
geeth/br-143-frontend-add-quick-event-summaries-to-analysis-page

Conversation

@geeth24

@geeth24 geeth24 commented Dec 1, 2025

Copy link
Copy Markdown
Contributor
  • Added functionality to fetch and display recent crisis events on the AnalysisPage.
  • Introduced a new API client method getRecentEvents to retrieve recent events based on selected filters.
  • Implemented loading states and conditional rendering for event summaries, improving user experience.
  • Added a link to view all events, enhancing navigation within the dashboard.

Summary by CodeRabbit

  • New Features
    • Introduced "Active Events Summary" dashboard section displaying recent crisis events, dynamically filtered by selected country and disaster type with loading indicators.
    • Launched comprehensive Design System page featuring UI component library, color palettes, typography, and downloadable brand assets with logo gallery.

✏️ Tip: You can customize this high-level summary in your review settings.

…tion

- Added functionality to fetch and display recent crisis events on the AnalysisPage.
- Introduced a new API client method `getRecentEvents` to retrieve recent events based on selected filters.
- Implemented loading states and conditional rendering for event summaries, improving user experience.
- Added a link to view all events, enhancing navigation within the dashboard.
@geeth24
geeth24 requested a review from a team as a code owner December 1, 2025 19:56
@coderabbitai

coderabbitai Bot commented Dec 1, 2025

Copy link
Copy Markdown

Walkthrough

The pull request adds event-driven features to the dashboard and introduces a new design system showcase page. Changes include a new API helper function for fetching recent events, integration of that function into the dashboard with state management and effects, and a comprehensive design system page with interactive color/component demonstrations and asset downloads.

Changes

Cohort / File(s) Summary
Dashboard Events Integration
client/app/dashboard/analysis/page.tsx
Added getRecentEvents API import and related icon imports; introduced recentEvents and eventsLoading state; added effect hook to fetch events based on filter changes; injected "Active Events Summary" UI section with loading skeletons, event cards grid, and empty-state handling.
API Client Enhancement
client/lib/api-client.ts
Added getRecentEvents(limit, country, disasterType) function that constructs query parameters (days=30, page=1, page_size) and makes GET request to /api/data-feed/weekly-crises; returns crisis array with pagination metadata.
Design System Showcase
client/app/design-system/page.tsx
New client-side page featuring: Logo downloads (PNG/SVG), color palette explorer with copy-to-hex functionality, severity color swatches, typography and component demonstrations (buttons, badges, cards), shadow/border-radius utilities, and helper functions for hex color computation and DOM interactions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas requiring extra attention:
    • Verify getRecentEvents query parameter construction handles missing country and disasterType correctly
    • Validate effect dependency array [selectedCountry, selectedDisasterTypes] prevents infinite loops or race conditions
    • Confirm design system page utility functions (getComputedHex, etc.) handle edge cases with canvas and DOM operations safely
    • Review error handling in the events fetch effect (whether errors are caught/displayed)

Possibly related PRs

Suggested labels

enhancement, version: minor

Suggested reviewers

  • Kammohan

Poem

🐰 A dashboard blooms with recent crises bright,
Design system colors dancing in the light,
Events flow and filters dance as one,
New showcases built—the work is done!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately reflects the main changes: it adds recent events summary display to the AnalysisPage and integrates API functionality to fetch those events.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch geeth/br-143-frontend-add-quick-event-summaries-to-analysis-page

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added enhancement New feature or request version: minor ✨ New features - bumps minor version (1.0.0 → 1.1.0) labels Dec 1, 2025
@github-actions

github-actions Bot commented Dec 1, 2025

Copy link
Copy Markdown

✨ Version Bump Prediction

When this PR is merged to main, the version will be bumped:

1.48.11.49.0 (minor)


💡 How to change the version bump type

The version bump is determined by your commit messages and PR title:

  • Major (2.0.0): Use BREAKING CHANGE: or MAJOR: in title/commits
  • Minor (1.49.0): Use feat: or feature: in title/commits
  • Patch (1.48.2): Use fix:, chore:, docs:, etc.

What I analyzed:

  • PR Title: feat: Enhance AnalysisPage with recent events summary and API integration
  • Commits: 1 commit(s)

Edit your PR title or commit messages to change the bump type.

@geeth24
geeth24 enabled auto-merge (squash) December 1, 2025 19:58
@github-actions github-actions Bot added version: minor ✨ New features - bumps minor version (1.0.0 → 1.1.0) and removed version: minor ✨ New features - bumps minor version (1.0.0 → 1.1.0) labels Dec 1, 2025
@github-actions

github-actions Bot commented Dec 1, 2025

Copy link
Copy Markdown

🚀 Preview Deployment Ready!

Backend: https://api-geeth-br-143-frontend-add-quic.private.bluerelief.app
Frontend: https://geeth-br-143-frontend-add-quic.private.bluerelief.app
Email Service: https://email-api-geeth-br-143-frontend-add-quic.private.bluerelief.app

Commit: 1482ba5


🔐 Authentication

Demo Login: Click "Google Sign In" → Use demo auth (no Google account needed)
Demo Account: demo@bluerelief.test
Note: Google OAuth not available for preview domains. Demo mode enabled for testing.


✨ Version Bump Prediction

When this PR is merged to main, the version will be bumped:

1.48.11.49.0 (minor)

💡 How to change the version bump type

  • For patch: Use fix:, chore:, docs:, or ci: in commit messages
  • For minor: Use feat: or feature: in commit messages
  • For major: Include BREAKING CHANGE or breaking: in commit messages

Preview will be automatically deleted when PR is closed or merged.

@geeth24
geeth24 merged commit c5572d1 into main Dec 1, 2025
9 of 10 checks passed
@geeth24
geeth24 deleted the geeth/br-143-frontend-add-quick-event-summaries-to-analysis-page branch December 1, 2025 19:59

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
client/app/design-system/page.tsx (1)

470-485: Consolidate duplicate color computation logic.

The functions getComputedHex (line 470) and getHexFromElement (line 572) share nearly identical canvas-based color computation logic. The only difference is that getHexFromElement accepts a property parameter to read different CSS properties.

Refactor to use a single, parameterized helper function:

-function getComputedHex(element: HTMLElement): string {
+function getComputedHex(element: HTMLElement, property: 'backgroundColor' | 'color' = 'backgroundColor'): string {
   const canvas = document.createElement('canvas');
   canvas.width = 1;
   canvas.height = 1;
   const ctx = canvas.getContext('2d');
   if (!ctx) return '#000000';
   
   const computedStyle = getComputedStyle(element);
-  ctx.fillStyle = computedStyle.backgroundColor;
+  ctx.fillStyle = computedStyle[property];
   ctx.fillRect(0, 0, 1, 1);
   
   const data = ctx.getImageData(0, 0, 1, 1).data;
   return '#' + [data[0], data[1], data[2]]
     .map(x => x.toString(16).padStart(2, '0'))
     .join('');
 }

Then in SeveritySwatch, remove the getHexFromElement function and use:

   React.useEffect(() => {
     if (bgRef.current && textRef.current) {
       setHexColors({
-        bg: getHexFromElement(bgRef.current, 'backgroundColor'),
-        text: getHexFromElement(textRef.current, 'color')
+        bg: getComputedHex(bgRef.current, 'backgroundColor'),
+        text: getComputedHex(textRef.current, 'color')
       });
     }
   }, [bgVar, textVar]);

Also applies to: 572-587

client/app/dashboard/analysis/page.tsx (2)

334-353: Consider adding error state for recent events fetching.

The fetchRecentEvents function logs errors to the console but provides no user-facing feedback when the API call fails. While this might be acceptable for a non-critical feature, users would benefit from knowing why the events section is empty.

Consider adding an error state for better user feedback:

   const [recentEvents, setRecentEvents] = useState<Array<{...}>>([]);
   const [eventsLoading, setEventsLoading] = useState(true);
+  const [eventsError, setEventsError] = useState<string | null>(null);

   useEffect(() => {
     const fetchRecentEvents = async () => {
       try {
         setEventsLoading(true);
+        setEventsError(null);
         const country = selectedCountry || undefined;
         const disasterType = selectedDisasterTypes.length > 0 
           ? selectedDisasterTypes.join(',') 
           : undefined;
         
         const eventsData = await getRecentEvents(8, country, disasterType);
         setRecentEvents(eventsData.crises);
       } catch (e) {
         console.error('Failed to fetch recent events:', e);
+        setEventsError('Unable to load recent events. Please try again later.');
       } finally {
         setEventsLoading(false);
       }
     };

     fetchRecentEvents();
   }, [selectedCountry, selectedDisasterTypes]);

Then update the CardContent to show the error state before the empty state check.


692-737: Remove redundant array slice operation.

Line 694 slices recentEvents to 8 items, but getRecentEvents is already called with a limit of 8 (line 343), making this slice operation redundant.

-            {recentEvents.slice(0, 8).map((event) => (
+            {recentEvents.map((event) => (
               <div 
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e65a9e and 6fd8c70.

📒 Files selected for processing (3)
  • client/app/dashboard/analysis/page.tsx (4 hunks)
  • client/app/design-system/page.tsx (1 hunks)
  • client/lib/api-client.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
client/app/dashboard/analysis/page.tsx (3)
client/lib/api-client.ts (1)
  • getRecentEvents (224-257)
client/components/lordicon.tsx (1)
  • Lordicon (15-113)
client/lib/lordicon-config.ts (2)
  • LORDICON_SOURCES (6-41)
  • LORDICON_SIZES (66-76)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (frontend, client, Dockerfile.prod, bluerelief/frontend)
🔇 Additional comments (2)
client/app/dashboard/analysis/page.tsx (1)

650-761: Well-implemented Active Events Summary section.

The implementation demonstrates good UX practices:

  • Loading skeletons provide visual feedback during data fetch
  • Empty states adapt messaging based on whether filters are active
  • Event cards display comprehensive information with appropriate formatting
  • Navigation link to the full data feed is clearly accessible
  • Responsive grid layout works well across screen sizes
client/app/design-system/page.tsx (1)

14-22: Verify logo asset availability.

The download function assumes logo files exist at /bluerelief-logo.png and /bluerelief-logo.svg. Ensure these files are present in the public directory to avoid 404 errors when users attempt downloads.

Comment thread client/lib/api-client.ts
Comment on lines +224 to +257
export async function getRecentEvents(limit = 10, country?: string, disasterType?: string) {
const params = new URLSearchParams();
params.append('days', '30');
params.append('page', '1');
params.append('page_size', limit.toString());

if (country) params.append('country', country);
if (disasterType) params.append('disaster_type', disasterType);

return apiGet<{
crises: Array<{
id: number;
crisis_name: string;
date: string;
region: string;
severity: string;
tweets_analyzed: number;
status: string;
description: string;
sentiment?: string | null;
sentiment_score?: number | null;
disaster_type: string;
bluesky_url: string | null;
}>;
pagination: {
page: number;
page_size: number;
total_count: number;
total_pages: number;
has_next: boolean;
has_prev: boolean;
}
}>(`/api/data-feed/weekly-crises?${params.toString()}`);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Reduce code duplication with existing getWeeklyCrises function.

The new getRecentEvents function is essentially a specialized wrapper around the same endpoint used by getWeeklyCrises (line 95), with hardcoded days=30 and page=1. The return type structure is also duplicated.

Refactor to reuse the existing function and eliminate duplication:

-export async function getRecentEvents(limit = 10, country?: string, disasterType?: string) {
-  const params = new URLSearchParams();
-  params.append('days', '30');
-  params.append('page', '1');
-  params.append('page_size', limit.toString());
-  
-  if (country) params.append('country', country);
-  if (disasterType) params.append('disaster_type', disasterType);
-  
-  return apiGet<{ 
-    crises: Array<{
-      id: number;
-      crisis_name: string;
-      date: string;
-      region: string;
-      severity: string;
-      tweets_analyzed: number;
-      status: string;
-      description: string;
-      sentiment?: string | null;
-      sentiment_score?: number | null;
-      disaster_type: string;
-      bluesky_url: string | null;
-    }>;
-    pagination: {
-      page: number;
-      page_size: number;
-      total_count: number;
-      total_pages: number;
-      has_next: boolean;
-      has_prev: boolean;
-    }
-  }>(`/api/data-feed/weekly-crises?${params.toString()}`);
+export async function getRecentEvents(limit = 10, country?: string, disasterType?: string) {
+  // Reuse getWeeklyCrises with 30-day window
+  return getWeeklyCrises(30, 1, limit, '', country, disasterType);
 }

Note: You'll need to update getWeeklyCrises signature to accept optional country and disasterType parameters for this refactor to work.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In client/lib/api-client.ts around lines 224 to 257, getRecentEvents duplicates
logic and types from getWeeklyCrises (around line 95); change getWeeklyCrises to
accept optional parameters country?: string and disasterType?: string (and keep
existing params for days, page, page_size) so it can build the same URL based on
those inputs, then replace getRecentEvents with a thin wrapper that calls
getWeeklyCrises({ days: 30, page: 1, page_size: limit, country, disasterType })
and returns its result so the endpoint construction and return type are reused
instead of duplicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request version: minor ✨ New features - bumps minor version (1.0.0 → 1.1.0)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants