Skip to content

Commit

Permalink
Fix [UI] Error displayed as a reason for failed job 1.7.1 (#2881)
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-prokopchuk authored Nov 18, 2024
1 parent 445ee7c commit a367751
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
22 changes: 17 additions & 5 deletions src/components/Details/DetailsHeader/DetailsHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ illegal under applicable law, and the grant of the foregoing license
under the Apache 2.0 license is conditioned upon your compliance with
such restriction.
*/
import React, { useCallback, useRef, useEffect, useState } from 'react'
import React, { useCallback, useRef, useEffect, useState, useMemo } from 'react'
import PropTypes from 'prop-types'
import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'
import { isEmpty } from 'lodash'
Expand Down Expand Up @@ -66,6 +66,16 @@ const DetailsHeader = ({
const { actionButton, withToggleViewBtn } = pageData.details
const headerRef = useRef()

const errorMessage = useMemo(
() =>
selectedItem.reason
? `Reason: ${selectedItem.reason}`
: selectedItem.error
? `Error: ${selectedItem.error}`
: '',
[selectedItem.error, selectedItem.reason]
)

const {
value: stateValue,
label: stateLabel,
Expand Down Expand Up @@ -184,12 +194,12 @@ const DetailsHeader = ({
{selectedItem.ui.customError.title} {selectedItem.ui.customError.message}
</Tooltip>
)}
{selectedItem.error && (
{errorMessage && (
<Tooltip
className="error-container"
template={<TextTooltipTemplate text={`Error - ${selectedItem.error}`} />}
template={<TextTooltipTemplate text={errorMessage} />}
>
Error - {selectedItem.error}
{errorMessage}
</Tooltip>
)}
{!isEmpty(detailsStore.pods.podsPending) && (
Expand Down Expand Up @@ -297,7 +307,9 @@ const DetailsHeader = ({
data-testid="details-close-btn"
to={
getCloseDetailsLink
? generateUrlFromRouterPath(getCloseDetailsLink(window.location, selectedItem.name))
? generateUrlFromRouterPath(
getCloseDetailsLink(window.location, selectedItem.name)
)
: `/projects/${params.projectName}/${pageData.page.toLowerCase()}${
params.pageTab ? `/${params.pageTab}` : tab ? `/${tab}` : ''
}`
Expand Down
17 changes: 13 additions & 4 deletions src/utils/getState.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import {
FAILED_STATE,
FUNCTION_INITIALIZED_STATE,
FUNCTIONS_PAGE,
JOBS_MONITORING_WORKFLOWS_TAB
JOBS_MONITORING_WORKFLOWS_TAB,
MONITOR_WORKFLOWS_TAB
} from '../constants'

const errorStates = [ERROR_STATE, FAIL_STATE, FAILED_STATE]

const getState = (state, page, kind, reason = '') => {
const getState = (state, page, kind, reason = '', error = '') => {
const stateExists = !isEmpty(state)

if (page === FUNCTIONS_PAGE) {
Expand All @@ -42,8 +43,16 @@ const getState = (state, page, kind, reason = '') => {
}`
}
} else {
const commonLabel = state ? commonStateLabels(page === JOBS_MONITORING_WORKFLOWS_TAB)[state] : ''
const label = reason && errorStates.includes(state) ? `${commonLabel}. Reason: ${reason}` : commonLabel
const commonLabel = state
? commonStateLabels(page === JOBS_MONITORING_WORKFLOWS_TAB || page === MONITOR_WORKFLOWS_TAB)[
state
]
: ''
const additionalLabel = reason ? `Reason: ${reason}` : error ? `${error}` : ''
const label =
additionalLabel && errorStates.includes(state)
? `${commonLabel}. ${additionalLabel}`
: commonLabel

return {
value: state ?? null,
Expand Down
6 changes: 4 additions & 2 deletions src/utils/parseJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const parseJob = (job, tab, customState, customError) => {
job.last_run?.status?.state,
JOBS_PAGE,
JOB_KIND_JOB,
job.last_run?.status?.reason ?? job.last_run?.status?.error
job.last_run?.status?.reason,
job.last_run?.status?.error
),
type:
job.kind === JOB_KIND_PIPELINE || jobHasWorkflowLabel(job) ? JOB_KIND_WORKFLOW : job.kind,
Expand Down Expand Up @@ -100,7 +101,8 @@ export const parseJob = (job, tab, customState, customError) => {
customState || job.status?.state,
JOBS_PAGE,
JOB_KIND_JOB,
job.status?.reason ?? job.status?.error
job.status?.reason,
job.status?.error
),
ui_run: job.status?.ui_url,
uid: job.metadata.uid,
Expand Down

0 comments on commit a367751

Please sign in to comment.