Skip to content

Commit

Permalink
Merge pull request #16 from Kentico/feat/settings-info-banner
Browse files Browse the repository at this point in the history
Add modal if appsettings are being used instead of admin UI settings.
  • Loading branch information
michalJakubis authored Aug 13, 2024
2 parents 0918431 + 32b3333 commit c74fd4a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Kentico.Xperience.Admin.Base;
using Kentico.Xperience.Admin.Base.Forms;
using Kentico.Xperience.Shopify.Admin;
using Kentico.Xperience.Shopify.Config;

[assembly: UIPage(
parentType: typeof(ShopifyIntegrationSettingsApplication),
Expand All @@ -17,11 +18,16 @@ namespace Kentico.Xperience.Shopify.Admin
/// </summary>
public class ShopifyIntegrationSettingsEdit : ModelEditPage<ShopifyIntegrationSettingsModel>
{
private readonly IShopifyIntegrationSettingsService settingsService;
/// <summary>
/// Initializes a new instance of the <see cref="ShopifyIntegrationSettingsEdit"/> class.
/// </summary>
public ShopifyIntegrationSettingsEdit(Xperience.Admin.Base.Forms.Internal.IFormItemCollectionProvider formItemCollectionProvider, IFormDataBinder formDataBinder) : base(formItemCollectionProvider, formDataBinder)
public ShopifyIntegrationSettingsEdit(
Xperience.Admin.Base.Forms.Internal.IFormItemCollectionProvider formItemCollectionProvider,
IFormDataBinder formDataBinder,
IShopifyIntegrationSettingsService settingsService) : base(formItemCollectionProvider, formDataBinder)
{
this.settingsService = settingsService;
}

private IntegrationSettingsInfo? settingsInfo;
Expand All @@ -40,7 +46,19 @@ public ShopifyIntegrationSettingsEdit(Xperience.Admin.Base.Forms.Internal.IFormI
/// <inheritdoc/>
public override Task ConfigurePage()
{
PageConfiguration.Headline = "It is recommended to use appsettings.json or user secrets to store API credentials. Use this primarly for developement.";

PageConfiguration.Headline = "It is recommended to use appsettings.json or user secrets to store API credentials. Use this primarily for development. Values in appsettings.json/user secrets will override these values.";

if (!settingsService.AdminUISettingsUsed())
{
PageConfiguration.SubmitConfiguration.ConfirmationConfiguration = new ConfirmationConfiguration()
{
Title = "Warning",
Detail = "These settings are overridden by values from appsettings.json or user secrets. Changes won't affect the application.",
Button = "Save",
};
}

return base.ConfigurePage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ public interface IShopifyIntegrationSettingsService
/// <see cref="ShopifyWebsiteChannelConfig"/> containing configuration for current website channel or default value if no configuration is found.
/// </returns>
ShopifyWebsiteChannelConfig? GetWebsiteChannelSettings();

/// <summary>
/// Check if settings from admin UI are being used. If not, values from appsettings.json or
/// user secrets are used.
/// </summary>
/// <returns>True if settings from admin UI are used. Otherwise False.</returns>
bool AdminUISettingsUsed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public ShopifyIntegrationSettingsService(
return websiteChannelConfig.Settings?.Find(x => x.ChannelName == currentChannel) ?? websiteChannelConfig.DefaultSetting;
}

public bool AdminUISettingsUsed()
=> !ShopifyConfigIsFilled(shopifyConfig);

private ShopifyConfig? GetConfigFromSettings()
{
var settingsInfo = integrationSettingsProvider.Get()
Expand Down

0 comments on commit c74fd4a

Please sign in to comment.