Skip to content

Add confirmation dialogs for contingency and study reload - #47

Merged
marota merged 3 commits into
mainfrom
claude/clear-contingency-state-7G5HC
Mar 10, 2026
Merged

marota merged 3 commits into
mainfrom
claude/clear-contingency-state-7G5HC

Conversation

@marota

@marota marota commented Mar 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds confirmation dialogs to prevent accidental loss of analysis state when switching contingencies or reloading the study. The implementation uses a ref-based approach to track the "committed" branch and only prompts when the user attempts to change to a different valid branch while analysis results exist.

Key Changes

  • Contingency Change Confirmation: When a user selects a different branch after running analysis, a confirmation dialog appears. Confirming clears analysis state and switches branches; canceling reverts the input to the previously committed branch.

  • Study Reload Confirmation: When clicking "Load Study" after running analysis, a confirmation dialog appears to warn that the network will be reloaded from scratch. Confirming proceeds with reload; canceling preserves the current state.

  • Committed Branch Tracking: Introduced committedBranchRef to track the last branch for which N-1 was successfully fetched. This allows the UI to distinguish between:

    • User typing partial text (no confirmation needed)
    • User selecting a valid branch different from the committed one (confirmation required)
    • User re-selecting the same branch (no confirmation needed)
  • State Management:

    • Added hasAnalysisState() helper to detect if any analysis results or manual selections exist
    • Added clearContingencyState() helper to clear analysis-related state while preserving network/config state
    • Moved confirmation logic from input change handler into the N-1 diagram fetch effect for cleaner separation of concerns
  • Comprehensive Test Coverage: Added 347 lines of test cases covering:

    • No confirmation when no analysis state exists
    • Confirmation dialog appearance and content
    • Confirm/cancel behavior for both contingency and study reload dialogs
    • Input reversion on cancel
    • Partial/invalid branch text handling

Implementation Details

The confirmation logic is now integrated into the useEffect that fetches the N-1 diagram. When a valid branch is selected that differs from committedBranchRef.current and analysis state exists, the dialog is shown and the input is reverted. Only after user confirmation (or if no confirmation was needed) does the branch get committed and the N-1 diagram fetched.

Both the React component (App.tsx) and the standalone HTML interface have been updated with identical logic to maintain consistency.

https://claude.ai/code/session_01YPX5uG246irRwHisuTu2Jo

claude added 3 commits March 10, 2026 19:37
The previous approach intercepted onChange on the datalist input, which
was unreliable because each keystroke triggered the handler with partial
text. The new approach intercepts at the N-1 diagram fetch useEffect:
when a valid branch is selected and differs from the last committed
branch, and analysis state exists, the dialog is shown and the input
reverts to the current branch. A committedBranchRef tracks which branch
was last confirmed/fetched.

https://claude.ai/code/session_01YPX5uG246irRwHisuTu2Jo
Applies the same committedBranchRef pattern to the standalone HTML
interface. Uses window.confirm() (matching the existing Load Study
and Apply Settings dialogs) to warn the user when switching
contingency with existing analysis state.

https://claude.ai/code/session_01YPX5uG246irRwHisuTu2Jo
9 test cases covering:
- No dialog when switching branch without analysis state
- Dialog shown when switching branch after running analysis
- State cleared and branch switched on confirm
- Input reverts to old branch on cancel
- No dialog triggered for partial/invalid branch text
- Load Study loads directly with no analysis state
- Dialog shown when clicking Load Study after analysis
- Study reloads on confirm, state preserved on cancel

Also fixes committedBranchRef to not reset when input is temporarily
cleared while analysis state exists (allows proper revert on cancel).

https://claude.ai/code/session_01YPX5uG246irRwHisuTu2Jo
@marota
marota merged commit c085e86 into main Mar 10, 2026
2 checks passed
marota pushed a commit that referenced this pull request Apr 30, 2026
Rewrites Phase 1 from the abstract CHANGELOG summary into a six-week
chronology grounded in PR descriptions:

- 1.1 Bootstrap (pre-#1) — scaffolding pushed direct to main
- 1.2 End-to-end loop (PRs #1–#15) — NAD scaling, multi-tab pan/zoom,
  manual actions, action variants, action scoring, svgUtils + usePanZoom
- 1.3 UX maturation (PRs #16–#24) — settings panel, OverloadPanel,
  monitoring factor, action filters, state-switching SLDs
- 1.4 Robustness + CI (PRs #25–#46) — backend/frontend test suites,
  CircleCI + GitHub Actions, lazy loading, divergence UI
- 1.5 Persistence + complex actions (PRs #47–#56) — save/reload sessions,
  combined actions w/ persistence, islanding MW, App.tsx Phase 1 hooks
- 1.6 Two-step + replay logging + rebrand (PRs #57–#65) — split analysis,
  config.json persistence, load shedding, MW Start, SLD highlights,
  InteractionLogger, ExpertAssist → Co-Study4Grid

Sections 2–4 left untouched (will be reconciled in a follow-up).

https://claude.ai/code/session_01Pg7fuCUG2edfm5PyHS6SbN
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.

2 participants