8000 feat: add oldest sort option to session replays by 0xHericles · Pull Request #30848 · PostHog/posthog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add oldest sort option to session replays #30848

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
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

0xHericles
Copy link
Contributor

Problem

As described in #30824, there's currently no way to sort session recordings from oldest to newest. This makes it harder to watch sessions in the order they happened. This PR adds an "Oldest" sorting option to make that easier.

Changes

  • Added an "Oldest" sorting option under the existing "Latest" option in session recordings.

Screenshots

CleanShot 2025-04-05 at 01 49 47@2x

CleanShot 2025-04-05 at 01 50 03@2x

Does this work well for both Cloud and self-hosted?

Yes, it works well for both Cloud and self-hosted deployments.

How did you test this code?

  • Manually verified sorting behavior locally by navigating session recordings and ensuring the order was correct for both "Latest" and "Oldest".
  • Confirmed no regressions on other sorting options.

Copy link
Contributor
@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR introduces an "Oldest" sorting option for session recordings, allowing users to view sessions from the beginning of a journey.

  • /frontend/src/scenes/session-recordings/playlist/SessionRecordingsPlaylistSettings.tsx: Added new "Oldest" entry and updated label logic via the getLabel helper to handle the 'older' direction.
  • /frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts: Enhanced sorting logic by propagating a new 'direction' parameter for proper ordering and pagination.
  • /frontend/src/types.ts: Updated type definitions with a new RecordingDirection union to support sorting by 'newer' or 'older'.

💡 (3/5) Reply to the bot's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

< 8000 div data-view-component="true" class="TimelineItem-body">
Copy link
Member
@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of naming comments but otherwise this is great 🚀

@0xHericles
Copy link
Contributor Author

@pauldambra nice. Done! ;D

Copy link
Member
@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the FE tests failures are real.

the others will be because of missing secrets in PRs from forks

i'm happy with this if you can update the FE tests :)

@0xHericles
Copy link
Contributor Author

Oh sure, gonna check those.

@0xHericles
Copy link
Contributor Author

Hey! It was actually a bug! 😰🐛 I accidentally mixed up the offset (load older) logic with the asc/desc ordering in the recordings query. So I had to make a few backend tweaks to get everything working properly. Also added a new test case for ordering, so the tests can keep protecting us from me pushing bad stuff again, haha 😅

Nice experience overall! Learned a bit more about the project through this 🎉

@0xHericles
Copy link
Contributor Author

Hey @pauldambra, can I ask for a quick help here?

Error: posthog/session_recordings/queries/session_recording_list_from_query.py:289: error: Item "SelectSetQuery" of "SelectQuery | SelectSetQuery" has no attribute "order_by"  [union-attr]

this was the only way I managed to make the order by work. Putting it direcly on the parse select was giving me some errors, duplicating the direction identifier and things like that

@0xHericles
Copy link
Contributor Author

did some tweaks and fixed some tests. also added this select query stuff to the mypy baseline, tests should pass now.

export interface RecordingUniversalFilters {
date_from?: string | null
date_to?: string | null
duration: RecordingDurationFilter[]
filter_test_accounts?: boolean
filter_group: UniversalFiltersGroup
order?: RecordingsQuery['order']
direction?: SortDirection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 so this makes the API more powerful than the UI
e.g. I can sort for least active
that's not a terrible thing
but we could copy the DRF/Django approach and accept start_time and -start_time and then pick that out when we construct the query

i'm not actually sure which I prefer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, UI can be just as powerful if we split the direction logic into a new button. Keeping order + direction felt cleaner and more type-safe to me, but I like the DRF-style too. Also not sure which I prefer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, even if we add a direction button in the UI, DRF style would still work fine… Looks like a solid way to go

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we've talked a few times about wanting to have more in the API than in the UI (so folk can always self-serve)

i think here no button in the UI is fine

and we can allow start_time and -start_time (or whatevs typed from memory 😅 )

that way we can avoid a lot of the schema changes and just check as we generate the order by in the query

i'm on PTO next week but @veryayskiy can help keep things moving if we don't nail this today, really appreciate your patience with backwards and forwards here! API/schema always slightly more painful to change since we're stuck with it once released

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, no worries at all. Really enjoying the back and forth. It’s been super nice contributing to PostHog! Probably won’t get to it before the weekend, but sounds like a solid plan. Enjoy the PTO and thanks for looping in @veryayskiy 🙌

@0xHericles 0xHericles force-pushed the feat/session-replay-sorting branch from e51f0b0 to 905135b Compare April 13, 2025 12:56
@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week. If you want to permanentely keep it open, use the waiting label.

@0xHericles
Copy link
Contributor Author

Just a quick note: been a bit swamped, but I’m getting back to this soon!

@pauldambra pauldambra added waiting Prevents stale-bot from marking the PR as stale. and removed stale labels Apr 23, 2025
@0xHericles
Copy link
Contributor Author

Hey @pauldambra, I'm keeping order as string instead of doing something fancy with template literals like RecordingOrder | -${RecordingOrder} or adding more accepted values like -start_time, directly to the type. Looking through the codebase, I saw some order: string elsewhere and it works well. But let me know if you have a better suggestion or want me to change it.

@0xHericles
Copy link
Contributor Author

I saw the schema has just changed. Fixing the conflicts soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting Prevents stale-bot from marking the PR as stale.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0