Skip to content

fix: workflowruns view, trigger, logs view when using clusterworkflows#392

Open
akila-i wants to merge 5 commits intoopenchoreo:mainfrom
akila-i:cluster-workflow-fix
Open

fix: workflowruns view, trigger, logs view when using clusterworkflows#392
akila-i wants to merge 5 commits intoopenchoreo:mainfrom
akila-i:cluster-workflow-fix

Conversation

@akila-i
Copy link
Contributor

@akila-i akila-i commented Mar 13, 2026

Purpose

Related: openchoreo/openchoreo#2562
This pull request introduces significant enhancements to support cluster-scoped workflows (ClusterWorkflows) in the OpenChoreo workflows UI and backend. The changes enable users to view, trigger, and manage runs for both namespace-scoped and cluster-scoped workflows, add support for selecting namespaces, and improve the display and handling of workflow metadata throughout the stack.

Backend API and Service Enhancements:

  • Added backend endpoints and service methods to fetch cluster workflow parameter schemas and list OpenChoreo namespaces, supporting namespace selection and cluster workflow operations. [1] [2] [3]
  • Improved logging and logic in GenericWorkflowService to distinguish between cluster and namespace-scoped workflows when creating runs. [1] [2] [3]

Client API Updates:

  • Extended the client API to support listing namespaces and fetching cluster workflow schemas, and updated the workflow run creation method to accept a workflow kind. [1] [2] [3] [4] [5]

UI/UX Improvements for ClusterWorkflows:

  • Added a new "Runs" tab for Generic entities, and improved the EntityNamespaceProvider to correctly resolve the namespace for cluster-scoped entities, defaulting to "default" if not specified. [1] [2]
  • Enhanced the workflow run trigger form and workflow runs content to support namespace selection and workflow kind, including a namespace selector UI and correct schema loading for both workflow types. [1] [2] [3] [4] [5] [6]

Workflow Metadata Display:

  • Improved the display of workflow options in the picker by showing descriptions and handling display names/metadata more robustly. [1] [2] [3] [4]

Workflow Run Details Consistency:

  • Ensured that workflow run logs and event components receive the correct namespace, improving reliability for cluster-scoped runs. [1] [2] [3]

These changes collectively enable robust support for both namespace and cluster-scoped workflows, improve user experience, and lay the groundwork for further extensibility in workflow management.

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

  • Refactored workflow type handling: Replaced isClusterScoped with workflowKind parameter to better differentiate between Workflow and ClusterWorkflow types across the API and components
  • Namespace selection: Added namespace selector for ClusterWorkflow entities and namespace parameters to workflow run components for improved cluster-scoped workflow management
  • Enhanced workflow run creation: Updated API and backend to support cluster-scoped workflow run creation with proper type resolution
  • Improved UI/UX:
    • Added workflow descriptions to BuildWorkflowPicker component
    • Enhanced WorkflowRunsContent to handle both namespace-scoped and cluster-scoped workflows
  • Hooks updates: Added useNamespaces hook and enhanced existing hooks (useWorkflowRunDetails, useWorkflowSchema, useWorkflowRuns) to support namespace-aware operations

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added support for cluster-scoped workflows alongside namespace-scoped workflows
    • Workflow descriptions now display in the build workflow picker
    • Added namespace selector for managing cluster workflow runs
    • Expanded "Runs" tab to include cluster workflow entities with namespace context
    • Improved workflow run details display with proper namespace handling

akila-i added 5 commits March 13, 2026 05:33
- Added a description field to the WorkflowOption interface for improved clarity.
- Updated the BuildWorkflowPicker component to render workflow descriptions below their names, enhancing user experience.
- Utilized Material-UI's Box and Typography components for better layout and styling of workflow options.

Signed-off-by: Akila-I <akila.99g@gmail.com>
- Introduced a new route for displaying workflow runs specific to cluster-scoped workflows.
- Implemented a namespace selector for ClusterWorkflow entities, allowing users to choose the appropriate OpenChoreo namespace for querying WorkflowRun CRs.
- Added hooks to fetch OpenChoreo namespaces and updated existing hooks to support namespace selection for workflow runs.
- Enhanced the WorkflowRunsContent component to handle both namespace-scoped and cluster-scoped workflows, improving user experience and functionality.

Signed-off-by: Akila-I <akila.99g@gmail.com>
- Added `isClusterScoped` parameter to the workflow run creation API, allowing users to specify if the workflow is a cluster-scoped `ClusterWorkflow`.
- Updated the `GenericWorkflowsClient` and backend router to handle the new parameter, ensuring correct workflow type resolution.
- Enhanced the `TriggerForm` component to set the workflow kind based on the `isClusterScoped` flag, improving user experience and functionality.

Signed-off-by: Akila-I <akila.99g@gmail.com>
- Added `namespaceName` prop to `WorkflowRunStepLogs`, `WorkflowRunEvents`, and `RunDetailView` components, allowing explicit namespace overrides for better handling of cluster-scoped workflows.
- Updated hooks and components to utilize the resolved namespace, improving the fetching of workflow run details and logs.
- Enhanced tests to ensure proper functionality with the new namespace handling.

This update improves user experience by providing clearer context for workflow runs across different namespaces.

Signed-off-by: Akila-I <akila.99g@gmail.com>
- Replaced `isClusterScoped` with `workflowKind` in the API and components to better differentiate between `Workflow` and `ClusterWorkflow`.
- Updated `GenericWorkflowsClient`, `GenericWorkflowsClientApi`, and related components to utilize the new `workflowKind` parameter for improved clarity and functionality.
- Enhanced the `TriggerForm` and `useWorkflowSchema` hooks to accommodate the new parameter, ensuring correct schema fetching based on workflow type.
- Adjusted backend service logic to handle the `workflowKind` parameter for creating workflow runs.

This change streamlines the workflow handling process and improves the overall codebase consistency.

Signed-off-by: Akila-I <akila.99g@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

This pull request introduces cluster-scoped workflow support (ClusterWorkflow) throughout the OpenChoreo plugin stack. Changes include new backend API endpoints for fetching cluster workflow schemas and listing namespaces, frontend components that display a namespace selector for ClusterWorkflow entities, updated hooks that accept explicit namespace parameters with fallback to context, and modifications to thread workflowKind and namespace information through the workflow runs UI pipeline.

Changes

Cohort / File(s) Summary
Cluster Workflow Routing
packages/app/src/components/catalog/EntityPage.tsx
Added "/runs" route to clusterWorkflowPage gated by Generic-type entity check, mirroring existing runs route pattern with WorkflowRunsContent wrapped in EntityNamespaceProvider.
Workflow Description Display
packages/app/src/scaffolder/BuildWorkflowPicker/BuildWorkflowPickerExtension.tsx
Extended WorkflowOption interface with optional description field; updated normalizeWorkflowItem to extract descriptions from metadata; enhanced UI to render two-line workflow items with name and description using Box and Typography components.
Backend API & Schema
plugins/openchoreo-workflows-backend/src/router.ts, plugins/openchoreo-workflows-backend/src/services/GenericWorkflowService.ts
Added GET endpoints for cluster workflow schema and namespace listing; introduced getClusterWorkflowSchema and listNamespaces service methods; updated log messages to distinguish between cluster and namespace-scoped workflows.
Client API Layer
plugins/openchoreo-workflows/src/api/GenericWorkflowsClient.ts, plugins/openchoreo-workflows/src/api/GenericWorkflowsClientApi.ts
Extended client interfaces and implementations with listNamespaces and getClusterWorkflowSchema methods; added optional workflowKind parameter to createWorkflowRun; updated listWorkflowRuns signature to accept optional workflowName.
Namespace Resolution & Context
plugins/openchoreo-workflows/src/components/EntityNamespaceProvider/EntityNamespaceProvider.tsx
Enhanced EntityNamespaceProvider to compute namespace with priority order: explicit annotation, cluster-scoped fallback to "default", entity metadata namespace, or empty string fallback.
Namespace Fetching Hook
plugins/openchoreo-workflows/src/hooks/useNamespaces.ts, plugins/openchoreo-workflows/src/hooks/index.ts
Introduced new useNamespaces hook that fetches and manages OpenChoreo namespaces list with loading and error states; exported hook from hooks index.
Workflow Schema & Kind Branching
plugins/openchoreo-workflows/src/hooks/useWorkflowSchema.ts
Updated useWorkflowSchema to accept workflowKind parameter and branch API calls: calls getClusterWorkflowSchema for ClusterWorkflow, otherwise calls getWorkflowSchema for namespace-scoped workflows.
Run Details & Logs with Retry Logic
plugins/openchoreo-workflows/src/hooks/useWorkflowRunDetails.ts, plugins/openchoreo-workflows/src/hooks/useWorkflowRunLogs.ts
Added optional namespaceName parameter to both hooks; implemented namespace resolution with context fallback; added NotFoundError retry logic (up to 5 retries, 2-second intervals) in useWorkflowRunDetails to handle delayed run availability.
Workflow Runs Listing & Filtering
plugins/openchoreo-workflows/src/hooks/useWorkflowRuns.ts
Extended useWorkflowRuns to accept optional namespaceName parameter; implemented namespace resolution mechanism that prefers explicit parameter over context; guards against missing namespace.
Run Details Page & Event Components
plugins/openchoreo-workflows/src/components/WorkflowRunDetailsPage/WorkflowRunDetailsPage.tsx, plugins/openchoreo-workflows/src/components/WorkflowRunEvents/WorkflowRunEvents.tsx, plugins/openchoreo-workflows/src/components/WorkflowRunStepLogs/WorkflowRunStepLogs.tsx
Updated components to accept and propagate optional namespaceName prop; implemented namespace resolution with context fallback to enable scoped data fetching.
Runs UI with Namespace Selector
plugins/openchoreo-workflows/src/components/WorkflowRunsContent/WorkflowRunsContent.tsx
Added namespace selector UI (rendered only for ClusterWorkflow entities); propagates workflowKind and namespaceName through TriggerForm and RunDetailView; populates namespace dropdown via useNamespaces; passes namespace context to schema and run management operations.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant Frontend as Frontend (WorkflowRunsContent)
    participant Hook as useWorkflowSchema Hook
    participant Client as GenericWorkflowsClient
    participant API as Backend API
    participant Service as GenericWorkflowService
    
    User->>Frontend: Select ClusterWorkflow entity
    Frontend->>Frontend: Initialize workflowKind = 'ClusterWorkflow'
    
    Frontend->>Hook: Call useWorkflowSchema(workflowName, 'ClusterWorkflow')
    activate Hook
    Hook->>Hook: Branch: workflowKind === 'ClusterWorkflow'
    Hook->>Client: Call getClusterWorkflowSchema(workflowName)
    deactivate Hook
    
    activate Client
    Client->>API: GET /cluster-workflows/{name}/schema
    deactivate Client
    
    activate API
    API->>Service: Call getClusterWorkflowSchema(name, userToken)
    deactivate API
    
    activate Service
    Service->>Service: Fetch cluster workflow schema via OpenChoreo API
    Service-->>API: Return schema JSON
    deactivate Service
    
    API-->>Client: Return 200 with schema
    Client-->>Hook: Return schema object
    Hook-->>Frontend: Update schema state
    
    Frontend->>Frontend: Render form with cluster workflow schema
    User->>Frontend: Submit workflow parameters
    
    Frontend->>Client: Call createWorkflowRun(namespace, name, params, 'ClusterWorkflow')
    Client->>API: POST /runs with workflowKind
    API->>Service: Create run with kind parameter
    Service-->>API: Return created WorkflowRun
    API-->>Client: Return 201
    Client-->>Frontend: Return run object
    Frontend->>Frontend: Display run in list
Loading
sequenceDiagram
    participant User as User
    participant Frontend as Frontend (WorkflowRunsContent)
    participant NamespaceHook as useNamespaces Hook
    participant RunDetailsHook as useWorkflowRunDetails Hook
    participant Client as GenericWorkflowsClient
    participant API as Backend API
    participant Service as GenericWorkflowService
    
    User->>Frontend: View ClusterWorkflow runs
    Frontend->>NamespaceHook: Call useNamespaces()
    activate NamespaceHook
    NamespaceHook->>Client: Call listNamespaces()
    deactivate NamespaceHook
    
    activate Client
    Client->>API: GET /namespaces
    deactivate Client
    
    activate API
    API->>Service: Call listNamespaces(userToken)
    deactivate API
    
    activate Service
    Service->>Service: Fetch available namespaces from OpenChoreo
    Service-->>API: Return namespace list
    deactivate Service
    
    API-->>Client: Return 200 with namespaces
    Client-->>NamespaceHook: Return string[]
    NamespaceHook-->>Frontend: Update namespaces state
    
    Frontend->>Frontend: Render namespace selector dropdown
    User->>Frontend: Select namespace from dropdown
    Frontend->>Frontend: Update runsNamespace = selectedNamespace
    
    Frontend->>RunDetailsHook: Call useWorkflowRunDetails(runName, runsNamespace)
    activate RunDetailsHook
    RunDetailsHook->>RunDetailsHook: Resolve namespace: runsNamespace ?? contextNamespace
    RunDetailsHook->>Client: Fetch run details with namespace
    Note over RunDetailsHook: Retry up to 5 times on NotFoundError (2s interval)
    deactivate RunDetailsHook
    
    Client-->>Frontend: Return run details
    Frontend->>Frontend: Display run details scoped to selected namespace
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • sameerajayasoma
  • jhivandb

🐰 A cluster of workflows blooms bright,
With namespaces dancing in the light,
Schemas branching, runs retry with care,
Cluster-scoped magic floating through the air!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes a detailed Purpose section linking to related issues and covering backend API enhancements, client API updates, UI/UX improvements, and workflow metadata display. However, several required sections are missing or incomplete: Goals, User stories, Release note, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Related PRs, Migrations, Test environment, and Learning sections are either blank or contain only placeholder text. Complete the missing sections in the PR description according to the template, particularly Goals, User stories, Release note, Documentation, Automation tests, Security checks, and Test environment details.
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: workflowruns view, trigger, logs view when using clusterworkflows' accurately describes the main changes in the pull request, which focus on enabling workflow runs view, triggering, and logs functionality for cluster-scoped workflows.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/app/src/scaffolder/BuildWorkflowPicker/BuildWorkflowPickerExtension.tsx (1)

290-300: Consider truncating long descriptions to prevent dropdown overflow.

The description display works correctly, but very long descriptions could cause the dropdown menu to overflow horizontally. Consider applying text truncation for better UX.

💡 Optional: Add text truncation with ellipsis
               {workflow.description && (
-                  <Typography variant="body2" color="textSecondary">
+                  <Typography
+                    variant="body2"
+                    color="textSecondary"
+                    style={{
+                      overflow: 'hidden',
+                      textOverflow: 'ellipsis',
+                      whiteSpace: 'nowrap',
+                      maxWidth: 300,
+                    }}
+                    title={workflow.description}
+                  >
                     {workflow.description}
                   </Typography>
                 )}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/app/src/scaffolder/BuildWorkflowPicker/BuildWorkflowPickerExtension.tsx`
around lines 290 - 300, The workflow description can grow very long and cause
the dropdown to overflow; update the rendering inside
BuildWorkflowPickerExtension.tsx by applying CSS truncation to the description
Typography (the element that renders workflow.description) — add styles like
overflow: hidden, textOverflow: ellipsis, whiteSpace: nowrap and a sensible
maxWidth or allow flexShrink so long descriptions are truncated with an ellipsis
instead of expanding the MenuItem; keep getWorkflowDisplayName and the title
Typography unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@plugins/openchoreo-workflows-backend/src/services/GenericWorkflowService.ts`:
- Around line 223-230: The client.GET call for the
'/api/v1/clusterworkflows/{clusterWorkflowName}/schema' endpoint in
GenericWorkflowService contains unnecessary "as any" casts that weaken type
safety; remove the "as any" casts around the path string and the options object
so the generated client types are used (locate the client.GET invocation in
GenericWorkflowService, referencing the
'/api/v1/clusterworkflows/{clusterWorkflowName}/schema' call and its params
object) and ensure the call matches the pattern used by other endpoints like
'/api/v1/namespaces/{namespaceName}/workflows/{workflowName}/schema'.

In
`@plugins/openchoreo-workflows/src/components/WorkflowRunsContent/WorkflowRunsContent.tsx`:
- Around line 748-759: The component currently calls setSelectedNamespace and
setNamespaceInitialised directly in the render body when workflowKind ===
'ClusterWorkflow' and namespaces are ready; move this logic into a useEffect to
avoid state updates during render. Create a useEffect that depends on
workflowKind, namespacesLoading, namespaces, and namespaceInitialised, and
inside the effect check the same conditions (workflowKind === 'ClusterWorkflow'
&& !namespacesLoading && namespaces.length > 0 && !namespaceInitialised),
compute the preferred namespace (prefer 'default' or namespaces[0]) and call
setSelectedNamespace(preferred) and setNamespaceInitialised(true) from within
the effect.

---

Nitpick comments:
In
`@packages/app/src/scaffolder/BuildWorkflowPicker/BuildWorkflowPickerExtension.tsx`:
- Around line 290-300: The workflow description can grow very long and cause the
dropdown to overflow; update the rendering inside
BuildWorkflowPickerExtension.tsx by applying CSS truncation to the description
Typography (the element that renders workflow.description) — add styles like
overflow: hidden, textOverflow: ellipsis, whiteSpace: nowrap and a sensible
maxWidth or allow flexShrink so long descriptions are truncated with an ellipsis
instead of expanding the MenuItem; keep getWorkflowDisplayName and the title
Typography unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c5f3ccc0-d3c7-485a-894f-3c4d30ac77a5

📥 Commits

Reviewing files that changed from the base of the PR and between cfb14fa and 0a54507.

📒 Files selected for processing (17)
  • packages/app/src/components/catalog/EntityPage.tsx
  • packages/app/src/scaffolder/BuildWorkflowPicker/BuildWorkflowPickerExtension.tsx
  • plugins/openchoreo-workflows-backend/src/router.ts
  • plugins/openchoreo-workflows-backend/src/services/GenericWorkflowService.ts
  • plugins/openchoreo-workflows/src/api/GenericWorkflowsClient.ts
  • plugins/openchoreo-workflows/src/api/GenericWorkflowsClientApi.ts
  • plugins/openchoreo-workflows/src/components/EntityNamespaceProvider/EntityNamespaceProvider.tsx
  • plugins/openchoreo-workflows/src/components/WorkflowRunDetailsPage/WorkflowRunDetailsPage.tsx
  • plugins/openchoreo-workflows/src/components/WorkflowRunEvents/WorkflowRunEvents.tsx
  • plugins/openchoreo-workflows/src/components/WorkflowRunStepLogs/WorkflowRunStepLogs.tsx
  • plugins/openchoreo-workflows/src/components/WorkflowRunsContent/WorkflowRunsContent.tsx
  • plugins/openchoreo-workflows/src/hooks/index.ts
  • plugins/openchoreo-workflows/src/hooks/useNamespaces.ts
  • plugins/openchoreo-workflows/src/hooks/useWorkflowRunDetails.ts
  • plugins/openchoreo-workflows/src/hooks/useWorkflowRunLogs.ts
  • plugins/openchoreo-workflows/src/hooks/useWorkflowRuns.ts
  • plugins/openchoreo-workflows/src/hooks/useWorkflowSchema.ts

Comment on lines +223 to +230
const { data, error, response } = await client.GET(
'/api/v1/clusterworkflows/{clusterWorkflowName}/schema' as any,
{
params: {
path: { clusterWorkflowName },
},
} as any,
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if the clusterworkflows endpoint is defined in the OpenAPI spec
fd -e yaml -e json 'openchoreo-api' --exec grep -l 'clusterworkflows' {} \;

Repository: openchoreo/backstage-plugins

Length of output: 133


🏁 Script executed:

cat -n packages/openchoreo-client-node/openapi/openchoreo-api.yaml | grep -A 20 "clusterworkflows.*schema"

Repository: openchoreo/backstage-plugins

Length of output: 985


🏁 Script executed:

# Check the structure of the endpoint definition
grep -B 5 -A 15 "/clusterworkflows/{clusterWorkflowName}/schema" packages/openchoreo-client-node/openapi/openchoreo-api.yaml

Repository: openchoreo/backstage-plugins

Length of output: 789


🏁 Script executed:

# Also check if there are other similar as any casts in the same file
rg "as any" plugins/openchoreo-workflows-backend/src/services/GenericWorkflowService.ts -B 2 -A 2

Repository: openchoreo/backstage-plugins

Length of output: 1927


🏁 Script executed:

# Check if there's a generated types file for the client
find packages/openchoreo-client-node -name "*.ts" -o -name "*.d.ts" | grep -E "(types|client|schema)" | head -20

Repository: openchoreo/backstage-plugins

Length of output: 1287


🏁 Script executed:

# Look for generated index or types that would export the operations
rg "getClusterWorkflowSchema" packages/openchoreo-client-node --type typescript --type json

Repository: openchoreo/backstage-plugins

Length of output: 106


🏁 Script executed:

# Search for getClusterWorkflowSchema in the generated client files
rg "getClusterWorkflowSchema" packages/openchoreo-client-node/src/generated/

Repository: openchoreo/backstage-plugins

Length of output: 282


🏁 Script executed:

# Check the structure of the generated openchoreo client index
head -100 packages/openchoreo-client-node/src/generated/openchoreo/index.ts

Repository: openchoreo/backstage-plugins

Length of output: 204


🏁 Script executed:

# Check if ClusterWorkflowNameParam is properly typed in the generated types
rg "ClusterWorkflowNameParam" packages/openchoreo-client-node/src/generated/

Repository: openchoreo/backstage-plugins

Length of output: 771


🏁 Script executed:

# Check the full definition of getClusterWorkflowSchema in the generated types
rg "getClusterWorkflowSchema" -A 20 packages/openchoreo-client-node/src/generated/openchoreo/types.ts

Repository: openchoreo/backstage-plugins

Length of output: 1137


🏁 Script executed:

# Check the client.GET method signature to understand what it expects
rg "GET\(" packages/openchoreo-client-node/src/generated/openchoreo/index.ts -B 2 -A 5

Repository: openchoreo/backstage-plugins

Length of output: 54


🏁 Script executed:

# Look at how other similar endpoints are called in GenericWorkflowService to compare
rg "client.GET" plugins/openchoreo-workflows-backend/src/services/GenericWorkflowService.ts -B 1 -A 5 | head -50

Repository: openchoreo/backstage-plugins

Length of output: 1471


Remove unnecessary as any type assertions—the endpoint is properly typed in the generated client.

The /api/v1/clusterworkflows/{clusterWorkflowName}/schema endpoint is defined in the OpenAPI spec and fully generated in the client types. The as any casts on lines 224 and 229 are unnecessary and bypass type safety. Other similar endpoints in this file (e.g., /api/v1/namespaces/{namespaceName}/workflows/{workflowName}/schema) call client.GET without these casts. Remove the as any assertions and rely on the proper types.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugins/openchoreo-workflows-backend/src/services/GenericWorkflowService.ts`
around lines 223 - 230, The client.GET call for the
'/api/v1/clusterworkflows/{clusterWorkflowName}/schema' endpoint in
GenericWorkflowService contains unnecessary "as any" casts that weaken type
safety; remove the "as any" casts around the path string and the options object
so the generated client types are used (locate the client.GET invocation in
GenericWorkflowService, referencing the
'/api/v1/clusterworkflows/{clusterWorkflowName}/schema' call and its params
object) and ensure the call matches the pattern used by other endpoints like
'/api/v1/namespaces/{namespaceName}/workflows/{workflowName}/schema'.

Comment on lines +748 to +759
if (
workflowKind === 'ClusterWorkflow' &&
!namespacesLoading &&
namespaces.length > 0 &&
!namespaceInitialised
) {
const preferred = namespaces.includes('default')
? 'default'
: namespaces[0];
setSelectedNamespace(preferred);
setNamespaceInitialised(true);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Avoid setting state directly in the render body; use useEffect instead.

Setting setSelectedNamespace and setNamespaceInitialised inside the component body (outside hooks/handlers) can cause unexpected behavior and violates React's rendering model. While the namespaceInitialised flag prevents infinite loops, this pattern is fragile and harder to reason about.

♻️ Proposed refactor to useEffect
-  const [namespaceInitialised, setNamespaceInitialised] = useState(false);
-  if (
-    workflowKind === 'ClusterWorkflow' &&
-    !namespacesLoading &&
-    namespaces.length > 0 &&
-    !namespaceInitialised
-  ) {
-    const preferred = namespaces.includes('default')
-      ? 'default'
-      : namespaces[0];
-    setSelectedNamespace(preferred);
-    setNamespaceInitialised(true);
-  }
+  useEffect(() => {
+    if (
+      workflowKind === 'ClusterWorkflow' &&
+      !namespacesLoading &&
+      namespaces.length > 0
+    ) {
+      const preferred = namespaces.includes('default')
+        ? 'default'
+        : namespaces[0];
+      setSelectedNamespace(preferred);
+    }
+  }, [workflowKind, namespacesLoading, namespaces]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@plugins/openchoreo-workflows/src/components/WorkflowRunsContent/WorkflowRunsContent.tsx`
around lines 748 - 759, The component currently calls setSelectedNamespace and
setNamespaceInitialised directly in the render body when workflowKind ===
'ClusterWorkflow' and namespaces are ready; move this logic into a useEffect to
avoid state updates during render. Create a useEffect that depends on
workflowKind, namespacesLoading, namespaces, and namespaceInitialised, and
inside the effect check the same conditions (workflowKind === 'ClusterWorkflow'
&& !namespacesLoading && namespaces.length > 0 && !namespaceInitialised),
compute the preferred namespace (prefer 'default' or namespaces[0]) and call
setSelectedNamespace(preferred) and setNamespaceInitialised(true) from within
the effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant