Repository navigation
feat: add the AI spend total spend card - #32338
Conversation
c2bb9d7 to
9772ff9
Compare
9772ff9 to
c8a2e29
Compare
5572d9a to
e63249b
Compare
e63249b to
6f99b0f
Compare
6f99b0f to
0887658
Compare
0887658 to
8e31c1b
Compare
8e31c1b to
141d658
Compare
141d658 to
03d16b8
Compare
03d16b8 to
5d47d37
Compare
c4af7f9 to
70fb240
Compare
70fb240 to
3a74621
Compare
3a74621 to
12286de
Compare
1bfa67d to
15b6cf1
Compare
15b6cf1 to
add0967
Compare
| {overviewError != null && <ErrorAlert error={overviewError} />} | ||
| {(overview !== undefined || overviewError == null) && ( |
There was a problem hiding this comment.
I'd prefer strict equality here. Loose != null / == null quietly treats undefined the same as null.
| {overviewError != null && <ErrorAlert error={overviewError} />} | |
| {(overview !== undefined || overviewError == null) && ( | |
| {overviewError !== null && <ErrorAlert error={overviewError} />} | |
| {(overview !== undefined || overviewError === null) && ( |
Tightening the prop type would make the strict check correct and discourage the loose one. useQuery already returns Error | null, so overviewError could be typed Error | null here (L21) and in AISpendPageView (the same goes for organizationsError and its != null checks there). The types in api/errors.ts don't fit: ApiError would need a cast from the query's Error, and network errors have no response. One catch: mockApiError isn't assignable to Error, so the stories would need a small adjustment.
Generated by Coder Agents on behalf of @jeremyruppel.
There was a problem hiding this comment.
I'm curious why we don't have a linter rule catching this?
There was a problem hiding this comment.
yeah 100% we should. agent had this to say in its investigation:
It's also an established pattern in this area of the code:
Other AI settings pages use it the same way, for example InstructionsPageView.tsx:83 (organizationAccessError != null) and OrganizationInstructionsSettings.tsx:68-113.
Across site/src, about 67 places use the loose == null / != null and about 354 use the strict form.
but I agree with you, I'm surprised we don't already have this locked down
There was a problem hiding this comment.
Yeah, it seems this pattern is used throughout the codebase, and the lint allows it. I applied the changes on this stack. @jeremyruppel @DanielleMaywood should I go ahead and create a linear issue just to keep track of this?
There was a problem hiding this comment.
Jeremy has already got a PR up for this, no need for you to track it
1e4e754 to
1376b61
Compare
1376b61 to
cc9b953
Compare
cc9b953 to
d3ab1ba
Compare
Description
Adds the Total spend card to the AI spend Overview tab. The total comes from the fast overview endpoint, and the "N models not set up" warning from
GET /api/experimental/organizations/{organization}/ai/model-prices/unpriced, which is slower, so the total renders first and the warning follows with its own loading state.Changes
API.experimental.getOrganizationUnpricedAIModelsand theorganizationUnpricedAIModelsquery. The page requests it alongside the overview, and viewers who cannot read the organization's model prices get a 403.StatCard, the labeled figure the overview cards share, andTotalSpendCard, which shows a skeleton until the total loads and a spinner while the unpriced models load.formatCostMicros, e.g. "$2,621.70", like the other spend amounts.MockUnpricedAIModels, a test for the unpriced models request, and stories for the card states, including the hidden warning when the request fails.Related to AIGOV-732
Note
Generated by Coder Agents on behalf of @ssncferreira.