-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7246a0
commit 063d875
Showing
8 changed files
with
175 additions
and
53 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
56 changes: 56 additions & 0 deletions
56
...ime/public/components/monitor/synthetics/step_detail/waterfall/waterfall_sidebar_item.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,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiBadge } from '@elastic/eui'; | ||
import { SidebarItem } from '../waterfall/types'; | ||
import { MiddleTruncatedText } from '../../waterfall'; | ||
import { SideBarItemHighlighter } from '../../waterfall/components/styles'; | ||
import { SIDEBAR_FILTER_MATCHES_SCREENREADER_LABEL } from '../../waterfall/components/translations'; | ||
|
||
interface SidebarItemProps { | ||
item: SidebarItem; | ||
renderFilterScreenReaderText?: boolean; | ||
} | ||
|
||
export const WaterfallSidebarItem = ({ item, renderFilterScreenReaderText }: SidebarItemProps) => { | ||
const { status, offsetIndex } = item; | ||
|
||
const isErrorStatusCode = (statusCode: number) => { | ||
const is400 = statusCode >= 400 && statusCode <= 499; | ||
const is500 = statusCode >= 500 && statusCode <= 599; | ||
const isSpecific300 = statusCode === 301 || statusCode === 307 || statusCode === 308; | ||
return is400 || is500 || isSpecific300; | ||
}; | ||
|
||
const isHighlighted = item.isHighlighted; | ||
const text = `${offsetIndex}. ${item.url}`; | ||
const ariaLabel = `${ | ||
isHighlighted && renderFilterScreenReaderText | ||
? `${SIDEBAR_FILTER_MATCHES_SCREENREADER_LABEL} ` | ||
: '' | ||
}${text}`; | ||
|
||
return ( | ||
<SideBarItemHighlighter | ||
isHighlighted={isHighlighted} | ||
data-test-subj={isHighlighted ? 'sideBarHighlightedItem' : 'sideBarDimmedItem'} | ||
> | ||
{!status || !isErrorStatusCode(status) ? ( | ||
<MiddleTruncatedText text={text} ariaLabel={ariaLabel} /> | ||
) : ( | ||
<EuiFlexGroup justifyContent="spaceBetween"> | ||
<EuiFlexItem> | ||
<MiddleTruncatedText text={text} ariaLabel={ariaLabel} /> | ||
</EuiFlexItem> | ||
<EuiFlexItem component="span" grow={false}> | ||
<EuiBadge color="danger">{status}</EuiBadge> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
)} | ||
</SideBarItemHighlighter> | ||
); | ||
}; |
50 changes: 50 additions & 0 deletions
50
...blic/components/monitor/synthetics/step_detail/waterfall/waterfalll_sidebar_item.test.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,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { SidebarItem } from '../waterfall/types'; | ||
|
||
import { render } from '../../../../../lib/helper/rtl_helpers'; | ||
|
||
import 'jest-canvas-mock'; | ||
import { WaterfallSidebarItem } from './waterfall_sidebar_item'; | ||
import { SIDEBAR_FILTER_MATCHES_SCREENREADER_LABEL } from '../../waterfall/components/translations'; | ||
|
||
describe('waterfall filter', () => { | ||
const url = 'http://www.elastic.co'; | ||
const offsetIndex = 1; | ||
const item: SidebarItem = { | ||
url, | ||
isHighlighted: true, | ||
offsetIndex, | ||
}; | ||
|
||
it('renders sidbar item', () => { | ||
const { getByText } = render(<WaterfallSidebarItem item={item} />); | ||
|
||
expect(getByText(`${offsetIndex}. ${url}`)); | ||
}); | ||
|
||
it('render screen reader text when renderFilterScreenReaderText is true', () => { | ||
const { getByLabelText } = render( | ||
<WaterfallSidebarItem item={item} renderFilterScreenReaderText={true} /> | ||
); | ||
|
||
expect( | ||
getByLabelText(`${SIDEBAR_FILTER_MATCHES_SCREENREADER_LABEL} ${offsetIndex}. ${url}`) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not render screen reader text when renderFilterScreenReaderText is false', () => { | ||
const { queryByLabelText } = render( | ||
<WaterfallSidebarItem item={item} renderFilterScreenReaderText={false} /> | ||
); | ||
|
||
expect( | ||
queryByLabelText(`${SIDEBAR_FILTER_MATCHES_SCREENREADER_LABEL} ${offsetIndex}. ${url}`) | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); |
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
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