Skip to content

Commit

Permalink
Create abstract BackendComponentBase and refactor Backend to BackendP…
Browse files Browse the repository at this point in the history
…rovider

Introduced an abstract BackendComponentBase to consolidate backend functionality for reuse and maintainability. Also, Backend has been renamed to BackendProvider for better clarity and consistency, and it now inherits from BackendComponentBase. This promotes better separation of concerns and a more structured approach to component hierarchy.
  • Loading branch information
sfmskywalker committed Dec 30, 2023
1 parent fd1bacd commit 928cb25
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Elsa.Studio.Components;

/// Base class for components. This class sets the <see cref="BlazorServiceAccessor.Services"/> property to the <see cref="IServiceProvider"/> instance.
/// See https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-7.0#access-server-side-blazor-services-from-a-different-di-scope
public class StudioComponentBase : ComponentBase, IHandleEvent, IHandleAfterRender
public abstract class StudioComponentBase : ComponentBase, IHandleEvent, IHandleAfterRender
{
private bool _hasCalledOnAfterRender;

Expand Down
21 changes: 0 additions & 21 deletions src/hosts/Elsa.Studio.Host.CustomElements/Components/Backend.razor

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Elsa.Studio.Components;
using Elsa.Studio.Host.CustomElements.Services;
using Microsoft.AspNetCore.Components;

namespace Elsa.Studio.Host.CustomElements.Components;

public abstract class BackendComponentBase : StudioComponentBase
{
[Parameter] public string? RemoteEndpoint { get; set; }
[Parameter] public string? ApiKey { get; set; }
[Parameter] public string? AccessToken { get; set; }
[Inject] private BackendService BackendService { get; set; } = default!;

protected override void OnInitialized()
{
if (!string.IsNullOrWhiteSpace(RemoteEndpoint))
BackendService.RemoteEndpoint = RemoteEndpoint;

if (!string.IsNullOrWhiteSpace(ApiKey))
BackendService.ApiKey = ApiKey;

if (!string.IsNullOrWhiteSpace(AccessToken))
BackendService.AccessToken = AccessToken;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@using Elsa.Studio.Host.CustomElements.Services
@using Elsa.Studio.Contracts
@using Elsa.Studio.Options
@using Microsoft.Extensions.Options
@inherits BackendComponentBase

@code {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@using Elsa.Studio.Contracts
@inherits StudioComponentBase
@inherits BackendComponentBase
@inject IThemeService ThemeService

<MudThemeProvider IsDarkMode="false" Theme="@ThemeService.CurrentTheme"/>
Expand Down
2 changes: 1 addition & 1 deletion src/hosts/Elsa.Studio.Host.CustomElements/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// Register the custom elements.
builder.RootComponents.RegisterCustomElsaStudioElements();
builder.RootComponents.RegisterCustomElement<Backend>("elsa-backend");
builder.RootComponents.RegisterCustomElement<BackendProvider>("elsa-backend-provider");
builder.RootComponents.RegisterCustomElement<WorkflowDefinitionEditorWrapper>("elsa-workflow-definition-editor");

// Register local services.
Expand Down
5 changes: 2 additions & 3 deletions src/samples/BlazorApp1/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@page "/"
@rendermode InteractiveServer
<Backend RemoteEndpoint="https://localhost:5001/elsa/api" ApiKey="48587230567A646D394B435A6277734A-4802fa49-e91e-45e8-b00f-b5492377e20b">
<WorkflowDefinitionEditorWrapper DefinitionId="57305c33e237893b"></WorkflowDefinitionEditorWrapper>
</Backend>
<BackendProvider RemoteEndpoint="https://localhost:5001/elsa/api" ApiKey="48587230567A646D394B435A6277734A-4802fa49-e91e-45e8-b00f-b5492377e20b"/>
<WorkflowDefinitionEditorWrapper DefinitionId="57305c33e237893b"></WorkflowDefinitionEditorWrapper>

0 comments on commit 928cb25

Please sign in to comment.