[FIX] Force trigger fetching contingency count from button action (using API Ref)#1140
[FIX] Force trigger fetching contingency count from button action (using API Ref)#1140thangqp wants to merge 6 commits into
Conversation
Signed-off-by: Thang PHAM <phamthang37@gmail.com>
…ing API Ref) Signed-off-by: Thang PHAM <phamthang37@gmail.com>
📝 WalkthroughWalkthroughAdds an imperative ref API to ContingencyTable (reset and refresh methods), exports formal types, and threads the ref through SecurityAnalysisParametersForm and SecurityAnalysisParametersInline to coordinate contingency count resets and refreshes. ChangesContingencyTable imperative ref API
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/components/parameters/common/contingency-table/contingency-table.tsx (1)
37-40: 💤 Low valueConsider using React 19's "ref as prop" pattern instead of
forwardRef.React 19 supports
refas a regular prop, makingforwardRefunnecessary. This would simplify the component definition.♻️ Optional simplification using React 19 ref-as-prop
-function ContingencyTableWithApiRef( - { name, showContingencyCount = false, fetchContingencyCount, isBuiltCurrentNode }: Readonly<ContingencyTableProps>, - apiRef: ForwardedRef<ContingencyTableApi> -) { +export function ContingencyTable({ + name, + showContingencyCount = false, + fetchContingencyCount, + isBuiltCurrentNode, + ref: apiRef, +}: Readonly<ContingencyTableProps & { ref?: ForwardedRef<ContingencyTableApi> }>) {And remove the export wrapper:
-export const ContingencyTable = forwardRef(ContingencyTableWithApiRef);Also applies to: 191-191
🤖 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 `@src/components/parameters/common/contingency-table/contingency-table.tsx` around lines 37 - 40, The component currently uses forwardRef; update it to React 19's "ref as prop" pattern by changing the function signature of ContingencyTableWithApiRef to accept apiRef as a regular prop (extend ContingencyTableProps to include apiRef?: ContingencyTableApi or appropriate type) instead of the second ForwardedRef parameter, remove any ForwardedRef type imports/usage, and delete the external forwardRef export wrapper (the export that wraps ContingencyTableWithApiRef with forwardRef); keep internal logic the same but reference apiRef from props. Ensure types (ContingencyTableProps and ContingencyTableApi) are adjusted/imported accordingly and any callers/export remain compatible with the new prop-based ref.
🤖 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.
Nitpick comments:
In `@src/components/parameters/common/contingency-table/contingency-table.tsx`:
- Around line 37-40: The component currently uses forwardRef; update it to React
19's "ref as prop" pattern by changing the function signature of
ContingencyTableWithApiRef to accept apiRef as a regular prop (extend
ContingencyTableProps to include apiRef?: ContingencyTableApi or appropriate
type) instead of the second ForwardedRef parameter, remove any ForwardedRef type
imports/usage, and delete the external forwardRef export wrapper (the export
that wraps ContingencyTableWithApiRef with forwardRef); keep internal logic the
same but reference apiRef from props. Ensure types (ContingencyTableProps and
ContingencyTableApi) are adjusted/imported accordingly and any callers/export
remain compatible with the new prop-based ref.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b2316059-e915-4c9c-8c7a-cb332491c6e1
📒 Files selected for processing (3)
src/components/parameters/common/contingency-table/contingency-table.tsxsrc/components/parameters/security-analysis/security-analysis-parameters-form.tsxsrc/components/parameters/security-analysis/security-analysis-parameters-inline.tsx
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/parameters/common/contingency-table/contingency-table.tsx (1)
100-120:⚠️ Potential issue | 🟠 Major | ⚡ Quick winGuard optional
fetchContingencyCountbefore chaining promise handlers.At Line 100,
fetchContingencyCount?.(...)can evaluate toundefined, and Line 106 then calls.then(...)unconditionally. That can throw at runtime whenshowContingencyCountis true but no fetcher is passed.💡 Proposed fix
+ if (!fetchContingencyCount) { + setIsLoading(false); + setSimulatedContingencyCount(null); + return () => {}; + } + - fetchContingencyCount?.( + fetchContingencyCount( contingencyListsInfos .filter((lists) => lists[ACTIVATED]) .flatMap((lists) => lists[CONTINGENCY_LISTS]?.map((contingencyList) => contingencyList[ID])), abortSignal )🤖 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 `@src/components/parameters/common/contingency-table/contingency-table.tsx` around lines 100 - 120, The code calls fetchContingencyCount?.(...) but then unconditionally chains .then/.catch which can throw if fetchContingencyCount is undefined; change this to guard the chain by first capturing the result of fetchContingencyCount (e.g. const p = fetchContingencyCount?.(...)) and only call p.then(...).catch(...) when p is defined, otherwise setSimulatedContingencyCount(null)/setIsLoading(false) or skip the fetch flow; update the existing handlers that call setSimulatedContingencyCount, setIsLoading and snackWithFallback so they remain in the same callbacks and preserve the abortSignal/IGNORE_SIGNAL check used in the current catch block.
🤖 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.
Outside diff comments:
In `@src/components/parameters/common/contingency-table/contingency-table.tsx`:
- Around line 100-120: The code calls fetchContingencyCount?.(...) but then
unconditionally chains .then/.catch which can throw if fetchContingencyCount is
undefined; change this to guard the chain by first capturing the result of
fetchContingencyCount (e.g. const p = fetchContingencyCount?.(...)) and only
call p.then(...).catch(...) when p is defined, otherwise
setSimulatedContingencyCount(null)/setIsLoading(false) or skip the fetch flow;
update the existing handlers that call setSimulatedContingencyCount,
setIsLoading and snackWithFallback so they remain in the same callbacks and
preserve the abortSignal/IGNORE_SIGNAL check used in the current catch block.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 64433207-23a4-46b8-9589-b55058c84bf2
📒 Files selected for processing (3)
src/components/parameters/common/contingency-table/contingency-table.tsxsrc/components/parameters/security-analysis/security-analysis-parameters-form.tsxsrc/components/parameters/security-analysis/security-analysis-parameters-inline.tsx



PR Summary
Expose an API Ref for ContingencyTable to control the trigger from an ancestor parent.