From c258cca7bdb6ffc7ce76420f804f30de16b72b2b Mon Sep 17 00:00:00 2001 From: George Drak Date: Wed, 8 Sep 2021 13:56:52 +0500 Subject: [PATCH] feat(display): remove entity from block list context cause it's never used --- .../Display/BlockComponent.cs | 10 +++++-- .../Display/Blocks/CutBlockComponent.cs | 2 +- .../Display/Blocks/FilesBlockComponent.cs | 2 +- .../Display/Blocks/GalleryBlockComponent.cs | 2 +- .../Display/Blocks/IframeBlockComponent.cs | 2 +- .../Display/Blocks/QuoteBlockComponent.cs | 3 +- .../Display/Blocks/TextBlockComponent.cs | 2 +- .../Display/Blocks/TwitchBlockComponent.cs | 2 +- .../Display/Blocks/TwitterBlockComponent.cs | 2 +- .../Display/Blocks/YoutubeBlockComponent.cs | 2 +- .../Display/BlocksList.cs | 28 +++++++------------ src/Sitko.Blockly/Display/BlockListContext.cs | 5 +--- 12 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/Sitko.Blockly.Blazor/Display/BlockComponent.cs b/src/Sitko.Blockly.Blazor/Display/BlockComponent.cs index 9404180..7aa8213 100644 --- a/src/Sitko.Blockly.Blazor/Display/BlockComponent.cs +++ b/src/Sitko.Blockly.Blazor/Display/BlockComponent.cs @@ -4,8 +4,7 @@ namespace Sitko.Blockly.Blazor.Display { - public abstract class BlockComponent : BaseComponent - where TListOptions : BlazorBlocklyListOptions, new() + public abstract class BlockComponent : BaseComponent where TBlock : ContentBlock { #if NET6_0_OR_GREATER @@ -13,12 +12,17 @@ public abstract class BlockComponent : BaseCompon #endif [Parameter] public TBlock Block { get; set; } = null!; + } + public abstract class BlockComponent : BlockComponent + where TListOptions : BlazorBlocklyListOptions, new() + where TBlock : ContentBlock + { #if NET6_0_OR_GREATER [EditorRequired] #endif [Parameter] - public BlockListContext Context { get; set; } = null!; + public BlockListContext Context { get; set; } = null!; protected TListOptions ListOptions { get; set; } = new(); diff --git a/src/Sitko.Blockly.Blazor/Display/Blocks/CutBlockComponent.cs b/src/Sitko.Blockly.Blazor/Display/Blocks/CutBlockComponent.cs index 5c7cf5d..c6c783b 100644 --- a/src/Sitko.Blockly.Blazor/Display/Blocks/CutBlockComponent.cs +++ b/src/Sitko.Blockly.Blazor/Display/Blocks/CutBlockComponent.cs @@ -1,7 +1,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks { public abstract class - CutBlockComponent : BlockComponent + CutBlockComponent : BlockComponent where TListOptions : BlazorBlocklyListOptions, new() { } diff --git a/src/Sitko.Blockly.Blazor/Display/Blocks/FilesBlockComponent.cs b/src/Sitko.Blockly.Blazor/Display/Blocks/FilesBlockComponent.cs index 7940700..0f689d4 100644 --- a/src/Sitko.Blockly.Blazor/Display/Blocks/FilesBlockComponent.cs +++ b/src/Sitko.Blockly.Blazor/Display/Blocks/FilesBlockComponent.cs @@ -1,7 +1,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks { public abstract class - FilesBlockComponent : BlockComponent : BlockComponent where TListOptions : BlazorBlocklyListOptions, new() { } diff --git a/src/Sitko.Blockly.Blazor/Display/Blocks/GalleryBlockComponent.cs b/src/Sitko.Blockly.Blazor/Display/Blocks/GalleryBlockComponent.cs index 346e784..cdca1c4 100644 --- a/src/Sitko.Blockly.Blazor/Display/Blocks/GalleryBlockComponent.cs +++ b/src/Sitko.Blockly.Blazor/Display/Blocks/GalleryBlockComponent.cs @@ -1,7 +1,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks { public abstract class - GalleryBlockComponent : BlockComponent : BlockComponent where TListOptions : BlazorBlocklyListOptions, new() { } diff --git a/src/Sitko.Blockly.Blazor/Display/Blocks/IframeBlockComponent.cs b/src/Sitko.Blockly.Blazor/Display/Blocks/IframeBlockComponent.cs index 3b9013c..6fd354d 100644 --- a/src/Sitko.Blockly.Blazor/Display/Blocks/IframeBlockComponent.cs +++ b/src/Sitko.Blockly.Blazor/Display/Blocks/IframeBlockComponent.cs @@ -1,7 +1,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks { public abstract class - IframeBlockComponent : BlockComponent : BlockComponent where TListOptions : BlazorBlocklyListOptions, new() { } diff --git a/src/Sitko.Blockly.Blazor/Display/Blocks/QuoteBlockComponent.cs b/src/Sitko.Blockly.Blazor/Display/Blocks/QuoteBlockComponent.cs index 2698f04..d1718f3 100644 --- a/src/Sitko.Blockly.Blazor/Display/Blocks/QuoteBlockComponent.cs +++ b/src/Sitko.Blockly.Blazor/Display/Blocks/QuoteBlockComponent.cs @@ -1,7 +1,6 @@ namespace Sitko.Blockly.Blazor.Display.Blocks { - public abstract class QuoteBlockComponent : BlockComponent : BlockComponent where TListOptions : BlazorBlocklyListOptions, new() { } diff --git a/src/Sitko.Blockly.Blazor/Display/Blocks/TextBlockComponent.cs b/src/Sitko.Blockly.Blazor/Display/Blocks/TextBlockComponent.cs index 6fa8a93..e3234f0 100644 --- a/src/Sitko.Blockly.Blazor/Display/Blocks/TextBlockComponent.cs +++ b/src/Sitko.Blockly.Blazor/Display/Blocks/TextBlockComponent.cs @@ -1,7 +1,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks { public abstract class - TextBlockComponent : BlockComponent : BlockComponent where TListOptions : BlazorBlocklyListOptions, new() { } diff --git a/src/Sitko.Blockly.Blazor/Display/Blocks/TwitchBlockComponent.cs b/src/Sitko.Blockly.Blazor/Display/Blocks/TwitchBlockComponent.cs index 81169dc..11c959f 100644 --- a/src/Sitko.Blockly.Blazor/Display/Blocks/TwitchBlockComponent.cs +++ b/src/Sitko.Blockly.Blazor/Display/Blocks/TwitchBlockComponent.cs @@ -8,7 +8,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks using Sitko.Blazor.ScriptInjector; public abstract class - TwitchBlockComponent : BlockComponent : BlockComponent where TListOptions : BlazorBlocklyListOptions, new() { protected ElementReference ContainerRef { get; set; } diff --git a/src/Sitko.Blockly.Blazor/Display/Blocks/TwitterBlockComponent.cs b/src/Sitko.Blockly.Blazor/Display/Blocks/TwitterBlockComponent.cs index 71a1d73..d5e0734 100644 --- a/src/Sitko.Blockly.Blazor/Display/Blocks/TwitterBlockComponent.cs +++ b/src/Sitko.Blockly.Blazor/Display/Blocks/TwitterBlockComponent.cs @@ -8,7 +8,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks using Sitko.Blazor.ScriptInjector; public abstract class - TwitterBlockComponent : BlockComponent : BlockComponent where TListOptions : BlazorBlocklyListOptions, new() { protected ElementReference ContainerRef { get; set; } diff --git a/src/Sitko.Blockly.Blazor/Display/Blocks/YoutubeBlockComponent.cs b/src/Sitko.Blockly.Blazor/Display/Blocks/YoutubeBlockComponent.cs index 29bf35b..32f814f 100644 --- a/src/Sitko.Blockly.Blazor/Display/Blocks/YoutubeBlockComponent.cs +++ b/src/Sitko.Blockly.Blazor/Display/Blocks/YoutubeBlockComponent.cs @@ -1,7 +1,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks { public abstract class - YoutubeBlockComponent : BlockComponent : BlockComponent where TListOptions : BlazorBlocklyListOptions, new() { } diff --git a/src/Sitko.Blockly.Blazor/Display/BlocksList.cs b/src/Sitko.Blockly.Blazor/Display/BlocksList.cs index 6a0b8cb..18a19f5 100644 --- a/src/Sitko.Blockly.Blazor/Display/BlocksList.cs +++ b/src/Sitko.Blockly.Blazor/Display/BlocksList.cs @@ -9,20 +9,10 @@ namespace Sitko.Blockly.Blazor.Display { using JetBrains.Annotations; - public abstract class BlocksList : BaseComponent where TOptions : BlazorBlocklyListOptions, new() + public abstract class BlocksList : BaseComponent where TOptions : BlazorBlocklyListOptions, new() { #if NET6_0_OR_GREATER [EditorRequired] -#endif - [Parameter] - public TEntity Entity { get; set; } = default!; -#if NET6_0_OR_GREATER - [EditorRequired] -#endif - [Parameter] - public string EntityUrl { get; set; } = null!; -#if NET6_0_OR_GREATER - [EditorRequired] #endif [Parameter] public IEnumerable EntityBlocks { get; set; } = null!; @@ -54,21 +44,23 @@ protected override void Initialize() { base.Initialize(); BlockDescriptors = Blockly.Descriptors.ToArray(); - Context = new BlockListContext(Entity, EntityUrl, ListOptions.Mode); + if (Context is null) + { + throw new InvalidOperationException(LocalizationProvider["You must provide block list context"]); + } } - protected BlockListContext Context { get; private set; } = null!; +#if NET6_0_OR_GREATER + [EditorRequired] +#endif + [Parameter] + public BlockListContext? Context { get; set; } [PublicAPI] public RenderFragment RenderBlock(IBlazorBlockDescriptor blockDescriptor, ContentBlock block) => builder => { var component = blockDescriptor.DisplayComponent; - if (blockDescriptor.DisplayComponent.IsGenericTypeDefinition) - { - component = blockDescriptor.DisplayComponent.MakeGenericType(typeof(TEntity)); - } - builder.OpenComponent(0, component); builder.AddAttribute(1, "Block", block); builder.AddAttribute(2, "Context", Context); diff --git a/src/Sitko.Blockly/Display/BlockListContext.cs b/src/Sitko.Blockly/Display/BlockListContext.cs index 6ae7287..f5699fa 100644 --- a/src/Sitko.Blockly/Display/BlockListContext.cs +++ b/src/Sitko.Blockly/Display/BlockListContext.cs @@ -6,8 +6,5 @@ public enum BlocksListMode Full } - public record BlockListContext(BlocksListMode Mode); - - public record BlockListContext - (TEntity Entity, string EntityUrl, BlocksListMode Mode) : BlockListContext(Mode); + public record BlockListContext(string EntityUrl, BlocksListMode Mode); }