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

Realign healthy icon in summary panel graph #6885

Merged
merged 2 commits into from
Nov 27, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/src/components/Health/HealthIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import * as React from 'react';
import { PopoverPosition, Tooltip } from '@patternfly/react-core';
import { HealthDetails } from './HealthDetails';
import * as H from '../../types/Health';
import { createIcon } from './Helper';
import { Size, createIcon } from './Helper';
import { createTooltipIcon } from '../../config/KialiIcon';
import { healthIndicatorStyle } from '../../styles/HealthStyle';

interface HealthIndicatorProps {
health?: H.Health;
id: string;
size?: Size;
tooltipPlacement?: PopoverPosition;
}

export const HealthIndicator: React.FC<HealthIndicatorProps> = (props: HealthIndicatorProps) => {
const globalStatus = props.health ? props.health.getGlobalStatus() : H.NA;

if (props.health) {
// HealthIndicator will render always in SMALL mode
const icon = createIcon(globalStatus, 'md');
const icon = createIcon(globalStatus, props.size ?? 'md');

return (
<Tooltip
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Health/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Status } from 'types/Health';
import { Icon } from '@patternfly/react-core';
import { kialiStyle } from 'styles/StyleUtils';

type Size = 'sm' | 'md' | 'lg' | 'xl';
export type Size = 'sm' | 'md' | 'lg' | 'xl';

export const createIcon = (status: Status, size?: Size) => {
const classForColor = kialiStyle({
Expand Down
20 changes: 10 additions & 10 deletions frontend/src/components/Pf/PfBadges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,29 @@ export const PFBadges: { [key: string]: PFBadgeType } = Object.freeze({
export const kialiBadge = kialiStyle({
backgroundColor: PFColors.Badge,
color: PFColors.White,
borderRadius: '1.25rem',
borderRadius: '20px',
flexShrink: 0,
fontFamily: 'var(--pf-v5-global--FontFamily--text)',
fontSize: 'var(--kiali-global--font-size)',
lineHeight: '1rem',
marginRight: '0.25rem',
lineHeight: '16px',
marginRight: '4px',
minWidth: '1.5em',
padding: '0.075rem 0.25rem',
padding: '1px 4px',
textAlign: 'center',
whiteSpace: 'nowrap'
});

export const kialiBadgeSmall = kialiStyle({
backgroundColor: PFColors.Badge,
color: PFColors.White,
borderRadius: '1.25rem',
borderRadius: '20px',
flexShrink: 0,
fontFamily: 'var(--pf-v5-global--FontFamily--text)',
fontSize: '0.75rem',
lineHeight: '0.75rem',
marginRight: '0.25rem',
fontSize: '12px',
lineHeight: '13px',
marginRight: '5px',
minWidth: '1.3em',
padding: '0.075rem 0.25rem',
padding: '1px 3px',
textAlign: 'center',
whiteSpace: 'nowrap'
});
Expand All @@ -110,7 +110,7 @@ type PFBadgeProps = {
position?: TooltipPosition; // default=auto
size?: 'global' | 'sm';
style?: CSSProperties;
tooltip?: React.ReactFragment;
tooltip?: React.ReactNode;
};

export const PFBadge: React.FC<PFBadgeProps> = (props: PFBadgeProps) => {
Expand Down
72 changes: 46 additions & 26 deletions frontend/src/pages/Graph/SummaryLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,47 @@ import {
DecoratedGraphNodeData
} from '../../types/Graph';
import { KialiIcon } from 'config/KialiIcon';
import { Badge, PopoverPosition } from '@patternfly/react-core';
import { PopoverPosition } from '@patternfly/react-core';
import { Health } from 'types/Health';
import { HealthIndicator } from 'components/Health/HealthIndicator';
import { PFBadge, PFBadges } from 'components/Pf/PfBadges';
import { homeCluster } from 'config';
import { KialiPageLink } from 'components/Link/KialiPageLink';
import { kialiStyle } from 'styles/StyleUtils';

interface LinkInfo {
link: string;
displayName: string;
key: string;
link: string;
}

const getTooltip = (tooltip: React.ReactFragment, nodeData: GraphNodeData): React.ReactFragment => {
const badgeStyle = kialiStyle({
display: 'inline-block',
marginRight: '0.5rem',
marginBottom: '0.25rem'
});

const getTooltip = (tooltip: React.ReactNode, nodeData: GraphNodeData): React.ReactNode => {
const addNamespace = nodeData.isBox !== BoxByType.NAMESPACE;

const addCluster =
nodeData.isBox !== BoxByType.CLUSTER &&
nodeData.cluster !== CLUSTER_DEFAULT &&
homeCluster?.name !== nodeData.cluster;

return (
<div style={{ textAlign: 'left' }}>
<span>{tooltip}</span>

{addNamespace && <div>{`Namespace: ${nodeData.namespace}`}</div>}

{addCluster && <div>{`Cluster: ${nodeData.cluster}`}</div>}
</div>
);
};

export const getBadge = (nodeData: GraphNodeData, nodeType?: NodeType) => {
switch (nodeType || nodeData.nodeType) {
export const getBadge = (nodeData: GraphNodeData, nodeType?: NodeType): React.ReactNode => {
switch (nodeType ?? nodeData.nodeType) {
case NodeType.AGGREGATE:
return (
<PFBadge
Expand Down Expand Up @@ -85,11 +96,17 @@ export const getBadge = (nodeData: GraphNodeData, nodeType?: NodeType) => {
}
};

export const getLink = (nodeData: GraphNodeData, nodeType?: NodeType, linkGenerator?: () => LinkInfo) => {
export const getLink = (
nodeData: GraphNodeData,
nodeType?: NodeType,
linkGenerator?: () => LinkInfo
): React.ReactNode => {
const { app, cluster, namespace, service, workload } = nodeData;

if (!nodeType || nodeData.nodeType === NodeType.UNKNOWN) {
nodeType = nodeData.nodeType;
}

let displayName: string = 'unknown';
let link: string | undefined;
let key: string | undefined;
Expand Down Expand Up @@ -154,7 +171,7 @@ export const getLink = (nodeData: GraphNodeData, nodeType?: NodeType, linkGenera
return <span key={key}>{displayName}</span>;
};

export const renderBadgedHost = (host: string) => {
export const renderBadgedHost = (host: string): React.ReactNode => {
return (
<div>
<PFBadge key={`badgedHost-${host}`} badge={PFBadges.Host} size="sm" />
Expand All @@ -163,15 +180,16 @@ export const renderBadgedHost = (host: string) => {
);
};

export const renderBadgedName = (nodeData: GraphNodeData, label?: string) => {
export const renderBadgedName = (nodeData: GraphNodeData, label?: string): React.ReactNode => {
return (
<div key={`badgedName-${nodeData.id}`}>
<span style={{ marginRight: '1em', marginBottom: '3px', display: 'inline-block' }}>
<span className={badgeStyle}>
{label && (
<span style={{ whiteSpace: 'pre' }}>
<b>{label}</b>
</span>
)}

{getBadge(nodeData)}
{getLink({ ...nodeData, isInaccessible: true })}
</span>
Expand All @@ -184,17 +202,18 @@ export const renderBadgedLink = (
nodeType?: NodeType,
label?: string,
linkGenerator?: () => LinkInfo
): React.ReactFragment => {
): React.ReactNode => {
const link = getLink(nodeData, nodeType, linkGenerator);

return (
<div key={`node-${nodeData.id}`}>
<span style={{ marginRight: '1em', marginBottom: '3px', display: 'inline-block' }}>
<span className={badgeStyle}>
{label && (
<span style={{ whiteSpace: 'pre' }}>
<b>{label}</b>
</span>
)}

{getBadge(nodeData, nodeType)}
{link}
</span>
Expand All @@ -203,27 +222,27 @@ export const renderBadgedLink = (
);
};

export const renderHealth = (health?: Health) => {
export const renderHealth = (health?: Health): React.ReactNode => {
return (
<>
<Badge style={{ fontWeight: 'normal', marginTop: '4px', marginBottom: '4px' }} isRead={true}>
<span style={{ margin: '3px 3px 1px 0' }}>
{health ? (
<HealthIndicator id="graph-health-indicator" health={health} tooltipPlacement={PopoverPosition.left} />
) : (
'n/a'
)}
</span>
health
</Badge>
</>
<span>
{health ? (
<HealthIndicator
id="graph-health-indicator"
health={health}
tooltipPlacement={PopoverPosition.left}
size="sm"
/>
) : (
'n/a'
)}
</span>
);
};

export const renderDestServicesLinks = (nodeData: DecoratedGraphNodeData) => {
export const renderDestServicesLinks = (nodeData: DecoratedGraphNodeData): React.ReactNode[] => {
const destServices: DestService[] | undefined = nodeData.destServices;

const links: any[] = [];
const links: React.ReactNode[] = [];
if (!destServices) {
return links;
}
Expand All @@ -243,6 +262,7 @@ export const renderDestServicesLinks = (nodeData: DecoratedGraphNodeData) => {
version: '',
workload: ''
};

links.push(renderBadgedLink(serviceNodeData));
});

Expand Down