-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[OPIK-8050] [FE] fix: paginate prompt version history and fix version labeling #8140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a7d83e1
[OPIK-8050] [FE] fix: paginate prompt version history and fix version…
natagh23 20afc75
fix(prompts): guard version-history pagination, dedupe fetcher, extra…
natagh23 60f0e33
fix(prompts): paginate Deploy menu owners, unify positional labels, d…
natagh23 9562adf
fix(prompts): keep compare dialog target correct during deep-link pag…
natagh23 247d732
fix(prompts): bound version-history refetch cost to actual changes
natagh23 90bede3
fix(prompts): disable window-focus refetch on version-history query
natagh23 9eece32
fix(prompts): guard pagination, dedupe scan cost, and stop compare-di…
natagh23 8791cb4
fix(prompts): keep compare dialog target correct during deep-link pag…
natagh23 537f6a7
fix(prompts): guard compare-dialog media diff on missing versions
natagh23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
apps/opik-frontend/src/api/prompts/getPromptVersionsById.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { QueryFunctionContext } from "@tanstack/react-query"; | ||
| import api, { PROMPTS_REST_ENDPOINT } from "@/api/api"; | ||
| import { PromptVersion } from "@/types/prompts"; | ||
| import { Sorting } from "@/types/sorting"; | ||
| import { processSorting } from "@/lib/sorting"; | ||
| import { Filter } from "@/types/filters"; | ||
| import { processFilters } from "@/lib/filters"; | ||
|
|
||
| export type GetPromptVersionsByIdParams = { | ||
| promptId: string; | ||
| page: number; | ||
| size: number; | ||
| sorting?: Sorting; | ||
| filters?: Filter[]; | ||
| search?: string; | ||
| }; | ||
|
|
||
| export type PromptVersionsByIdResponse = { | ||
| content: PromptVersion[]; | ||
| page: number; | ||
| size: number; | ||
| total: number; | ||
| sortable_by: string[]; | ||
| }; | ||
|
|
||
| export const getPromptVersionsById = async ( | ||
| { signal }: QueryFunctionContext, | ||
| { | ||
| promptId, | ||
| size, | ||
| page, | ||
| sorting, | ||
| filters, | ||
| search, | ||
| }: GetPromptVersionsByIdParams, | ||
| ): Promise<PromptVersionsByIdResponse> => { | ||
| const { data } = await api.get( | ||
| `${PROMPTS_REST_ENDPOINT}${promptId}/versions`, | ||
| { | ||
| signal, | ||
| params: { | ||
| ...processFilters(filters), | ||
| ...processSorting(sorting), | ||
| size, | ||
| page, | ||
| ...(search && { search }), | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| return data; | ||
| }; |
63 changes: 9 additions & 54 deletions
63
apps/opik-frontend/src/api/prompts/usePromptVersionsById.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
apps/opik-frontend/src/api/prompts/usePromptVersionsByIdInfinite.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { useInfiniteQuery } from "@tanstack/react-query"; | ||
| import { Sorting } from "@/types/sorting"; | ||
| import { Filter } from "@/types/filters"; | ||
| import { | ||
| getPromptVersionsById, | ||
| PromptVersionsByIdResponse, | ||
| } from "./getPromptVersionsById"; | ||
|
|
||
| const PAGE_SIZE = 25; | ||
|
|
||
| type UsePromptVersionsByIdInfiniteParams = { | ||
| promptId: string; | ||
| sorting?: Sorting; | ||
| filters?: Filter[]; | ||
| search?: string; | ||
| }; | ||
|
|
||
| type UsePromptVersionsByIdInfiniteOptions = { | ||
| enabled?: boolean; | ||
| refetchInterval?: number; | ||
| refetchOnWindowFocus?: boolean; | ||
| }; | ||
|
|
||
| export default function usePromptVersionsByIdInfinite( | ||
| params: UsePromptVersionsByIdInfiniteParams, | ||
| options?: UsePromptVersionsByIdInfiniteOptions, | ||
| ) { | ||
| return useInfiniteQuery<PromptVersionsByIdResponse>({ | ||
| // Shares the "prompt-versions" key prefix with usePromptVersionsById so | ||
| // the mutation hooks that invalidate that prefix (create/delete/deploy a | ||
| // version) also invalidate this list — otherwise the sidebar goes stale | ||
| // after every write. The explicit `view: "infinite"` marker keeps the two | ||
| // hooks' cache entries apart without relying on the fragile "this one | ||
| // never has page/size" invariant, which a future change to either hook | ||
| // could silently break. | ||
| queryKey: ["prompt-versions", { ...params, view: "infinite" as const }], | ||
| queryFn: (context) => | ||
| getPromptVersionsById(context, { | ||
| ...params, | ||
| size: PAGE_SIZE, | ||
| page: context.pageParam as number, | ||
| }), | ||
| // `size` on the response is the actual item count returned (not the | ||
| // requested page size), so it shrinks on the last page and hits 0 past | ||
| // it — `page * size` is not a valid "items seen so far" once that | ||
| // happens. Sum each page's real content length instead. An empty page | ||
| // always ends pagination outright: trusting `total` past that point can | ||
| // loop forever if it's out of sync with the actual row count (e.g. a | ||
| // concurrent delete between the count and the page query). | ||
| getNextPageParam: (lastPage, allPages) => { | ||
| if (lastPage.content.length === 0) return undefined; | ||
| const fetchedCount = allPages.reduce( | ||
| (sum, p) => sum + p.content.length, | ||
| 0, | ||
| ); | ||
| return fetchedCount < lastPage.total ? allPages.length + 1 : undefined; | ||
|
natagh23 marked this conversation as resolved.
|
||
| }, | ||
| initialPageParam: 1, | ||
| ...options, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.