Skip to content

Misc fixes in the pivot functionallity #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 29, 2024
Merged

Misc fixes in the pivot functionallity #216

merged 8 commits into from
Oct 29, 2024

Conversation

likp
Copy link
Contributor

@likp likp commented Oct 28, 2024

  • Modified TableApiController.cs to:
    • Inject IPlacementHandler dependency.
    • Use CommaSeparatedStringToListOfStrings model binder for heading and stub query parameters.
    • Replace inline placement logic with PlacementHandler.
  • Added VariablePlacementTests class in VariablePlacementTests.cs to test PlacementHandler.
  • Introduced PlacementHandler class in PlacementHandler.cs implementing IPlacementHandler.
  • Added IPlacementHandler interface in IPlacementHandler.cs.
  • Updated ModelStore.cs with CreateModelA method for sample PXModel.
  • Added CommaSeparatedStringToListOfStrings model binder in CommaSeparatedStringToListOfStrings.cs.
  • Added IllegalPlacementSelection method in ProblemUtility.cs.
  • Registered IPlacementHandler service in Program.cs.

- Added `VariablePlacementTests` class in `VariablePlacementTests.cs` to test `PlacementHandler`.
- Introduced `PlacementHandler` class in `PlacementHandler.cs` implementing `IPlacementHandler`.
- Added `IPlacementHandler` interface in `IPlacementHandler.cs`.
- Updated `ModelStore.cs` with `CreateModelA` method for sample `PXModel`.
- Added `CommaSeparatedStringToListOfStrings` model binder in `CommaSeparatedStringToListOfStrings.cs`.
- Modified `TableApiController.cs` to:
  * Inject `IPlacementHandler` dependency.
  * Use `CommaSeparatedStringToListOfStrings` model binder for `heading` and `stub` query parameters.
  * Replace inline placement logic with `PlacementHandler`.
- Added `IllegalPlacementSelection` method in `ProblemUtility.cs`.
- Registered `IPlacementHandler` service in `Program.cs`.
likp added 6 commits October 28, 2024 20:21
In `PlacementHandler.cs`:
- Changed method to find the first time variable from `FirstOrDefault` to `Find`.
- Updated method to check if all variables are in the model from using `All` to `TrueForAll`.

In `CommaSeparatedStringToListOfStrings.cs`:
- Simplified retrieval of query keys by removing unnecessary list conversions.
- Removed null key check and moved query value retrieval outside the null check.
- Refactored splitting of query values into items for conciseness.
- Extracted logic for cleaning and adding items to the result list into a new private method `CleanValue`.
- `CleanValue` method now trims items and removes surrounding square brackets if present.
Encapsulated the logic for replacing the "TIME" constant with the
actual time code into a new private static method `ReplaceTimeConstant`.
This method improves code readability and maintainability by handling
the replacement within a dedicated function. The original inline code
has been removed and replaced with a call to this new method.
Extracted complex conditional checks into new methods
`AllVariablesExistsInSelection` and `OnlyHeadOrStubIsSpecified`
to improve readability and maintainability. Replaced inline
conditions with method calls. Moved `ReplaceTimeConstant`
method to accommodate new methods.
Reordered parameters in `Assert.AreEqual` calls in `VariablePlacementTests.cs` to place the expected value first and the actual value second. This change improves readability and consistency, aligning with common unit testing practices.
string? q = bindingContext.HttpContext.Request.Query[key];
if (q != null)
{
var items = Regex.Split(q, ",(?=[^\\]]*(?:\\[|$))", RegexOptions.IgnoreCase,
Copy link
Contributor

@JohannesFinsveen JohannesFinsveen Oct 29, 2024

Choose a reason for hiding this comment

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

Should we add try catch around the timeout add log something clever :-)
? Why IgnoreCase :-) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that we can let code higher up in the chain catch the error. I Changed to ReqexOptions.None instead no need for case insensitivity.

{
return value.Substring(1, item2.Length - 2);
}
return item2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should "return value.Substring(1, item2.Length - 2);" also have a Trim() ?

Copy link
Contributor Author

@likp likp Oct 29, 2024

Choose a reason for hiding this comment

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

good point, I will add that

- Introduced BindModelAsync method to handle model binding asynchronously, with a check for null bindingContext.
- Changed RegexOptions in Regex.Split from IgnoreCase to None for case-sensitive splitting.
- Added a foreach loop to clean and process each item in the split query string.
- Enhanced CleanValue method to trim leading and trailing whitespace from cleaned substrings.
Copy link

Copy link
Contributor

@JohannesFinsveen JohannesFinsveen left a comment

Choose a reason for hiding this comment

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

👍

@likp likp merged commit 9545a60 into main Oct 29, 2024
8 checks passed
@likp likp deleted the fix/pivot branch October 29, 2024 14:30
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