Skip to content

[WEB-4323] refactor: Analytics refactor #7213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 16, 2025
Merged

Conversation

JayashTripathy
Copy link
Member

@JayashTripathy JayashTripathy commented Jun 13, 2025

Type of Change

  • Code refactoring

Summary by CodeRabbit

  • Refactor
    • Analytics tabs now feature localized labels and dynamic enable/disable states.
    • Analytics insights fields constant renamed for clarity and consistency.
    • Analytics wrapper and page titles updated to support internationalization.
    • Chart axis labels updated for improved positioning and localization keys.
    • Data table headers improved with enhanced styling for better readability.
  • Chores
    • Removed obsolete analytics tabs file and updated imports accordingly.
  • New Features
    • Added a new Russian translation key for entity counts.

…te analytics tab import to use getAnalyticsTabs function
Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

Walkthrough

The updates rename the insightsFields constant to ANALYTICS_INSIGHTS_FIELDS and update all references accordingly. The analytics tabs configuration is refactored from a static constant to a function (getAnalyticsTabs) that generates tab data with localization support. Related imports and usages are updated, and the obsolete static tabs file is removed. Additionally, components are modified to use internationalization keys for titles. Minor adjustments to chart label positioning and translation keys are also included.

Changes

File(s) Change Summary
packages/constants/src/analytics/common.ts Renamed insightsFields to ANALYTICS_INSIGHTS_FIELDS.
web/core/components/analytics/total-insights.tsx Updated all references from insightsFields to ANALYTICS_INSIGHTS_FIELDS.
web/ce/components/analytics/tabs.ts Removed file; previously exported static ANALYTICS_TABS array.
web/ce/components/analytics/tabs.tsx Added new module exporting getAnalyticsTabs function for generating tab configs with localization.
web/app/(all)/[workspaceSlug]/(projects)/analytics/page.ts(x) Replaced static ANALYTICS_TABS import with getAnalyticsTabs and updated tabs logic to use new structure.
web/core/components/analytics/analytics-wrapper.tsx Changed title prop to i18nTitle and added translation via useTranslation.
web/core/components/analytics/overview/root.tsx Updated AnalyticsWrapper usage to pass i18nTitle key instead of static title string.
web/core/components/analytics/work-items/root.tsx Updated AnalyticsWrapper usage to pass i18nTitle key instead of static title string.
packages/i18n/src/locales/ru/translations.json Added new translation key "no_of": "Количество {entity}" under "common.states".
web/core/components/analytics/work-items/created-vs-resolved.tsx Changed yAxis label translation key to "common.no_of" and adjusted label positioning.
web/core/components/analytics/work-items/priority-chart.tsx Changed yAxis label translation key to "common.no_of" and adjusted y-axis label vertical offset.
packages/propel/src/charts/bar-chart/root.tsx Modified YAxis label offset and dx to use optional chaining with fallback values.
web/core/components/analytics/insight-table/data-table.ts(x) Added whitespace-nowrap CSS class to <TableHead> component.
packages/types/src/analytics.d.ts Added interface AnalyticsTab defining tab structure with keys, labels, content, and disabled status.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AnalyticsPage
    participant getAnalyticsTabs
    participant TabsComponent

    User->>AnalyticsPage: Visit analytics page
    AnalyticsPage->>getAnalyticsTabs: Call getAnalyticsTabs(t)
    getAnalyticsTabs-->>AnalyticsPage: Return localized tab configs
    AnalyticsPage->>TabsComponent: Render Tabs with tab configs
    TabsComponent-->>User: Display analytics tabs
Loading

Suggested labels

🛠️refactor, ready_to_merge

Suggested reviewers

  • aaryan610

Poem

In the warren of code, a change hops in,
Constants renamed, where once they'd been.
Tabs now speak the user's tongue,
Old files gone, new functions sprung.
With every tweak, the dashboard grows bright—
Rabbits rejoice in code's new light! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b3beed and 88aa62d.

📒 Files selected for processing (2)
  • packages/types/src/analytics.d.ts (1 hunks)
  • web/core/components/analytics/insight-table/data-table.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • web/core/components/analytics/insight-table/data-table.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/types/src/analytics.d.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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)
packages/constants/src/analytics/common.ts (1)

14-14: Add readonly / as const for safer immutability & better type-narrowing

ANALYTICS_INSIGHTS_FIELDS is a pure lookup table that shouldn’t be mutated at runtime. Marking the structure as immutable gives you:

  1. Compile-time prevention of accidental writes.
  2. Precise string-literal inference when consumers index into the record.
-export const ANALYTICS_INSIGHTS_FIELDS: Record<TAnalyticsTabsBase, IInsightField[]> = {
+export const ANALYTICS_INSIGHTS_FIELDS: Record<TAnalyticsTabsBase, readonly IInsightField[]> = {
+} as const;

A tiny tweak, but it tightens the type-safety contract for downstream code.

web/core/components/analytics/total-insights.tsx (2)

83-87: Avoid recomputing the modulo expression on every render

ANALYTICS_INSIGHTS_FIELDS[analyticsType]?.length is evaluated twice during each render just to decide the grid size.
Cache the length once for readability and a (micro) performance win.

-        !peekView
-          ? ANALYTICS_INSIGHTS_FIELDS[analyticsType]?.length % 5 === 0
-            ? "gap-10 lg:grid-cols-5"
-            : "gap-8 lg:grid-cols-4"
+        !peekView
+          ? insightsLen % 5 === 0
+            ? "gap-10 lg:grid-cols-5"
+            : "gap-8 lg:grid-cols-4"

Place const insightsLen = ANALYTICS_INSIGHTS_FIELDS[analyticsType]?.length ?? 0; just above the return.


89-97: Minor: extract insights into a useMemo for stability

Mapping over ANALYTICS_INSIGHTS_FIELDS[...] directly means a new array reference each render, which can cause unnecessary child reconciling. A quick memoisation keeps the reference stable until its dependencies change.

-      {ANALYTICS_INSIGHTS_FIELDS[analyticsType]?.map((item) => (
+      {insights.map((item) => (
const insights = useMemo(
  () => ANALYTICS_INSIGHTS_FIELDS[analyticsType] ?? [],
  [analyticsType]
);

Not critical, but helps when the list grows.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6fe0415 and 2902fa0.

📒 Files selected for processing (5)
  • packages/constants/src/analytics/common.ts (1 hunks)
  • web/app/(all)/[workspaceSlug]/(projects)/analytics/page.tsx (2 hunks)
  • web/ce/components/analytics/tabs.ts (0 hunks)
  • web/ce/components/analytics/tabs.tsx (1 hunks)
  • web/core/components/analytics/total-insights.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • web/ce/components/analytics/tabs.ts
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/constants/src/analytics/common.ts (1)
packages/types/src/analytics.d.ts (1)
  • TAnalyticsTabsBase (5-5)
web/core/components/analytics/total-insights.tsx (1)
packages/constants/src/analytics/common.ts (1)
  • ANALYTICS_INSIGHTS_FIELDS (14-95)
web/app/(all)/[workspaceSlug]/(projects)/analytics/page.tsx (2)
web/ce/components/analytics/tabs.tsx (1)
  • getAnalyticsTabs (4-10)
packages/i18n/src/store/index.ts (1)
  • t (211-232)
web/ce/components/analytics/tabs.tsx (3)
packages/i18n/src/store/index.ts (1)
  • t (211-232)
web/core/components/analytics/overview/root.tsx (1)
  • Overview (19-19)
web/core/components/analytics/work-items/root.tsx (1)
  • WorkItems (19-19)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
web/core/components/analytics/total-insights.tsx (1)

5-5: Import rename looks good

The switch to ANALYTICS_INSIGHTS_FIELDS aligns with the new constant name – no further action needed.

web/app/(all)/[workspaceSlug]/(projects)/analytics/page.tsx (1)

43-44: Memo dependency list should include t or drop the outer memo

getAnalyticsTabs(t) already depends on t, but ANALYTICS_TABS is memoised with [t], while the second useMemo depends on ANALYTICS_TABS and router.
Since ANALYTICS_TABS is recreated when t changes, the second memo will also update – the current setup is fine. Just ensure ESLint’s react-hooks/exhaustive-deps rule stays green; otherwise, add t explicitly to the second dependency array.

@JayashTripathy JayashTripathy changed the title Analytics refactor refactor: Analytics refactor Jun 13, 2025
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this translation which got missed in last PR

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2902fa0 and 4c65734.

📒 Files selected for processing (4)
  • packages/i18n/src/locales/ru/translations.json (1 hunks)
  • web/core/components/analytics/analytics-wrapper.tsx (1 hunks)
  • web/core/components/analytics/overview/root.tsx (1 hunks)
  • web/core/components/analytics/work-items/root.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • web/core/components/analytics/work-items/root.tsx
  • packages/i18n/src/locales/ru/translations.json
🧰 Additional context used
🧬 Code Graph Analysis (1)
web/core/components/analytics/analytics-wrapper.tsx (2)
packages/i18n/src/hooks/use-translation.ts (1)
  • useTranslation (23-35)
packages/i18n/src/store/index.ts (1)
  • t (211-232)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
web/core/components/analytics/overview/root.tsx (1)

8-8:

❓ Verification inconclusive

i18n key existence check

Good move switching to a translation key.
Please double-check that "common.overview" is present in every locale file, otherwise the fallback behaviour will simply render the key string.


🏁 Script executed:

#!/bin/bash
# Quickly grep for the key in all locale JSON files
fd -e json -d 3 | xargs rg -n '"common.overview"'

Length of output: 51


🏁 Script executed:

#!/bin/bash
# Recursively search all JSON and YAML locale files for the translation key "common.overview"
rg -n '"common.overview"' -g '*.json' -g '*.yml' -g '*.yaml'

Length of output: 62


Please verify the common.overview key in all locale files
I ran a repo-wide grep for "common.overview" in JSON/YAML files and found no matches. Make sure this key exists in every locale (for example under src/locales/{en,fr,…}/common.json), otherwise users will see the raw key string at runtime.

To double-check, you can run:

rg -n '"common\.overview"' -g '*.json' -g '*.yml' -g '*.yaml'
web/core/components/analytics/analytics-wrapper.tsx (2)

3-4: Nice addition of useTranslation hook

Importing useTranslation and centralising translation in the wrapper keeps pages clean.
No issues spotted here.


12-18:

✅ Verification successful

Verify all call-sites migrated

Now that the prop name changed, ensure no old title="…" usages remain.


🏁 Script executed:

#!/bin/bash
# Search for outdated prop usage across repo
rg -n '<AnalyticsWrapper[^>]+title='

Length of output: 38


Continuing verification to catch multi-line usages:


🏁 Script executed:

#!/bin/bash
# List all AnalyticsWrapper call-sites with surrounding context to check for any remaining `title` props
rg -n '<AnalyticsWrapper' -C5

Length of output: 2052


✅ All AnalyticsWrapper Call-Sites Updated
No instances of the old title="…" prop remain—every usage now correctly uses i18nTitle.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c65734 and 0f3cef7.

📒 Files selected for processing (3)
  • packages/propel/src/charts/bar-chart/root.tsx (1 hunks)
  • web/core/components/analytics/work-items/created-vs-resolved.tsx (1 hunks)
  • web/core/components/analytics/work-items/priority-chart.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • web/core/components/analytics/work-items/created-vs-resolved.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
web/core/components/analytics/work-items/priority-chart.tsx (1)
packages/i18n/src/store/index.ts (1)
  • t (211-232)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (1)
packages/propel/src/charts/bar-chart/root.tsx (1)

127-129: Good addition, but update typing so offset / dx aren’t silently any

TBarChartProps['yAxis'] currently doesn’t expose offset and dx, so downstream callers need a type-cast or get an implicit any. Add them as optional numbers in the shared type (and bump the constant defaults here accordingly).

Would you like me to open a follow-up PR with the type additions?

@pushya22 pushya22 changed the title refactor: Analytics refactor [WEB-4323] refactor: Analytics refactor Jun 13, 2025
Copy link

makeplane bot commented Jun 13, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

@sriramveeraghanta sriramveeraghanta merged commit 0fa9c8b into preview Jun 16, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the analytics-refactor branch June 16, 2025 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants