Skip to content

Fixes #2834 Separator Selector is styled differently and pops-under pk-sim#2835

Merged
rwmcintosh merged 2 commits intodevelopfrom
2834-csv-separator-modal
Apr 18, 2026
Merged

Fixes #2834 Separator Selector is styled differently and pops-under pk-sim#2835
rwmcintosh merged 2 commits intodevelopfrom
2834-csv-separator-modal

Conversation

@rwmcintosh
Copy link
Copy Markdown
Member

@rwmcintosh rwmcintosh commented Apr 17, 2026

Fixes #2834 Separator Selector is styled differently and pops-under pk-sim

Description

We were opening a new dialog from within the heavyworkmanager and not setting the parent handle

Type of change

Please mark relevant options with an x in the brackets.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires documentation changes (link at least one user or developer documentation issue):
  • Algorithm update - updates algorithm documentation/questions/answers etc.
  • Other (please describe):

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Integration tests
  • Unit tests
  • Manual tests
  • No tests required

Reviewer checklist

Mark everything that needs to be checked before merging the PR.

  • Check if the code is well documented
  • Check if the behavior is what is expected
  • Check if the code is well tested
  • Check if the code is readable and well formatted
  • Additional checks (document below if any)
  • Check if documentation update issue(s) are created if the option This change requires a documentation update above is selected

Screenshots (if appropriate):

Questions (if appropriate):

Summary by CodeRabbit

  • Bug Fixes

    • Improved data file loading robustness and cancellation handling for CSV and Excel imports.
  • Refactor

    • Restructured internal data source file loading mechanism for better separation of concerns.
    • Enhanced CSV separator management for more reliable file parsing.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

Warning

Rate limit exceeded

@rwmcintosh has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 42 minutes and 22 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 42 minutes and 22 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7a90f247-05ca-4c7e-8d51-e64afeeaed0a

📥 Commits

Reviewing files that changed from the base of the PR and between b01c2bc and 0dc2d08.

📒 Files selected for processing (2)
  • src/OSPSuite.Infrastructure.Import/Core/DataSourceFile.cs
  • src/OSPSuite.UI/Views/Importer/CsvSeparatorSelectorView.cs
📝 Walkthrough

Walkthrough

The refactoring replaces direct property assignment with an explicit LoadFromFile() public method that orchestrates data loading through a work manager. The abstract LoadFromFile() method is renamed to DoLoadWork() and made protected, enabling separation of concerns between the public loading API and the implementation logic.

Changes

Cohort / File(s) Summary
Core Loading Infrastructure
src/OSPSuite.Infrastructure.Import/Core/DataSourceFile.cs
Refactored IDataSourceFile.Path to read-only; introduced public LoadFromFile(string path) method; renamed abstract method to DoLoadWork() and made protected; implemented work delegation through _heavyWorkManager.
CSV and Excel Readers
src/OSPSuite.Infrastructure.Import/Core/DataSourceFileReaders/CsvDataSourceFile.cs, src/OSPSuite.Infrastructure.Import/Core/DataSourceFileReaders/ExcelDataSourceFile.cs
Updated method overrides to use new DoLoadWork() signature; CSV reader now stores separator selections in instance field and calls base LoadFromFile() after validation; Excel reader method renamed to match new abstract pattern.
Calling Code Updates
src/OSPSuite.Infrastructure.Import/Core/DataSourceFileParser.cs, src/OSPSuite.Presentation/Presenters/Importer/ImporterDataPresenter.cs
Updated to invoke LoadFromFile(path) method instead of assigning Path property directly.
View Constructor Update
src/OSPSuite.UI/Views/Importer/CsvSeparatorSelectorView.cs
Constructor now requires IShell parameter; added supporting using directive.
Test Updates
tests/OSPSuite.Presentation.Tests/Importer/Core/DataSourceFileReaders/CsvDataSourceFileSpecs.cs, tests/OSPSuite.Presentation.Tests/Importer/Core/DataSourceFileReaders/ExcelDataSourceFileSpecs.cs, tests/OSPSuite.Presentation.Tests/Importer/Presenters/ImporterPresenterSpecs.cs
Updated test setup to call LoadFromFile() instead of setting Path property; adjusted exception assertions to reflect new loading flow.

Sequence Diagram

sequenceDiagram
    participant Caller as Caller
    participant DSF as DataSourceFile
    participant HWM as HeavyWorkManager
    participant Child as CsvDataSourceFile/<br/>ExcelDataSourceFile
    
    Caller->>DSF: LoadFromFile(path)
    activate DSF
    DSF->>DSF: Path = path
    DSF->>DSF: Create CancellationTokenSource
    DSF->>HWM: Start(action with DoLoadWork)
    activate HWM
    HWM->>Child: DoLoadWork(path, token)
    activate Child
    Child->>Child: Read/Parse file
    Child->>Child: Update DataSheets
    Child-->>Child: Handle exceptions & rollback
    deactivate Child
    HWM-->>DSF: Complete/Suppress OperationCanceledException
    deactivate HWM
    DSF-->>Caller: Return
    deactivate DSF
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A rabbit hops through loading lanes,
No more paths set as self-assigned chains,
With DoLoadWork tucked safe inside,
The CSV and Excel ride with pride,
The separator selector now stands tall,
A proper interface for one and all!

🚥 Pre-merge checks | ✅ 1 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title states the fix is for issue #2834 about separator selector styling, but the code changes focus on refactoring DataSourceFile loading logic and constructor signatures, not directly addressing the parent window handle issue. The title references the correct issue, but the changeset appears to address the root cause of separator selector dialog initialization indirectly. Clarify whether these structural changes actually resolve the parent window handle or styling problem described in #2834.
Out of Scope Changes check ⚠️ Warning The PR contains extensive refactoring of DataSourceFile loading mechanisms (Path property changes, LoadFromFile refactoring, CancellationToken handling) that extends beyond the stated UI styling issue in #2834. These structural changes appear out of scope for fixing a dialog styling/window positioning bug. Either justify why this refactoring is necessary to fix #2834, or split UI styling changes from the loading logic refactoring into separate PRs.
Linked Issues check ❓ Inconclusive The PR claims to fix #2834 (separator selector styling and window positioning), but the changes don't show explicit parent window handle assignment or dialog ownership configuration needed to resolve the stated issue. Review whether the refactored LoadFromFile flow (moving initialization out of Path setter) indirectly ensures proper dialog initialization context. Verify the separator selector is now created with correct parent window when called from LoadFromFile.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2834-csv-separator-modal

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.

❤️ Share

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

@rwmcintosh rwmcintosh self-assigned this Apr 17, 2026
@rwmcintosh rwmcintosh added this to V12.3 Apr 17, 2026
Copy link
Copy Markdown

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/OSPSuite.Infrastructure.Import/Core/DataSourceFileReaders/CsvDataSourceFile.cs (1)

17-17: Consider passing CSVSeparators instead of storing it as a field.

_csvSeparators is effectively a hidden parameter to DoLoadWork. This works today because DoLoadWork is only ever reached via this class's LoadFromFile override, but it's fragile: any future code path that invokes base.LoadFromFile (or a subclass of CsvDataSourceFile that forgets the override) will enter DoLoadWork with a stale or null _csvSeparators and NRE on _csvSeparators.ColumnSeparator / .DecimalSeparator. A cleaner shape would be to thread the separators through as parameters (e.g., an overload DoLoadWork(string path, CSVSeparators separators, CancellationToken ct) on this class, still called from within the heavy work closure), or at minimum add a defensive null-check at the top of DoLoadWork.

Also applies to: 35-43

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/OSPSuite.Infrastructure.Import/Core/DataSourceFileReaders/CsvDataSourceFile.cs`
at line 17, Do not rely on the private field `_csvSeparators` as an implicit
dependency for `DoLoadWork`; instead add a `CSVSeparators separators` parameter
to `DoLoadWork` (e.g., `DoLoadWork(string path, CSVSeparators separators,
CancellationToken ct)`) and update `LoadFromFile` to pass the resolved
separators into that call (remove the `_csvSeparators` field or stop using it),
and if you prefer a minimal change add an explicit defensive null-check at the
start of `DoLoadWork` that throws a clear ArgumentNullException referencing
`separators`/`_csvSeparators`; update any internal calls or overrides to use the
new signature so no code path can reach `DoLoadWork` with a stale or null
separators instance.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/OSPSuite.Infrastructure.Import/Core/DataSourceFile.cs`:
- Around line 64-79: In LoadFromFile, don't set the Path property before running
the heavy load; currently Path = path runs before _heavyWorkManager.Start and
can remain set when DoLoadWork fails, diverging from DataSheets. Move the Path
assignment to after the call to _heavyWorkManager.Start and only assign when
Start indicates success (check its bool return value), so that Path is updated
only if the load completed successfully; keep the existing
CancellationTokenSource, the try/catch around DoLoadWork, and the same call
signature to _heavyWorkManager.Start when implementing this change.
- Around line 64-79: LoadFromFile currently calls _heavyWorkManager.Start(...)
and ignores its boolean result so exceptions thrown by DoLoadWork are swallowed;
modify LoadFromFile (the method that creates the CancellationTokenSource and
calls _heavyWorkManager.Start) to either capture any exception from the
background action (e.g. store it in a local Exception variable from inside the
closure) and rethrow it after Start returns, or check the bool return value of
_heavyWorkManager.Start and, when false, throw the appropriate
InvalidObservedDataFileException (or wrap/propagate the captured exception) so
failures in DoLoadWork surface to the caller.

In `@src/OSPSuite.UI/Views/Importer/CsvSeparatorSelectorView.cs`:
- Line 20: The WinForms designer needs a parameterless design-time constructor
for the CSVSeparatorSelectorView class; add a public parameterless constructor
CSVSeparatorSelectorView() that delegates to the existing
CSVSeparatorSelectorView(IShell shell) by calling : this(null) (or internally
calling the shell-aware constructor with null) so the partial class can be
instantiated at design time consistent with other views like ObjectBaseView.

---

Nitpick comments:
In
`@src/OSPSuite.Infrastructure.Import/Core/DataSourceFileReaders/CsvDataSourceFile.cs`:
- Line 17: Do not rely on the private field `_csvSeparators` as an implicit
dependency for `DoLoadWork`; instead add a `CSVSeparators separators` parameter
to `DoLoadWork` (e.g., `DoLoadWork(string path, CSVSeparators separators,
CancellationToken ct)`) and update `LoadFromFile` to pass the resolved
separators into that call (remove the `_csvSeparators` field or stop using it),
and if you prefer a minimal change add an explicit defensive null-check at the
start of `DoLoadWork` that throws a clear ArgumentNullException referencing
`separators`/`_csvSeparators`; update any internal calls or overrides to use the
new signature so no code path can reach `DoLoadWork` with a stale or null
separators instance.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f3f7278a-99f2-4ac3-aa3e-86049bfcb306

📥 Commits

Reviewing files that changed from the base of the PR and between b2cf131 and b01c2bc.

📒 Files selected for processing (9)
  • src/OSPSuite.Infrastructure.Import/Core/DataSourceFile.cs
  • src/OSPSuite.Infrastructure.Import/Core/DataSourceFileParser.cs
  • src/OSPSuite.Infrastructure.Import/Core/DataSourceFileReaders/CsvDataSourceFile.cs
  • src/OSPSuite.Infrastructure.Import/Core/DataSourceFileReaders/ExcelDataSourceFile.cs
  • src/OSPSuite.Presentation/Presenters/Importer/ImporterDataPresenter.cs
  • src/OSPSuite.UI/Views/Importer/CsvSeparatorSelectorView.cs
  • tests/OSPSuite.Presentation.Tests/Importer/Core/DataSourceFileReaders/CsvDataSourceFileSpecs.cs
  • tests/OSPSuite.Presentation.Tests/Importer/Core/DataSourceFileReaders/ExcelDataSourceFileSpecs.cs
  • tests/OSPSuite.Presentation.Tests/Importer/Presenters/ImporterPresenterSpecs.cs

Comment thread src/OSPSuite.Infrastructure.Import/Core/DataSourceFile.cs
Comment thread src/OSPSuite.UI/Views/Importer/CsvSeparatorSelectorView.cs
@rwmcintosh rwmcintosh requested review from Yuri05 and msevestre April 17, 2026 19:07
public override void LoadFromFile(string path)
{
var csvSeparators = _csvSeparatorSelector.GetCsvSeparator(path);
_csvSeparators = _csvSeparatorSelector.GetCsvSeparator(path);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This opens a modal dialog and cannot be done from within HeavyWorkManager

@rwmcintosh rwmcintosh merged commit 4475595 into develop Apr 18, 2026
6 checks passed
@rwmcintosh rwmcintosh deleted the 2834-csv-separator-modal branch April 18, 2026 13:20
@github-project-automation github-project-automation bot moved this to Done in V12.3 Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Separator Selector is styled differently and pops-under pk-sim

2 participants