From 0fdb470c86db706af2aaae4710eeaf2f8ede9eda Mon Sep 17 00:00:00 2001 From: Unperceivable Date: Thu, 2 Jan 2025 10:12:40 +0000 Subject: [PATCH] feat: use clusterScope to determine if workflow is a clusterWorkflow or not in setWorkflowFromReference Signed-off-by: Unperceivable --- .../components/editors/graph-viewer.tsx | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/ui/src/shared/components/editors/graph-viewer.tsx b/ui/src/shared/components/editors/graph-viewer.tsx index d6c7b085643d..5f4f363a3b0a 100644 --- a/ui/src/shared/components/editors/graph-viewer.tsx +++ b/ui/src/shared/components/editors/graph-viewer.tsx @@ -4,7 +4,7 @@ import {useEffect, useState} from 'react'; import {genres} from '../../../workflows/components/workflow-dag/genres'; import {WorkflowDagRenderOptions} from '../../../workflows/components/workflow-dag/workflow-dag'; import {WorkflowDagRenderOptionsPanel} from '../../../workflows/components/workflow-dag/workflow-dag-render-options-panel'; -import {ClusterWorkflowTemplate, CronWorkflow, DAGTask, Template, Workflow, WorkflowStep, WorkflowTemplate} from '../../models'; +import {ClusterWorkflowTemplate, CronWorkflow, DAGTask, Template, Workflow, WorkflowStep, WorkflowTemplate, WorkflowTemplateRef} from '../../models'; import {services} from '../../services'; import {GraphPanel} from '../graph/graph-panel'; import {Graph} from '../graph/types'; @@ -32,7 +32,7 @@ export function GraphViewer({workflowDefinition}: {workflowDefinition: Workflow useEffect(() => { if ('workflowTemplateRef' in workflowDefinition.spec && isLoading) { - setWorkflowFromRefrence(workflowDefinition.spec.workflowTemplateRef.name) + setWorkflowFromRefrence(workflowDefinition.spec.workflowTemplateRef) .then(() => { setError(null); setIsLoading(false); @@ -75,24 +75,31 @@ export function GraphViewer({workflowDefinition}: {workflowDefinition: Workflow /> ); - function setWorkflowFromRefrence(name: string): Promise { - return services.workflowTemplate - .get(name, workflowDefinition.metadata.namespace) - .then(workflowTemplate => { - setWorkflow(workflowTemplate); - }) - .catch(() => { - return services.clusterWorkflowTemplate - .get(name) - .then(clusterWorkflowTemplate => { - setWorkflow(clusterWorkflowTemplate); - }) - .catch(err => { - const explicitError = new Error(`${err.message}, no workflowTemplateRef "${name}" found in workflowTemplates or clusterWorkflowTemplates`); - explicitError.stack = err.stack; - throw explicitError; - }); - }); + function setWorkflowFromRefrence(workflowTemplateRef: WorkflowTemplateRef): Promise { + const referenceName = workflowTemplateRef.name; + if ('clusterScope' in workflowTemplateRef && workflowTemplateRef.clusterScope == true) { + return services.clusterWorkflowTemplate + .get(referenceName) + .then(clusterWorkflowTemplate => { + setWorkflow(clusterWorkflowTemplate); + }) + .catch(err => { + const explicitError = new Error(`${err.message}, no workflowTemplateRef "${referenceName}" found in clusterWorkflowTemplates`); + explicitError.stack = err.stack; + throw explicitError; + }); + } else { + return services.workflowTemplate + .get(referenceName, workflowDefinition.metadata.namespace) + .then(workflowTemplate => { + setWorkflow(workflowTemplate); + }) + .catch(err => { + const explicitError = new Error(`${err.message}, no workflowTemplateRef "${referenceName}" found in workflowTemplates`); + explicitError.stack = err.stack; + throw explicitError; + }); + } } function convertFromCronWorkflow(cronWorkflow: CronWorkflow): Workflow {