-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(replay): Implement accessibility details panel (#60268)
Relates to: #55293
- Loading branch information
Showing
11 changed files
with
351 additions
and
40 deletions.
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
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
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
118 changes: 118 additions & 0 deletions
118
static/app/views/replays/detail/accessibility/details/components.tsx
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,118 @@ | ||
import {Fragment, ReactNode, useState} from 'react'; | ||
import styled from '@emotion/styled'; | ||
|
||
import {KeyValueTable, KeyValueTableRow} from 'sentry/components/keyValueTable'; | ||
import {IconChevron} from 'sentry/icons'; | ||
import {t} from 'sentry/locale'; | ||
import {space} from 'sentry/styles/space'; | ||
|
||
export const Indent = styled('div')` | ||
padding-left: ${space(4)}; | ||
`; | ||
|
||
const NotFoundText = styled('span')` | ||
color: ${p => p.theme.subText}; | ||
font-size: ${p => p.theme.fontSizeSmall}; | ||
`; | ||
|
||
export type KeyValueTuple = { | ||
key: string; | ||
value: string | ReactNode; | ||
type?: 'warning' | 'error'; | ||
}; | ||
|
||
export function keyValueTableOrNotFound(data: KeyValueTuple[], notFoundText: string) { | ||
return data.length ? ( | ||
<StyledKeyValueTable noMargin> | ||
{data.map(({key, value, type}) => ( | ||
<KeyValueTableRow | ||
key={key} | ||
keyName={key} | ||
type={type} | ||
value={<ValueContainer>{value}</ValueContainer>} | ||
/> | ||
))} | ||
</StyledKeyValueTable> | ||
) : ( | ||
<Indent> | ||
<NotFoundText>{notFoundText}</NotFoundText> | ||
</Indent> | ||
); | ||
} | ||
|
||
const ValueContainer = styled('span')` | ||
overflow: scroll; | ||
`; | ||
|
||
const SectionTitle = styled('dt')``; | ||
|
||
const SectionTitleExtra = styled('span')` | ||
flex-grow: 1; | ||
text-align: right; | ||
font-weight: normal; | ||
`; | ||
|
||
const SectionData = styled('dd')` | ||
font-size: ${p => p.theme.fontSizeExtraSmall}; | ||
`; | ||
|
||
const ToggleButton = styled('button')` | ||
background: ${p => p.theme.background}; | ||
border: 0; | ||
color: ${p => p.theme.headingColor}; | ||
font-size: ${p => p.theme.fontSizeSmall}; | ||
font-weight: 600; | ||
line-height: ${p => p.theme.text.lineHeightBody}; | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-start; | ||
gap: ${space(1)}; | ||
padding: ${space(0.5)} ${space(1)}; | ||
:hover { | ||
background: ${p => p.theme.backgroundSecondary}; | ||
} | ||
`; | ||
|
||
export function SectionItem({ | ||
children, | ||
title, | ||
titleExtra, | ||
}: { | ||
children: ReactNode; | ||
title: ReactNode; | ||
titleExtra?: ReactNode; | ||
}) { | ||
const [isOpen, setIsOpen] = useState(true); | ||
|
||
return ( | ||
<Fragment> | ||
<SectionTitle> | ||
<ToggleButton aria-label={t('toggle section')} onClick={() => setIsOpen(!isOpen)}> | ||
<IconChevron direction={isOpen ? 'down' : 'right'} size="xs" /> | ||
{title} | ||
{titleExtra ? <SectionTitleExtra>{titleExtra}</SectionTitleExtra> : null} | ||
</ToggleButton> | ||
</SectionTitle> | ||
<SectionData>{isOpen ? children : null}</SectionData> | ||
</Fragment> | ||
); | ||
} | ||
|
||
const StyledKeyValueTable = styled(KeyValueTable)` | ||
& > dt { | ||
font-size: ${p => p.theme.fontSizeSmall}; | ||
padding-left: ${space(4)}; | ||
} | ||
& > dd { | ||
${p => p.theme.overflowEllipsis}; | ||
font-size: ${p => p.theme.fontSizeSmall}; | ||
display: flex; | ||
justify-content: flex-end; | ||
white-space: normal; | ||
text-align: right; | ||
} | ||
`; |
28 changes: 28 additions & 0 deletions
28
static/app/views/replays/detail/accessibility/details/content.tsx
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,28 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
import type {SectionProps} from 'sentry/views/replays/detail/accessibility/details/sections'; | ||
import { | ||
ElementSection, | ||
GeneralSection, | ||
} from 'sentry/views/replays/detail/accessibility/details/sections'; | ||
import FluidHeight from 'sentry/views/replays/detail/layout/fluidHeight'; | ||
|
||
type Props = SectionProps; | ||
|
||
export default function AccessibilityDetailsContent(props: Props) { | ||
return ( | ||
<OverflowFluidHeight> | ||
<SectionList> | ||
<ElementSection {...props} /> | ||
<GeneralSection {...props} /> | ||
</SectionList> | ||
</OverflowFluidHeight> | ||
); | ||
} | ||
|
||
const OverflowFluidHeight = styled(FluidHeight)` | ||
overflow: auto; | ||
`; | ||
const SectionList = styled('dl')` | ||
margin: 0; | ||
`; |
85 changes: 85 additions & 0 deletions
85
static/app/views/replays/detail/accessibility/details/index.tsx
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,85 @@ | ||
import {Fragment, MouseEvent} from 'react'; | ||
import styled from '@emotion/styled'; | ||
|
||
import {Button} from 'sentry/components/button'; | ||
import Stacked from 'sentry/components/replays/breadcrumbs/stacked'; | ||
import {IconClose} from 'sentry/icons'; | ||
import {t} from 'sentry/locale'; | ||
import {space} from 'sentry/styles/space'; | ||
import type {HydratedA11yFrame} from 'sentry/utils/replays/hydrateA11yFrame'; | ||
import {useResizableDrawer} from 'sentry/utils/useResizableDrawer'; | ||
import AccessibilityDetailsContent from 'sentry/views/replays/detail/accessibility/details/content'; | ||
import SplitDivider from 'sentry/views/replays/detail/layout/splitDivider'; | ||
|
||
type Props = { | ||
item: null | HydratedA11yFrame; | ||
onClose: () => void; | ||
startTimestampMs: number; | ||
} & Omit<ReturnType<typeof useResizableDrawer>, 'size'>; | ||
|
||
function AccessibilityDetails({ | ||
isHeld, | ||
item, | ||
onClose, | ||
onDoubleClick, | ||
onMouseDown, | ||
startTimestampMs, | ||
}: Props) { | ||
if (!item) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
<StyledStacked> | ||
<StyledSplitDivider | ||
data-is-held={isHeld} | ||
data-slide-direction="updown" | ||
onDoubleClick={onDoubleClick} | ||
onMouseDown={onMouseDown} | ||
/> | ||
<CloseButtonWrapper> | ||
<Button | ||
aria-label={t('Hide accessibility details')} | ||
borderless | ||
icon={<IconClose isCircled size="sm" color="subText" />} | ||
onClick={(e: MouseEvent) => { | ||
e.preventDefault(); | ||
onClose(); | ||
}} | ||
size="zero" | ||
/> | ||
</CloseButtonWrapper> | ||
</StyledStacked> | ||
|
||
<AccessibilityDetailsContent item={item} startTimestampMs={startTimestampMs} /> | ||
</Fragment> | ||
); | ||
} | ||
|
||
const StyledStacked = styled(Stacked)` | ||
position: relative; | ||
border-top: 1px solid ${p => p.theme.border}; | ||
border-bottom: 1px solid ${p => p.theme.border}; | ||
`; | ||
|
||
const CloseButtonWrapper = styled('div')` | ||
position: absolute; | ||
right: 0; | ||
height: 100%; | ||
padding: ${space(1)}; | ||
z-index: ${p => p.theme.zIndex.initial}; | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
const StyledSplitDivider = styled(SplitDivider)` | ||
padding: ${space(0.75)}; | ||
:hover, | ||
&[data-is-held='true'] { | ||
z-index: ${p => p.theme.zIndex.initial}; | ||
} | ||
`; | ||
|
||
export default AccessibilityDetails; |
63 changes: 63 additions & 0 deletions
63
static/app/views/replays/detail/accessibility/details/sections.tsx
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,63 @@ | ||
import {MouseEvent} from 'react'; | ||
import beautify from 'js-beautify'; | ||
|
||
import {CodeSnippet} from 'sentry/components/codeSnippet'; | ||
import {useReplayContext} from 'sentry/components/replays/replayContext'; | ||
import {t} from 'sentry/locale'; | ||
import type {HydratedA11yFrame} from 'sentry/utils/replays/hydrateA11yFrame'; | ||
import { | ||
keyValueTableOrNotFound, | ||
KeyValueTuple, | ||
SectionItem, | ||
} from 'sentry/views/replays/detail/accessibility/details/components'; | ||
import TimestampButton from 'sentry/views/replays/detail/timestampButton'; | ||
|
||
export type SectionProps = { | ||
item: HydratedA11yFrame; | ||
startTimestampMs: number; | ||
}; | ||
|
||
export function ElementSection({item}: SectionProps) { | ||
return ( | ||
<SectionItem title={t('DOM Element')}> | ||
<CodeSnippet language="html" hideCopyButton> | ||
{beautify.html(item.element.element, {indent_size: 2})} | ||
</CodeSnippet> | ||
</SectionItem> | ||
); | ||
} | ||
|
||
export function GeneralSection({item, startTimestampMs}: SectionProps) { | ||
const {setCurrentTime} = useReplayContext(); | ||
|
||
const data: KeyValueTuple[] = [ | ||
{ | ||
key: t('Impact'), | ||
value: item.impact, | ||
type: item.impact === 'critical' ? 'warning' : undefined, | ||
}, | ||
{key: t('Type'), value: item.id}, | ||
{key: t('Help'), value: <a href={item.help_url}>{item.description}</a>}, | ||
{key: t('Path'), value: item.element.target.join(' ')}, | ||
{ | ||
key: t('Timestamp'), | ||
value: ( | ||
<TimestampButton | ||
format="mm:ss.SSS" | ||
onClick={(event: MouseEvent) => { | ||
event.stopPropagation(); | ||
setCurrentTime(item.offsetMs); | ||
}} | ||
startTimestampMs={startTimestampMs} | ||
timestampMs={item.timestampMs} | ||
/> | ||
), | ||
}, | ||
]; | ||
|
||
return ( | ||
<SectionItem title={t('General')}> | ||
{keyValueTableOrNotFound(data, t('Missing details'))} | ||
</SectionItem> | ||
); | ||
} |
Oops, something went wrong.