WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@liamgold
Copy link
Owner

Summary

Adds comprehensive historical tracking capabilities to the sustainability module, allowing users to view historical reports, analyze trends over time, and load paginated report history.

Key Features

  • Historical Reports View: Toggle between current report and historical reports with paginated "Load More" functionality
  • Trend Visualization: Two separate side-by-side charts showing CO₂ emissions (red) and page weight (blue) trends over time with independent Y-axis scales
  • Historical Report Cards: Collapsible cards displaying past reports with date, rating, metrics, and top 3 resource groups

Technical Changes

Frontend Refactor:

  • Reorganized components into view-based architecture (tab-template/current/ and tab-template/history/)
  • Created 7 new reusable components: CurrentReportView, HistoryView, TrendChart, HistoricalReportCard, StatCard, ResourceGroupCard
  • Added shared utils.ts for rating colors, resource icons, and hosting status helpers
  • Moved types to tab-template/types.ts for better organization

Backend Improvements:

  • Implemented page-based pagination with COUNT-based hasMore detection
  • Added GetReportHistory() method with current report exclusion via .WhereNotEquals()
  • Added LoadMoreHistory PageCommand for loading additional historical reports
  • Captured SustainabilityPageDataID after save to enable proper filtering

Bug Fixes:

  • Fixed JSON parameter binding (camelCase TypeScript → PascalCase C# auto-mapping)
  • Changed from offset-based to clean page-based pagination using .Page(pageIndex, limit)
  • Eliminated duplicate current report in history list
  • Accurate "Load More" button visibility controlled by backend COUNT query

Documentation:

  • Comprehensive CLAUDE.md updates documenting pagination patterns, data flow, and debugging tips
  • Updated README.md with historical tracking feature description
  • Added 5 specialized agent profiles for project development

Version: Bumped to 2.7.0

Files Changed

  • 28 files changed: 2,198 insertions(+), 1,109 deletions
  • Major additions: 8 new React components, pagination system, trend charts
  • Refactored monolithic SustainabilityTabTemplate.tsx into organized component structure

Test plan

  • Install/upgrade package in a Kentico instance
  • Navigate to a content page and run initial sustainability report
  • Verify current report displays correctly with all metrics and resource groups
  • Click "View Report History" to toggle to history view
  • Verify trend charts display correctly with independent scales
  • Verify current report does not appear in historical reports list
  • Run another sustainability report and verify new report becomes current
  • Verify history updates and previous current report moves to history
  • For pages with >10 historical reports, verify "Load More History" button appears
  • Click "Load More History" and verify additional reports load without duplicates
  • Verify "Load More History" button disappears when all reports are loaded
  • Expand historical report cards and verify resource groups display
  • Test pagination edge cases (1 report, exactly 10 reports, 11 reports)

🤖 Generated with Claude Code

liamgold and others added 9 commits November 18, 2025 22:35
- Reorganize components into tab-template/ with current/ and history/ subdirectories
- Extract CurrentReportView and HistoryView into separate components
- Create reusable components: StatCard, ResourceGroupCard, TrendChart, HistoricalReportCard
- Move all types and commands to tab-template/types.ts (YAGNI - will extract when dashboard needs them)
- Create shared utils.ts for rating colors, resource icons, and hosting status helpers
- Improve file organization with consistent naming: tab-template/, dashboard-template/
- Update CLAUDE.md with new architecture and component documentation

This refactor improves maintainability by:
- Grouping view-specific components together
- Separating concerns (current report vs historical reports)
- Co-locating types with their usage
- Following YAGNI principle for shared code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
## Issues Fixed
1. JSON parameter binding - TypeScript was sending PascalCase but ASP.NET Core expects camelCase, causing offset/pageIndex to always be 0
2. Pagination logic - Changed from offset-based to clean page-based pagination using .Page(pageIndex, limit)
3. Current report duplication - Used .WhereNotEquals() to exclude current report at query level instead of client-side filtering
4. Missing report IDs - Added SustainabilityPageDataID to SustainabilityResponse and captured it after database save
5. Inaccurate "Load More" button - Backend now returns hasMore flag based on COUNT query instead of client guessing

## Technical Changes
- **Backend**: Added COUNT query to accurately calculate hasMore flag, returns tuple (reports, hasMore)
- **Frontend**: Receives hasMoreHistory from backend, eliminating client-side guesswork
- **Service**: Modified GetReportHistory to exclude current report by ID using WhereNotEquals
- **Models**: Added SustainabilityPageDataID property to SustainabilityResponse (JsonIgnore)

## Result
- No duplicate items in history
- "Load More" button only appears when there's actually more data
- Works correctly for all scenarios (1 item, 10 items, 11 items, etc.)
- Clean page-based pagination without offset math issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Update CLAUDE.md to comprehensively document the historical reports
view functionality and pagination implementation added in this branch.

Key documentation additions:

1. Service Layer (GetReportHistory):
   - Updated method signature to reflect tuple return pattern
   - Documented excludeReportId parameter for filtering current report
   - Explained COUNT-based hasMore detection pattern
   - Clarified page index vs offset-based pagination

2. UI Layer (SustainabilityTab PageCommands):
   - Documented RunReport return structure with hasMoreHistory flag
   - Explained report ID capture pattern for proper exclusion
   - Updated LoadMoreHistory parameter (pageIndex, not offset)
   - Documented tuple return pattern for pagination metadata

3. Frontend (History View):
   - Comprehensive pagination pattern documentation
   - Explained COUNT-based button visibility (not client-side guessing)
   - Documented state management (nextPageIndex, hasMoreHistory)
   - Added JSON parameter binding section (camelCase TypeScript → PascalCase C#)

4. Data Flow:
   - Added complete "Loading Historical Reports (Pagination)" section
   - Documented initial load, load more, and post-new-report flows
   - Explained .WhereNotEquals() pattern for current report exclusion
   - Clarified .Page(pageIndex, limit) semantics

5. Data Models:
   - Added SustainabilityResponse.cs documentation
   - Explained SustainabilityPageDataID role in exclusion logic
   - Documented all properties and their purposes

6. Debugging Tips:
   - Added pagination-specific troubleshooting guidance
   - Covered JSON casing issues, hasMore flag problems, ID capture issues

This documentation provides developers with a complete understanding of how
the historical reports pagination system works, common pitfalls to avoid
(offset vs pageIndex, camelCase JSON binding), and debugging strategies.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Split dual-axis trend chart into two separate side-by-side charts
  - CO₂ emissions chart (red) and page weight chart (blue) now independent
  - Each chart has its own Y-axis scale for clearer interpretation
  - Added rotated Y-axis labels showing units
  - Increased chart size (550x200px) for better visibility
  - Charts now spread across container with space-between layout

- Add explanatory text above charts
  - Shows number of reports being displayed (up to 10 loaded)
  - Clarifies chronological order (oldest to newest)

- Restructure historical report card layout
  - Left: Date and resource count
  - Right: Carbon rating badge, metrics, and chevron grouped together
  - Metrics use center alignment with consistent spacing
  - Chevron icon now neutral gray (#6b7280) instead of default color

- Fix loading state management
  - Removed unused setIsLoadingMore prop from HistoryView
  - Parent component now manages loading state via onLoadMore callback
  - Cleaner separation of concerns between components

These changes make the trend analysis much clearer and the report cards
more visually balanced.
Add custom agent profile for Kentico XbyK development assistance:
- Helps with admin UI customization, UIPages, and React components
- References official Kentico documentation via MCP tools
- Provides guidance specific to this sustainability project's patterns
- Includes expertise in PageCommands, module installation, and InfoProvider patterns
Add 5 new agent profiles tailored to this project's needs:

- nuget-package-maintainer: Version management, SemVer decisions, package configuration
- playwright-integration-specialist: Browser automation, performance measurement, resource tracking
- react-admin-ui-developer: XbyK admin UI patterns, PageCommands, component architecture
- xbyk-component-reference: Quick reference for native XbyK components and design system
- documentation-maintainer: Keep CLAUDE.md accurate, concise, and optimized for context windows

All agents include project-specific patterns, file references, and examples from the codebase.
Copilot AI review requested due to automatic review settings November 22, 2025 16:28
@liamgold liamgold linked an issue Nov 22, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive historical tracking capabilities to the sustainability module, enabling users to view past reports, analyze trends over time, and load paginated report history. The implementation refactors the monolithic React component into a clean view-based architecture while adding backend pagination support with COUNT-based "hasMore" detection.

Key Changes:

  • Reorganized frontend into reusable component architecture with separate current/history views
  • Implemented page-based pagination with accurate "Load More" button visibility
  • Added dual-chart trend visualization showing CO₂ emissions and page weight independently
  • Fixed JSON parameter binding and duplicate report issues

Reviewed changes

Copilot reviewed 24 out of 27 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
XperienceCommunity.Sustainability.csproj Version bump to 2.7.0
SustainabilityTab.cs Added LoadMoreHistory PageCommand and initial history loading in ConfigureTemplateProperties
SustainabilityService.cs Implemented GetReportHistory with pagination and proper ID capture for exclusion
SustainabilityResponse.cs Added SustainabilityPageDataID property for report filtering
entry.tsx Updated exports to reflect new file structure
utils.ts Extracted shared utilities for rating colors, resource icons, and hosting status
types.ts Centralized tab-specific types and command constants
TrendChart.tsx New component with two independent SVG charts for emissions and page weight
HistoryView.tsx New history view with trend charts and paginated report list
HistoricalReportCard.tsx Collapsible card component for displaying historical reports
StatCard.tsx Extracted reusable metric display card
ResourceGroupCard.tsx Extracted expandable resource list component
CurrentReportView.tsx Extracted current report display with hero section and resource breakdown
SustainabilityTabTemplate.tsx Refactored main orchestrator with view toggle and pagination state management
SustainabilityTabTemplate.tsx (deleted) Removed old monolithic file in favor of new structure
README.md Added Historical Tracking feature documentation
CLAUDE.md Comprehensive updates documenting pagination patterns, data flow, and parameter binding
Agent profiles Added 5 specialized agent profiles for project development guidance

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Address 3 of 4 Copilot recommendations from PR review:

1. [Rejected] SustainabilityPageDataID [JsonIgnore] attribute
   - Intentionally excluded from JSON serialization
   - Internal DB identifier only used for backend query filtering
   - Frontend doesn't need this ID - proper encapsulation

2. [Fixed] Extract magic number 10 to named constant
   - Added MAX_TREND_REPORTS constant in TrendChart.tsx
   - Documents relationship to pagination limit
   - Improves maintainability

3. [Fixed] Add user-facing message for insufficient trend data
   - Previously returned null silently when < 2 reports
   - Now shows helpful message: "Trend analysis requires at least 2 data points"
   - Better UX for users with only 1 report

4. [Fixed] Remove unnecessary null-coalescing operator
   - LoadMoreHistory parameter is non-nullable
   - Removed redundant commandData?.PageIndex ?? 0
   - Simplified to commandData.PageIndex

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@liamgold liamgold merged commit eb8ba85 into main Nov 22, 2025
5 checks passed
@liamgold liamgold deleted the feature/3-historical-tracking branch November 22, 2025 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add historical tracking and comparison for sustainability reports

2 participants