Add field presenter variant concept for context-aware rendering
What does this MR do and why?
Adds a field presenter variant concept for context-aware rendering in list displays. This is the third MR in a stack that adds CodeSuggestion analytics support to the GitLab UI.
What Changed
- FieldPresenter variant prop: added a
variantprop to FieldPresenter that allows presenter resolution to be context-aware. ThepresentersByFieldKeymap now supports variant keys (lowercase, e.g.compact) alongside typename keys (PascalCase). Variant matches take precedence over typename matches, withdefaultas the fallback. For example, theuserfield key usesUserAvatarPresenterwhen the item typename isDuoCodeSuggestionsAggregationResponseDimensions, but thecompactvariant overrides this to useUserPresenterinstead. - ListPresenter: conditionally renders a title heading only when a
titlefield is present (supporting analytics data which has no title), and passesvariant="compact"to field presenters for non-title fields - DataPresenter: removed the
modeprop and analytics-specific routing, sinceListPresenternow handles both standard and analytics list displays through the variant mechanism
MR Stack
- !233396 (merged) — Backend + GLQL pipeline
- !233397 (merged) — Analytics presenters
- This MR — Field presenter variants for context-aware list rendering
References
- GLQL UI integration for CodeSuggestion analytics (#592262)
- Add CodeSuggestions support to GLQL in GitLab UI (!228129 - closed)
- GLQL MR !347 (Analytics Infrastructure)
- GLQL MR !348 (CodeSuggestions Source)
- Work Item 592262
- ClickHouse Setup Documentation
- GLQL User Documentation
Screenshots or screen recordings
| Scenario | GLQL query | Output |
|---|---|---|
| Every metric and dimension - list | ![]() |
![]() |
| Every metric and dimension - ordered list | ![]() |
![]() |
| In the Data Analyst Agent | Requires a lot of cajoling until Data Analyst agent integration for CodeSuggesti... (#592264) is complete | ![]() |
| With feature flag disabled | ![]() |
![]() |
| Trying to use it outside analytics mode | ![]() |
![]() |
Trying to use fields |
![]() |
![]() |
Trying to use dimensions or metrics in standard mode |
![]() |
![]() |
How to set up and validate locally
Prerequisites
- Setup clickhouse
- Make sure to run migrations:
bundle exec rake gitlab:clickhouse:migrate - Enable clickhouse analytics:
echo "Gitlab::CurrentSettings.current_application_settings.update(use_clickhouse_for_analytics: true)" | rails c - Seed test data:
FILTER=ai_usage_stats bundle exec rake db:seed_fu
UI Testing
-
Navigate to a seeded projects issue or merge request (by default this is the
toolboxgroup), and go to a markdown enabled field (comments or descriptions for instance) -
Test that without the feature flag enabled, the
CodeSuggestiontype returns an error:mode: analytics display: orderedList query: type = CodeSuggestion and timestamp >= -30d dimensions: language metrics: totalCount, acceptanceRate sort: totalCount desc limit: 10 -
Enable the feature flag:
echo "Feature.enable(:glql_code_suggestion_analytics_aggregation)" | rails c -
Refresh the page, test that the query no longer errors and returns results
-
Now test other variants like: Ide comparison by language
mode: analytics display: list query: type = CodeSuggestion and language in ("ruby", "javascript", "python") dimensions: language, ideName metrics: totalCount, acceptedCount, rejectedCount, acceptanceRate sort: acceptanceRate descRecent activity
mode: analytics display: orderedList query: type = CodeSuggestion and timestamp >= -7d dimensions: language metrics: totalCount, usersCount, suggestionSizeSum sort: usersCount desc limit: 5User-specific
mode: analytics display: list query: type = CodeSuggestion and user = 2 and timestamp >= -14d dimensions: language, ideName metrics: totalCount, acceptanceRate, acceptedCount sort: totalCount desc -
Also verify that percentage presenters like
acceptanceRateshow as percentages -
Also verify that number presenters like
totalCountformat according to your browser language (e.g. 1,234 or 1.234)
Rest API endpoint
Test the /api/v4/glql REST API endpoint:
# Get a personal access token from GitLab UI: User Settings > Access Tokens
curl -H "PRIVATE-TOKEN: your_token" \
-H "Content-Type: application/json" \
-d '{
"glql_yaml": "query: type = CodeSuggestion and language = \"ruby\"\nmode: \"analytics\"\ndimensions: \"language\"\nmetrics: \"totalCount, acceptanceRate\"\nproject: \"toolbox/gitlab-smoke-tests\""
}' \
http://gdk.test:8080/api/v4/glql 












