:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(replay): keep bulk-delete selection in sync with what's on screen (#77139)
posthog[bot]1500d332990b
diff --git a/frontend/src/lib/utils/confirmationText.test.ts b/frontend/src/lib/utils/confirmationText.test.tsnew file mode 100644index 000000000000..51e784cafb55--- /dev/null+++ b/frontend/src/lib/utils/confirmationText.test.ts@@ -0,0 +1,13 @@+import { matchesConfirmationText } from 'lib/utils/confirmationText'++describe('matchesConfirmationText', () => {+ it.each([+ ['delete', 'delete', true],+ ['Delete', 'delete', true],+ [' delete ', 'delete', true],+ ['delet', 'delete', false],+ ['', 'delete', false],+ ])('matchesConfirmationText(%p, %p) === %p', (input, expected, result) => {+ expect(matchesConfirmationText(input, expected)).toBe(result)+ })+})diff --git a/frontend/src/lib/utils/confirmationText.ts b/frontend/src/lib/utils/confirmationText.tsnew file mode 100644index 000000000000..4bb5e48110e5--- /dev/null+++ b/frontend/src/lib/utils/confirmationText.ts@@ -0,0 +1,4 @@+/** Compares a user-typed confirmation phrase against the expected one, ignoring case and surrounding whitespace. */+export function matchesConfirmationText(input: string, expected: string): boolean {+ return input.trim().toLowerCase() === expected.trim().toLowerCase()+}diff --git a/frontend/src/scenes/data-management/managed-viewsets/DataWarehouseManagedViewsetImpactModal.tsx b/frontend/src/scenes/data-management/managed-viewsets/DataWarehouseManagedViewsetImpactModal.tsxindex cf96eee435b5..033cc8e38e55 100644--- a/frontend/src/scenes/data-management/managed-viewsets/DataWarehouseManagedViewsetImpactModal.tsx+++ b/frontend/src/scenes/data-management/managed-viewsets/DataWarehouseManagedViewsetImpactModal.tsx@@ -5,6 +5,7 @@ import { LemonButton, LemonInput, LemonModal, LemonTag } from '@posthog/lemon-uiimport { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'import { TeamMembershipLevel } from 'lib/constants'import { LemonBanner } from 'lib/lemon-ui/LemonBanner'+import { matchesConfirmationText } from 'lib/utils/confirmationText'import { DataWarehouseManagedViewsetSavedQuery } from '~/types'@@ -41,7 +42,7 @@ export function DataWarehouseManagedViewsetImpactModal({minimumAccessLevel: TeamMembershipLevel.Admin,})- const isConfirmationValid = confirmationInput === confirmText+ const isConfirmationValid = matchesConfirmationText(confirmationInput, confirmText)const views = propViews !== undefined ? propViews : logicViewsconst onConfirm = async (): Promise<void> => {diff --git a/frontend/src/scenes/persons/PersonDeleteModal.tsx b/frontend/src/scenes/persons/PersonDeleteModal.tsxindex 64e363613ea7..860648f7baf2 100644--- a/frontend/src/scenes/persons/PersonDeleteModal.tsx+++ b/frontend/src/scenes/persons/PersonDeleteModal.tsx@@ -3,6 +3,7 @@ import { useState } from 'react'import { LemonBanner, LemonButton, LemonCheckbox, LemonDivider, LemonInput, LemonModal, Link } from '@posthog/lemon-ui'+import { matchesConfirmationText } from 'lib/utils/confirmationText'import { personDeleteModalLogic } from 'scenes/persons/personDeleteModalLogic'import { PersonType } from '~/types'@@ -68,7 +69,7 @@ export function PersonDeleteModal(): JSX.Element | null {autoFocus/></div>- {deleteConfirmationText == DELETE_CONFIRMATION_TEXT && (+ {matchesConfirmationText(deleteConfirmationText, DELETE_CONFIRMATION_TEXT) && (<LemonBanner type="warning">Do NOT delete this person if you want to re-use the distinct IDs. Instead use split ID. Re-usingthe distinct ID of a deleted person is not supported and will result in a bad application state.@@ -83,7 +84,7 @@ export function PersonDeleteModal(): JSX.Element | null {type="primary"status="danger"disabledReason={- deleteConfirmationText !== DELETE_CONFIRMATION_TEXT+ !matchesConfirmationText(deleteConfirmationText, DELETE_CONFIRMATION_TEXT)? 'Please type the correct confirmation text': undefined}diff --git a/frontend/src/scenes/session-recordings/playlist/SessionRecordingsPlaylistSettings.tsx b/frontend/src/scenes/session-recordings/playlist/SessionRecordingsPlaylistSettings.tsxindex e4709fffe21c..11e5be894ce5 100644--- a/frontend/src/scenes/session-recordings/playlist/SessionRecordingsPlaylistSettings.tsx+++ b/frontend/src/scenes/session-recordings/playlist/SessionRecordingsPlaylistSettings.tsx@@ -12,6 +12,7 @@ import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { LemonMenu, LemonMenuItem } from 'lib/lemon-ui/LemonMenu/LemonMenu'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'+import { matchesConfirmationText } from 'lib/utils/confirmationText'import { sessionRecordingCollectionsLogic } from 'scenes/session-recordings/collections/sessionRecordingCollectionsLogic'import { urls } from 'scenes/urls'@@ -201,12 +202,21 @@ function SortedBy({}function ConfirmDeleteRecordings({ shortId }: { shortId?: string }): JSX.Element {- const { selectedRecordingsIds, isDeleteSelectedRecordingsDialogOpen, deleteConfirmationText } =- useValues(sessionRecordingsPlaylistLogic)+ const {+ selectedRecordingsIds,+ isDeleteSelectedRecordingsDialogOpen,+ deleteConfirmationText,+ isDeletingSelectedRecordings,+ } = useValues(sessionRecordingsPlaylistLogic)const { setIsDeleteSelectedRecordingsDialogOpen, setDeleteConfirmationText, handleDeleteSelectedRecordings } =useActions(sessionRecordingsPlaylistLogic)+ const isConfirmationValid = matchesConfirmationText(deleteConfirmationText, DELETE_CONFIRMATION_TEXT)+const handleClose = (): void => {+ if (isDeletingSelectedRecordings) {+ return+ }setIsDeleteSelectedRecordingsDialogOpen(false)setDeleteConfirmationText('')}@@ -232,24 +242,32 @@ function ConfirmDeleteRecordings({ shortId }: { shortId?: string }): JSX.ElementonChange={setDeleteConfirmationText}placeholder={DELETE_CONFIRMATION_TEXT}className="w-full"+ disabled={isDeletingSelectedRecordings}autoFocus/>+ {deleteConfirmationText.length > 0 && !isConfirmationValid && (+ <p className="text-danger text-sm mb-0">+ That doesn't match. Please type "{DELETE_CONFIRMATION_TEXT}" to confirm.+ </p>+ )}</div><div className="bg-warning-highlight border border-warning rounded p-2 text-sm">This action cannot be undone. Deleting recordings doesn't affect your billing.</div></div><div className="flex justify-end gap-2 mt-4">- <LemonButton type="secondary" onClick={handleClose}>+ <LemonButton+ type="secondary"+ onClick={handleClose}+ disabledReason={isDeletingSelectedRecordings ? 'Deleting...' : undefined}+ >Cancel</LemonButton><LemonButtontype="primary"- disabledReason={- deleteConfirmationText !== DELETE_CONFIRMATION_TEXT- ? 'Please type the correct confirmation text'- : undefined- }+ status="danger"+ loading={isDeletingSelectedRecordings}+ disabledReason={!isConfirmationValid ? 'Please type the correct confirmation text' : undefined}onClick={() => handleDeleteSelectedRecordings(shortId)}>Deletediff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.tsindex b09af9b4af37..0a683a34b29d 100644--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts@@ -957,6 +957,47 @@ describe('sessionRecordingsPlaylistLogic', () => {otherRecordings: [bRecording],})})++ it('clears a stale selection when filters change, instead of deleting recordings the user can no longer see', async () => {+ await expectLogic(logic)+ .toDispatchActions(['loadSessionRecordingsSuccess'])+ .toMatchValues({ otherRecordings: [aRecording, bRecording] })++ logic.actions.setSelectedRecordingsIds(['abc', 'def'])+ await expectLogic(logic).toMatchValues({ selectedRecordingsIds: ['abc', 'def'] })++ logic.actions.setFilters({ date_from: '-30d' })++ await expectLogic(logic).toMatchValues({ selectedRecordingsIds: [] })+ })++ it('ignores a second delete request while one is already in flight', async () => {+ let resolveDelete: (value: {+ success: boolean+ deleted_count: number+ total_requested: number+ failed_ids: string[]+ }) => void = () => {}+ jest.spyOn(api.recordings, 'bulkDeleteRecordings').mockReturnValue(+ new Promise((resolve) => {+ resolveDelete = resolve+ })+ )++ await expectLogic(logic)+ .toDispatchActions(['loadSessionRecordingsSuccess'])+ .toMatchValues({ otherRecordings: [aRecording, bRecording] })++ logic.actions.setSelectedRecordingsIds(['abc', 'def'])++ logic.actions.handleDeleteSelectedRecordings(undefined)+ logic.actions.handleDeleteSelectedRecordings(undefined)++ resolveDelete({ success: true, deleted_count: 2, total_requested: 2, failed_ids: [] })+ await expectLogic(logic).toDispatchActions(['addDeletedRecordings'])++ expect(api.recordings.bulkDeleteRecordings).toHaveBeenCalledTimes(1)+ })})})diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.tsindex 81a2344d6258..f7b732edd2a5 100644--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts@@ -497,6 +497,7 @@ export interface sessionRecordingsPlaylistLogicValues {isAddToCollectionModalOpen: booleanisCreatingNewCollectionInModal: booleanisDeleteSelectedRecordingsDialogOpen: boolean+ isDeletingSelectedRecordings: booleanlogicProps: SessionRecordingPlaylistLogicPropsmatchingEventsMatchType: MatchingEventsMatchTypenewCollectionName: string@@ -731,6 +732,9 @@ export interface sessionRecordingsPlaylistLogicActions {setIsDeleteSelectedRecordingsDialogOpen: (isDeleteSelectedRecordingsDialogOpen: boolean) => {isDeleteSelectedRecordingsDialogOpen: boolean}+ setIsDeletingSelectedRecordings: (isDeletingSelectedRecordings: boolean) => {+ isDeletingSelectedRecordings: boolean+ }setNewCollectionName: (newCollectionName: string) => {newCollectionName: string}@@ -887,6 +891,9 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogicisDeleteSelectedRecordingsDialogOpen,}),setDeleteConfirmationText: (deleteConfirmationText: string) => ({ deleteConfirmationText }),+ setIsDeletingSelectedRecordings: (isDeletingSelectedRecordings: boolean) => ({+ isDeletingSelectedRecordings,+ }),handleDeleteSelectedRecordings: (shortId?: string) => ({ shortId }),setIsAddToCollectionModalOpen: (isAddToCollectionModalOpen: boolean) => ({ isAddToCollectionModalOpen }),setAddToCollectionSearch: (addToCollectionSearch: string) => ({ addToCollectionSearch }),@@ -1178,6 +1185,11 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogic[] as string[],{setSelectedRecordingsIds: (_, { recordingsIds }) => recordingsIds,+ // The filtered/pinned lists reload from scratch on a filter change, so a prior selection+ // can no longer be matched against what's on screen - drop it rather than risk deleting+ // recordings the user can't see.+ setFilters: () => [],+ resetFilters: () => [],},],isDeleteSelectedRecordingsDialogOpen: [@@ -1193,6 +1205,12 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogicsetDeleteConfirmationText: (_, { deleteConfirmationText }) => deleteConfirmationText,},],+ isDeletingSelectedRecordings: [+ false,+ {+ setIsDeletingSelectedRecordings: (_, { isDeletingSelectedRecordings }) => isDeletingSelectedRecordings,+ },+ ],isAddToCollectionModalOpen: [false,{@@ -1224,418 +1242,449 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogic},],})),- listeners(({ props, actions, values }) => ({- loadAllRecordings: () => {- actions.loadSessionRecordings()- actions.loadPinnedRecordings()- },- setFilters: ({ filters }) => {- actions.loadSessionRecordings(undefined, filters)- props.onFiltersChange?.(values.filters)- actions.loadEventsHaveSessionId()- },-- resetFilters: () => {- actions.loadSessionRecordings()- props.onFiltersChange?.(values.filters)- },-- applyPropertyFilter: ({ propertyKey, propertyValue }) => {- // Validate property value- if (propertyValue === undefined || propertyValue === null) {+ listeners(({ props, actions, values }) => {+ // Selection is only ever set by user action, so it can go stale once the underlying+ // list changes shape - keep it intersected with what's actually rendered.+ const pruneSelectedRecordingsIds = (): void => {+ if (values.selectedRecordingsIds.length === 0) {return}-- // Determine property filter type- // For recordings: $browser, $os, $device_type, etc are Event properties- // $geoip_* and custom properties (no $) are Person properties- // Everything else with $ is Session property- const filterType =- propertyKey.startsWith('$geoip_') || !propertyKey.startsWith('$')- ? PropertyFilterType.Person- : ['$browser', '$os', '$device_type', '$initial_device_type', '$os_name'].includes(propertyKey)- ? PropertyFilterType.Event- : PropertyFilterType.Session-- // Create property filter object- const filter = {- type: filterType,- key: propertyKey,- value: propertyValue,- operator: PropertyOperator.Exact,- } as AnyPropertyFilter-- // Clone the current filter group structure and add to the first nested group- const currentGroup = values.filters.filter_group- const newGroup: UniversalFiltersGroup = {- ...currentGroup,- values: currentGroup.values.map((nestedGroup, index) => {- // Add to the first nested group (index 0)- if (index === 0 && 'values' in nestedGroup) {- return {- ...nestedGroup,- values: [...nestedGroup.values, filter],- } as UniversalFiltersGroup- }- return nestedGroup- }),- }-- actions.setFilters({ filter_group: newGroup })-- // Show toast notification with human-readable label and view filters button- const filterLabel = formatPropertyLabel(filter, {})- lemonToast.success(`Filter applied: ${filterLabel}`, {- toastId: `filter-applied-${propertyKey}`,- button: {- label: 'View filters',- action: () => {- actions.setIsFiltersExpanded(true)- },- },- })- },-- togglePropertyFilter: ({ propertyKey, propertyValue }) => {- // Validate property value- if (propertyValue === undefined || propertyValue === null) {- return+ const visibleIds = new Set(values.recordings.map((r) => r.id))+ const prunedIds = values.selectedRecordingsIds.filter((id) => visibleIds.has(id))+ if (prunedIds.length !== values.selectedRecordingsIds.length) {+ actions.setSelectedRecordingsIds(prunedIds)}+ }- // Determine property filter type- const filterType =- propertyKey.startsWith('$geoip_') || !propertyKey.startsWith('$')- ? PropertyFilterType.Person- : ['$browser', '$os', '$device_type', '$initial_device_type', '$os_name'].includes(propertyKey)- ? PropertyFilterType.Event- : PropertyFilterType.Session-- const currentGroup = values.filters.filter_group- const firstNestedGroup = currentGroup.values[0]+ return {+ loadAllRecordings: () => {+ actions.loadSessionRecordings()+ actions.loadPinnedRecordings()+ },+ setFilters: ({ filters }) => {+ actions.loadSessionRecordings(undefined, filters)+ props.onFiltersChange?.(values.filters)+ actions.loadEventsHaveSessionId()+ },- if (!firstNestedGroup || !('values' in firstNestedGroup)) {- return- }+ resetFilters: () => {+ actions.loadSessionRecordings()+ props.onFiltersChange?.(values.filters)+ },- // Check if filter with exact (key, value) exists - if so, remove it- const exactMatchIndex = firstNestedGroup.values.findIndex((filter) => {- if ('key' in filter && 'value' in filter && 'operator' in filter) {- return (- filter.key === propertyKey &&- filter.value === propertyValue &&- filter.operator === PropertyOperator.Exact- )+ applyPropertyFilter: ({ propertyKey, propertyValue }) => {+ // Validate property value+ if (propertyValue === undefined || propertyValue === null) {+ return}- return false- })- let newGroup: UniversalFiltersGroup- let actionLabel: string+ // Determine property filter type+ // For recordings: $browser, $os, $device_type, etc are Event properties+ // $geoip_* and custom properties (no $) are Person properties+ // Everything else with $ is Session property+ const filterType =+ propertyKey.startsWith('$geoip_') || !propertyKey.startsWith('$')+ ? PropertyFilterType.Person+ : ['$browser', '$os', '$device_type', '$initial_device_type', '$os_name'].includes(propertyKey)+ ? PropertyFilterType.Event+ : PropertyFilterType.Session++ // Create property filter object+ const filter = {+ type: filterType,+ key: propertyKey,+ value: propertyValue,+ operator: PropertyOperator.Exact,+ } as AnyPropertyFilter- if (exactMatchIndex !== -1) {- // Remove the exact match- newGroup = {+ // Clone the current filter group structure and add to the first nested group+ const currentGroup = values.filters.filter_group+ const newGroup: UniversalFiltersGroup = {...currentGroup,values: currentGroup.values.map((nestedGroup, index) => {+ // Add to the first nested group (index 0)if (index === 0 && 'values' in nestedGroup) {return {...nestedGroup,- values: nestedGroup.values.filter((_, i) => i !== exactMatchIndex),+ values: [...nestedGroup.values, filter],} as UniversalFiltersGroup}return nestedGroup}),}- actionLabel = 'Filter removed'- } else {- // Check if filter with same key but different value exists- const sameKeyIndex = firstNestedGroup.values.findIndex((filter) => {- if ('key' in filter && 'operator' in filter) {- return filter.key === propertyKey && filter.operator === PropertyOperator.Exact++ actions.setFilters({ filter_group: newGroup })++ // Show toast notification with human-readable label and view filters button+ const filterLabel = formatPropertyLabel(filter, {})+ lemonToast.success(`Filter applied: ${filterLabel}`, {+ toastId: `filter-applied-${propertyKey}`,+ button: {+ label: 'View filters',+ action: () => {+ actions.setIsFiltersExpanded(true)+ },+ },+ })+ },++ togglePropertyFilter: ({ propertyKey, propertyValue }) => {+ // Validate property value+ if (propertyValue === undefined || propertyValue === null) {+ return+ }++ // Determine property filter type+ const filterType =+ propertyKey.startsWith('$geoip_') || !propertyKey.startsWith('$')+ ? PropertyFilterType.Person+ : ['$browser', '$os', '$device_type', '$initial_device_type', '$os_name'].includes(propertyKey)+ ? PropertyFilterType.Event+ : PropertyFilterType.Session++ const currentGroup = values.filters.filter_group+ const firstNestedGroup = currentGroup.values[0]++ if (!firstNestedGroup || !('values' in firstNestedGroup)) {+ return+ }++ // Check if filter with exact (key, value) exists - if so, remove it+ const exactMatchIndex = firstNestedGroup.values.findIndex((filter) => {+ if ('key' in filter && 'value' in filter && 'operator' in filter) {+ return (+ filter.key === propertyKey &&+ filter.value === propertyValue &&+ filter.operator === PropertyOperator.Exact+ )}return false})- const newFilter = {- type: filterType,- key: propertyKey,- value: propertyValue,- operator: PropertyOperator.Exact,- }+ let newGroup: UniversalFiltersGroup+ let actionLabel: string- if (sameKeyIndex !== -1) {- // Replace the existing filter with same key+ if (exactMatchIndex !== -1) {+ // Remove the exact matchnewGroup = {...currentGroup,values: currentGroup.values.map((nestedGroup, index) => {if (index === 0 && 'values' in nestedGroup) {return {...nestedGroup,- values: nestedGroup.values.map((filter, i) =>- i === sameKeyIndex ? newFilter : filter- ),+ values: nestedGroup.values.filter((_, i) => i !== exactMatchIndex),} as UniversalFiltersGroup}return nestedGroup}),}- actionLabel = 'Filter replaced'+ actionLabel = 'Filter removed'} else {- // Add new filter- newGroup = {- ...currentGroup,- values: currentGroup.values.map((nestedGroup, index) => {- if (index === 0 && 'values' in nestedGroup) {- return {- ...nestedGroup,- values: [...nestedGroup.values, newFilter],- } as UniversalFiltersGroup- }- return nestedGroup- }),+ // Check if filter with same key but different value exists+ const sameKeyIndex = firstNestedGroup.values.findIndex((filter) => {+ if ('key' in filter && 'operator' in filter) {+ return filter.key === propertyKey && filter.operator === PropertyOperator.Exact+ }+ return false+ })++ const newFilter = {+ type: filterType,+ key: propertyKey,+ value: propertyValue,+ operator: PropertyOperator.Exact,+ }++ if (sameKeyIndex !== -1) {+ // Replace the existing filter with same key+ newGroup = {+ ...currentGroup,+ values: currentGroup.values.map((nestedGroup, index) => {+ if (index === 0 && 'values' in nestedGroup) {+ return {+ ...nestedGroup,+ values: nestedGroup.values.map((filter, i) =>+ i === sameKeyIndex ? newFilter : filter+ ),+ } as UniversalFiltersGroup+ }+ return nestedGroup+ }),+ }+ actionLabel = 'Filter replaced'+ } else {+ // Add new filter+ newGroup = {+ ...currentGroup,+ values: currentGroup.values.map((nestedGroup, index) => {+ if (index === 0 && 'values' in nestedGroup) {+ return {+ ...nestedGroup,+ values: [...nestedGroup.values, newFilter],+ } as UniversalFiltersGroup+ }+ return nestedGroup+ }),+ }+ actionLabel = 'Filter applied'}- actionLabel = 'Filter applied'}- }- actions.setFilters({ filter_group: newGroup })-- // Show toast notification- const filterLabel = formatPropertyLabel(- { type: filterType, key: propertyKey, value: propertyValue, operator: PropertyOperator.Exact },- {}- )- lemonToast.success(`${actionLabel}: ${filterLabel}`, {- toastId: `filter-toggled-${propertyKey}`,- button: {- label: 'View filters',- action: () => {- actions.setIsFiltersExpanded(true)- },- },- })- },+ actions.setFilters({ filter_group: newGroup })- maybeLoadSessionRecordings: ({ direction }) => {- if (direction === 'older' && !values.hasNext) {- return // Nothing more to load- }- if (values.sessionRecordingsResponseLoading) {- return // We don't want to load if we are currently loading- }+ // Show toast notification+ const filterLabel = formatPropertyLabel(+ { type: filterType, key: propertyKey, value: propertyValue, operator: PropertyOperator.Exact },+ {}+ )+ lemonToast.success(`${actionLabel}: ${filterLabel}`, {+ toastId: `filter-toggled-${propertyKey}`,+ button: {+ label: 'View filters',+ action: () => {+ actions.setIsFiltersExpanded(true)+ },+ },+ })+ },- actions.loadSessionRecordings(direction)- },+ maybeLoadSessionRecordings: ({ direction }) => {+ if (direction === 'older' && !values.hasNext) {+ return // Nothing more to load+ }+ if (values.sessionRecordingsResponseLoading) {+ return // We don't want to load if we are currently loading+ }- loadSessionRecordingsSuccess: ({ sessionRecordingsResponse }) => {- actions.maybeLoadPropertiesForSessions(values.sessionRecordings)- props.onRecordingsLoaded?.(sessionRecordingsResponse.results)- },+ actions.loadSessionRecordings(direction)+ },- setSelectedRecordingId: ({ id }) => {- // Close filters when selecting a recording- actions.setIsFiltersExpanded(false)+ loadSessionRecordingsSuccess: ({ sessionRecordingsResponse }) => {+ actions.maybeLoadPropertiesForSessions(values.sessionRecordings)+ props.onRecordingsLoaded?.(sessionRecordingsResponse.results)+ pruneSelectedRecordingsIds()+ },- if (id) {- props.onRecordingSelected?.(id)- }+ loadPinnedRecordingsSuccess: () => {+ pruneSelectedRecordingsIds()+ },- const recordingIndex = values.sessionRecordings.findIndex((s) => s.id === values.selectedRecordingId)+ setSelectedRecordingId: ({ id }) => {+ // Close filters when selecting a recording+ actions.setIsFiltersExpanded(false)- // If recording not found in current list, reload with the new selected recording- // The backend will automatically include it via session_recording_id parameter- if (recordingIndex === -1 && values.selectedRecordingId) {- actions.loadSessionRecordings()- }+ if (id) {+ props.onRecordingSelected?.(id)+ }- // If we are at the end of the list then try to load more- if (recordingIndex === values.sessionRecordings.length - 1) {- actions.maybeLoadSessionRecordings('older')- }+ const recordingIndex = values.sessionRecordings.findIndex((s) => s.id === values.selectedRecordingId)- globalSetupLogic.findMounted()?.actions.markTaskAsCompleted(SetupTaskId.WatchSessionRecording)- },+ // If recording not found in current list, reload with the new selected recording+ // The backend will automatically include it via session_recording_id parameter+ if (recordingIndex === -1 && values.selectedRecordingId) {+ actions.loadSessionRecordings()+ }- addDeletedRecordings: ({ ids }) => {- if (values.selectedRecordingId && ids.includes(values.selectedRecordingId)) {- actions.setSelectedRecordingId(null)- }- },+ // If we are at the end of the list then try to load more+ if (recordingIndex === values.sessionRecordings.length - 1) {+ actions.maybeLoadSessionRecordings('older')+ }- setHideViewedRecordings: () => {- // Filtering happens server-side, so toggling the filter changes the result set entirely.- // Reset and refetch from the first page rather than paginating onto the stale cursor.- actions.loadSessionRecordings()- },- handleBulkAddToPlaylist: async ({ short_id }: { short_id: string }) => {- await lemonToast.promise(- (async () => {- try {- await api.recordings.bulkAddRecordingsToPlaylist(short_id, values.selectedRecordingsIds)- actions.setSelectedRecordingsIds([])+ globalSetupLogic.findMounted()?.actions.markTaskAsCompleted(SetupTaskId.WatchSessionRecording)+ },- // Reload the playlist to show the new recordings- handleLoadCollectionRecordings(short_id)- } catch (e) {- posthog.captureException(e)- }- })(),- {- success: `${values.selectedRecordingsIds.length} recording${- values.selectedRecordingsIds.length > 1 ? 's' : ''- } added to collection!`,- error: 'Failed to add to collection!',- pending: `Adding ${values.selectedRecordingsIds.length} recording${- values.selectedRecordingsIds.length > 1 ? 's' : ''- } to the collection...`,- },- {- button: {- label: 'View collection',- action: () => router.actions.push(urls.replayPlaylist(short_id)),- },+ addDeletedRecordings: ({ ids }) => {+ if (values.selectedRecordingId && ids.includes(values.selectedRecordingId)) {+ actions.setSelectedRecordingId(null)}- )- },- handleBulkDeleteFromPlaylist: async ({ short_id }: { short_id: string }) => {- await lemonToast.promise(- (async () => {- try {- await api.recordings.bulkDeleteRecordingsFromPlaylist(short_id, values.selectedRecordingsIds)- actions.setSelectedRecordingsIds([])+ pruneSelectedRecordingsIds()+ },- // Reload the playlist to see the recordings without the deleted ones- handleLoadCollectionRecordings(short_id)- } catch (e) {- posthog.captureException(e)+ setHideViewedRecordings: () => {+ // Filtering happens server-side, so toggling the filter changes the result set entirely.+ // Reset and refetch from the first page rather than paginating onto the stale cursor.+ actions.loadSessionRecordings()+ },+ handleBulkAddToPlaylist: async ({ short_id }: { short_id: string }) => {+ await lemonToast.promise(+ (async () => {+ try {+ await api.recordings.bulkAddRecordingsToPlaylist(short_id, values.selectedRecordingsIds)+ actions.setSelectedRecordingsIds([])++ // Reload the playlist to show the new recordings+ handleLoadCollectionRecordings(short_id)+ } catch (e) {+ posthog.captureException(e)+ }+ })(),+ {+ success: `${values.selectedRecordingsIds.length} recording${+ values.selectedRecordingsIds.length > 1 ? 's' : ''+ } added to collection!`,+ error: 'Failed to add to collection!',+ pending: `Adding ${values.selectedRecordingsIds.length} recording${+ values.selectedRecordingsIds.length > 1 ? 's' : ''+ } to the collection...`,+ },+ {+ button: {+ label: 'View collection',+ action: () => router.actions.push(urls.replayPlaylist(short_id)),+ },}- })(),- {- success: `${values.selectedRecordingsIds.length} recording${- values.selectedRecordingsIds.length > 1 ? 's' : ''- } removed from collection!`,- error: 'Failed to remove from collection!',- pending: `Removing ${values.selectedRecordingsIds.length} recording${- values.selectedRecordingsIds.length > 1 ? 's' : ''- } to the collection...`,+ )+ },+ handleBulkDeleteFromPlaylist: async ({ short_id }: { short_id: string }) => {+ await lemonToast.promise(+ (async () => {+ try {+ await api.recordings.bulkDeleteRecordingsFromPlaylist(+ short_id,+ values.selectedRecordingsIds+ )+ actions.setSelectedRecordingsIds([])++ // Reload the playlist to see the recordings without the deleted ones+ handleLoadCollectionRecordings(short_id)+ } catch (e) {+ posthog.captureException(e)+ }+ })(),+ {+ success: `${values.selectedRecordingsIds.length} recording${+ values.selectedRecordingsIds.length > 1 ? 's' : ''+ } removed from collection!`,+ error: 'Failed to remove from collection!',+ pending: `Removing ${values.selectedRecordingsIds.length} recording${+ values.selectedRecordingsIds.length > 1 ? 's' : ''+ } to the collection...`,+ }+ )+ },+ handleSelectUnselectAll: ({ checked, type }: { checked: boolean; type: 'filters' | 'collection' }) => {+ if (checked) {+ const recordings = type === 'filters' ? values.otherRecordings : values.visiblePinnedRecordings+ actions.setSelectedRecordingsIds(recordings.map((s) => s.id))+ } else {+ actions.setSelectedRecordingsIds([])}- )- },- handleSelectUnselectAll: ({ checked, type }: { checked: boolean; type: 'filters' | 'collection' }) => {- if (checked) {- const recordings = type === 'filters' ? values.otherRecordings : values.visiblePinnedRecordings- actions.setSelectedRecordingsIds(recordings.map((s) => s.id))- } else {- actions.setSelectedRecordingsIds([])- }- },- handleDeleteSelectedRecordings: async ({ shortId }: { shortId?: string }) => {- const idsToDelete = [...values.selectedRecordingsIds]- const deleteCount = idsToDelete.length- actions.setDeleteConfirmationText('')- actions.setIsDeleteSelectedRecordingsDialogOpen(false)-- try {- const result = await api.recordings.bulkDeleteRecordings(idsToDelete, values.filters.date_from)- const deletedIds = idsToDelete.filter((id) => !(result.failed_ids ?? []).includes(id))- actions.addDeletedRecordings(deletedIds)- actions.setSelectedRecordingsIds([])-- if (shortId) {- handleLoadCollectionRecordings(shortId)+ },+ handleDeleteSelectedRecordings: async ({ shortId }: { shortId?: string }) => {+ if (values.isDeletingSelectedRecordings) {+ return}- const actualCount = deletedIds.length- if (actualCount < deleteCount) {- lemonToast.warning(- `${actualCount} of ${deleteCount} recording${deleteCount > 1 ? 's' : ''} deleted. ${deleteCount - actualCount} failed.`- )- } else {- lemonToast.success(`${actualCount} recording${actualCount > 1 ? 's' : ''} deleted!`)- }- } catch (e) {- lemonToast.error('Failed to delete recordings!')- posthog.captureException(e)- }- },- handleCreateNewCollectionBulkAdd: async ({ onSuccess }) => {- const newPlaylist = await createPlaylist({- name: values.newCollectionName,- type: 'collection',- })+ const idsToDelete = [...values.selectedRecordingsIds]+ const deleteCount = idsToDelete.length+ actions.setIsDeletingSelectedRecordings(true)- if (newPlaylist) {- actions.handleBulkAddToPlaylist(newPlaylist.short_id)- actions.setIsAddToCollectionModalOpen(false)- onSuccess()- }- },- setIsAddToCollectionModalOpen: ({ isAddToCollectionModalOpen }) => {- if (isAddToCollectionModalOpen) {- actions.loadCollectionsForBulkAdd(null)- }- },- setAddToCollectionSearch: async (_, breakpoint) => {- await breakpoint(200)- actions.loadCollectionsForBulkAdd(null)- },- handleBulkMarkAsViewed: async ({ shortId }: { shortId?: string }) => {- await lemonToast.promise(- (async () => {- try {- await api.recordings.bulkViewedRecordings(values.selectedRecordingsIds)- actions.setSelectedRecordingsIds([])+ try {+ const result = await api.recordings.bulkDeleteRecordings(idsToDelete, values.filters.date_from)+ const deletedIds = idsToDelete.filter((id) => !(result.failed_ids ?? []).includes(id))+ actions.addDeletedRecordings(deletedIds)+ actions.setSelectedRecordingsIds([])+ actions.setDeleteConfirmationText('')+ actions.setIsDeleteSelectedRecordingsDialogOpen(false)- // If it was a collection then we need to reload it, otherwise we need to reload the recordings- if (shortId) {- handleLoadCollectionRecordings(shortId)- } else {- actions.loadSessionRecordings()- }- } catch (e) {- posthog.captureException(e)+ if (shortId) {+ handleLoadCollectionRecordings(shortId)}- })(),- {- success: `${values.selectedRecordingsIds.length} recording${- values.selectedRecordingsIds.length > 1 ? 's' : ''- } marked as viewed!`,- error: 'Failed to mark as viewed!',- pending: `Marking ${values.selectedRecordingsIds.length} recording${- values.selectedRecordingsIds.length > 1 ? 's' : ''- }...`,++ const actualCount = deletedIds.length+ if (actualCount < deleteCount) {+ lemonToast.warning(+ `${actualCount} of ${deleteCount} recording${deleteCount > 1 ? 's' : ''} deleted. ${deleteCount - actualCount} failed.`+ )+ } else {+ lemonToast.success(`${actualCount} recording${actualCount > 1 ? 's' : ''} deleted!`)+ }+ } catch (e) {+ lemonToast.error('Failed to delete recordings!')+ posthog.captureException(e)+ } finally {+ actions.setIsDeletingSelectedRecordings(false)}- )- },- handleBulkMarkAsNotViewed: async ({ shortId }: { shortId?: string }) => {- await lemonToast.promise(- (async () => {- try {- await api.recordings.bulkNotViewedRecordings(values.selectedRecordingsIds)- actions.setSelectedRecordingsIds([])+ },+ handleCreateNewCollectionBulkAdd: async ({ onSuccess }) => {+ const newPlaylist = await createPlaylist({+ name: values.newCollectionName,+ type: 'collection',+ })- // If it was a collection then we need to reload it, otherwise we need to reload the recordings- if (shortId) {- handleLoadCollectionRecordings(shortId)- } else {- actions.loadSessionRecordings()+ if (newPlaylist) {+ actions.handleBulkAddToPlaylist(newPlaylist.short_id)+ actions.setIsAddToCollectionModalOpen(false)+ onSuccess()+ }+ },+ setIsAddToCollectionModalOpen: ({ isAddToCollectionModalOpen }) => {+ if (isAddToCollectionModalOpen) {+ actions.loadCollectionsForBulkAdd(null)+ }+ },+ setAddToCollectionSearch: async (_, breakpoint) => {+ await breakpoint(200)+ actions.loadCollectionsForBulkAdd(null)+ },+ handleBulkMarkAsViewed: async ({ shortId }: { shortId?: string }) => {+ await lemonToast.promise(+ (async () => {+ try {+ await api.recordings.bulkViewedRecordings(values.selectedRecordingsIds)+ actions.setSelectedRecordingsIds([])++ // If it was a collection then we need to reload it, otherwise we need to reload the recordings+ if (shortId) {+ handleLoadCollectionRecordings(shortId)+ } else {+ actions.loadSessionRecordings()+ }+ } catch (e) {+ posthog.captureException(e)}- } catch (e) {- posthog.captureException(e)+ })(),+ {+ success: `${values.selectedRecordingsIds.length} recording${+ values.selectedRecordingsIds.length > 1 ? 's' : ''+ } marked as viewed!`,+ error: 'Failed to mark as viewed!',+ pending: `Marking ${values.selectedRecordingsIds.length} recording${+ values.selectedRecordingsIds.length > 1 ? 's' : ''+ }...`,}- })(),- {- success: `${values.selectedRecordingsIds.length} recording${- values.selectedRecordingsIds.length > 1 ? 's' : ''- } marked as not viewed!`,- error: 'Failed to mark as not viewed!',- pending: `Marking ${values.selectedRecordingsIds.length} recording${- values.selectedRecordingsIds.length > 1 ? 's' : ''- }...`,- }- )- },- })),+ )+ },+ handleBulkMarkAsNotViewed: async ({ shortId }: { shortId?: string }) => {+ await lemonToast.promise(+ (async () => {+ try {+ await api.recordings.bulkNotViewedRecordings(values.selectedRecordingsIds)+ actions.setSelectedRecordingsIds([])++ // If it was a collection then we need to reload it, otherwise we need to reload the recordings+ if (shortId) {+ handleLoadCollectionRecordings(shortId)+ } else {+ actions.loadSessionRecordings()+ }+ } catch (e) {+ posthog.captureException(e)+ }+ })(),+ {+ success: `${values.selectedRecordingsIds.length} recording${+ values.selectedRecordingsIds.length > 1 ? 's' : ''+ } marked as not viewed!`,+ error: 'Failed to mark as not viewed!',+ pending: `Marking ${values.selectedRecordingsIds.length} recording${+ values.selectedRecordingsIds.length > 1 ? 's' : ''+ }...`,+ }+ )+ },+ }+ }),selectors({logicProps: [() => [(_, props) => props], (props): SessionRecordingPlaylistLogicProps => props],