-
Notifications
You must be signed in to change notification settings - Fork 1.9k
chore: clip dialogue window #37576
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
chore: clip dialogue window #37576
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f671f2f
chore: clip dialogue window
veryayskiy 8f688d7
refactoring
veryayskiy c4cd36b
fix
veryayskiy d3e8bad
fix
veryayskiy 1ec1006
remove FF
veryayskiy 01558dd
proper offset
veryayskiy 9d4c039
we should have only one layover at a time
veryayskiy 898da86
Merge branch 'master' into feat/sr/clip-length
veryayskiy ecdb31c
Check playwright & ffmpe installed for flox
veryayskiy 86c579b
remove 30 sec as it's heavy
veryayskiy baadd5b
Merge branch 'master' into feat/sr/clip-length
veryayskiy 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Check if we're in a flox environment | ||
if ! command -v flox &> /dev/null; then | ||
echo "Error: flox not found. This script is optimized for flox environments." | ||
exit 1 | ||
fi | ||
|
||
# Check if Playwright is installed | ||
if ! command -v playwright &> /dev/null; then | ||
echo "Installing Playwright via flox..." | ||
flox install playwright | ||
# Install Playwright browsers | ||
flox activate -- playwright install | ||
else | ||
echo "Playwright is already installed" | ||
fi | ||
|
||
# Check if FFmpeg is installed | ||
if ! command -v ffmpeg &> /dev/null; then | ||
echo "Installing FFmpeg via flox..." | ||
flox install ffmpeg | ||
else | ||
echo "FFmpeg is already installed" | ||
fi | ||
|
||
echo "Video dependencies check complete" |
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
158 changes: 158 additions & 0 deletions
158
frontend/src/scenes/session-recordings/player/controller/ClipRecording.tsx
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,158 @@ | ||
import { useActions, useValues } from 'kea' | ||
import { useState } from 'react' | ||
|
||
import { LemonButton, LemonSegmentedButton, LemonTag } from '@posthog/lemon-ui' | ||
|
||
import { LemonSegmentedSelect } from 'lib/lemon-ui/LemonSegmentedSelect' | ||
import { IconRecordingClip } from 'lib/lemon-ui/icons' | ||
import { colonDelimitedDuration } from 'lib/utils' | ||
import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic' | ||
|
||
import { KeyboardShortcut } from '~/layout/navigation-3000/components/KeyboardShortcut' | ||
import { ExporterFormat } from '~/types' | ||
|
||
interface ClipTimes { | ||
current: string | ||
startClip: string | ||
endClip: string | ||
} | ||
|
||
function calculateClipTimes(currentTimeMs: number | null, sessionDurationMs: number, clipDuration: number): ClipTimes { | ||
const startTimeSeconds = (currentTimeMs ?? 0) / 1000 | ||
const endTimeSeconds = Math.floor(sessionDurationMs / 1000) | ||
const fixedUnits = endTimeSeconds > 3600 ? 3 : 2 | ||
|
||
const current = colonDelimitedDuration(startTimeSeconds, fixedUnits) | ||
|
||
// Calculate ideal start/end centered around current time | ||
let idealStart = startTimeSeconds - clipDuration / 2 | ||
let idealEnd = startTimeSeconds + clipDuration / 2 | ||
|
||
// Adjust if we hit the beginning boundary | ||
if (idealStart < 0) { | ||
idealStart = 0 | ||
idealEnd = Math.min(clipDuration, endTimeSeconds) | ||
} | ||
|
||
// Adjust if we hit the end boundary | ||
if (idealEnd > endTimeSeconds) { | ||
idealEnd = endTimeSeconds | ||
idealStart = Math.max(0, endTimeSeconds - clipDuration) | ||
} | ||
|
||
const startClip = colonDelimitedDuration(idealStart, fixedUnits) | ||
const endClip = colonDelimitedDuration(idealEnd, fixedUnits) | ||
|
||
return { current, startClip, endClip } | ||
} | ||
|
||
export function ClipOverlay(): JSX.Element | null { | ||
const { currentPlayerTime, sessionPlayerData, showingClipParams } = useValues(sessionRecordingPlayerLogic) | ||
const { getClip, setShowingClipParams } = useActions(sessionRecordingPlayerLogic) | ||
const [duration, setDuration] = useState(5) | ||
const [format, setFormat] = useState(ExporterFormat.MP4) | ||
|
||
const { current, startClip, endClip } = calculateClipTimes( | ||
currentPlayerTime, | ||
sessionPlayerData.durationMs, | ||
duration | ||
) | ||
|
||
if (!showingClipParams) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className="absolute bottom-4 right-4 z-20 w-64 space-y-3 p-2 bg-primary border border-border rounded shadow-lg"> | ||
<div className="space-y-1 text-center"> | ||
<div className="text-sm font-medium text-default"> | ||
Clipping from {startClip} to {endClip} | ||
</div> | ||
<div className="text-muted">(centered around {current})</div> | ||
</div> | ||
<div className="space-y-1"> | ||
<label className="block text-sm font-medium text-default">Format</label> | ||
<LemonSegmentedButton | ||
fullWidth | ||
size="xsmall" | ||
value={format} | ||
onChange={(value) => setFormat(value)} | ||
options={[ | ||
{ | ||
value: ExporterFormat.MP4, | ||
label: 'MP4', | ||
tooltip: 'Video file - higher quality, better for detailed analysis', | ||
'data-attr': 'replay-screenshot-mp4', | ||
}, | ||
{ | ||
value: ExporterFormat.GIF, | ||
label: 'GIF', | ||
tooltip: 'Animated GIF - smaller file size, good for sharing', | ||
'data-attr': 'replay-screenshot-gif', | ||
}, | ||
]} | ||
/> | ||
</div> | ||
|
||
<div className="space-y-1"> | ||
<label className="block text-sm font-medium text-default">Duration (seconds)</label> | ||
<LemonSegmentedSelect | ||
fullWidth | ||
size="xsmall" | ||
options={[ | ||
{ value: 5, label: '5', 'data-attr': 'replay-clip-duration-5' }, | ||
{ value: 10, label: '10', 'data-attr': 'replay-clip-duration-10' }, | ||
{ value: 15, label: '15', 'data-attr': 'replay-clip-duration-15' }, | ||
]} | ||
value={duration} | ||
onChange={(value) => setDuration(value)} | ||
/> | ||
</div> | ||
|
||
<LemonButton | ||
onClick={() => { | ||
getClip(format, duration) | ||
setShowingClipParams(false) | ||
}} | ||
type="primary" | ||
className="mt-3 mx-auto" | ||
disabledReason={ | ||
!duration || duration < 5 || duration > 15 ? 'Duration must be between 5 and 15 seconds' : undefined | ||
} | ||
> | ||
Create clip | ||
</LemonButton> | ||
</div> | ||
) | ||
} | ||
|
||
export function ClipRecording(): JSX.Element { | ||
const { showingClipParams, currentPlayerTime, sessionPlayerData } = useValues(sessionRecordingPlayerLogic) | ||
const { setPause, setShowingClipParams } = useActions(sessionRecordingPlayerLogic) | ||
|
||
const { current } = calculateClipTimes(currentPlayerTime, sessionPlayerData.durationMs, 5) | ||
|
||
return ( | ||
<LemonButton | ||
size="xsmall" | ||
active={showingClipParams} | ||
onClick={() => { | ||
setPause() | ||
setShowingClipParams(!showingClipParams) | ||
}} | ||
tooltip={ | ||
<div className="flex items-center gap-2"> | ||
<span> | ||
Create clip around {current} <KeyboardShortcut x /> | ||
</span> | ||
<LemonTag type="warning" size="small"> | ||
BETA | ||
</LemonTag> | ||
</div> | ||
} | ||
icon={<IconRecordingClip className="text-xl" />} | ||
data-attr="replay-clip" | ||
tooltipPlacement="top" | ||
/> | ||
) | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.