Skip to content

Commit

Permalink
Get latest status message
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradPietocha committed Jan 10, 2025
1 parent fefbf28 commit de98e36
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/components/Extensibility/components/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,15 @@ export function Badge({
arrayItems,
});

const extractMessageAndCheckValidity = description => {
if (!description && typeof description !== 'string') {
return '';
}
// Extracts a message from the string.
const messageArray = description.split('message');
// Removes the colon and blank, leaving only the value.
const messageValue = messageArray[messageArray.length - 1].replace(
/:|\s/g,
'',
const getLatestStatusMessage = (resource, defaultValue) => {
const getTime = date => new Date(date)?.getTime();
const latestStatus = resource?.status?.conditions?.reduce((prev, current) =>
prev &&
getTime(prev.lastTransitionTime) > getTime(current.lastTransitionTime)
? prev
: current,
);
// Checks if it is valid.
return messageValue === 'null' || messageValue === 'undefined'
? ''
: description;
return latestStatus?.message ?? defaultValue;
};

const [tooltip, tooltipError] = jsonata(structure?.description);
Expand Down Expand Up @@ -97,7 +91,7 @@ export function Badge({
tooltipContent={
tooltip && !tooltipError
? tooltip
: extractMessageAndCheckValidity(structure.description)
: getLatestStatusMessage(originalResource, structure.description)
}
>
{tExt(value)}
Expand Down

0 comments on commit de98e36

Please sign in to comment.