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

Fix [UI] Error displayed as a reason for failed job #340

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 14 additions & 5 deletions src/utils/getState.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ such restriction.

import { isEmpty } from 'lodash'
import {
ERROR_STATE,
ERROR_STATE,
FAIL_STATE,
FAILED_STATE, FUNCTION_INITIALIZED_STATE,
FAILED_STATE,
FUNCTION_INITIALIZED_STATE,
FUNCTIONS_PAGE,
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 || page === MONITOR_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)
Expand Down Expand Up @@ -102,7 +103,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
Loading