Repository navigation
Added static Newsletters tab to Post Analytics - #23231
Conversation
|
Warning Rate limit exceeded@peterzimon has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 45 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📥 CommitsReviewing files that changed from the base of the PR and between f22ba2c83084da5f8ad71d7629d0585e8dbdc653 and b9224d1. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (16)
WalkthroughThis change introduces a new "Newsletter" analytics view to the post analytics section of the application. It adds a new route ( Possibly related PRs
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (8)
apps/stats/src/views/Stats/Newsletters.tsx (1)
329-348: Consider adding a comment explaining the commented-out mock data.You've commented out several mock newsletter entries, reducing the dataset from 20 to 12 items. It would be helpful to add a brief comment explaining why some entries are commented out (e.g., for performance, visual simplicity, or testing purposes).
Also, I notice the dates have been updated from March 2024 to April 2025, which ensures the data appears current during development and testing.
apps/posts/src/views/PostAnalytics/Newsletter.tsx (7)
10-10: Empty interface should be replaced with a type alias.The empty interface
postAnalyticsPropsdoesn't add any value and could be simplified.-interface postAnalyticsProps {} +type PostAnalyticsProps = Record<string, never>;Also, consider following the PascalCase naming convention for types and interfaces.
🧰 Tools
🪛 Biome (1.9.4)
[error] 9-10: An empty interface is equivalent to {}.
Safe fix: Use a type alias instead.
(lint/suspicious/noEmptyInterface)
16-16: Apply PascalCase for component props type.Component props types should follow PascalCase convention.
-const Newsletter: React.FC<postAnalyticsProps> = () => { +const Newsletter: React.FC<PostAnalyticsProps> = () => {
22-24: Commented-out code should be removed or implemented.There are several commented-out lines that appear to be placeholders for future API integration. Consider either implementing these or adding more descriptive TODO comments if they're meant to be implemented later.
- // const {isLoading: isConfigLoading} = useGlobalData(); - // const {postId} = useParams(); - // const {stats: postReferrers, totals, isLoading} = usePostReferrers(postId || ''); + // TODO: Implement API integration for loading post data + // Will use: + // - useGlobalData() for configuration + // - useParams() to get postId + // - usePostReferrers() to fetch referrer stats
26-37: URL editing functionality is incomplete.The
handleEditmethod sets up state for editing, buthandleUpdateonly resets state without actually updating anything. This matches the TODO comment on line 32, but should be completed for full functionality.Would you like me to help implement a more complete version of this functionality that would work with an API?
60-60: Loading state is hardcoded.The
isLoadingstate is hardcoded tofalseinstead of being derived from actual API calls. This is fine for a static implementation, but should be replaced when integrating with real data.- const isLoading = false; + // TODO: Replace with actual loading state when API integration is added + const isLoading = false; // Temporary static value
107-107: Consider adding a proper loading state UI.The loading state is just displaying "Loading" text. Consider using a more user-friendly loading indicator or skeleton UI.
- {isLoading ? 'Loading' : + {isLoading ? ( + <div className="flex flex-col items-stretch gap-6"> + <Card> + <CardContent className="flex flex-col items-center justify-center py-20"> + <LucideIcon.Loader className="mb-4 size-10 animate-spin text-muted-foreground" /> + <p className="text-muted-foreground">Loading newsletter analytics...</p> + </CardContent> + </Card> + </div> + ) :
222-256: URL editing UX could be improved.The URL editing implementation could benefit from some UX improvements:
- There's no way to cancel editing other than clicking outside
- No validation is performed on the edited URL
- The input field doesn't maintain the full URL format (with protocol)
Consider adding:
- A cancel button next to the update button
- Basic URL validation
- Consistent URL format handling
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between c5b8882 and f22ba2c83084da5f8ad71d7629d0585e8dbdc653.
⛔ Files ignored due to path filters (1)
ghost/admin/public/assets/icons/stats-newsletter.svgis excluded by!**/*.svg
📒 Files selected for processing (14)
apps/posts/src/routes.tsx(2 hunks)apps/posts/src/views/PostAnalytics/Growth.tsx(2 hunks)apps/posts/src/views/PostAnalytics/Newsletter.tsx(1 hunks)apps/posts/src/views/PostAnalytics/Web.tsx(1 hunks)apps/posts/src/views/PostAnalytics/components/KpiCard.tsx(1 hunks)apps/posts/src/views/PostAnalytics/components/Sidebar.tsx(1 hunks)apps/posts/src/views/PostAnalytics/components/Web/Kpis.tsx(1 hunks)apps/shade/src/components/ui/tabs.tsx(2 hunks)apps/shade/styles.css(2 hunks)apps/stats/src/views/Stats/Newsletters.tsx(2 hunks)apps/stats/src/views/Stats/Web.tsx(1 hunks)ghost/admin/app/components/posts/analytics.hbs(1 hunks)ghost/admin/app/router.js(1 hunks)ghost/admin/app/routes/posts/analytics/newsletter-stats.js(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/posts/src/views/PostAnalytics/Growth.tsx (2)
apps/shade/src/components/ui/card.tsx (5)
Card(153-153)CardHeader(153-153)CardTitle(153-153)CardDescription(153-153)CardContent(153-153)apps/posts/src/views/PostAnalytics/components/KpiCard.tsx (4)
KpiCardIcon(4-10)KpiCardContent(12-18)KpiCardLabel(20-26)KpiCardValue(28-34)
🪛 Biome (1.9.4)
apps/posts/src/views/PostAnalytics/Newsletter.tsx
[error] 9-10: An empty interface is equivalent to {}.
Safe fix: Use a type alias instead.
(lint/suspicious/noEmptyInterface)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Unit tests (Node 22.13.1)
- GitHub Check: Unit tests (Node 20.11.1)
- GitHub Check: Lint
- GitHub Check: Admin tests - Chrome
🔇 Additional comments (26)
apps/shade/styles.css (2)
57-57: LGTM: New chart color variable addition for light modeThe addition of the
--chart-grayvariable provides a consistent way to style chart elements. This aligns well with the existing chart color variables.
98-98: LGTM: Consistent dark mode implementationThe dark mode implementation of
--chart-graymaintains consistency with the light mode version, using an appropriate darkness value that should maintain sufficient contrast in dark theme.apps/posts/src/views/PostAnalytics/components/KpiCard.tsx (5)
6-10: LGTM: Improved KpiCardIcon stylingThe icon container has been restyled with better spacing, sizing, and alignment properties. The use of square dimensions (
size-11) and flex layout ensures consistent icon presentation.
12-18: LGTM: New KpiCardContent componentGood addition of a dedicated content wrapper component with a flex column layout. This provides better structure and reusability for the KPI card content.
22-22: LGTM: Improved label stylingThe label styling has been refined with appropriate text size, color, and weight properties for better readability.
30-30: LGTM: Enhanced value displayThe value styling has been enhanced with better typography properties including tracking, leading, and font weight that should make the numbers more prominent.
38-38: LGTM: Improved main container layoutThe main KpiCard container has been restyled as a flex container with better spacing, border, and padding properties. This creates a more consistent and clean appearance.
apps/posts/src/views/PostAnalytics/Web.tsx (1)
66-66: LGTM: Reduced grid gap for better layoutThe reduction in grid gap from
gap-8togap-6creates a more compact layout between Sources and Locations components, which should improve the visual relationship between these related elements.apps/posts/src/views/PostAnalytics/components/Web/Kpis.tsx (1)
111-111: LGTM: Reduced grid column countChanging from
grid-cols-4togrid-cols-2adjusts the layout to focus on the two main metrics (visitors and pageviews). This aligns with similar grid column reductions in related components for consistent UI presentation.apps/stats/src/views/Stats/Web.tsx (1)
128-128: Grid column count updated for UI consistency.The
TabsListgrid layout was changed from 4 columns to 2 columns, which aligns with similar grid adjustments in other KPI components. This change maintains a consistent UI appearance across the application.apps/posts/src/views/PostAnalytics/components/Sidebar.tsx (1)
25-30: New Newsletter tab added to the sidebar navigation.The Newsletter tab has been properly added to the sidebar with consistent styling and navigation handling. It follows the same pattern as other navigation links, using the appropriate mail icon and correct path structure.
ghost/admin/app/components/posts/analytics.hbs (1)
277-279: New Newsletter link added to the Ember admin sidebar.The Newsletter analytics link has been correctly implemented in the Ember admin sidebar, maintaining consistency with the React implementation. The SVG icon and route naming follow the established pattern of the other analytics sidebar items.
apps/posts/src/routes.tsx (2)
2-2: Newsletter component import added.The Newsletter component is properly imported from the correct path.
30-34: New route configuration for Newsletter analytics.The route configuration for the Newsletter analytics view has been correctly implemented following the established pattern of other analytics routes. It uses the appropriate path structure and renders the Newsletter component.
ghost/admin/app/router.js (1)
40-40: Great addition of the newsletter-stats route!The new route follows existing patterns, keeping the same template and component naming conventions as sibling routes. This ensures consistency in the codebase.
ghost/admin/app/routes/posts/analytics/newsletter-stats.js (1)
1-10: Clean implementation of the NewsletterStatsRoute class.The route implementation correctly extends the base AnalyticsRoute class and follows the same rendering pattern as sibling analytics routes. This maintains consistency in how templates are rendered across the analytics section.
apps/stats/src/views/Stats/Newsletters.tsx (1)
253-253: Good UI enhancement with maxBarSize.Adding a maximum size for the bars improves the visual consistency of the chart across different data sets.
apps/posts/src/views/PostAnalytics/Growth.tsx (2)
1-1: Good update to include KpiCardContent in imports.The import has been properly updated to include the new KpiCardContent component.
30-66: Nice refactoring of the KPI cards layout.The KPI cards section has been refactored to use a more structured component hierarchy, with a Card wrapper and nested KpiCardContent components. This improves:
- Consistency with the newly added Newsletter tab
- Better semantic structure with proper Card components
- Clearer separation of concerns between container and content
The icon update from Wallet to WalletCards is also a good improvement for visual clarity.
apps/shade/src/components/ui/tabs.tsx (2)
51-51: Simplified and more consistent styling for KPI tabs.The padding and spacing for KPI tabs lists has been streamlined to a cleaner gap-1 with p-3 padding. This change helps maintain consistent spacing in the analytics views.
83-83: Improved hover and active states for KPI tabs.The styling has been simplified and improved by:
- Removing the shadow effect on active state
- Changing from background-based to muted-based colors for hover and active states
- Adding proper rounded corners for better visual consistency
These changes align well with the broader UI updates in the Newsletter analytics feature.
apps/posts/src/views/PostAnalytics/Newsletter.tsx (5)
64-77: Well-structured chart configuration.The chart data and configuration are well-organized and follow good practices:
- Clear separation of data and configuration
- Type safety with
satisfies ChartConfig- Consistent color variables using CSS custom properties
This structure will make it easy to replace with dynamic data later.
79-96: Mock data follows a good structure for future API integration.The mock data for links is structured in a way that will make it easy to replace with real API data later. The structure is clear and includes all necessary fields.
144-198: Accessibility improvements for chart component.The chart implementation includes good accessibility features like:
- Using the
accessibilityLayerprop on the BarChart- Proper formatting of percentages
- Clear tooltips with descriptive content
This is excellent for maintaining an accessible application.
12-14: URL sanitization function is simple and effective.The
sanitizeUrlfunction effectively removes protocol prefixes for cleaner display while preserving the actual URL for linking. This is a good approach.
115-143: KPI card layout is well-structured and consistent.The KPI cards are well-implemented with:
- Clear separation of icon, label, and value
- Consistent styling and spacing
- Appropriate icons for each metric
- Proper number formatting
This provides a clear and concise summary of newsletter performance metrics.
There was a problem hiding this comment.
🛠️ Refactor suggestion
Security improvement: Add noopener to external links.
When opening links in new tabs with target="_blank", it's recommended to include both noopener and noreferrer for security reasons.
<a
className='inline-flex items-center gap-2 font-medium hover:underline'
href={row.url}
- rel="noreferrer"
+ rel="noreferrer noopener"
target='_blank'
>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| className='inline-flex items-center gap-2 font-medium hover:underline' | |
| href={row.url} | |
| rel="noreferrer" | |
| target='_blank' | |
| > | |
| <span>{sanitizeUrl(row.url)}</span> | |
| </a> | |
| <a | |
| className='inline-flex items-center gap-2 font-medium hover:underline' | |
| href={row.url} | |
| rel="noreferrer noopener" | |
| target='_blank' | |
| > | |
| <span>{sanitizeUrl(row.url)}</span> | |
| </a> |
a975fe4 to
a4d5edf
Compare
ref https://linear.app/ghost/issue/PROD-1635/add-newsletters-tab-to-post-analytics-context - Added static Newsletters tab to Post Analytics beta to get started
3e56c72 to
b9224d1
Compare
ref https://linear.app/ghost/issue/PROD-1635/add-newsletters-tab-to-post-analytics-context