77
88import type { SentryContext } from "../../../context.js" ;
99import { buildCommand } from "../../../lib/command.js" ;
10- import { formatWidgetTypes } from "../../../lib/formatters/human .js" ;
10+ import { renderMarkdown } from "../../../lib/formatters/markdown .js" ;
1111import { CommandOutput } from "../../../lib/formatters/output.js" ;
12+ import { type Column , writeTable } from "../../../lib/formatters/table.js" ;
1213import {
1314 AGGREGATE_ALIASES ,
1415 DEFAULT_WIDGET_SIZE ,
@@ -21,6 +22,7 @@ import {
2122 SPAN_AGGREGATE_FUNCTIONS ,
2223 WIDGET_TYPES ,
2324} from "../../../types/dashboard.js" ;
25+ import type { Writer } from "../../../types/index.js" ;
2426
2527/** Category classification for display types */
2628const DISPLAY_TYPE_CATEGORY : Record <
@@ -59,6 +61,72 @@ export type WidgetTypesResult = {
5961 aggregateAliases : Record < string , string > ;
6062} ;
6163
64+ /**
65+ * Format widget types info for human-readable terminal output.
66+ *
67+ * Renders grid info, a display types table, a datasets table, and
68+ * aggregate function summaries.
69+ */
70+ function formatWidgetTypesHuman ( result : WidgetTypesResult ) : string {
71+ const parts : string [ ] = [ ] ;
72+ const buffer : Writer = { write : ( s ) => parts . push ( s ) } ;
73+
74+ // Grid header
75+ parts . push ( renderMarkdown ( `**Grid:** ${ result . grid . columns } columns` ) ) ;
76+ parts . push ( "\n" ) ;
77+
78+ // Display types table
79+ type DisplayRow = WidgetTypesResult [ "displayTypes" ] [ number ] ;
80+ const dtColumns : Column < DisplayRow > [ ] = [
81+ { header : "DISPLAY TYPE" , value : ( r ) => r . name } ,
82+ { header : "WIDTH:" , value : ( r ) => String ( r . defaultWidth ) , align : "right" } ,
83+ {
84+ header : "HEIGHT:" ,
85+ value : ( r ) => String ( r . defaultHeight ) ,
86+ align : "right" ,
87+ } ,
88+ { header : "CATEGORY" , value : ( r ) => r . category } ,
89+ ] ;
90+ writeTable ( buffer , result . displayTypes , dtColumns ) ;
91+
92+ parts . push ( "\n" ) ;
93+
94+ // Datasets table
95+ type DatasetRow = WidgetTypesResult [ "datasets" ] [ number ] ;
96+ const dsColumns : Column < DatasetRow > [ ] = [
97+ { header : "DATASET" , value : ( r ) => r . name } ,
98+ { header : "DEFAULT" , value : ( r ) => ( r . isDefault ? "✓" : "" ) } ,
99+ ] ;
100+ writeTable ( buffer , result . datasets , dsColumns ) ;
101+
102+ parts . push ( "\n" ) ;
103+
104+ // Aggregate functions
105+ const aggLines : string [ ] = [ ] ;
106+ aggLines . push (
107+ `**Aggregates (spans):** ${ result . aggregateFunctions . spans . join ( ", " ) } `
108+ ) ;
109+
110+ const spanSet = new Set ( result . aggregateFunctions . spans ) ;
111+ const discoverOnly = result . aggregateFunctions . discover . filter (
112+ ( f ) => ! spanSet . has ( f )
113+ ) ;
114+ if ( discoverOnly . length > 0 ) {
115+ aggLines . push ( `**Aggregates (discover):** + ${ discoverOnly . join ( ", " ) } ` ) ;
116+ }
117+
118+ const aliasEntries = Object . entries ( result . aggregateAliases ) ;
119+ if ( aliasEntries . length > 0 ) {
120+ aggLines . push (
121+ `**Aliases:** ${ aliasEntries . map ( ( [ k , v ] ) => `${ k } → ${ v } ` ) . join ( ", " ) } `
122+ ) ;
123+ }
124+
125+ parts . push ( renderMarkdown ( aggLines . join ( "\n" ) ) ) ;
126+
127+ return parts . join ( "" ) . trimEnd ( ) ;
128+ }
129+
62130export const typesCommand = buildCommand ( {
63131 docs : {
64132 brief : "Show available widget display types and layout info" ,
@@ -76,7 +144,7 @@ export const typesCommand = buildCommand({
76144 " sentry dashboard widget types --json" ,
77145 } ,
78146 output : {
79- human : formatWidgetTypes ,
147+ human : formatWidgetTypesHuman ,
80148 } ,
81149 parameters : {
82150 positional : { kind : "array" , parameter : { brief : "" , parse : String } } ,
0 commit comments