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 [Workflow] Error on attempt to select deploy step 1.3.x #1759

Draft
wants to merge 1 commit into
base: 1.3.x
Choose a base branch
from
Draft
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
14 changes: 8 additions & 6 deletions src/components/Workflow/Workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const Workflow = ({
forEach(workflow.graph, job => {
const sourceHandle = getWorkflowSourceHandle(job.phase)

if (hiddenWorkflowStepTypes.includes(job.type)) return
if (hiddenWorkflowStepTypes.includes(job.type) && !job.ui?.isHiddenJobVisible) return

const customData = {
function: job.function,
Expand All @@ -123,11 +123,11 @@ const Workflow = ({
}

if (job.function) {
const [, , functionName = '', functionHash = ''] =
job.function?.match(/(.+)\/([^@]+)(?:@(.+))?/) ?? []
const [, , functionName = '', functionHash = '', functionTag = ''] =
job.function?.match(/^([\w.-]+)\/([\w.-]+)(?:@(\w+))?(?::(\w+))?$/) ?? []

customData.functionName = functionName
customData.functionHash = functionHash
customData.functionHash = functionHash ?? functionTag
}

let nodeItem = {
Expand Down Expand Up @@ -173,8 +173,10 @@ const Workflow = ({
nodes.push(nodeItem)
})

setElements(getLayoutedElements(nodes.concat(edges)))
setJobsContent(jobs)
if (!isEmpty(nodes)) {
setElements(getLayoutedElements(nodes.concat(edges)))
setJobsContent(jobs)
}
}, [selectedFunction.hash, selectedFunction.name, selectedJob.uid, workflow.graph])

const onElementClick = (event, element) => {
Expand Down
34 changes: 31 additions & 3 deletions src/components/Workflow/workflow.util.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 { cloneDeep, forEach, isEmpty } from 'lodash'
import { cloneDeep, forEach, isEmpty, set } from 'lodash'

import { page } from '../Jobs/jobs.util'
import { DETAILS_OVERVIEW_TAB, WORKFLOW_TYPE_SKIPPED } from '../../constants'
Expand Down Expand Up @@ -77,8 +77,8 @@ const isFunctionTypeSelectable = (job = {}) => {
export const isWorkflowJobSelected = (job, selectedJob) => {
return (
(job.run_uid && selectedJob.uid === job.run_uid) ||
(job.run_type === 'deploy' && job.function.includes(selectedJob.hash)) ||
(job.run_type === 'build' && job.function.includes(selectedJob.name))
((job.run_type === 'deploy' || job.run_type === 'build') &&
(job.function.includes(selectedJob.hash) || job.function.includes(selectedJob.name)))
)
}

Expand All @@ -102,6 +102,31 @@ export const isWorkflowStepExecutable = job => {
* @returns {Object} The parsed workflow.
*/
export const parseWorkflow = workflow => {
/**
* Sets the visibility of hidden jobs that have ancestor with type `TaskGroup`.
* @param {Object} job - The job to process.
* @param {boolean} ancestorIsTaskGroup - Indicates if the current job's ancestor is a task group.
*/
const setHiddenJobVisibility = (job, ancestorIsTaskGroup) => {
if (job.type === 'TaskGroup' && !ancestorIsTaskGroup) {
setHiddenJobVisibility(job, true)
}

job.children?.forEach(jobChildId => {
let jobChild = newWorkflow.graph[jobChildId]

// Check if the jobChild's type is in the hiddenWorkflowStepTypes and the ancestor is a `TaskGroup`
if (hiddenWorkflowStepTypes.includes(jobChild.type) && ancestorIsTaskGroup) {
set(jobChild, 'ui.isHiddenJobVisible', true)
}

// Recursively call setHiddenJobVisibility for the jobChild if it's a TaskGroup or the ancestor is a task group
if (jobChild.type === 'TaskGroup' || ancestorIsTaskGroup) {
setHiddenJobVisibility(jobChild, true)
}
})
}

const newWorkflow = cloneDeep(workflow)
const parentsMap = {}

Expand All @@ -116,6 +141,9 @@ export const parseWorkflow = workflow => {
parentsMap[childId] = [workflowStep.id]
}
})

// Define if hidden jobs should be visible
setHiddenJobVisibility(workflowStep)
})

// Loop through each Retry node in the graph and modify the parent-child relationships
Expand Down