Skip to content

Commit

Permalink
Fix [Job Artifacts] artifacts tab fails to load for workflow job (#2995)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taras-Hlukhovetskyi authored Jan 8, 2025
1 parent 8a82259 commit 396c30f
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 48 deletions.
45 changes: 23 additions & 22 deletions src/components/DetailsArtifacts/DetailsArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const DetailsArtifacts = ({

const dispatch = useDispatch()
const artifactsStore = useSelector(store => store.artifactsStore)
const isJobLoading = useSelector(store => Boolean(store.jobsStore.jobLoadingCounter))

const showArtifact = useCallback(
id => {
Expand Down Expand Up @@ -148,7 +149,7 @@ const DetailsArtifacts = ({

if (workflowId) {
return dispatch(
fetchJob({
fetchJob({ // todo remove this request in ML-8608 and use data from the selectedJob (it will be up to date)
project: job.project || params.projectName,
jobId: params.jobId,
iter: iteration
Expand All @@ -166,39 +167,39 @@ const DetailsArtifacts = ({
}
}
)
}
} else {
if (iteration) {
config.params.iter = iteration
}

if (iteration) {
config.params.iter = iteration
dispatch(
fetchArtifacts({
project: job.project || params.projectName,
filters: {},
config,
setRequestErrorMessage
})
)
.unwrap()
.then(result => {
if (result) {
setArtifactsPreviewContent(generateArtifactsPreviewContent(job, result))
}
})
}

dispatch(
fetchArtifacts({
project: job.project || params.projectName,
filters: {},
config,
setRequestErrorMessage
})
)
.unwrap()
.then(result => {
if (result) {
setArtifactsPreviewContent(generateArtifactsPreviewContent(job, result))
}
})
},
[dispatch, params.jobId, params.projectName]
)

useEffect(() => {
if (params.jobId === selectedItem.uid || isDetailsPopUp) {
if ((params.jobId === selectedItem.uid || isDetailsPopUp) && !isJobLoading) {
if (selectedItem.iterationStats?.length > 0 && iteration) {
getJobArtifacts(selectedItem, iteration)
} else if (selectedItem.iterationStats?.length === 0) {
getJobArtifacts(selectedItem, null)
}
}
}, [getJobArtifacts, iteration, params.jobId, params.projectName, selectedItem, isDetailsPopUp])
}, [getJobArtifacts, iteration, params.jobId, params.projectName, selectedItem, isDetailsPopUp, isJobLoading])

useEffect(() => {
return () => {
Expand All @@ -208,7 +209,7 @@ const DetailsArtifacts = ({
}, [params.jobId, params.projectName, selectedItem, iteration])

return artifactsStore.loading ? (
<Loader />
<Loader section />
) : artifactsPreviewContent.length === 0 ? (
<NoData message={requestErrorMessage} />
) : (
Expand Down
1 change: 1 addition & 0 deletions src/components/JobWizard/JobWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ const JobWizard = ({
{(functionsStore.loading ||
functionsStore.funcLoading ||
jobsStore.loading ||
Boolean(jobsStore.jobLoadingCounter) ||
projectIsLoading) && <Loader />}
</>
)
Expand Down
15 changes: 10 additions & 5 deletions src/components/Jobs/Jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ const Jobs = () => {
return defaultsDeep(
{
[MONITOR_JOBS_TAB]: {
handleRefresh: handleRefreshJobs
handleRefresh: (...args) => {
setSelectedJob({})
handleRefreshJobs(...args)
}
},
[MONITOR_WORKFLOWS_TAB]: {
handleRefresh: getWorkflows
Expand Down Expand Up @@ -231,7 +234,11 @@ const Jobs = () => {
onClick: () => handleMonitoring(selectedJob, true)
}
]}
autoRefreshIsStopped={jobWizardIsOpened || jobsStore.loading}
autoRefreshIsStopped={
jobWizardIsOpened ||
jobsStore.loading ||
Boolean(jobsStore.jobLoadingCounter)
}
autoRefreshStopTrigger={!isEmpty(selectedJob)}
filters={filters}
filtersConfig={initialTabData[selectedTab].filtersConfig}
Expand Down Expand Up @@ -292,10 +299,8 @@ const Jobs = () => {
>
<Outlet />
</JobsContext.Provider>
{(jobsStore.loading ||
workflowsStore.workflows.loading ||
{(Boolean(jobsStore.jobLoadingCounter) ||
workflowsStore.activeWorkflow.loading ||
functionsStore.loading ||
functionsStore.funcLoading) && <Loader />}
</div>
</div>
Expand Down
16 changes: 14 additions & 2 deletions src/components/ProjectsJobsMonitoring/ProjectsJobsMonitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import ActionBar from '../ActionBar/ActionBar'
import JobsMonitoringFilters from './JobsMonitoring/JobsMonitoringFilters'
import ScheduledMonitoringFilters from './ScheduledMonitoring/ScheduledMonitoringFilters'
import WorkflowsMonitoringFilters from './WorkflowsMonitoring/WorkflowsMonitoringFilters'
import Loader from '../../common/Loader/Loader'

import { STATS_TOTAL_CARD, tabs } from './projectsJobsMotinoring.util'
import {
Expand Down Expand Up @@ -67,6 +68,8 @@ const ProjectsJobsMonitoring = () => {
const navigate = useNavigate()
const artifactsStore = useSelector(store => store.artifactsStore)
const jobsStore = useSelector(store => store.jobsStore)
const workflowsStore = useSelector(store => store.workflowsStore)
const functionsStore = useSelector(store => store.functionsStore)

const jobsFiltersConfig = useMemo(
() => getJobsFiltersConfig(params.jobName, true),
Expand Down Expand Up @@ -145,7 +148,10 @@ const ProjectsJobsMonitoring = () => {
return defaultsDeep(
{
[JOBS_MONITORING_JOBS_TAB]: {
handleRefresh: handleRefreshJobs
handleRefresh: (...args) => {
setSelectedJob({})
handleRefreshJobs(...args)
}
},
[JOBS_MONITORING_WORKFLOWS_TAB]: {
handleRefresh: getWorkflows
Expand Down Expand Up @@ -182,7 +188,10 @@ const ProjectsJobsMonitoring = () => {
<ActionBar
autoRefreshIsEnabled={selectedTab === JOBS_MONITORING_JOBS_TAB}
autoRefreshIsStopped={
jobWizardIsOpened || jobsStore.loading || !isEmpty(selectedJob)
jobWizardIsOpened ||
jobsStore.loading ||
Boolean(jobsStore.jobLoadingCounter) ||
!isEmpty(selectedJob)
}
filters={filters}
filtersConfig={tabData[selectedTab].filtersConfig}
Expand Down Expand Up @@ -242,6 +251,9 @@ const ProjectsJobsMonitoring = () => {
>
<Outlet />
</ProjectJobsMonitoringContext.Provider>
{(Boolean(jobsStore.jobLoadingCounter) ||
workflowsStore.activeWorkflow.loading ||
functionsStore.funcLoading) && <Loader />}
</div>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { isEmpty } from 'lodash'

import WorkflowsTable from '../../../elements/WorkflowsTable/WorkflowsTable'
import { ProjectJobsMonitoringContext } from '../ProjectsJobsMonitoring'
import Loader from '../../../common/Loader/Loader'

import {
JOBS_MONITORING_PAGE,
Expand All @@ -46,8 +45,6 @@ const WorkflowsMonitoring = ({ fetchFunctionLogs }) => {
const [itemIsSelected, setItemIsSelected] = useState(false)
const [selectedJob, setSelectedJob] = useState({})
const workflowsStore = useSelector(state => state.workflowsStore)
const jobIsLoading = useSelector(store => store.jobsStore.loading)
const funcIsLoading = useSelector(store => store.functionsStore.funcLoading)
const params = useParams()
const dispatch = useDispatch()
const { isStagingMode } = useMode()
Expand Down Expand Up @@ -109,7 +106,6 @@ const WorkflowsMonitoring = ({ fetchFunctionLogs }) => {

return (
<>
{(jobIsLoading || funcIsLoading || workflowsStore.activeWorkflow.loading) && <Loader />}
<WorkflowsTable
backLink={`/projects/*/${JOBS_MONITORING_PAGE}/${JOBS_MONITORING_WORKFLOWS_TAB}${window.location.search}`}
context={ProjectJobsMonitoringContext}
Expand Down
4 changes: 2 additions & 2 deletions src/elements/JobsTable/JobsTable.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, { useMemo, useCallback, useEffect } from 'react'
import React, { useMemo, useCallback, useEffect, useLayoutEffect } from 'react'
import PropTypes from 'prop-types'
import { isEmpty } from 'lodash'
import { useDispatch, useSelector } from 'react-redux'
Expand Down Expand Up @@ -311,7 +311,7 @@ const JobsTable = React.forwardRef(
setJobWizardMode
])

useEffect(() => {
useLayoutEffect(() => {
checkForSelectedJob(
paginatedJobs,
params.jobName,
Expand Down
8 changes: 4 additions & 4 deletions src/elements/WorkflowsTable/WorkflowsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,10 @@ const WorkflowsTable = React.forwardRef(
return (
<>
{workflowsStore.workflows.loading && <Loader />}
{(!workflowsStore.workflows.loading &&
!params.workflowId &&
workflowsStore.workflows.data.length === 0) ||
requestErrorMessage ? (
{workflowsStore.workflows.loading ? null : (!workflowsStore.workflows.loading &&
!params.workflowId &&
workflowsStore.workflows.data.length === 0) ||
requestErrorMessage ? (
<NoData
message={getNoDataMessage(
filters,
Expand Down
31 changes: 22 additions & 9 deletions src/reducers/jobReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { getNewJobErrorMsg } from '../components/JobWizard/JobWizard.util'
const initialState = {
jobsData: [],
job: {},
jobLoadingCounter: 0,
jobFunc: {},
jobRuns: [],
jobs: [],
Expand Down Expand Up @@ -313,27 +314,39 @@ const jobsSlice = createSlice({
state.loading = false
})
builder.addCase(fetchAllJobRuns.rejected, hideLoading)
builder.addCase(fetchJob.pending, showLoading)
builder.addCase(fetchJob.pending, (state, action) => {
state.jobLoadingCounter++
})
builder.addCase(fetchJob.fulfilled, (state, action) => {
state.error = null
state.job = action.payload
state.loading = false
state.jobLoadingCounter--
})
builder.addCase(fetchJob.rejected, (state, action) => {
state.jobLoadingCounter--
})
builder.addCase(fetchJobFunction.pending, (state, action) => {
state.jobLoadingCounter++
})
builder.addCase(fetchJob.rejected, hideLoading)
builder.addCase(fetchJobFunction.pending, showLoading)
builder.addCase(fetchJobFunction.fulfilled, (state, action) => {
state.error = null
state.jobFunc = action.payload
state.loading = false
state.jobLoadingCounter--
})
builder.addCase(fetchJobFunction.rejected, (state, action) => {
state.jobLoadingCounter--
})
builder.addCase(fetchJobFunctions.rejected, (state, action) => {
state.jobLoadingCounter--
})
builder.addCase(fetchJobFunctions.pending, (state, action) => {
state.jobLoadingCounter++
})
builder.addCase(fetchJobFunction.rejected, hideLoading)
builder.addCase(fetchJobFunctions.pending, showLoading)
builder.addCase(fetchJobFunctions.fulfilled, (state, action) => {
state.error = null
state.jobFunc = action.payload
state.loading = false
state.jobLoadingCounter--
})
builder.addCase(fetchJobFunctions.rejected, hideLoading)
builder.addCase(fetchJobLogs.pending, (state, action) => {
state.logs.loading = true
state.logs.error = null
Expand Down

0 comments on commit 396c30f

Please sign in to comment.