-
Notifications
You must be signed in to change notification settings - Fork 514
Data-grid overhaul + session-replays / team-payments dashboard surfaces #1424
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
Open
mantrakp04
wants to merge
14
commits into
dev
Choose a base branch
from
refactor/data-grid-and-dashboard-surfaces
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2adafbc
refactor(dashboard): data-grid overhaul + session-replays / team-paym…
mantrakp04 cabcf19
feat(dashboard): implement paginated teams listing and enhance permis…
mantrakp04 c8ce7f4
update docs
mantrakp04 0ef67be
Merge branch 'dev' into refactor/data-grid-and-dashboard-surfaces
mantrakp04 8ea4ccc
refactor(dashboard): enhance permission handling and pagination
mantrakp04 de9b714
fix(dashboard): improve session replay query handling and data grid s…
mantrakp04 c43647d
Merge branch 'dev' into refactor/data-grid-and-dashboard-surfaces
mantrakp04 b0d290e
chore: remove unused 'dev:tui' script from multiple package.json files
mantrakp04 9a55c2a
refactor(api): streamline user and team data retrieval with pagination
mantrakp04 99f94e3
fix(api): improve pagination error handling and sorting logic
mantrakp04 bc9b1e5
fix(api): enhance pagination validation and error handling
mantrakp04 37ead67
fix(dashboard): enhance user permissions handling and loading states
mantrakp04 8b7e60a
fix(dashboard): enhance data grid state management and pagination
mantrakp04 bb11dd8
Merge branch 'dev' into refactor/data-grid-and-dashboard-surfaces
mantrakp04 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
There are no files selected for viewing
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
5 changes: 5 additions & 0 deletions
5
...ackend/prisma/migrations/20260507000000_add_project_user_last_active_at_idx/migration.sql
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,5 @@ | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS "ProjectUser_lastActiveAt" | ||
| ON "ProjectUser"("tenancyId", "isAnonymous", "lastActiveAt"); |
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
75 changes: 75 additions & 0 deletions
75
apps/backend/src/app/api/latest/permission-definitions-pagination.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,75 @@ | ||
| import { yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields"; | ||
| import { StatusError } from "@stackframe/stack-shared/dist/utils/errors"; | ||
| import { stringCompare } from "@stackframe/stack-shared/dist/utils/strings"; | ||
|
|
||
| // Binary search: index of the first item whose id > cursor, in an | ||
| // array already sorted by `stringCompare(a.id, b.id)`. | ||
| function firstIndexAfter<T extends { id: string }>(sorted: T[], cursor: string): number { | ||
| let lo = 0; | ||
| let hi = sorted.length; | ||
| while (lo < hi) { | ||
| const mid = (lo + hi) >>> 1; | ||
| if (stringCompare(sorted[mid].id, cursor) <= 0) lo = mid + 1; | ||
| else hi = mid; | ||
| } | ||
| return lo; | ||
| } | ||
|
|
||
| type PermissionDefinition = { | ||
| id: string, | ||
| description?: string, | ||
| contained_permission_ids: string[], | ||
| }; | ||
|
|
||
| type ListQuery = { | ||
| limit?: number, | ||
| cursor?: string, | ||
| query?: string, | ||
| }; | ||
|
|
||
| export const permissionDefinitionsListQuerySchema = yupObject({ | ||
| limit: yupNumber().integer().min(1).max(200).optional().meta({ openapiField: { onlyShowInOperations: ['List'], description: "Maximum number of items to return (capped at 200). When set, the response is paginated via cursor." } }), | ||
| cursor: yupString().optional().meta({ openapiField: { onlyShowInOperations: ['List'], description: "Cursor (permission id) to start the next page from. Requires `limit` to also be set." } }), | ||
| query: yupString().optional().meta({ openapiField: { onlyShowInOperations: ['List'], description: "Free-text filter applied to permission id and description (case-insensitive)." } }), | ||
| }); | ||
|
|
||
| export function paginatePermissionDefinitions(items: PermissionDefinition[], query: ListQuery) { | ||
| if (query.cursor != null && query.limit === undefined) { | ||
| throw new StatusError(StatusError.BadRequest, "`cursor` requires `limit` to also be set."); | ||
| } | ||
|
|
||
| const search = query.query?.trim().toLowerCase(); | ||
| const filtered = (search | ||
| ? items.filter((p) => | ||
| p.id.toLowerCase().includes(search) | ||
| || (p.description?.toLowerCase().includes(search) ?? false)) | ||
| : items.slice() | ||
| ).sort((a, b) => stringCompare(a.id, b.id)); | ||
|
|
||
| if (query.limit === undefined) { | ||
| return { items: filtered, is_paginated: false as const }; | ||
| } | ||
|
|
||
| let startIdx = 0; | ||
| if (query.cursor != null) { | ||
| const cursorIdx = filtered.findIndex((p) => p.id === query.cursor); | ||
| // If the cursor row was deleted (or filtered out) between page | ||
| // requests, fall back to "first id strictly greater than the cursor" | ||
| // rather than 400'ing the client mid-scroll. Worst case the user | ||
| // sees a one-row gap; the alternative is a hard error on infinite | ||
| // scroll for any concurrent edit. | ||
| startIdx = cursorIdx === -1 | ||
| ? firstIndexAfter(filtered, query.cursor) | ||
| : cursorIdx + 1; | ||
| } | ||
| const slice = filtered.slice(startIdx, startIdx + query.limit); | ||
| const hasMore = startIdx + query.limit < filtered.length; | ||
|
|
||
| return { | ||
| items: slice, | ||
| is_paginated: true as const, | ||
| pagination: { | ||
| next_cursor: hasMore && slice.length > 0 ? slice[slice.length - 1].id : null, | ||
| }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }; | ||
| } | ||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lastEventAtFromfilter is silently dropped from cursor validation when both bounds are set.Two separate object spreads target the same
lastEventAtkey:When both bounds are provided, the second spread overwrites the first, so
findFirstonly enforceslteand thegtelower bound is lost. This means a cursor whoselastEventAtis beforelastEventAtFromwill still pass validation (noItemNotFound), even though the main query at lines 218–219 correctly excludes such rows. The result is a cursor that anchors paging outside the active filter window — defeating the whole purpose of the validation block called out in the PR commit ("ensure the cursor matches the current filter set").Note the
teamIdsFilteranduserIdsFilterare also keyed ontenancyId/teamIdbut those collisions happen to merge cleanly via Prisma nested types; only thelastEventAtpair self-collides.🐛 Proposed fix: combine into a single `lastEventAt` clause
const row = await prisma.sessionReplay.findFirst({ where: { tenancyId: auth.tenancy.id, id: cursorId, ...userIdsFilter.length > 0 ? { projectUserId: { in: userIdsFilter } } : {}, - ...lastEventAtFrom ? { lastEventAt: { gte: lastEventAtFrom } } : {}, - ...lastEventAtTo ? { lastEventAt: { lte: lastEventAtTo } } : {}, + ...(lastEventAtFrom || lastEventAtTo) ? { + lastEventAt: { + ...lastEventAtFrom ? { gte: lastEventAtFrom } : {}, + ...lastEventAtTo ? { lte: lastEventAtTo } : {}, + }, + } : {}, ...teamIdsFilter.length > 0 ? {🤖 Prompt for AI Agents