Skip to content

OCPBUGS-74346: Fix useOperatorCatalogCategories hook.#16093

Open
TheRealJon wants to merge 1 commit intoopenshift:mainfrom
TheRealJon:OCPBUGS-74346
Open

OCPBUGS-74346: Fix useOperatorCatalogCategories hook.#16093
TheRealJon wants to merge 1 commit intoopenshift:mainfrom
TheRealJon:OCPBUGS-74346

Conversation

@TheRealJon
Copy link
Member

@TheRealJon TheRealJon commented Mar 3, 2026

Make useOperatorCatalogCategories hook safe for PackageManifests that don't have annotations.

Summary by CodeRabbit

Bug Fixes

  • Fixed operator catalog category loading to gracefully handle missing or unavailable data, preventing potential application crashes and ensuring stable catalog browsing.

Make useOperatorCatalogCategories hook safe for PackageManifests that
don't have annotations.
@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Mar 3, 2026
@openshift-ci-robot
Copy link
Contributor

@TheRealJon: This pull request references Jira Issue OCPBUGS-74346, which is invalid:

  • expected the bug to target the "4.22.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Make useOperatorCatalogCategories hook safe for PackageManifests that don't have annotations.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested review from jhadvig and rhamilto March 3, 2026 14:39
@openshift-ci openshift-ci bot added component/olm Related to OLM approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 3, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

This change introduces defensive programming to the category derivation logic in the operator catalog categories hook. The modification adds optional chaining when accessing nested annotations properties on currentCSVDescription, preventing potential runtime errors when upstream data structures are undefined or malformed. The fallback to an empty array ensures graceful degradation of category rendering without cascading failures in the reduction pipeline. The change maintains backward compatibility while improving robustness of the CSV metadata extraction.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly references the bug fix (OCPBUGS-74346) and clearly describes the main change: fixing the useOperatorCatalogCategories hook for safe property access.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

Copy link
Contributor

@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.

🧹 Nitpick comments (1)
frontend/packages/operator-lifecycle-manager/src/hooks/useOperatorCatalogCategories.ts (1)

23-35: Consider filtering out empty/falsy categories early (pre-existing, optional follow-up).

Not blocking this PR, but I noticed the existing logic can produce null entries in the returned array when category strings are empty (e.g., trailing comma in annotations yields ''). The if (c) check returns null, which then gets spread into the accumulator. This could surprise downstream consumers expecting a clean CatalogCategory[].

A future cleanup could filter before mapping:

♻️ Optional: filter falsy values early
       const categories =
         currentCSVDescription?.annotations?.[OLMAnnotation.Categories]?.split(',') || [];
-      const catalogCategories = categories.map((c) => {
+      const catalogCategories = categories.filter(Boolean).map((c) => {
         const label = c.trim();
         const id = label.toLowerCase();
-        if (c) {
-          return {
-            id,
-            label,
-            tags: [id],
-          };
-        }
-        return null;
+        return {
+          id,
+          label,
+          tags: [id],
+        };
       });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@frontend/packages/operator-lifecycle-manager/src/hooks/useOperatorCatalogCategories.ts`
around lines 23 - 35, The mapping currently returns null for falsy/empty
category strings (in the catalogCategories creation), which leads to null
entries being merged into the accumulator; update the logic in
useOperatorCatalogCategories (the categories -> catalogCategories
transformation) to filter out falsy values before mapping (or filter out nulls
after mapping) so catalogCategories contains only valid objects, and then return
_.uniqBy([...acc, ...catalogCategories], 'id') as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@frontend/packages/operator-lifecycle-manager/src/hooks/useOperatorCatalogCategories.ts`:
- Around line 23-35: The mapping currently returns null for falsy/empty category
strings (in the catalogCategories creation), which leads to null entries being
merged into the accumulator; update the logic in useOperatorCatalogCategories
(the categories -> catalogCategories transformation) to filter out falsy values
before mapping (or filter out nulls after mapping) so catalogCategories contains
only valid objects, and then return _.uniqBy([...acc, ...catalogCategories],
'id') as before.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between f913459 and e11db4b.

📒 Files selected for processing (1)
  • frontend/packages/operator-lifecycle-manager/src/hooks/useOperatorCatalogCategories.ts

@TheRealJon
Copy link
Member Author

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Mar 3, 2026
@openshift-ci-robot
Copy link
Contributor

@TheRealJon: This pull request references Jira Issue OCPBUGS-74346, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.22.0) matches configured target version for branch (4.22.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @yapei

Details

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested a review from yapei March 3, 2026 14:52
@TheRealJon
Copy link
Member Author

/retest

Appears to be a flake

@TheRealJon
Copy link
Member Author

/cherry-pick release-4.21

@openshift-cherrypick-robot

@TheRealJon: once the present PR merges, I will cherry-pick it on top of release-4.21 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick release-4.21

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Member

@logonoff logonoff left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 4, 2026
Copy link
Member

@jhadvig jhadvig left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 4, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jhadvig, logonoff, TheRealJon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 4, 2026

@TheRealJon: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-gcp-console e11db4b link true /test e2e-gcp-console

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. component/olm Related to OLM jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants