Skip to content

OU-1384: Remove some of the set-state-in-effect overrides#1006

Open
PeterYurkovich wants to merge 1 commit into
openshift:mainfrom
PeterYurkovich:ou-1384-set-state-in-effect
Open

OU-1384: Remove some of the set-state-in-effect overrides#1006
PeterYurkovich wants to merge 1 commit into
openshift:mainfrom
PeterYurkovich:ou-1384-set-state-in-effect

Conversation

@PeterYurkovich

@PeterYurkovich PeterYurkovich commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

These lint rule updates provide refactors of react code to remove the set-state-in-effect overrides. You can read more about this rule here: https://react.dev/reference/eslint-plugin-react-hooks/lints/set-state-in-effect

These fixes were done by eliminating excess state tracking and returning values directly from useMemo's rather than triggering useEffects off of changes to the useMemo value

Summary by CodeRabbit

  • Refactor
    • Enhanced chart sizing calculations in AlertsChart and IncidentsChart components for improved performance and consistency.
    • Optimized suggestion computation in the autocomplete component for better efficiency.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 16, 2026
@openshift-ci-robot

openshift-ci-robot commented Jun 16, 2026

Copy link
Copy Markdown

@PeterYurkovich: This pull request references OU-1384 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

These lint rule updates provide refactors of react code to remove the set-state-in-effect overrides. You can read more about this rule here: https://react.dev/reference/eslint-plugin-react-hooks/lints/set-state-in-effect

These fixes were done by eliminating excess state tracking and returning values directly from useMemo's rather than triggering useEffects off of changes to the useMemo value

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 etmurasaki and jgbernalp June 16, 2026 11:22
@openshift-ci

openshift-ci Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: PeterYurkovich

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 openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 16, 2026
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Walkthrough

Three components replace useState/useEffect patterns for derived state with useMemo. AlertsChart exports two default height constants and computes chart data and container/chart heights in one memo. IncidentsChart imports those constants and applies the same consolidation. autocomplete.tsx derives the filtered suggestions list via useMemo instead of effect-driven state updates.

Changes

Chart Height Computation Refactor

Layer / File(s) Summary
AlertsChart constants and unified sizing memo
web/src/components/Incidents/AlertsChart/AlertsChart.tsx
Exports DEFAULT_CHART_CONTAINER_HEIGHT = 300 and DEFAULT_CHART_HEIGHT = 250, merges chartData derivation and dynamic height computation into one useMemo, and removes @ts-ignore comments around the resize observer call.
IncidentsChart unified sizing memo using shared constants
web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx
Imports the new height constants from AlertsChart, replaces separate useState/useEffect height tracking with a single useMemo that returns chartData, chartContainerHeight, and chartHeight together, with an early return to defaults when incidentsData is absent or empty.

Autocomplete Suggestions Refactor

Layer / File(s) Summary
Autocomplete suggestions derived via useMemo
web/src/components/console/public/components/autocomplete.tsx
Removes useState/useEffect imports and the suggestions state variable; replaces the effect-based filtering with a useMemo that applies fuzzy filtering and suggestionCount slicing directly from render-time inputs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactoring work: removing set-state-in-effect linting rule overrides by consolidating state management into useMemo hooks across multiple components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed The PR contains only React component files (AlertsChart.tsx, IncidentsChart.tsx, autocomplete.tsx). The custom check for Ginkgo test name stability is not applicable to this PR as no Ginkgo tests a...
Test Structure And Quality ✅ Passed PR contains no Ginkgo test code changes. Custom check is inapplicable to React component refactoring PR focusing on React hooks patterns.
Microshift Test Compatibility ✅ Passed No Ginkgo e2e tests are added in this PR. All changes are TypeScript/React component refactoring; the check is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests added in this PR. Changes are React component refactoring (.tsx files) only, not e2e test additions. SNO compatibility check is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only React frontend components for hook refactoring; no deployment manifests, operators, or scheduling constraints are added/modified, so the topology-aware scheduling check is not appl...
Ote Binary Stdout Contract ✅ Passed OTE Binary Stdout Contract check is not applicable: PR modifies React/TypeScript web components and plugin backend (non-test code), which fall outside the scope of test binary stdout contract enfor...
Ipv6 And Disconnected Network Test Compatibility ✅ Passed This PR only modifies React/TypeScript components (AlertsChart.tsx, IncidentsChart.tsx, autocomplete.tsx) and does not add any Ginkgo e2e tests. The custom check for IPv6 and disconnected network c...
No-Weak-Crypto ✅ Passed The PR modifies only UI/React chart components (AlertsChart, IncidentsChart, autocomplete) with no cryptographic code, weak crypto algorithms, or security-sensitive comparisons.
Container-Privileges ✅ Passed PR contains no privileged container settings (privileged:true, hostPID, hostNetwork, hostIPC, SYS_ADMIN, allowPrivilegeEscalation:true). Container configs follow security best practices with allowP...
No-Sensitive-Data-In-Logs ✅ Passed No logging of sensitive data found. All three modified files contain only React state refactoring with useMemo, with no console logging, JSON.stringify, or sensitive data exposure.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
web/src/components/console/public/components/autocomplete.tsx (1)

151-151: ⚡ Quick win

Use a named export for AutocompleteInput (Line 151).

Please replace the default export with a named export to match the repository TSX component convention.

Suggested diff
-const AutocompleteInput: FC<AutocompleteInputProps> = (props) => {
+export const AutocompleteInput: FC<AutocompleteInputProps> = (props) => {
   ...
 };
-
-export default AutocompleteInput;

As per coding guidelines, “Always use named exports for React components instead of default exports.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/components/console/public/components/autocomplete.tsx` at line 151,
The AutocompleteInput component is currently exported as a default export on
line 151. Replace the default export statement with a named export to align with
the repository's TSX component convention. Change the export statement from
`export default AutocompleteInput;` to a named export format `export {
AutocompleteInput };`. Additionally, update all import statements throughout the
codebase that currently import AutocompleteInput as a default import to use the
named import syntax instead.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/src/components/Incidents/AlertsChart/AlertsChart.tsx`:
- Line 48: Both chart components violate the TSX component contract by using
inline prop typing and default exports. Fix both files to follow the consistent
pattern: (1) In web/src/components/Incidents/AlertsChart/AlertsChart.tsx at line
48, replace the inline props destructuring { theme: 'light' | 'dark' } with a
named AlertsChartProps type and declare the component as const AlertsChart:
FC<AlertsChartProps>; then at line 280, replace the default export with a named
export. (2) In web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx at
lines 59-75, replace the inline props typing with a named IncidentsChartProps
type and declare the component as const IncidentsChart: FC<IncidentsChartProps>;
then at line 299, replace the default export (including the memo wrapper) with a
named export form using memo.

---

Nitpick comments:
In `@web/src/components/console/public/components/autocomplete.tsx`:
- Line 151: The AutocompleteInput component is currently exported as a default
export on line 151. Replace the default export statement with a named export to
align with the repository's TSX component convention. Change the export
statement from `export default AutocompleteInput;` to a named export format
`export { AutocompleteInput };`. Additionally, update all import statements
throughout the codebase that currently import AutocompleteInput as a default
import to use the named import syntax instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: dfdedcd6-5559-4da6-b1b2-93b775cbe6a6

📥 Commits

Reviewing files that changed from the base of the PR and between d01a05c and c883d5b.

📒 Files selected for processing (3)
  • web/src/components/Incidents/AlertsChart/AlertsChart.tsx
  • web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx
  • web/src/components/console/public/components/autocomplete.tsx

export const DEFAULT_CHART_CONTAINER_HEIGHT = 300;
export const DEFAULT_CHART_HEIGHT = 250;

const AlertsChart = ({ theme }: { theme: 'light' | 'dark' }) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift

Both modified incident chart components violate the same TSX component contract (default export + non-FC declaration). Apply one consistent component pattern across both files: define a Props type, declare const Component: FC<Props>, and use named exports.

  • web/src/components/Incidents/AlertsChart/AlertsChart.tsx#L48-L48: replace inline props typing with AlertsChartProps + FC<AlertsChartProps>.
  • web/src/components/Incidents/AlertsChart/AlertsChart.tsx#L280-L280: replace default export with named export.
  • web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx#L59-L75: replace inline props typing with IncidentsChartProps + FC<IncidentsChartProps>.
  • web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx#L299-L299: replace export default memo(IncidentsChart) with named export form (e.g., named memo export).

As per coding guidelines, “Use functional components with explicit type annotations and FC type for React components” and “Always use named exports for React components instead of default exports.”

📍 Affects 2 files
  • web/src/components/Incidents/AlertsChart/AlertsChart.tsx#L48-L48 (this comment)
  • web/src/components/Incidents/AlertsChart/AlertsChart.tsx#L280-L280
  • web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx#L59-L75
  • web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx#L299-L299
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/components/Incidents/AlertsChart/AlertsChart.tsx` at line 48, Both
chart components violate the TSX component contract by using inline prop typing
and default exports. Fix both files to follow the consistent pattern: (1) In
web/src/components/Incidents/AlertsChart/AlertsChart.tsx at line 48, replace the
inline props destructuring { theme: 'light' | 'dark' } with a named
AlertsChartProps type and declare the component as const AlertsChart:
FC<AlertsChartProps>; then at line 280, replace the default export with a named
export. (2) In web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx at
lines 59-75, replace the inline props typing with a named IncidentsChartProps
type and declare the component as const IncidentsChart: FC<IncidentsChartProps>;
then at line 299, replace the default export (including the memo wrapper) with a
named export form using memo.

Source: Coding guidelines

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. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants