@@ -26,7 +26,7 @@ import {
2626 spendRatio ,
2727 spendSeverity
2828} from './format'
29- import type { RequestyStore } from './state'
29+ import type { RequestyData , RequestyStore } from './state'
3030import type { RequestyTheme } from './ui-types'
3131
3232/** Model rows shown in the scrollbox before it scrolls. */
@@ -75,9 +75,13 @@ export function RequestyDetailDialog(props: DetailDialogProps): JSX.Element {
7575 when = { data ( ) }
7676 fallback = { < CenteredMessage theme = { theme ( ) } > { state ( ) . status === 'loading' ? 'Loading Requesty usage…' : 'No data yet.' } </ CenteredMessage > }
7777 >
78- < KpiRow store = { props . store } theme = { theme ( ) } thresholds = { props . thresholds } />
79- < BudgetSection store = { props . store } theme = { theme ( ) } thresholds = { props . thresholds } />
80- < ModelSection store = { props . store } theme = { theme ( ) } />
78+ { ( snapshot ) => (
79+ < >
80+ < KpiRow data = { snapshot ( ) } theme = { theme ( ) } thresholds = { props . thresholds } />
81+ < BudgetSection data = { snapshot ( ) } theme = { theme ( ) } thresholds = { props . thresholds } />
82+ < ModelSection data = { snapshot ( ) } theme = { theme ( ) } />
83+ </ >
84+ ) }
8185 </ Show >
8286 </ box >
8387 </ box >
@@ -91,9 +95,11 @@ function Title(props: { store: RequestyStore; theme: RequestyTheme; showKeyName:
9195 return (
9296 < text fg = { props . theme . text } >
9397 < Show when = { props . store . data ( ) } fallback = { < strong > Requesty</ strong > } >
94- < a href = { analyticsUrl ( props . store . data ( ) ! . keyInfo . name ) } >
95- < strong > Requesty{ props . showKeyName ? ` (${ props . store . data ( ) ! . keyInfo . name } )` : '' } </ strong >
96- </ a >
98+ { ( data ) => (
99+ < a href = { analyticsUrl ( data ( ) . keyInfo . name ) } >
100+ < strong > Requesty{ props . showKeyName ? ` (${ data ( ) . keyInfo . name } )` : '' } </ strong >
101+ </ a >
102+ ) }
97103 </ Show >
98104 </ text >
99105 )
@@ -107,8 +113,8 @@ function CenteredMessage(props: { children: string; theme: RequestyTheme; error?
107113 )
108114}
109115
110- function KpiRow ( props : { store : RequestyStore ; theme : RequestyTheme ; thresholds : SpendThresholds } ) : JSX . Element {
111- const data = ( ) => props . store . data ( ) !
116+ function KpiRow ( props : { data : RequestyData ; theme : RequestyTheme ; thresholds : SpendThresholds } ) : JSX . Element {
117+ const data = ( ) => props . data
112118 const limit = ( ) => data ( ) . keyInfo . monthly_limit
113119 const spend = ( ) => data ( ) . keyInfo . monthly_spend
114120 const ratio = ( ) => spendRatio ( spend ( ) , limit ( ) )
@@ -125,27 +131,29 @@ function KpiRow(props: { store: RequestyStore; theme: RequestyTheme; thresholds:
125131 < Metric label = "Remaining" value = { formatUsd ( limit ( ) - spend ( ) ) } theme = { props . theme } color = { severityColor ( severity ( ) , props . theme ) } />
126132 </ Show >
127133 < Show when = { projectionParts ( ) } >
128- < TrendMetric
129- label = { `End of Month ( ${ projectionMethodLabel ( projectionParts ( ) ! . method ) } )` }
130- value = { `~ ${ formatUsd ( projectionParts ( ) ! . projected ) } ` }
131- theme = { props . theme }
132- color = { isProjectionOverLimit ( spend ( ) , limit ( ) , new Date ( ) , projection ( ) ) ? props . theme . error : props . theme . text }
133- indicator = {
134- projectionParts ( ) ! . arrow ? { text : projectionParts ( ) ! . arrow , color : paceColor ( projectionParts ( ) ! . pace , props . theme ) } : undefined
135- }
136- />
134+ { ( parts ) => (
135+ < TrendMetric
136+ label = { `End of Month ( ${ projectionMethodLabel ( parts ( ) . method ) } ) ` }
137+ value = { `~ ${ formatUsd ( parts ( ) . projected ) } ` }
138+ theme = { props . theme }
139+ color = { isProjectionOverLimit ( spend ( ) , limit ( ) , new Date ( ) , projection ( ) ) ? props . theme . error : props . theme . text }
140+ indicator = { parts ( ) . arrow ? { text : parts ( ) . arrow , color : paceColor ( parts ( ) . pace , props . theme ) } : undefined }
141+ />
142+ ) }
137143 </ Show >
138144 < Show when = { monthDelta ( ) } >
139- < TrendMetric
140- label = "last month"
141- value = { formatUsd ( data ( ) . lastMonthSpend ) }
142- theme = { props . theme }
143- color = { props . theme . text }
144- indicator = { {
145- text : `${ monthDelta ( ) ! . arrow } ${ monthDelta ( ) ! . sign } ${ monthDelta ( ) ! . pct } %` ,
146- color : monthDelta ( ) ! . pct > 0 ? props . theme . error : monthDelta ( ) ! . pct < 0 ? props . theme . success : props . theme . textMuted
147- } }
148- />
145+ { ( delta ) => (
146+ < TrendMetric
147+ label = "last month"
148+ value = { formatUsd ( data ( ) . lastMonthSpend ) }
149+ theme = { props . theme }
150+ color = { props . theme . text }
151+ indicator = { {
152+ text : `${ delta ( ) . arrow } ${ delta ( ) . sign } ${ delta ( ) . pct } %` ,
153+ color : delta ( ) . pct > 0 ? props . theme . error : delta ( ) . pct < 0 ? props . theme . success : props . theme . textMuted
154+ } }
155+ />
156+ ) }
149157 </ Show >
150158 </ box >
151159 )
@@ -156,7 +164,7 @@ function Metric(props: { label: string; value: string; theme: RequestyTheme; col
156164 < box flexDirection = "column" flexGrow = { 1 } flexBasis = { 0 } >
157165 < text fg = { props . color } >
158166 < strong > { props . value } </ strong >
159- < Show when = { props . tokens } > { formatTokenInline ( props . tokens ! . input , props . tokens ! . output ) } </ Show >
167+ < Show when = { props . tokens } > { ( tokens ) => < > { formatTokenInline ( tokens ( ) . input , tokens ( ) . output ) } </ > } </ Show >
160168 </ text >
161169 < text fg = { props . theme . textMuted } > { props . label } </ text >
162170 </ box >
@@ -178,16 +186,20 @@ function TrendMetric(props: {
178186 < text fg = { props . theme . textMuted } >
179187 { props . label }
180188 < Show when = { props . indicator } >
181- { ' ' }
182- < span style = { { fg : props . indicator ! . color } } > { props . indicator ! . text } </ span >
189+ { ( indicator ) => (
190+ < >
191+ { ' ' }
192+ < span style = { { fg : indicator ( ) . color } } > { indicator ( ) . text } </ span >
193+ </ >
194+ ) }
183195 </ Show >
184196 </ text >
185197 </ box >
186198 )
187199}
188200
189- function BudgetSection ( props : { store : RequestyStore ; theme : RequestyTheme ; thresholds : SpendThresholds } ) : JSX . Element {
190- const data = ( ) => props . store . data ( ) !
201+ function BudgetSection ( props : { data : RequestyData ; theme : RequestyTheme ; thresholds : SpendThresholds } ) : JSX . Element {
202+ const data = ( ) => props . data
191203 const limit = ( ) => data ( ) . keyInfo . monthly_limit
192204 const spend = ( ) => data ( ) . keyInfo . monthly_spend
193205 const ratio = ( ) => spendRatio ( spend ( ) , limit ( ) )
@@ -261,8 +273,8 @@ function StatusBadge(props: { overBudget: boolean; theme: RequestyTheme }): JSX.
261273 )
262274}
263275
264- function ModelSection ( props : { store : RequestyStore ; theme : RequestyTheme } ) : JSX . Element {
265- const data = ( ) => props . store . data ( ) !
276+ function ModelSection ( props : { data : RequestyData ; theme : RequestyTheme } ) : JSX . Element {
277+ const data = ( ) => props . data
266278 const models = ( ) => data ( ) . models
267279 const totalSpend = ( ) => models ( ) . reduce ( ( sum , model ) => sum + model . spend , 0 )
268280 const monthSpend = ( ) => data ( ) . keyInfo . monthly_spend
0 commit comments