Repository navigation
feat: show the total number of AI spend unpriced models - #32553
Conversation
a26e049 to
18757ae
Compare
18757ae to
c465e93
Compare
mollymaefraser
left a comment
There was a problem hiding this comment.
LGTM 🚀 few nits but nothing blocking
| const endDateSearchParam = "endDate"; | ||
| // The number of unpriced models the total spend card lists. 100 is the most the | ||
| // endpoint returns. | ||
| const UNPRICED_MODELS_COUNT = 100; |
There was a problem hiding this comment.
nit: could we export this the way TOP_SPENDERS_COUNT is exported from topSpenders.ts, and use it in AISpendPage.test.tsx instead of the literal 100? Then the tests follow the constant if it changes.
Small question: the list is capped at max-h-48 and "and M more" covers the rest, so do we need 100 rows? You mentioned this query is slow to compute, so a smaller page (10–20?) might be cheaper. Fine to keep 100 if it's intentional.
There was a problem hiding this comment.
Moved it to unpricedModels.ts like TOP_SPENDERS_COUNT and used it in the tests.
100 is intentional. It's the endpoint's maximum and the same limit the notification uses. Ideally, admins would fix unpriced models from a dedicated page, but until that exists, we want to show as many as possible here. In practice, a deployment is unlikely to have that many unpriced models. Once that page or workflow exists, we should revisit the limit.
On cost, the query already scans every unpriced model to compute count, so a bigger page mostly adds payload, not query time.
| const headingId = useId(); | ||
| // TODO(AIGOV-730): adjust once the unpriced models endpoint is paginated. | ||
| const isSingle = models.length === 1; | ||
| const isSingleModel = count === 1; |
There was a problem hiding this comment.
nit: count === 1 is right for the wording. The compact single-row layout (p-0, no px-2, no ScrollArea) depends on how many rows we render, though. They're equivalent today because count >= models.length, but splitting them would make the intent clearer:
const isSingleModel = count === 1;
const isSingleRow = models.length === 1 && count === 1;
Or just leave a comment saying why count is safe for both. Not blocking.
There was a problem hiding this comment.
The popover only renders with at least one model and count is never less than models.length, so count === 1 always means one row. I kept a single flag so the two can't drift.
| {unlistedCount > 0 && ( | ||
| <li className="p-2 text-sm text-content-secondary"> | ||
| and {unlistedCount} more | ||
| </li> | ||
| )} |
There was a problem hiding this comment.
nit (a11y): because "and M more" is an
- (a
right after the list, still inside the ScrollArea) keeps the list count accurate. Not blocking.
There was a problem hiding this comment.
Good catch, moved it to a <p> after the list so the item count is accurate.
| }; | ||
|
|
||
| /** More models have no price than the first page lists. */ | ||
| export const MoreModelsThanListed: Story = { |
There was a problem hiding this comment.
nit: this story renders the new "and M more" row, but nothing checks it. Could we add a play that opens the popover (like the meta play) and then checks await expect(screen.getByText("and 5 more")).toBeInTheDocument();? That makes it a regression test for the new behaviour.
There was a problem hiding this comment.
In our guidelines, stories only capture visual state and their play functions don't assert, so Pixel shows what changed. Assertions belong in Vitest tests, but in this case I think the story is enough: if the "and 5 more" row is removed or changed, it shows up in Pixel.
Description
The unpriced models endpoint is now paginated (#32170), so
modelsis one page andcountis the total. The total spend card used the number of listed models, so it would undercount with more than one page.Changes
UNPRICED_MODELS_COUNT.N Models not set upwithcount.and M moreunder the list for the models it doesn't show,countminus the listed models.TODO(AIGOV-730).Related to AIGOV-730
Note
Generated by Coder Agents on behalf of @ssncferreira.