Skip to content
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

feat: allow switching timing view #18647

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export function ItemPerformanceEvent({
tabs={[
{
key: 'timings',
label: 'timings',
label: 'Timings',
content: (
<>
<SimpleKeyValueList item={sanitizedProps} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { PerformanceEvent } from '~/types'
import { getSeriesColor } from 'lib/colors'
import { humanFriendlyMilliseconds } from 'lib/utils'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { useState } from 'react'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { LemonDivider } from 'lib/lemon-ui/LemonDivider'
import { SimpleKeyValueList } from 'scenes/session-recordings/player/inspector/components/SimpleKeyValueList'
import { LemonButton } from 'lib/lemon-ui/LemonButton'

function colorForEntry(entryType: string | undefined): string {
switch (entryType) {
Expand Down Expand Up @@ -217,11 +222,7 @@ function percentagesWithinEventRange({
return { startPercentage: `${partStartPercentage}%`, widthPercentage: `${partPercentage}%` }
}

export const NetworkRequestTiming = ({
performanceEvent,
}: {
performanceEvent: PerformanceEvent
}): JSX.Element | null => {
const TimeLineView = ({ performanceEvent }: { performanceEvent: PerformanceEvent }): JSX.Element => {
const rangeStart = performanceEvent.start_time
const rangeEnd = performanceEvent.response_end
if (typeof rangeStart === 'number' && typeof rangeEnd === 'number') {
Expand Down Expand Up @@ -276,5 +277,44 @@ export const NetworkRequestTiming = ({
</div>
)
}
return null
return <LemonBanner type={'warning'}>Cannot render performance timeline for this request</LemonBanner>
}

const TableView = ({ performanceEvent }: { performanceEvent: PerformanceEvent }): JSX.Element => {
const timingProperties = Object.entries(performanceEvent).reduce((acc, [key, val]) => {
if (key.includes('time') || key.includes('end') || key.includes('start')) {
acc[key] = val
}
return acc
}, {})
return <SimpleKeyValueList item={timingProperties} />
}

export const NetworkRequestTiming = ({
performanceEvent,
}: {
performanceEvent: PerformanceEvent
}): JSX.Element | null => {
const [timelineMode, setTimelineMode] = useState<boolean>(true)

return (
<div className={'flex flex-col space-y-2'}>
<div className={'flex flex-row justify-end'}>
<LemonButton
type={'secondary'}
status={'stealth'}
onClick={() => setTimelineMode(!timelineMode)}
data-attr={`switch-timing-to-${timelineMode ? 'table' : 'timeline'}-view`}
>
{timelineMode ? 'Table view' : 'Timeline view'}
</LemonButton>
</div>
<LemonDivider dashed={true} />
{timelineMode ? (
<TimeLineView performanceEvent={performanceEvent} />
) : (
<TableView performanceEvent={performanceEvent} />
)}
</div>
)
}
Loading