Conversation
…ionality, and improved loading state
…g enhancements to the Campaigns component
Greptile OverviewGreptile SummaryThis PR enhances the Campaigns dashboard block with sortable columns, source favicons with display names, a pageviews column, and comprehensive export functionality (CSV from the block, PDF/Excel from the main Export modal). The loading state was improved from a spinner to a skeleton loader, empty values now display em-dash (—), and rows use stable keys for better React reconciliation. Key changes:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| components/dashboard/Campaigns.tsx | Added sortable columns, favicons, pageviews column, skeleton loading, CSV export, and stable row keys. Minor CSV injection risk in export. |
| components/dashboard/ExportModal.tsx | Added campaigns prop and export support for PDF and Excel formats using existing patterns consistently. |
| app/sites/[id]/page.tsx | Added campaigns data fetching with getCampaigns and passed campaigns to ExportModal. Clean integration with existing dashboard. |
| CHANGELOG.md | Added comprehensive changelog entry describing all Campaigns block improvements accurately. |
Sequence Diagram
sequenceDiagram
participant User
participant Page as SiteDashboardPage
participant API as getCampaigns API
participant Campaigns as Campaigns Component
participant Export as ExportModal
User->>Page: Load dashboard
Page->>API: getCampaigns(siteId, dateRange, 100)
API-->>Page: campaigns data
Page->>Campaigns: Pass campaigns via props
Page->>Export: Pass campaigns to ExportModal
User->>Campaigns: Click column header
Campaigns->>Campaigns: handleSort(key)
Campaigns->>Campaigns: Update sortKey/sortDir state
Campaigns->>Campaigns: Re-render with sortedData
User->>Campaigns: Click Export button
Campaigns->>Campaigns: handleExportCampaigns()
Campaigns->>Campaigns: Generate CSV from sortedData
Campaigns->>User: Download campaigns_[dateRange].csv
User->>Export: Click main Export, choose PDF
Export->>Export: Generate PDF with campaigns table
Export->>User: Download PDF with Campaigns section
User->>Export: Click main Export, choose Excel
Export->>Export: Create Campaigns sheet
Export->>User: Download Excel with Campaigns tab
Comment on lines
+130
to
+132
| ...rows.map(r => | ||
| [r.source, r.medium || EMPTY_LABEL, r.campaign || EMPTY_LABEL, r.visitors, r.pageviews].join(',') | ||
| ), |
There was a problem hiding this comment.
CSV values with special characters (, " newlines) or formula injection chars (= + - @) aren't escaped, which could break CSV parsing or create security issues
Suggested change
| ...rows.map(r => | |
| [r.source, r.medium || EMPTY_LABEL, r.campaign || EMPTY_LABEL, r.visitors, r.pageviews].join(',') | |
| ), | |
| ...rows.map(r => { | |
| const escapeCSV = (val: string | number) => { | |
| if (typeof val === 'number') return val.toString() | |
| const str = val.toString() | |
| if (str.includes(',') || str.includes('"') || str.includes('\n') || /^[=+\-@]/.test(str)) { | |
| return `"${str.replace(/"/g, '""')}"` | |
| } | |
| return str | |
| } | |
| return [ | |
| escapeCSV(r.source), | |
| escapeCSV(r.medium || EMPTY_LABEL), | |
| escapeCSV(r.campaign || EMPTY_LABEL), | |
| r.visitors, | |
| r.pageviews | |
| ].join(',') | |
| }), |
Prompt To Fix With AI
This is a comment left during a code review.
Path: components/dashboard/Campaigns.tsx
Line: 130:132
Comment:
CSV values with special characters (`,` `"` newlines) or formula injection chars (`=` `+` `-` `@`) aren't escaped, which could break CSV parsing or create security issues
```suggestion
...rows.map(r => {
const escapeCSV = (val: string | number) => {
if (typeof val === 'number') return val.toString()
const str = val.toString()
if (str.includes(',') || str.includes('"') || str.includes('\n') || /^[=+\-@]/.test(str)) {
return `"${str.replace(/"/g, '""')}"`
}
return str
}
return [
escapeCSV(r.source),
escapeCSV(r.medium || EMPTY_LABEL),
escapeCSV(r.campaign || EMPTY_LABEL),
r.visitors,
r.pageviews
].join(',')
}),
```
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work Item
PULSE-53
Summary
Changes
campaigns?: CampaignStat[]prop; campaigns table in PDF export; campaigns sheet in Excel export; use getReferrerDisplayName for source displayTest Plan