Skip to content

fix(tables-data): Multiple selection expressions on same variable #359

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 3 commits into from
Apr 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions PxWeb/Code/Api2/DataSelection/SelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,16 @@
{

var modelVariable = model.Meta.Variables.GetByCode(variable.VariableCode);
var valueCodes = variable.ValueCodes.ToList();

for (int i = 0; i < variable.ValueCodes.Count; i++)
foreach (var valueCode in valueCodes)
{
var valueCode = variable.ValueCodes[i];
// Try to get the value using the code specified by the API user
Value? pxValue = modelVariable.Values.FirstOrDefault(x => x.Code.Equals(valueCode, System.StringComparison.InvariantCultureIgnoreCase));

if (pxValue is null)
if (!ExpandValue(ref problem, variable, modelVariable, valueCode, pxValue))
{
return ExpandSelectionExpression(variable, modelVariable, valueCode, out problem);
}
else
{
variable.ValueCodes[i] = pxValue.Code;
return false;
}
}

Expand All @@ -135,6 +131,29 @@
return true;
}

private static bool ExpandValue(ref Problem? problem, VariableSelection variable, Variable modelVariable, string valueCode, Value? pxValue)
{
if (pxValue is null)
{
if (ExpandSelectionExpression(variable, modelVariable, valueCode, out problem))
{
variable.ValueCodes.Remove(valueCode);
}
else
{
return false;
}
}
else
{
if (valueCode != pxValue.Code)
{
variable.ValueCodes[variable.ValueCodes.IndexOf(valueCode)] = pxValue.Code;
}
}
return true;
}

/// <summary>
/// Expand selection expression and add to selection
/// This method should only be
Expand Down Expand Up @@ -341,7 +360,7 @@
/// <returns></returns>
private static VariablesSelection AddVariables(VariablesSelection variablesSelection, PXModel model)
{
foreach (var variable in model.Meta.Variables)

Check warning on line 363 in PxWeb/Code/Api2/DataSelection/SelectionHandler.cs

View workflow job for this annotation

GitHub Actions / build

Loop should be simplified by calling Select(variable => variable.Code)) (https://rules.sonarsource.com/csharp/RSPEC-3267)

Check warning on line 363 in PxWeb/Code/Api2/DataSelection/SelectionHandler.cs

View workflow job for this annotation

GitHub Actions / build

Loop should be simplified by calling Select(variable => variable.Code)) (https://rules.sonarsource.com/csharp/RSPEC-3267)

Check warning on line 363 in PxWeb/Code/Api2/DataSelection/SelectionHandler.cs

View workflow job for this annotation

GitHub Actions / build

Loop should be simplified by calling Select(variable => variable.Code)) (https://rules.sonarsource.com/csharp/RSPEC-3267)
{
if (!variablesSelection.Selection.Any(x => x.VariableCode.Equals(variable.Code, System.StringComparison.InvariantCultureIgnoreCase)))
{
Expand Down