From acea500fde740e8bffd19746b03ec3f837fa4924 Mon Sep 17 00:00:00 2001 From: Pietocha Date: Tue, 7 Jan 2025 09:41:55 +0100 Subject: [PATCH 1/4] Checking validity of the messsage --- src/components/Extensibility/components/Badge.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/Extensibility/components/Badge.js b/src/components/Extensibility/components/Badge.js index 3bf5f717e4..bd1aee44f3 100644 --- a/src/components/Extensibility/components/Badge.js +++ b/src/components/Extensibility/components/Badge.js @@ -38,6 +38,14 @@ export function Badge({ arrayItems, }); + const extractMessageAndCheckValidity = text => { + const messageArray = `${text}`.split('message'); + const message = messageArray[messageArray.length - 1]; + return message.includes('null') || message.includes('undefined') + ? '' + : text; + }; + const [tooltip, tooltipError] = jsonata(structure?.description); let type = null; @@ -78,7 +86,9 @@ export function Badge({ autoResolveType={!type} type={type} tooltipContent={ - tooltip && !tooltipError ? tooltip : structure.description + tooltip && !tooltipError + ? tooltip + : extractMessageAndCheckValidity(structure.description) } > {tExt(value)} From fefbf2879edbdcb0d8d3dbc34ee23d5c09378140 Mon Sep 17 00:00:00 2001 From: Pietocha Date: Thu, 9 Jan 2025 12:09:35 +0100 Subject: [PATCH 2/4] Improved message checking --- .../Extensibility/components/Badge.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/Extensibility/components/Badge.js b/src/components/Extensibility/components/Badge.js index bd1aee44f3..17fe77df79 100644 --- a/src/components/Extensibility/components/Badge.js +++ b/src/components/Extensibility/components/Badge.js @@ -38,12 +38,21 @@ export function Badge({ arrayItems, }); - const extractMessageAndCheckValidity = text => { - const messageArray = `${text}`.split('message'); - const message = messageArray[messageArray.length - 1]; - return message.includes('null') || message.includes('undefined') + 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, + '', + ); + // Checks if it is valid. + return messageValue === 'null' || messageValue === 'undefined' ? '' - : text; + : description; }; const [tooltip, tooltipError] = jsonata(structure?.description); From de98e368558ce7903e6252bf6f6958e1ebcf317e Mon Sep 17 00:00:00 2001 From: Pietocha Date: Fri, 10 Jan 2025 13:09:29 +0100 Subject: [PATCH 3/4] Get latest status message --- .../Extensibility/components/Badge.js | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/components/Extensibility/components/Badge.js b/src/components/Extensibility/components/Badge.js index 17fe77df79..2d5c8f1eb2 100644 --- a/src/components/Extensibility/components/Badge.js +++ b/src/components/Extensibility/components/Badge.js @@ -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); @@ -97,7 +91,7 @@ export function Badge({ tooltipContent={ tooltip && !tooltipError ? tooltip - : extractMessageAndCheckValidity(structure.description) + : getLatestStatusMessage(originalResource, structure.description) } > {tExt(value)} From c0fde4ac57a5a280d7335dd7baa504190b4cb1d2 Mon Sep 17 00:00:00 2001 From: Pietocha Date: Fri, 10 Jan 2025 13:59:35 +0100 Subject: [PATCH 4/4] PR Correction --- .../Extensibility/components/Badge.js | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/components/Extensibility/components/Badge.js b/src/components/Extensibility/components/Badge.js index 2d5c8f1eb2..0405c5d1cf 100644 --- a/src/components/Extensibility/components/Badge.js +++ b/src/components/Extensibility/components/Badge.js @@ -38,17 +38,6 @@ export function Badge({ arrayItems, }); - 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, - ); - return latestStatus?.message ?? defaultValue; - }; - const [tooltip, tooltipError] = jsonata(structure?.description); let type = null; @@ -82,17 +71,23 @@ export function Badge({ type = TYPE_FALLBACK.get(type) || type; + const getTooltipContent = description => { + if (tooltip && !tooltipError) { + return tooltip; + } + if (!tooltip && !tooltipError) { + return ''; + } + return description; + }; + return isNil(value) ? ( emptyLeafPlaceholder ) : structure?.description ? ( {tExt(value)}