-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add skip inactivity button in SSH session recording playback #59492
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /** | ||
| * Teleport | ||
| * Copyright (C) 2023 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| /* MIT License | ||
|
|
||
| Copyright (c) 2020 Phosphor Icons | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
|
|
||
| */ | ||
|
|
||
| import { forwardRef } from 'react'; | ||
|
|
||
| import { Icon, IconProps } from '../Icon'; | ||
|
|
||
| /* | ||
|
|
||
| THIS FILE IS GENERATED. DO NOT EDIT. | ||
|
|
||
| */ | ||
|
|
||
| export const FastForward = forwardRef<HTMLSpanElement, IconProps>( | ||
| ({ size = 24, color, ...otherProps }, ref) => ( | ||
| <Icon | ||
| size={size} | ||
| color={color} | ||
| className="icon icon-fastforward" | ||
| {...otherProps} | ||
| ref={ref} | ||
| > | ||
| <path | ||
| stroke="#000" | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| strokeWidth="1.5" | ||
| d="M3 6.736v10.528a.741.741 0 0 0 1.142.618l8.268-5.264a.73.73 0 0 0 0-1.236L4.142 6.118A.741.741 0 0 0 3 6.736" | ||
| /> | ||
| <path | ||
| stroke="#000" | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| strokeWidth="1.5" | ||
| d="M12.75 6.736v10.528a.74.74 0 0 0 1.142.618l8.268-5.264a.73.73 0 0 0 0-1.236l-8.268-5.264a.741.741 0 0 0-1.142.618" | ||
| /> | ||
| </Icon> | ||
| ) | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /** | ||
| * Teleport | ||
| * Copyright (C) 2025 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| import { | ||
| useCallback, | ||
| useImperativeHandle, | ||
| useMemo, | ||
| useRef, | ||
| useState, | ||
| type ReactNode, | ||
| type Ref, | ||
| } from 'react'; | ||
| import styled from 'styled-components'; | ||
|
|
||
| import { ButtonPrimary } from 'design/Button'; | ||
| import { FastForward } from 'design/Icon'; | ||
|
|
||
| import { | ||
| SessionRecordingEventType, | ||
| type SessionRecordingEvent, | ||
| } from 'teleport/services/recordings'; | ||
| import { formatSessionRecordingDuration } from 'teleport/SessionRecordings/list/RecordingItem'; | ||
|
|
||
| export interface CurrentEventInfoHandle { | ||
| setTime: (time: number) => void; | ||
| } | ||
|
|
||
| interface CurrentEventInfoProps { | ||
| events: SessionRecordingEvent[]; | ||
| onSeek: (time: number) => void; | ||
| ref?: Ref<CurrentEventInfoHandle>; | ||
| } | ||
|
|
||
| const EventsList = styled.div` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: ${props => props.theme.space[2]}px; | ||
| position: absolute; | ||
| top: ${props => props.theme.space[4]}px; | ||
| right: ${props => props.theme.space[4]}px; | ||
| z-index: 2; | ||
| `; | ||
|
|
||
| export function CurrentEventInfo({ | ||
| events, | ||
| onSeek, | ||
| ref, | ||
| }: CurrentEventInfoProps) { | ||
| const [currentEvents, setCurrentEvents] = useState<SessionRecordingEvent[]>( | ||
| [] | ||
| ); | ||
| const currentEventsRef = useRef<SessionRecordingEvent[]>([]); | ||
|
|
||
| useImperativeHandle(ref, () => ({ | ||
| setTime(time: number) { | ||
| const eventsInTimePeriod = events.filter( | ||
| e => e.startTime <= time && e.endTime >= time | ||
| ); | ||
|
|
||
| const hasChanged = | ||
| eventsInTimePeriod.length !== currentEventsRef.current.length || | ||
| eventsInTimePeriod.some( | ||
| (event, index) => event !== currentEventsRef.current[index] | ||
| ); | ||
|
|
||
| if (hasChanged) { | ||
| currentEventsRef.current = eventsInTimePeriod; | ||
| setCurrentEvents(eventsInTimePeriod); | ||
| } | ||
| }, | ||
| })); | ||
|
|
||
| const handleSkipToEnd = useCallback( | ||
| (time: number) => { | ||
| onSeek(time + 1); | ||
| }, | ||
| [onSeek] | ||
| ); | ||
|
|
||
| const items = useMemo(() => { | ||
| if (currentEvents.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const items: ReactNode[] = []; | ||
|
|
||
| for (const [index, event] of currentEvents.entries()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im curious if there is any reason to use this over something like
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preference, I hate .forEach lol
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough |
||
| if (event.type !== SessionRecordingEventType.Inactivity) { | ||
| continue; | ||
| } | ||
|
|
||
| items.push( | ||
| <ButtonPrimary | ||
| key={`event-${index}-${event.type}`} | ||
| onClick={() => { | ||
| handleSkipToEnd(event.endTime); | ||
| }} | ||
| px={2} | ||
| > | ||
| Skip {formatSessionRecordingDuration(event.endTime - event.startTime)}{' '} | ||
| of inactivity | ||
| <FastForward size="small" ml={2} /> | ||
| </ButtonPrimary> | ||
| ); | ||
| } | ||
|
|
||
| if (items.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return items; | ||
| }, [currentEvents, handleSkipToEnd]); | ||
|
|
||
| if (currentEvents.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return <EventsList>{items}</EventsList>; | ||
| } | ||
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.
why not use
styled(Flex)