OCPBUGS-74346: Fix useOperatorCatalogCategories hook.#16093
OCPBUGS-74346: Fix useOperatorCatalogCategories hook.#16093TheRealJon wants to merge 1 commit intoopenshift:mainfrom
Conversation
Make useOperatorCatalogCategories hook safe for PackageManifests that don't have annotations.
|
@TheRealJon: This pull request references Jira Issue OCPBUGS-74346, which is invalid:
Comment The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
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. |
📝 WalkthroughWalkthroughThis change introduces defensive programming to the category derivation logic in the operator catalog categories hook. The modification adds optional chaining when accessing nested 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Comment |
There was a problem hiding this comment.
🧹 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
nullentries in the returned array when category strings are empty (e.g., trailing comma in annotations yields''). Theif (c)check returnsnull, which then gets spread into the accumulator. This could surprise downstream consumers expecting a cleanCatalogCategory[].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
📒 Files selected for processing (1)
frontend/packages/operator-lifecycle-manager/src/hooks/useOperatorCatalogCategories.ts
|
/jira refresh |
|
@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
Requesting review from QA contact: DetailsIn response to this:
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. |
|
/retest Appears to be a flake |
|
/cherry-pick release-4.21 |
|
@TheRealJon: once the present PR merges, I will cherry-pick it on top of DetailsIn response to this:
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. |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@TheRealJon: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
Make useOperatorCatalogCategories hook safe for PackageManifests that don't have annotations.
Summary by CodeRabbit
Bug Fixes