forked from PostHog/posthog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add replay to omnisearch (PostHog#24978)
- Loading branch information
1 parent
e46f90d
commit ac44668
Showing
2 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
100 changes: 100 additions & 0 deletions
100
frontend/src/scenes/session-recordings/replayPaletteCommands.ts
This file contains 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,100 @@ | ||
import { IconRewindPlay } from '@posthog/icons' | ||
import { Command, GLOBAL_COMMAND_SCOPE } from 'lib/components/CommandPalette/commandPaletteLogic' | ||
import { isURL } from 'lib/utils' | ||
import { urls } from 'scenes/urls' | ||
|
||
import { | ||
FilterLogicalOperator, | ||
PropertyFilterType, | ||
PropertyOperator, | ||
RecordingDurationFilter, | ||
RecordingUniversalFilters, | ||
ReplayTabs, | ||
} from '~/types' | ||
|
||
function isUUIDLike(candidate: string): boolean { | ||
return candidate.length === 36 && !!candidate.toLowerCase().match(/^[0-9a-f-]+$/)?.length | ||
} | ||
|
||
export const WATCH_RECORDINGS_OF_KEY = 'watch-recordings-of' | ||
export const watchRecordingsOfCommand = ( | ||
push: ( | ||
url: string, | ||
searchInput?: string | Record<string, any> | undefined, | ||
hashInput?: string | Record<string, any> | undefined | ||
) => void | ||
): Command => ({ | ||
key: WATCH_RECORDINGS_OF_KEY, | ||
scope: GLOBAL_COMMAND_SCOPE, | ||
resolver: (argument: string | undefined) => { | ||
if (argument === undefined) { | ||
return null | ||
} | ||
|
||
const replayFilter = ( | ||
key: 'snapshot_source' | 'visited_page', | ||
value: string | ||
): Partial<RecordingUniversalFilters> => ({ | ||
date_from: '-3d', | ||
filter_group: { | ||
type: FilterLogicalOperator.And, | ||
values: [ | ||
{ | ||
type: FilterLogicalOperator.And, | ||
values: [ | ||
{ | ||
key: key, | ||
value: [value], | ||
operator: PropertyOperator.Exact, | ||
type: PropertyFilterType.Recording, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
duration: [ | ||
{ | ||
type: PropertyFilterType.Recording, | ||
key: 'duration', | ||
value: 1, | ||
operator: 'gt', | ||
} as RecordingDurationFilter, | ||
], | ||
}) | ||
|
||
const words = argument.split(' ') | ||
if (words.includes('web') || words.includes('mobile')) { | ||
return { | ||
icon: IconRewindPlay, | ||
display: `Watch ${argument} recordings`, | ||
executor: () => { | ||
push(urls.replay(ReplayTabs.Home, replayFilter('snapshot_source', argument))) | ||
}, | ||
} | ||
} | ||
|
||
const url = words.find((word) => isURL(word)) | ||
if (url) { | ||
return { | ||
icon: IconRewindPlay, | ||
display: `Watch recordings of visits to ${url}`, | ||
executor: () => { | ||
push(urls.replay(ReplayTabs.Home, replayFilter('visited_page', url))) | ||
}, | ||
} | ||
} | ||
|
||
const uuid = words.find((word) => isUUIDLike(word)) | ||
if (uuid) { | ||
return { | ||
icon: IconRewindPlay, | ||
display: `Watch recording of session: ${uuid}`, | ||
executor: () => { | ||
push(urls.replaySingle(uuid)) | ||
}, | ||
} | ||
} | ||
|
||
return null | ||
}, | ||
}) |