Skip to content

Moved duplicated admin analytics files into shared module - #29685

Merged
9larsons merged 2 commits into
mainfrom
slars/merge-analytics-dup-components
Jul 30, 2026
Merged

9larsons merged 2 commits into
mainfrom
slars/merge-analytics-dup-components

Conversation

@9larsons

Copy link
Copy Markdown
Contributor

Deduplicates a handful of small analytics files in apps/admin between the site-wide (src/analytics) and post-scoped (src/posts/analytics) surfaces.

Merged

  • empty-stat-view — the two copies were identical except for a -mt-10 offset in the site version. Moved to src/shared/analytics/empty-stat-view.tsx with an optional className prop merged via cn onto the element the offset was on; the site call site now passes -mt-10, so both surfaces render exactly as before. Both originals deleted.
  • POST_ANALYTICS_INCLUDE — folded src/posts/analytics/utils/constants.ts (a single constant) into src/shared/analytics/constants.ts; it had no name or value conflict with any shared constant. Importers updated, small file deleted.
  • GrowthSources named exports — both growth-sources components exported an unused named GrowthSources alongside their default export; the named exports are dropped (all call sites import the default). The two components themselves are intentionally left separate.

Left divergent on purpose

  • KPI_METRICS records (src/analytics/views/Stats/Web/web-kpi-metrics.ts vs src/posts/analytics/Web/components/kpi-metrics.ts) — concluded these are legitimately divergent rather than accidental drift, because the post record encodes post-page semantics the site record doesn't: a different metric key/label (duration/"Time on page" vs visit-duration/"Visit duration") and different chart colors; only the already-shared KpiMetric type is common.
  • Stats date-range-select (src/analytics/views/Stats/components/date-range-select.tsx) — not a pure re-export: it binds the shared DateRangeSelect to the site-wide analytics context (useAnalytics range state) so call sites don't each read the context, so it stays.

Verification

  • cd apps/admin && pnpm lint — clean
  • cd apps/admin && pnpm test:unit — 100 files, 1083 tests passed
  • cd apps/admin && pnpm typecheck — clean

no ref

- site and post analytics each had an identical empty-stat-view, differing only by a -mt-10 offset; the shared copy takes a className prop and the site call site passes the offset, so both surfaces render exactly as before
- POST_ANALYTICS_INCLUDE now lives with the rest of the shared analytics constants; it had no counterpart or conflict there
- dropped the unused named GrowthSources exports (all call sites import the default); the two growth-sources components themselves stay separate as they intentionally differ per surface
- the site/post KPI_METRICS records and the Stats date-range-select wrapper are deliberately left in place: the records encode surface-specific metrics and colors (visit-duration vs time-on-page), and the wrapper meaningfully binds the shared select to the site analytics context
@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 52f1ddcb-a9f1-4522-8f99-1222bdcc5a85

📥 Commits

Reviewing files that changed from the base of the PR and between 58587b3 and 7ab515c.

📒 Files selected for processing (1)
  • apps/admin/src/shared/analytics/empty-stat-view.tsx

Walkthrough

Analytics empty-state UI is consolidated into a shared component with optional class-name support, and analytics views update their imports and layout usage. The post-analytics include constant moves to shared analytics constants, with its consumers updated. Both GrowthSources components remove their named exports while retaining default exports.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: deduplicating admin analytics code into shared modules.
Description check ✅ Passed The description clearly matches the changeset and explains the shared-module refactor and verification steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch slars/merge-analytics-dup-components

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.

@nx-cloud

nx-cloud Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 58587b3

Command Status Duration Result
nx run @tryghost/admin:test:acceptance ✅ Succeeded 5m 41s View ↗
nx run-many -t test:unit -p @tryghost/admin ✅ Succeeded 2m 4s View ↗
nx run ghost-monorepo:lint:boundaries ✅ Succeeded 22s View ↗
nx run-many -t lint -p @tryghost/admin,ghost-mo... ✅ Succeeded 55s View ↗
nx run @tryghost/admin:build ✅ Succeeded 16s View ↗
nx run-many --target=build --projects=tag:publi... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-07-30 14:21:16 UTC

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/admin/src/shared/analytics/empty-stat-view.tsx`:
- Around line 10-11: Move the className merge from the icon container to the
outer empty-state wrapper in the empty-state component, so StatsView’s layout
classes such as -mt-10 affect the complete icon-and-message block. Keep the icon
container’s existing styling unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 484b0ca6-79ca-4f32-97e4-6354237ae8af

📥 Commits

Reviewing files that changed from the base of the PR and between 1938a05 and 58587b3.

📒 Files selected for processing (11)
  • apps/admin/src/analytics/views/Stats/Growth/components/growth-sources.tsx
  • apps/admin/src/analytics/views/Stats/layout/empty-stat-view.tsx
  • apps/admin/src/analytics/views/Stats/layout/stats-view.tsx
  • apps/admin/src/posts/analytics/Growth/components/growth-sources.tsx
  • apps/admin/src/posts/analytics/components/empty-stat-view.tsx
  • apps/admin/src/posts/analytics/components/post-analytics-view.tsx
  • apps/admin/src/posts/analytics/hooks/use-post-details.ts
  • apps/admin/src/posts/analytics/providers/post-analytics-provider.tsx
  • apps/admin/src/posts/analytics/utils/constants.ts
  • apps/admin/src/shared/analytics/constants.ts
  • apps/admin/src/shared/analytics/empty-stat-view.tsx
💤 Files with no reviewable changes (3)
  • apps/admin/src/posts/analytics/components/empty-stat-view.tsx
  • apps/admin/src/posts/analytics/utils/constants.ts
  • apps/admin/src/analytics/views/Stats/layout/empty-stat-view.tsx

ref #29685

Applied custom layout classes to the complete empty state so its icon and message move together.
@9larsons
9larsons enabled auto-merge (squash) July 30, 2026 14:22
@9larsons
9larsons merged commit cb818fd into main Jul 30, 2026
45 checks passed
@9larsons
9larsons deleted the slars/merge-analytics-dup-components branch July 30, 2026 14:30
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.

1 participant