GLQL: Add stat display type support
Add `stat` display type support to GLQL, enabling single metric visualization for any GLQL data type. **Note:** For trend indicators (% change), see #592912 which adds `showTrends` support for both stats and tables. This is a **GLQL-level visualization feature** that works with any data type (CodeSuggestion, Pipeline, MergeRequest, etc.) once their respective aggregation engines are available. **Part 2 of 6 visualization types** needed for SDLC dashboard migration: 1. Tables (#592262) - 18.11 GA ✅ 2. **Stats (this issue)** - Post-18.11 - Basic stat display 3. Sparklines (#592781) - Post-18.11 4. Bar Charts (#592782) - Post-18.11 5. Column Charts (#592784) - Post-18.11 6. Area Charts (#592783) - Post-18.11 7. showTrends (#592912) - Post-18.11 - Adds trends to stats and tables **Aligned with research issue #589575** for GLQL visualization syntax. **SDLC Dashboard use cases (CodeSuggestion):** - GitLab Duo Code Suggestions usage (Last 30 days) - count metric - GitLab Duo Code Suggestions acceptance rate (Last 30 days) - percentage metric - (For trends/% change, see #592912) ## Acceptance Criteria - [ ] GLQL UI renders queries with `display: stat` correctly - [ ] Query validation: Must have exactly 1 metric and 0 dimensions, otherwise error - [ ] Percentage-based metrics display with % formatting (e.g., "73.5%") - [ ] Count-based metrics display with comma formatting (e.g., "1,234") - [ ] Single stat shows metric label/title - [ ] Works with any GLQL data type (not CodeSuggestion-specific) - [ ] Feature flag `glql_stat_display_type` gates functionality using a `gitlab_com_derisk` flag - [ ] When flag is disabled, returns error: "stat display type not available" - [ ] No JavaScript console errors - [ ] Frontend tests cover stat rendering and validation ## Example GLQL Queries *Valid - Percentage metric:* ```yaml type: CodeSuggestion mode: analytics query: timestamp >= -30d display: stat aggregate: metrics: acceptanceRate as 'Acceptance Rate' ``` *Valid - Count metric:* ```yaml type: CodeSuggestion mode: analytics query: timestamp >= -30d display: stat aggregate: metrics: totalCount as 'Total Suggestions' ``` *Invalid - Multiple metrics (returns error):* ```yaml type: CodeSuggestion mode: analytics display: stat aggregate: metrics: totalCount as 'Total', acceptanceRate as 'Rate' # Error: "stat display type requires exactly 1 metric" ``` *Invalid - Has dimensions (returns error):* ```yaml type: CodeSuggestion mode: analytics display: stat aggregate: dimensions: language metrics: totalCount as 'Total' # Error: "stat display type cannot have dimensions (use showTrends in #592912 for time-based comparisons)" ``` ## Implementation Notes *Files to modify:* - `app/assets/javascripts/glql/` - Add stat display type renderer *Query validation:* - Must have exactly 1 metric - Must have 0 dimensions - Error if multiple metrics or any dimensions specified *Automatic formatting:* - Metrics ending in "Rate" or "Percentage" → format as percentage - Numeric count metrics → comma-separated formatting - Should handle any numeric metric from any data type *Size handling:* - Single default size - Dashboard layout framework controls actual sizing/positioning *Feature flag behavior:* - When `glql_stat_display_type` is disabled, return error with message *Relationship to showTrends (#592912):* - This issue covers basic stat display only - For trend indicators (▲ 12.5%), see #592912 - showTrends requires a time dimension and is a separate feature - This keeps stat display simple and focused ## Related Issues - Depends on: #592261 (GLQL Parser support) - Epic: &21212 (CodeSuggestion aggregations) - Related: #592262 (Tables), #592781 (Sparklines), #592782 (Bar Charts), #592783 (Area Charts), #592784 (Column Charts) - **See also:** #592912 (showTrends - adds % change indicators to stats and tables) - Research: #589575 (GLQL visualization requirements and syntax)
issue