Skip to content

Commit

Permalink
adjust types
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiqueclarke committed Sep 18, 2024
1 parent 5dbeebf commit 4e88a54
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ describe('getSeriesAndDomain', () => {
});

it('handles formatting when mime type is not mapped to a specific mime type bucket', () => {
const { series, metadata } = getSeriesAndDomain(
const { metadata } = getSeriesAndDomain(
networkItemsWithUnknownMimeType,
false,
mockDateFormatter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
Metadata,
MimeType,
MimeTypesMap,
SidebarItem,
WaterfallNetworkItem,
WaterfallTooltipItem,
TIMING_ORDER,
Timings,
} from './types';
Expand Down Expand Up @@ -305,7 +306,7 @@ const formatMetadata = ({
requestStart: number;
dateFormatter: DateFormatter;
showTooltip: boolean;
networkItemTooltipProps?: Array<Record<string, string | number>>;
networkItemTooltipProps: WaterfallTooltipItem[];
}) => {
const {
certificates,
Expand Down Expand Up @@ -404,7 +405,7 @@ export const getSidebarItems = (
onlyHighlighted: boolean,
query: string,
activeFilters: string[]
): SidebarItem[] => {
): WaterfallNetworkItem[] => {
const queryMatcher = getQueryMatcher(query);
const filterMatcher = getFilterMatcher(activeFilters);
const sideBarItems = items.map((item, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ interface Props {
index: number;
highestIndex: number;
ariaLabel: string;
text: string;
onClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
setButtonRef?: (ref: HTMLButtonElement | HTMLAnchorElement | null) => void;
url: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,29 @@ const getChartHeight = (data: WaterfallData): number => {
};

const CustomTooltip: CustomChartTooltip = (tooltipInfo) => {
const { data, sidebarItems } = useWaterfallContext();
const { sidebarItems, metadata } = useWaterfallContext();
return useMemo(() => {
const sidebarItem = sidebarItems?.find((item) => item.index === tooltipInfo.header?.value);
const relevantItems = data.filter((item) => {
return (
item.x === tooltipInfo.header?.value && item.config.showTooltip && item.config.tooltipProps
);
});
return relevantItems.length ? (
if (!sidebarItem) {
return null;
}
const metadataEntry = metadata?.[sidebarItem.index];
const showTooltip =
metadataEntry?.showTooltip && metadataEntry?.networkItemTooltipProps.length > 1;
return showTooltip ? (
<TooltipContainer>
<WaterfallChartTooltip>
{sidebarItem && (
<WaterfallTooltipContent
text={formatTooltipHeading(sidebarItem.index + 1, sidebarItem.url)}
text={formatTooltipHeading(sidebarItem.offsetIndex, sidebarItem.url)}
url={sidebarItem.url}
index={sidebarItem.offsetIndex}
/>
)}
</WaterfallChartTooltip>
</TooltipContainer>
) : null;
}, [data, sidebarItems, tooltipInfo.header?.value]);
}, [sidebarItems, tooltipInfo.header?.value, metadata]);
};

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ describe('useFlyoutHook', () => {
value: 'text/html',
},
],
showTooltip: false,
networkItemTooltipProps: [],
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('WaterfallFlyout', () => {
value: 'text/html',
},
],
showTooltip: false,
networkItemTooltipProps: [],
};

const defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import React, { RefObject, useMemo, useCallback, useState } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiBadge } from '@elastic/eui';
import { SidebarItem } from '../../common/network_data/types';
import { WaterfallNetworkItem } from '../../common/network_data/types';
import { MiddleTruncatedText } from './middle_truncated_text';
import { SideBarItemHighlighter } from './styles';
import { SIDEBAR_FILTER_MATCHES_SCREENREADER_LABEL } from './translations';
import { OnSidebarClick } from './waterfall_flyout/use_flyout';

interface SidebarItemProps {
item: SidebarItem;
item: WaterfallNetworkItem;
renderFilterScreenReaderText?: boolean;
onClick?: OnSidebarClick;
highestIndex: number;
Expand Down Expand Up @@ -44,13 +44,11 @@ export const WaterfallSidebarItem = React.memo(function WaterfallSidebarItem({
return is400 || is500 || isSpecific300;
};

const text = item.url;

const ariaLabel = `${
isHighlighted && renderFilterScreenReaderText
? `${SIDEBAR_FILTER_MATCHES_SCREENREADER_LABEL} `
: ''
}${text}`;
}${url}`;

return (
<SideBarItemHighlighter
Expand All @@ -62,7 +60,6 @@ export const WaterfallSidebarItem = React.memo(function WaterfallSidebarItem({
<EuiFlexItem grow={false} style={{ minWidth: 0 }}>
<MiddleTruncatedText
index={offsetIndex}
text={text}
url={url}
ariaLabel={ariaLabel}
onClick={handleSidebarClick}
Expand All @@ -76,7 +73,6 @@ export const WaterfallSidebarItem = React.memo(function WaterfallSidebarItem({
<EuiFlexItem grow={false} style={{ minWidth: 0 }}>
<MiddleTruncatedText
index={offsetIndex}
text={text}
url={url}
ariaLabel={ariaLabel}
onClick={handleSidebarClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useWaterfallContext } from './context/waterfall_context';
interface Props {
text: string;
url: string;
index: string;
index: number;
}

const StyledText = euiStyled(EuiText)`
Expand All @@ -25,7 +25,7 @@ const StyledHorizontalRule = euiStyled(EuiHorizontalRule)`
`;

export const WaterfallTooltipContent: React.FC<Props> = ({ text, url, index }) => {
const { renderTooltipItem, sidebarItems, metadata } = useWaterfallContext();
const { renderTooltipItem, metadata } = useWaterfallContext();
// the passed index is base 1, so we need to subtract 1 to get the correct index
const metadataEntry = metadata?.[index - 1];
const tooltipItems = metadataEntry?.networkItemTooltipProps;
Expand Down

0 comments on commit 4e88a54

Please sign in to comment.