Skip to content

Commit

Permalink
Merge pull request #564 from bartoval/polish_charts_size
Browse files Browse the repository at this point in the history
refactor(Metrics): ♻️ Polish charts resize
  • Loading branch information
bartoval authored Jan 31, 2025
2 parents 709af16 + cc5708b commit cde587b
Show file tree
Hide file tree
Showing 16 changed files with 456 additions and 413 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

![alt text](https://github.com/user-attachments/assets/b5c7941f-bc4d-4f72-875a-d12890c1e9a7)

![alt text](https://github.com/user-attachments/assets/862e61a3-067d-48ed-b612-bee1efd1ffc2)
![alt text](https://github.com/user-attachments/assets/ba57d9ce-369c-4ada-b41c-993fba830350)

## Enable the console from Skupper

Expand Down
15 changes: 12 additions & 3 deletions __tests__/__snapshots__/Metric.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ exports[`Metrics Component > renders correctly 1`] = `
</svg>
</div>
</div>
<div
class="pf-v6-l-stack pf-m-gutter"
>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -513,8 +518,8 @@ exports[`Metrics Component > renders correctly 1`] = `
class="pf-v6-l-stack__item"
>
<div
aria-label="Latency"
class="pf-v6-c-card pf-m-expanded pf-m-full-height"
aria-label="Tcp latency"
class="pf-v6-c-card pf-m-expanded"
data-ouia-component-id="OUIA-Generated-Card-3"
data-ouia-component-type="PF6/Card"
data-ouia-safe="true"
Expand Down Expand Up @@ -566,7 +571,7 @@ exports[`Metrics Component > renders correctly 1`] = `
<div
class="pf-v6-c-card__title-text"
>
Latency
Tcp latency
</div>
</div>
</div>
Expand All @@ -576,6 +581,7 @@ exports[`Metrics Component > renders correctly 1`] = `
>
<div
class="pf-v6-c-card__body"
style="min-height: 350px; display: grid;"
>
<div
style="position: absolute; width: 100%; height: 100%; background-color: rgba(255, 255, 255, 0.5); left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 1;"
Expand All @@ -602,6 +608,9 @@ exports[`Metrics Component > renders correctly 1`] = `
</svg>
</div>
</div>
<div
class="pf-v6-l-flex pf-m-row-on-xl pf-m-column pf-m-gap-4xl"
/>
</div>
</div>
</div>
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
"@patternfly/react-icons": "6.1.0",
"@patternfly/react-table": "6.1.0",
"@patternfly/react-tokens": "6.1.0",
"@tanstack/react-query": "5.64.2",
"@tanstack/react-query": "5.66.0",
"axios": "1.7.9",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-error-boundary": "5.0.0",
"react-router-dom": "7.1.3",
"victory": "37.3.2"
"react-router-dom": "7.1.4",
"victory": "37.3.6"
},
"_comment": "Note: Victory 37.3.4 break legend in @patternfly/react-charts",
"devDependencies": {
Expand All @@ -58,7 +58,7 @@
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.2.0",
"@testing-library/user-event": "^14.6.1",
"@types/node": "^22.10.10",
"@types/node": "^22.12.0",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
Expand All @@ -68,7 +68,7 @@
"commitizen": "^4.3.1",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.2",
"cypress": "^14.0.0",
"cypress": "^14.0.1",
"cz-git": "^1.11.0",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
Expand All @@ -80,15 +80,15 @@
"html-webpack-plugin": "^5.6.3",
"husky": "^9.1.7",
"jsdom": "^26.0.0",
"lint-staged": "^15.4.2",
"lint-staged": "^15.4.3",
"mini-css-extract-plugin": "^2.9.2",
"miragejs": "^0.1.48",
"prettier": "^3.4.2",
"start-server-and-test": "^2.0.10",
"terser-webpack-plugin": "^5.3.11",
"ts-loader": "^9.5.2",
"typescript": "^5.7.3",
"typescript-eslint": "^8.21.0",
"typescript-eslint": "^8.22.0",
"vite": "^6.0.11",
"vitest": "^3.0.4",
"webpack": "^5.97.1",
Expand Down
10 changes: 5 additions & 5 deletions src/config/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const Labels = {
TerminatedConnections: 'Closed connections',
LiveConnections: 'Open connections',
Requests: 'Http requests',
RequestRateByMethod: 'Requests Per Second by Method',
Responses: 'Http responses',

Created: 'Created',
Expand Down Expand Up @@ -58,6 +59,7 @@ export const Labels = {
Inbound: 'Inbound',
NoClients: 'No Clients',
OpenConnections: 'Open connections',
ConnectionActivity: 'Connection Activity',
OldConnections: 'Connection history',
TcpTrafficTx: 'Outbound traffic ',
TcpTrafficRx: 'Inbound traffic',
Expand Down Expand Up @@ -102,8 +104,6 @@ export const Labels = {
AllConnectedProcesses: 'All connected processes',
AllProtocols: 'All protocols',

PercentileOverTimeIn: 'Inbound Connections',
PercentileOverTimeOut: 'Outbound Connections',
LatencyMetric50quantile: '50th percentile',
LatencyMetric90quantile: '90th percentile',
LatencyMetric95quantile: '95th percentile',
Expand Down Expand Up @@ -143,7 +143,7 @@ export const Labels = {
BytesOut: 'Data Out',
BytesIn: 'Data In',
ByteRate: 'Byte rate',
Latency: 'Latency',
Latency: 'Tcp latency',
LatencyOut: 'Tcp latency Out',
LatencyIn: 'Tcp latency In',

Expand Down Expand Up @@ -177,6 +177,6 @@ export const Labels = {
'No metrics are currently accessible or meet the filter criteria. Please modify all filters, then attempt the operation again.',
NoBiflowFoundDescription:
'As new connections or requests are established, they will be dynamically added to the table for display',
ByteRateDataOutDescription: 'Analyze outbound and inbound traffic when sending data',
ByteRateDataInDescription: 'Analyze outbound and inbound traffic when receiving data'
ByteRateDataOutDescription: 'Client Role Traffic',
ByteRateDataInDescription: 'Server Role Traffic'
} as const; // makes sure that all values are treated as literal types
25 changes: 17 additions & 8 deletions src/core/components/SkChartArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ import {
ChartArea,
ChartLine
} from '@patternfly/react-charts/victory';
import { getResizeObserver } from '@patternfly/react-core';
import { getResizeObserver, Title } from '@patternfly/react-core';

import { skAxisXY } from '../../../types/SkChartArea.interfaces';
import { formatChartDate } from '../../utils/formatChartDate';

const DEFAULT_CHART_PADDING = {
bottom: 70,
bottom: 0,
left: 70,
right: 0,
top: 20
top: 0
};

interface SkChartAreaProps extends ChartProps {
data: skAxisXY[][];
title?: string;
subTitle?: string;
formatY?: Function;
formatYTooltip?: Function;
formatX?: Function;
Expand All @@ -44,6 +46,8 @@ const SkChartArea: FC<SkChartAreaProps> = function ({
legendLabels = [],
showLegend = true,
isChartLine = false,
title,
subTitle,
height = 300,
...props
}) {
Expand Down Expand Up @@ -74,10 +78,15 @@ const SkChartArea: FC<SkChartAreaProps> = function ({
const startDate = data[0][0]?.x;

return (
<div ref={chartContainerRef} style={{ width: '100%', height: `100%` }}>
<div ref={chartContainerRef} style={{ width: '100%', height: `${height + 0}px`, position: 'relative' }}>
<div style={{ position: 'absolute', left: '35px', top: '10px' }}>
<Title headingLevel="h4">{title}</Title>
<p>{subTitle} </p>
</div>

<Chart
width={width}
height={height}
height={height - 110}
legendData={showLegend ? legendData : []}
legendOrientation={legendOrientation}
legendPosition={legendPosition}
Expand Down Expand Up @@ -106,7 +115,7 @@ const SkChartArea: FC<SkChartAreaProps> = function ({
>
<ChartAxis
style={{
tickLabels: { fontSize: 10 }
tickLabels: { fontSize: 12 }
}}
tickFormat={(tick) => tick && formatX(tick, startDate)}
showGrid
Expand All @@ -116,8 +125,8 @@ const SkChartArea: FC<SkChartAreaProps> = function ({
dependentAxis
minDomain={{ y: 0 }}
style={{
tickLabels: { fontSize: 10 },
axisLabel: { fontSize: 15, padding: 90 }
tickLabels: { fontSize: 12 },
axisLabel: { fontSize: 15, padding: 0 }
}}
tickFormat={(tick) => tick && formatY(tick < 0.001 ? 0 : tick)}
showGrid
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/SkChartPie/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const SkChartPie: FC<SkChartPieProps> = function ({
}));

return (
<div ref={chartContainerRef} style={{ width: '100%', height: `100%` }}>
<div ref={chartContainerRef} style={{ width: `100%`, height: `${height}px` }}>
<ChartDonut
width={width}
height={height}
Expand Down
29 changes: 12 additions & 17 deletions src/pages/shared/Metrics/components/Latency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface LatencyProps {
refetchInterval?: number;
}

const minChartHeight = 350;

const Latency: FC<LatencyProps> = function ({ title = '', selectedFilters, refetchInterval }) {
const [isExpanded, setIsExpanded] = useState(true);

Expand Down Expand Up @@ -45,30 +47,23 @@ const Latency: FC<LatencyProps> = function ({ title = '', selectedFilters, refet
}, [isExpanded]);

return (
<Card isExpanded={isExpanded} aria-label={title} isFullHeight>
<Card isExpanded={isExpanded} aria-label={title}>
<CardHeader onExpand={handleExpand}>
<CardTitle>{title}</CardTitle>
</CardHeader>

<CardExpandableContent>
{/*display grid center the child SKEmptyData */}
<CardBody>
<CardBody style={{ minHeight: minChartHeight, display: 'grid' }}>
{dataIn.isLoading && dataOut.isLoading && <SkIsLoading />}

{!dataIn.isLoading && dataIn.data?.length && (
<>
{!dataIn.isLoading && dataIn.isRefetching && <SkIsLoading />}
<LatencyCharts latenciesData={dataIn.data} title={Labels.PercentileOverTimeOut} />
</>
)}

{!dataOut.isLoading && dataOut.data?.length && (
<>
{!dataOut.isLoading && dataOut.isRefetching && <SkIsLoading />}
<LatencyCharts latenciesData={dataOut.data} title={Labels.PercentileOverTimeIn} />
</>
)}

<LatencyCharts
inboundData={dataIn.data}
outboundData={dataOut.data}
isInboundLoading={dataIn.isLoading}
isOutboundLoading={dataOut.isLoading}
isInboundRefetching={dataIn.isRefetching}
isOutboundRefetching={dataOut.isRefetching}
/>
{!dataIn.isLoading && !dataOut.isLoading && !dataIn.data?.length && !dataOut.data?.length && (
<SKEmptyData
message={Labels.NoMetricFound}
Expand Down
59 changes: 42 additions & 17 deletions src/pages/shared/Metrics/components/LatencyCharts.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
import { FC, memo } from 'react';

import { Stack, StackItem, Title } from '@patternfly/react-core';
import { Flex, FlexItem } from '@patternfly/react-core';

import { Labels } from '../../../../config/labels';
import SkChartArea from '../../../../core/components/SkChartArea';
import SkIsLoading from '../../../../core/components/SkIsLoading';
import { formatLatency } from '../../../../core/utils/formatLatency';
import { LatencyMetrics } from '../../../../types/Metrics.interfaces';

const LatencyCharts: FC<{
latenciesData: LatencyMetrics[];
title: string;
}> = memo(({ latenciesData, title }) => (
<Stack hasGutter>
<StackItem>
<Title headingLevel="h4">{title}</Title>
<SkChartArea
formatY={formatLatency}
legendLabels={latenciesData.map(({ label }) => label)}
data={latenciesData.map(({ data }) => data)}
isChartLine={true}
/>
</StackItem>
</Stack>
));
interface LatencyChartsProps {
inboundData?: LatencyMetrics[] | null;
outboundData?: LatencyMetrics[] | null;
isInboundLoading: boolean;
isOutboundLoading: boolean;
isInboundRefetching: boolean;
isOutboundRefetching: boolean;
}

const LatencyCharts: FC<LatencyChartsProps> = memo(
({ inboundData, outboundData, isInboundLoading, isOutboundLoading, isInboundRefetching, isOutboundRefetching }) => (
<Flex direction={{ xl: 'row', default: 'column' }} gap={{ default: 'gap4xl' }}>
{!isOutboundLoading && outboundData?.length && (
<FlexItem flex={{ default: 'flex_1' }}>
{!isOutboundLoading && isOutboundRefetching && <SkIsLoading />}
<SkChartArea
title={Labels.Inbound}
formatY={formatLatency}
legendLabels={outboundData.map(({ label }) => label)}
data={outboundData.map(({ data }) => data)}
isChartLine={true}
/>
</FlexItem>
)}
{!isInboundLoading && inboundData?.length && (
<FlexItem flex={{ default: 'flex_1' }}>
{!isInboundLoading && isInboundRefetching && <SkIsLoading />}
<SkChartArea
title={Labels.Outbound}
formatY={formatLatency}
legendLabels={inboundData.map(({ label }) => label)}
data={inboundData.map(({ data }) => data)}
isChartLine={true}
/>
</FlexItem>
)}
</Flex>
)
);

export default LatencyCharts;
10 changes: 7 additions & 3 deletions src/pages/shared/Metrics/components/Request.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC, useCallback, useState } from 'react';

import { Card, CardBody, CardExpandableContent, CardHeader, CardTitle, Title } from '@patternfly/react-core';
import { Card, CardBody, CardExpandableContent, CardHeader, CardTitle } from '@patternfly/react-core';
import { SearchIcon } from '@patternfly/react-icons';
import { keepPreviousData, useQuery } from '@tanstack/react-query';

Expand Down Expand Up @@ -43,6 +43,7 @@ const Request: FC<RequestProps> = function ({ selectedFilters, refetchInterval }
<CardHeader onExpand={handleExpand}>
<CardTitle>{Labels.Requests}</CardTitle>
</CardHeader>

<CardExpandableContent>
{/*display grid center the child SKEmptyData */}
<CardBody style={{ minHeight: minChartHeight, display: 'grid' }}>
Expand All @@ -51,8 +52,11 @@ const Request: FC<RequestProps> = function ({ selectedFilters, refetchInterval }
{!isLoading && request?.requestRateData?.length && (
<>
{isRefetching && <SkIsLoading />}
<Title headingLevel="h4">{Labels.RequestRate} </Title>
<RequestCharts requestRateData={request.requestRateData} requestPerf={request.requestPerf} />
<RequestCharts
title={Labels.RequestRateByMethod}
requestRateData={request.requestRateData}
requestPerf={request.requestPerf}
/>
</>
)}

Expand Down
Loading

0 comments on commit cde587b

Please sign in to comment.