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

Bug 1866034: Fix to reduce pod donut text size when text is long #6299

Merged
merged 1 commit into from
Aug 19, 2020
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
8 changes: 5 additions & 3 deletions frontend/packages/console-shared/src/utils/pod-ring-text.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
font-size: 14px !important;
fill: var(--pf-global--Color--200) !important;
}
tspan:first-of-type {
font-size: 24px !important;
fill: var(--pf-global--Color--100) !important;
&:not(.pod-ring__long-text) {
tspan:first-of-type {
font-size: var(--pf-chart-global--FontSize--2xl) !important;
fill: var(--pf-global--Color--100) !important;
}
}
}

Expand Down
31 changes: 21 additions & 10 deletions frontend/packages/console-shared/src/utils/pod-ring-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import * as _ from 'lodash';
import * as classNames from 'classnames';
import {
DeploymentConfigModel,
DeploymentModel,
Expand Down Expand Up @@ -98,11 +99,13 @@ const getTitleAndSubtitle = (
) => {
let titlePhrase;
let subTitlePhrase = '';
let longTitle = false;
let longSubtitle = false;

// handles the initial state when the first pod is coming up and the state for no pods(scaled to zero)
if (!currentPodCount) {
titlePhrase = isPending ? '0' : `Scaled to 0`;
longTitle = !isPending;
if (desiredPodCount) {
subTitlePhrase = `scaling to ${desiredPodCount}`;
longSubtitle = true;
Expand All @@ -120,17 +123,25 @@ const getTitleAndSubtitle = (
}
}

return { title: titlePhrase, subTitle: subTitlePhrase, longSubtitle };
return { title: titlePhrase, longTitle, subTitle: subTitlePhrase, longSubtitle };
};

const getTitleComponent = (longSubtitle: boolean = false, reversed: boolean = false) =>
React.createElement(ChartLabel, {
const getTitleComponent = (
longTitle: boolean = false,
longSubtitle: boolean = false,
reversed: boolean = false,
) => {
const labelClasses = classNames('pf-chart-donut-title', {
'pod-ring__center-text--reversed': reversed,
'pod-ring__center-text': !reversed,
'pod-ring__long-text': longTitle,
});
return React.createElement(ChartLabel, {
dy: longSubtitle ? -5 : 0,
style: { lineHeight: '11px' },
className: `pf-chart-donut-title ${
reversed ? 'pod-ring__center-text--reversed' : 'pod-ring__center-text'
}`,
className: labelClasses,
});
};

export const podRingLabel = (
obj: K8sResourceKind,
Expand All @@ -154,7 +165,7 @@ export const podRingLabel = (
return {
title: titleData.title,
subTitle: titleData.subTitle,
titleComponent: getTitleComponent(titleData.longSubtitle),
titleComponent: getTitleComponent(titleData.longTitle, titleData.longSubtitle),
};
case RevisionModel.kind:
currentPodCount = (obj.status?.readyReplicas || 0) + failedPodCount;
Expand All @@ -166,7 +177,7 @@ export const podRingLabel = (
return {
title,
subTitle,
titleComponent: getTitleComponent(false, true),
titleComponent: getTitleComponent(false, false, true),
};
}
if (isPending) {
Expand Down Expand Up @@ -202,7 +213,7 @@ export const podRingLabel = (
return {
title: titleData.title,
subTitle: titleData.subTitle,
titleComponent: getTitleComponent(titleData.longSubtitle),
titleComponent: getTitleComponent(titleData.longTitle, titleData.longSubtitle),
};
}
};
Expand All @@ -220,7 +231,7 @@ export const hpaPodRingLabel = (
return {
title: scaling ? 'Autoscaling' : 'Autoscaled',
subTitle: `to ${desiredPods}`,
titleComponent: getTitleComponent(false, true),
titleComponent: getTitleComponent(false, false, true),
};
};

Expand Down