Skip to content

Commit

Permalink
Improve badge color text parsing (#12396)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac authored Oct 29, 2024
1 parent 3d49895 commit 46ac400
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions shell/models/management.cattle.io.cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { LINUX, WINDOWS } from '@shell/store/catalog';
import { KONTAINER_TO_DRIVER } from './management.cattle.io.kontainerdriver';
import { PINNED_CLUSTERS } from '@shell/store/prefs';

const DEFAULT_BADGE_COLOR = '#707070';

// See translation file cluster.providers for list of providers
// If the logo is not named with the provider name, add an override here
const PROVIDER_LOGO_OVERRIDE = {};
Expand Down Expand Up @@ -295,20 +297,30 @@ export default class MgmtCluster extends HybridModel {

// Custom badge to show for the Cluster (if the appropriate annotations are set)
get badge() {
const text = this.metadata?.annotations?.[CLUSTER_BADGE.TEXT];
const icon = this.metadata?.annotations?.[CLUSTER_BADGE.ICON_TEXT];
const comment = this.metadata?.annotations?.[CLUSTER_BADGE.TEXT];

if (!text) {
if (!icon && !comment) {
return undefined;
}

const color = this.metadata?.annotations[CLUSTER_BADGE.COLOR] || '#7f7f7f';
let color = this.metadata?.annotations[CLUSTER_BADGE.COLOR] || DEFAULT_BADGE_COLOR;
const iconText = this.metadata?.annotations[CLUSTER_BADGE.ICON_TEXT] || '';
let foregroundColor;

try {
foregroundColor = textColor(parseColor(color.trim())); // Remove any whitespace
} catch (_e) {
// If we could not parse the badge color, use the defaults
color = DEFAULT_BADGE_COLOR;
foregroundColor = textColor(parseColor(color));
}

return {
text,
text: comment || undefined,
color,
textColor: textColor(parseColor(color)),
iconText: iconText.substr(0, 2)
textColor: foregroundColor,
iconText: iconText.substr(0, 3)
};
}

Expand Down

0 comments on commit 46ac400

Please sign in to comment.