Skip to content

fix: resolve settings/usage chart crash and add ClickHouse usage event seeds#19039

Open
FelixMalfait wants to merge 13 commits intomainfrom
fix/settings-usage-chart-crash-and-clickhouse-seeds
Open

fix: resolve settings/usage chart crash and add ClickHouse usage event seeds#19039
FelixMalfait wants to merge 13 commits intomainfrom
fix/settings-usage-chart-crash-and-clickhouse-seeds

Conversation

@FelixMalfait
Copy link
Copy Markdown
Member

Summary

  • Fix settings/usage page crash: The GraphWidgetLineChart component used on settings/usage was crashing with "Instance id is not provided and cannot be found in context" because it requires WidgetComponentInstanceContext (for tooltip/crosshair component states) which is only provided inside the widget system. Wraps the standalone chart usages with the required context provider.
  • Avoid mounting GraphWidgetLegend when hidden: The legend component calls useIsPageLayoutInEditMode() which requires PageLayoutEditModeProviderContext — another context only available inside the widget system. Since the settings page passes showLegend={false}, the fix conditionally unmounts the legend instead of always mounting it with a show prop. Applied consistently across all four chart types (line, bar, pie, gauge).
  • Add ClickHouse usage event seeds: Generates ~400 realistic usageEvent rows spanning the past 35 days with weighted user activity, weekday/weekend patterns, and gradual ramp-up. Enables developers to see the usage analytics page with data locally.

Test plan

  • Navigate to settings/usage — page should render without errors
  • Verify the daily usage line chart displays correctly
  • Navigate to a user detail page from the usage list
  • Verify the user detail chart renders without errors
  • Run npx nx clickhouse:seed twenty-server and confirm usage events are seeded
  • Verify chart legend still works correctly on dashboard widgets (no regression)

Made with Cursor

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 8 files

@FelixMalfait
Copy link
Copy Markdown
Member Author

FelixMalfait commented Mar 27, 2026

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:12256

This environment will automatically shut down after 5 hours.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/twenty-front/src/pages/settings/SettingsUsageUserDetail.tsx">

<violation number="1" location="packages/twenty-front/src/pages/settings/SettingsUsageUserDetail.tsx:103">
P2: Unconditional `previousData` fallback can render stale analytics for a different user when `userWorkspaceId` changes.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

…t seeds

The GraphWidgetLineChart used on the settings/usage page was crashing with
"Instance id is not provided and cannot be found in context" because it was
rendered outside the widget system context. This adds the required
WidgetComponentInstanceContext provider and avoids mounting GraphWidgetLegend
(which needs PageLayoutEditModeContext) when showLegend is false — applied
consistently across all four chart types.

Also adds usage event seeds to ClickHouse so developers get realistic
credit consumption data spanning the past month for the usage analytics page.

Made-with: Cursor
Pie chart tooltip now uses the same design language as GraphWidgetTooltip
(background, border, shadow, legend dot, proper font styles) instead of a
raw unstyled div.

Period selector changes no longer flash the entire page. Uses Apollo's
previousData to keep the current content visible while the new data loads,
only showing a blank state on the very first load.

Made-with: Cursor
…ge tab with Enterprise gating, model breakdown, and dollar/credit display

- Split AI_TOKEN operation type into AI_CHAT_TOKEN and AI_WORKFLOW_TOKEN
- Add conditional dollar vs credit display based on billing status
- Add operationTypes filter to usage analytics GraphQL API
- Add AI usage tab in Settings > AI (Enterprise only)
- Add AI usage by model breakdown (pie chart)
- Add per-user AI usage detail page
- Add toDollars utility in its own file
- Update ClickHouse seeds with new AI operation types and model IDs
- Fix EnterprisePlanModal card layout and button colors
- Link cloud usage page to AI breakdown

Made-with: Cursor
@FelixMalfait FelixMalfait force-pushed the fix/settings-usage-chart-crash-and-clickhouse-seeds branch from 41db6e3 to 775a84b Compare March 28, 2026 07:57
- Add getAdminAiUsageByWorkspace method to UsageAnalyticsService (cross-workspace query)
- Add getAdminAiUsageByWorkspace GraphQL query to AdminPanelResolver with workspace name resolution
- Import UsageModule in AdminPanelModule
- Add AI Usage by Workspace table section with Enterprise badge and period selector in SettingsAdminAI
- Use existing Enterprise Tag badge pattern for the AI usage empty state
- Fix duplicate import in SettingsAI and unused import in SettingsAIUsageUserDetail

Made-with: Cursor
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 8 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/twenty-front/src/modules/settings/admin-panel/ai/components/SettingsAdminAI.tsx">

<violation number="1" location="packages/twenty-front/src/modules/settings/admin-panel/ai/components/SettingsAdminAI.tsx:260">
P2: The usage section treats query loading as an empty dataset, so it can briefly display a false “No AI usage data recorded yet.” state before the request completes.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

…AI usage section

- Show period selector in adornment when Enterprise is active, Enterprise badge otherwise
- Use same BREAKDOWN_QUERY_LIMIT for admin workspace query instead of separate constant

Made-with: Cursor
FelixMalfait and others added 5 commits March 28, 2026 09:23
- Extract the Enterprise feature gate card (lock icon + Activate button) into a reusable component
- Use it in both SettingsAIUsageTab and SettingsAdminAI
- Show the gate card instead of the table when Enterprise is not active in admin AI usage section
- Skip usage query when Enterprise is not active

Made-with: Cursor
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 22 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/twenty-server/src/database/clickHouse/seeds/fixtures.ts">

<violation number="1" location="packages/twenty-server/src/database/clickHouse/seeds/fixtures.ts:103">
P2: Use the canonical Anthropic model ID (`claude-opus-4-6`) in seed data; `claude-opus-4.6` is not a valid catalog model key.</violation>
</file>

<file name="packages/twenty-front/src/pages/settings/ai/SettingsAIUsageUserDetail.tsx">

<violation number="1" location="packages/twenty-front/src/pages/settings/ai/SettingsAIUsageUserDetail.tsx:77">
P2: Pass `skip: !userWorkspaceId` to each usage section query to avoid running unscoped analytics requests when the route param is missing.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

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