Skip to content
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

Bug fix/ginger ops #3927

Merged
merged 8 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions Ginger/Ginger/Environments/AppsListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
<DockPanel>
<Label Style="{StaticResource $LabelStyle}" Content="Release:"/>
<ComboBox x:Name="xReleaseCombobox" IsEnabled="True" Style="{StaticResource $FlatEditInputComboBoxStyle}" Margin="0,0,0,20" MinWidth="300px" HorizontalAlignment="Left"></ComboBox>
<usercontrols2:ImageMakerControl x:Name="xProcessingImage" ImageType="Processing" Margin="630,-30,0,0" HorizontalAlignment="Left" Height="30" Width="20" Visibility="Hidden"></usercontrols2:ImageMakerControl>
<usercontrols2:ucButton x:Name="xGASyncBtn" IsEnabled="True" Width="200" Margin="0,-30,0,0" DockPanel.Dock="Top" HorizontalAlignment="Right" Visibility="Collapsed" ButtonType="RoundTextAndImageButton" ButtonText="Sync with GingerOps" ButtonImageType="Retry" ButtonFontImageSize="12" ButtonImageWidth="12" ButtonImageHeight="12" Click="xGASyncBtn_Click" ButtonStyle="{StaticResource $RoundTextAndImageButtonStyle}" ToolTip="Sync with GingerOps"/>
<Grid x:Name="xGOpsSyncBtnGrid">
<usercontrols2:ImageMakerControl x:Name="xProcessingImage" ImageType="Processing" Margin="0,0,205,0" HorizontalAlignment="Right" Height="30" Width="20" Visibility="Hidden"></usercontrols2:ImageMakerControl>
<usercontrols2:ucButton x:Name="xGASyncBtn" IsEnabled="True" Width="205" Padding="0,0,0,0" HorizontalAlignment="Right" Visibility="Collapsed" ButtonType="RoundTextAndImageButton" ButtonText="Sync with GingerOps" ButtonImageType="Retry" ButtonFontImageSize="18" ButtonImageWidth="18" ButtonImageHeight="18" Click="xGASyncBtn_Click" ButtonStyle="{StaticResource $RoundTextAndImageButtonStyle}" ToolTip="Sync with GingerOps"/>
</Grid>
</DockPanel>

<CheckBox x:Name="xPublishcheckbox" IsEnabled="True" Content="Publish" ToolTip="Publish to third party applications" DockPanel.Dock="Top" HorizontalAlignment="Left" Margin="0,-5,0,0" Style="{StaticResource $CeckBoxStyle}"/>
Expand Down
23 changes: 12 additions & 11 deletions Ginger/Ginger/Environments/AppsListPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public AppsListPage(ProjEnvironment env)
xPublishcheckbox.IsEnabled = true;
xGASyncBtn.Visibility = Visibility.Collapsed;
InitReleaseComboBox();
grdApps.AddToolbarTool("@Share_16x16.png", "Add Selected Applications to All Environments", new RoutedEventHandler(AddAppsToOtherEnvironments));
}

grdApps.AddToolbarTool("@Share_16x16.png", "Add Selected Applications to All Environments", new RoutedEventHandler(AddAppsToOtherEnvironments));
BindingHandler.ObjFieldBinding(EnvNameTextBox, TextBox.TextProperty, env, ProjEnvironment.Fields.Name);
EnvNameTextBox.AddValidationRule(new EnvironemntNameValidationRule());
xShowIDUC.Init(AppEnvironment);
Expand Down Expand Up @@ -108,7 +108,7 @@ private void InitReleaseComboBox()
private void SetGridView()
{
//Set the grid name
grdApps.Title = $"'{AppEnvironment.Name}' Environment Applications";
grdApps.Title = GetGrdAppsTitle();
grdApps.SetTitleLightStyle = true;

//Set the Tool Bar look
Expand Down Expand Up @@ -139,13 +139,8 @@ private void SetGridData()
if (AppEnvironment.GOpsFlag)
{
grdApps.DisableGridColoumns();
grdApps.btnDelete.IsEnabled = false;
grdApps.btnAdd.IsEnabled = false;
grdApps.btnCut.IsEnabled = false;
grdApps.btnUndo.IsEnabled = false;
grdApps.btnClearAll.IsEnabled = false;
grdApps.btnDuplicate.Visibility = Visibility.Collapsed;
grdApps.btnCopy.IsEnabled = false;
grdApps.btnDelete.IsEnabled = false;
}
}

Expand Down Expand Up @@ -188,7 +183,13 @@ private void AddAppsToOtherEnvironments(object sender, RoutedEventArgs e)

private void EnvNameTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
grdApps.Title = $"'{EnvNameTextBox.Text}' Environment Applications";
grdApps.Title = GetGrdAppsTitle();
}

private string GetGrdAppsTitle()
{
string grdEnvName = General.EscapeAccessKey(EnvNameTextBox.Text);
return $"'{grdEnvName}' Environment Applications";
}

private async void xGASyncBtn_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -270,7 +271,7 @@ private void UpdateExistingApplication(EnvApplication existingApp, GingerOpsAppl
{
if (param.Name != "Application Type" && param.Name != "Application URL")
{
existingApp.AddVariable(new VariableString() { Name = param.Name, Value = param.Value });
existingApp.AddVariable(new VariableString() { Name = param.Name, Value = param.Value, GOpsFlag = true, SetAsInputValue = false, SetAsOutputValue = false });
}
}
}
Expand All @@ -292,7 +293,7 @@ private void AddNewApplication(GingerOpsApplication item)
{
if (param.Name != "Application Type" && param.Name != "Application URL")
{
newEnvApp.AddVariable(new VariableString() { Name = param.Name, Value = param.Value });
newEnvApp.AddVariable(new VariableString() { Name = param.Name, Value = param.Value, GOpsFlag = true, SetAsInputValue = false, SetAsOutputValue = false });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void WizardEvent(WizardEventArgs WizardEventArgs)
{
case EventType.Init:
mWizard = (AddGingerOpsEnvWizard)WizardEventArgs.Wizard;
mWizard.mWizardWindow.SetFinishButtonEnabled(false);
LoadComboBoxData();
foreach (var appPlat in environmentListGOps)
{
Expand All @@ -91,7 +92,10 @@ public void WizardEvent(WizardEventArgs WizardEventArgs)
break;
case EventType.LeavingForNextPage:
xEnvironmentComboBox_SelectionChanged();
break;
break;
case EventType.Prev:
mWizard.mWizardWindow.SetFinishButtonEnabled(false);
break;
default:
break;

Expand Down Expand Up @@ -166,6 +170,11 @@ public async void xEnvironmentComboBox_SelectionChanged()
{
await HandleEnvironmentSelection(env);
}

if (mWizard.ImportedEnvs.Any(k => k.GingerOpsStatus == "Import Successful"))
{
mWizard.mWizardWindow.SetFinishButtonEnabled(true);
}
}
}
catch (Exception ex)
Expand Down Expand Up @@ -251,7 +260,7 @@ private async Task AddApplicationsToEnvironment(GingerOpsAPIResponseInfo.GingerO
{
if (param.Name != "Application Type" && param.Name != "Application URL")
{
envApp.AddVariable(new VariableString() { Name = param.Name, Value = param.Value, GOpsFlag=true });
envApp.AddVariable(new VariableString() { Name = param.Name, Value = param.Value, GOpsFlag=true, SetAsInputValue = false, SetAsOutputValue = false });
}
}
newEnvironment.Applications.Add(envApp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ public void WizardEvent(WizardEventArgs WizardEventArgs)
{
case EventType.Init:
mWizard = (AddGingerOpsEnvWizard)WizardEventArgs.Wizard;
break;
case EventType.Active:
SelectApplicationGrid.DataSourceList = mWizard.ImportedEnvs;
break;
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</Grid>
<Grid>
<usercontrols:ucButton x:Name="xTestConBtn" IsEnabled="True" DockPanel.Dock="Top" HorizontalAlignment="Left" Margin="10,25,0,0" ButtonType="RoundTextAndImageButton" ButtonText="Test Connection" ButtonImageType="Run" ButtonFontImageSize="12" ButtonImageWidth="12" ButtonImageHeight="12" Click="xTestConBtn_Click" ButtonStyle="{StaticResource $RoundTextAndImageButtonStyle}" ToolTip="Test GingerOps Connection"/>
<usercontrols:ImageMakerControl x:Name="xProcessingImage" ImageType="Processing" Margin="187,12,0,0" HorizontalAlignment="Left" Height="25" Width="20" Visibility="Hidden"></usercontrols:ImageMakerControl>
<usercontrols:ImageMakerControl x:Name="xProcessingImage" ImageType="Processing" Margin="187,28,0,3" HorizontalAlignment="Left" Height="25" Width="20" Visibility="Collapsed"></usercontrols:ImageMakerControl>

</Grid>
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private async void xTestConBtn_Click(object sender, RoutedEventArgs e)

GingerCoreNET.GeneralLib.General.CreateGingerOpsConfiguration();


if (GingerOpsAPI.IsTokenValid())
{
Reporter.ToUser(eUserMsgKey.GingerOpsConnectionSuccess);
Expand Down
15 changes: 15 additions & 0 deletions Ginger/Ginger/GeneralLib/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,5 +640,20 @@ public static bool IsAdmin()
}
return false;
}

/// <summary>
/// Escape all underscores ('_') from the provided string <paramref name="s"/> with double underscores ('__'). This is helpful in case of displaying underscore in <see cref="Label"/> controls where the first underscore is considered as Access Key. For more details, https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/1427.
/// </summary>
/// <param name="s">string to escape</param>
/// <returns>Escaped string where all the underscores ('_') is escaped using double underscores ('__').</returns>
public static string EscapeAccessKey(string s)
{
if (string.IsNullOrEmpty(s))
{
return s;
}

return s.Replace("_", "__");
}
Comment on lines +643 to +657
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Address method duplication and ensure consistent usage of EscapeAccessKey.

To maintain consistency and reduce redundancy in the codebase:

  1. Consolidate Escaping Logic:

    • Replace instances of Replace("_", " ") and similar string escaping methods with the standardized EscapeAccessKey method.
    • This ensures a uniform approach to handling underscores across all Label controls and related components.
  2. Refactor Existing Methods:

    • Identify and update files where alternative string escaping is performed to utilize EscapeAccessKey.
    • Ensure that all usages align with the intended functionality of escaping underscores for Label controls.
  3. Remove Redundant Utilities:

    • If any methods duplicate the functionality of EscapeAccessKey without additional benefits, consider removing them to streamline the codebase.

Implementing these steps will enhance code maintainability and prevent potential inconsistencies related to string escaping.

Analysis chain

Verify usage and check for similar utilities.

The EscapeAccessKey method is a useful addition to handle underscore escaping for Label controls. To ensure its effective integration:

  1. Verify that this method is being used consistently wherever Label controls with potential underscore issues are created or updated.
  2. Check if there are any existing methods or utilities in the codebase that perform similar string escaping functions to avoid duplication.

Run the following script to check for potential usage and similar methods:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential usage of EscapeAccessKey and similar methods

# Test 1: Search for potential usage of EscapeAccessKey
echo "Potential usage of EscapeAccessKey:"
rg --type csharp "EscapeAccessKey\(" -g '!GeneralLib/General.cs'

# Test 2: Search for Label creation or content setting
echo "\nPotential places where Label controls are created or updated:"
rg --type csharp "new Label\(|\.Content\s*=" -g '!GeneralLib/General.cs'

# Test 3: Search for similar string escaping methods
echo "\nPotential similar string escaping methods:"
rg --type csharp "Replace\(\"_\"" -g '!GeneralLib/General.cs'

Length of output: 84330

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ private void DeleteEnvTreeItems()
}
private void Delete(object sender, RoutedEventArgs e)
{
if (!ProjEnvironment.GOpsFlag)
if (EnvApplication.GOpsFlag)
{
Reporter.ToUser(eUserMsgKey.GingerOpsDeleteDisable);
}
else
{
DeleteEnvTreeItems();
}
Expand Down
19 changes: 2 additions & 17 deletions Ginger/Ginger/UserControlsLib/ConsumerComboBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,30 +250,15 @@ private void SetText()
displayText.Append(consumer.Name);
displayText.Append(',');
}
Text = EscapeAccessKey(displayText.ToString().TrimEnd(','));
Text = General.EscapeAccessKey(displayText.ToString().TrimEnd(','));
}
// set DefaultText if nothing else selected
if (string.IsNullOrEmpty(Text))
{
Text = EscapeAccessKey(DefaultText);
Text = General.EscapeAccessKey(DefaultText);
}
}

/// <summary>
/// Escape all underscores ('_') from the provided string <paramref name="s"/> with double underscores ('__'). This is helpful in case of displaying underscore in <see cref="Label"/> controls where the first underscore is considered as Access Key. For more details, https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/1427.
/// </summary>
/// <param name="s">string to escape</param>
/// <returns>Escaped string where all the underscores ('_') is escaped using double underscores ('__').</returns>
private static string EscapeAccessKey(string s)
{
if (string.IsNullOrEmpty(s))
{
return s;
}

return s.Replace("_", "__");
}

private string? GetConsumerName(Guid consumerGuid)
{
return
Expand Down
8 changes: 6 additions & 2 deletions Ginger/Ginger/UserControlsLib/ucGridView/ucGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ limitations under the License.
using Ginger.Help;
using Ginger.UserControls;
using Ginger.UserControlsLib;
using GingerCore.Environments;
using GingerCore.GeneralLib;
using GingerWPF.DragDropLib;
using System;
Expand Down Expand Up @@ -774,6 +775,7 @@ private void btnClearAll_Click(object sender, RoutedEventArgs e)

if ((Reporter.ToUser(eUserMsgKey.SureWantToDeleteAll)) == Amdocs.Ginger.Common.eUserMsgSelection.Yes)
{
// Save undo data before modifying the list
mObjList.SaveUndoData();
mObjList.ClearAll();
}
Expand All @@ -793,10 +795,12 @@ private void btnDelete_Click(object sender, RoutedEventArgs e)

List<object> SelectedItemsList = grdMain.SelectedItems.Cast<object>().ToList();

bool IsItemsDeleted = false;
foreach (object o in SelectedItemsList)
{
mObjList.Remove(o);
RemoveFromLiteDB(o);
mObjList.Remove(o);
RemoveFromLiteDB(o);

}
}
finally
Expand Down
1 change: 0 additions & 1 deletion Ginger/Ginger/Variables/VariableEditPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public VariableEditPage(VariableBase v, Context context, bool setGeneralConfigsA
{
xVarNameTxtBox.IsEnabled = false;
xVarDescritpiontxtBox.IsEnabled = false;
xPublishcheckbox.IsEnabled = false;
}

if (parent is EnvApplication)
Expand Down
12 changes: 12 additions & 0 deletions Ginger/Ginger/Variables/VariablesListViewHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ public List<ListItemOperation> GetItemOperationsList(object item)
itemUsage.OperationHandler = ViewRepositoryItemUsageHandler;
operationsList.Add(itemUsage);

//removing for gingerops
if (item is VariableBase vb && vb.GOpsFlag)
{
operationsList.Remove(edit);
operationsList.Remove(delete);
}

return operationsList;
}

Expand All @@ -467,6 +474,11 @@ public List<ListItemOperation> GetItemExtraOperationsList(object item)
SetItem(item);
List<ListItemOperation> extraOperationsList = new List<ListItemOperation>();

if (item is VariableBase vb && vb.GOpsFlag)
{
return extraOperationsList;
}

if (mVariable.SupportResetValue)
{
ListItemOperation reset = new ListItemOperation();
Expand Down
2 changes: 1 addition & 1 deletion Ginger/Ginger/WizardLib/WizardWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

<UserControls:ucButton x:Name="xPrevButton" ButtonType="RoundTextAndImageButton" ButtonText="Previous" ButtonImageType="GoBack" ButtonFontImageSize="15" ButtonImageWidth="15" ButtonImageHeight="15" Click="PrevButton_Click" ButtonStyle="{StaticResource $RoundTextAndImageButtonStyle}" IsEnabled="False"/>
<UserControls:ucButton x:Name="xNextButton" ButtonType="RoundTextAndImageButton" ButtonText="Next" ButtonImageType="GoNext" ButtonFontImageSize="15" ButtonImageWidth="15" ButtonImageHeight="15" Click="NextButton_Click" ButtonStyle="{StaticResource $RoundTextAndImageButtonStyle}"/>
<UserControls:ucButton x:Name="xFinishButton" ButtonType="RoundTextAndImageButton" ButtonText="Finish" ButtonImageType="Finish" ButtonFontImageSize="15" ButtonImageWidth="15" ButtonImageHeight="15" Click="FinishButton_Click" ButtonStyle="{StaticResource $RoundTextAndImageButtonStyle}"/>
<UserControls:ucButton x:Name="xFinishButton" ButtonType="RoundTextAndImageButton" ButtonText="Finish" ButtonImageType="Finish" ButtonFontImageSize="15" ButtonImageWidth="15" ButtonImageHeight="15" IsEnabled="True" Click="FinishButton_Click" ButtonStyle="{StaticResource $RoundTextAndImageButtonStyle}"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Reconsider always enabling the Finish button

The change to set IsEnabled="True" on the Finish button could lead to potential issues:

  1. Users might be able to complete the wizard prematurely, without filling in all necessary information.
  2. This could result in incomplete or invalid data being submitted.

Consider the following alternatives:

  1. Remove the IsEnabled attribute entirely and manage the button's enabled state dynamically in the code-behind or view model. This allows you to enable the button only when all required steps are completed.

  2. If this change is addressing a specific bug, consider a more targeted fix that doesn't compromise the wizard's integrity.

Example of managing the button state in code-behind:

public partial class WizardWindow : Window
{
    public WizardWindow()
    {
        InitializeComponent();
        UpdateFinishButtonState();
    }

    private void UpdateFinishButtonState()
    {
        xFinishButton.IsEnabled = AreAllRequiredStepsCompleted();
    }

    private bool AreAllRequiredStepsCompleted()
    {
        // Implement logic to check if all required steps are completed
    }
}

This approach ensures that the Finish button is only enabled when appropriate, maintaining the integrity of the wizard flow.

<UserControls:ucButton x:Name="xCancelButton" ButtonType="RoundTextAndImageButton" ButtonText="Cancel" ButtonImageType="Cancel" ButtonFontImageSize="15" ButtonImageWidth="15" ButtonImageHeight="15" Click="CancelButton_Click" ButtonStyle="{StaticResource $RoundTextAndImageButtonStyle}"/>

</StackPanel>
Expand Down
9 changes: 7 additions & 2 deletions Ginger/Ginger/WizardLib/WizardWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ private void UpdatePrevNextButton()
if (mWizard.IsLastPage())
{
xNextButton.IsEnabled = false;
xFinishButton.IsEnabled = true;
if (mWizard.DisableBackBtnOnLastPage == true)

if (mWizard.DisableBackBtnOnLastPage)
{
xPrevButton.IsEnabled = false;
return;
Expand Down Expand Up @@ -424,6 +424,11 @@ void IWizardWindow.NextButton(bool isEnabled)
xNextButton.IsEnabled = isEnabled;
}

void IWizardWindow.SetFinishButtonEnabled(bool isEnabled)
{
xFinishButton.IsEnabled = isEnabled;
}

bool WindowCloseWasHandled = false;

private void CloseWindowClicked(object sender, System.ComponentModel.CancelEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public string IdentityServiceURL
{
mIdentityServiceURL = value;
OnPropertyChanged(nameof(IdentityServiceURL));
InvalidateToken();
}
}
}
Expand All @@ -105,6 +106,7 @@ public string ClientId
{
mClientId = value;
OnPropertyChanged(nameof(ClientId));
InvalidateToken();
}
}
}
Expand All @@ -123,6 +125,7 @@ public string ClientSecret
{
mClientSecret = value;
OnPropertyChanged(nameof(ClientSecret));
InvalidateToken();
}
}
}
Expand Down Expand Up @@ -153,6 +156,14 @@ public override string ItemName
}
}

private void InvalidateToken()
{
if (!string.IsNullOrEmpty(mToken))
{
mToken = string.Empty;
}
}

public override string GetNameForFileName() { return Name; }

}
Expand Down
Loading
Loading