Skip to content

Commit ac8a933

Browse files
committed
Code TidyUp, fixed all warnings
1 parent f8eee28 commit ac8a933

11 files changed

Lines changed: 130 additions & 117 deletions

File tree

src/Sitecore.AspNetCore.SDK.Pages/Request/Handlers/GraphQL/GraphQLEditingServiceHandler.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Sitecore.AspNetCore.SDK.Pages.Request.Handlers.GraphQL;
2020
/// <summary>
2121
/// Initializes a new instance of the <see cref="GraphQLEditingServiceHandler"/> class.
2222
/// </summary>
23-
/// <param name="client">The GraphQL Client used for requests</param>
23+
/// <param name="client">The GraphQL Client used for requests.</param>
2424
/// <param name="logger">The <see cref="ILogger"/> to use for logging.</param>
2525
/// <param name="dictionaryService">DictionaryService used to return all dictionary items for a Sitecore site.</param>
2626
/// <param name="serializer">The serializer to handle response data.</param>
@@ -126,6 +126,7 @@ private static Placeholder ProcessPlaceholder(string name, string id, Placeholde
126126
{
127127
ProcessField(updatedFields, field);
128128
}
129+
129130
component.Fields = updatedFields;
130131

131132
// Add the component to the output
@@ -150,8 +151,7 @@ private static Placeholder ProcessPlaceholder(string name, string id, Placeholde
150151
placeholderValue,
151152
processedPlaceholder,
152153
component,
153-
placeholderKey
154-
));
154+
placeholderKey));
155155

156156
// Store the processed placeholder for later assignment
157157
component.Placeholders[placeholderKey] = processedPlaceholder;
@@ -204,15 +204,15 @@ private static void ProcessField(Dictionary<string, IFieldReader> updatedFields,
204204
{
205205
datasource = new
206206
{
207-
id = editableField?.MetaData?.DataSource?.Id,
208-
language = editableField?.MetaData?.DataSource?.Language,
209-
revision = editableField?.MetaData?.DataSource?.Revision,
210-
version = editableField?.MetaData?.DataSource?.Version
207+
id = editableField.MetaData?.DataSource?.Id,
208+
language = editableField.MetaData?.DataSource?.Language,
209+
revision = editableField.MetaData?.DataSource?.Revision,
210+
version = editableField.MetaData?.DataSource?.Version
211211
},
212-
title = editableField?.MetaData?.Title,
213-
fieldId = editableField?.MetaData?.FieldId,
214-
fieldType = editableField?.MetaData?.FieldType,
215-
rawValue = editableField?.MetaData?.RawValue
212+
title = editableField.MetaData?.Title,
213+
fieldId = editableField.MetaData?.FieldId,
214+
fieldType = editableField.MetaData?.FieldType,
215+
rawValue = editableField.MetaData?.RawValue
216216
};
217217

218218
editableField.OpeningChrome = GenerateEditableChrome("field", "open", string.Empty, JsonSerializer.Serialize(openingChromeContent));

src/Sitecore.AspNetCore.SDK.Pages/Request/Handlers/GraphQL/PlaceholderWorkItem.cs

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,50 @@
22

33
namespace Sitecore.AspNetCore.SDK.Pages.Request.Handlers.GraphQL;
44

5-
public partial class GraphQLEditingServiceHandler
5+
/// <summary>
6+
/// Represents a work item with associated features and output, optionally linked to a parent component.
7+
/// </summary>
8+
/// <param name="name">Specifies the name of the work item.</param>
9+
/// <param name="id">Defines a unique identifier for the work item.</param>
10+
/// <param name="features">Holds the features associated with the work item.</param>
11+
/// <param name="output">Contains the output related to the work item.</param>
12+
/// <param name="parentComponent">Links to a parent component if applicable.</param>
13+
/// <param name="placeholderKey">Provides an optional key for placeholder identification.</param>
14+
public class PlaceholderWorkItem(
15+
string name,
16+
string id,
17+
Placeholder features,
18+
Placeholder output,
19+
Component? parentComponent = null,
20+
string? placeholderKey = null)
621
{
7-
// Define the work item class outside of the method to avoid nested class issues
8-
private class PlaceholderWorkItem
9-
{
10-
public string Name { get; }
11-
public string Id { get; }
12-
public Placeholder Features { get; }
13-
public Placeholder Output { get; }
14-
public Component ParentComponent { get; }
15-
public string PlaceholderKey { get; }
22+
/// <summary>
23+
/// Gets the name of an entity. It is a read-only property initialized with the value of the 'name' variable.
24+
/// </summary>
25+
public string Name { get; } = name;
1626

17-
public PlaceholderWorkItem(
18-
string name,
19-
string id,
20-
Placeholder features,
21-
Placeholder output,
22-
Component parentComponent = null,
23-
string placeholderKey = null)
24-
{
25-
Name = name;
26-
Id = id;
27-
Features = features;
28-
Output = output;
29-
ParentComponent = parentComponent;
30-
PlaceholderKey = placeholderKey;
31-
}
32-
}
33-
}
27+
/// <summary>
28+
/// Gets the unique identifier as a read-only string property. It is initialized with the value of 'id'.
29+
/// </summary>
30+
public string Id { get; } = id;
31+
32+
/// <summary>
33+
/// Gets the collection of features. It is a read-only property that initializes with the value of 'features'.
34+
/// </summary>
35+
public Placeholder Features { get; } = features;
36+
37+
/// <summary>
38+
/// Gets the output placeholder. It is a read-only property initialized with the value of 'output'.
39+
/// </summary>
40+
public Placeholder Output { get; } = output;
41+
42+
/// <summary>
43+
/// Gets the parent component of the current component. It is a read-only property initialized with the provided parentComponent.
44+
/// </summary>
45+
public Component? ParentComponent { get; } = parentComponent;
46+
47+
/// <summary>
48+
/// Gets the read-only property that returns the value of the placeholderKey variable. It is used to access a specific key for placeholders.
49+
/// </summary>
50+
public string? PlaceholderKey { get; } = placeholderKey;
51+
}

src/Sitecore.AspNetCore.SDK.Pages/TagHelpers/EditingScriptsTagHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class EditingScriptsTagHelper : TagHelper
2323
public ViewContext? ViewContext { get; set; }
2424

2525
/// <inheritdoc />
26-
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
26+
public override void Process(TagHelperContext context, TagHelperOutput output)
2727
{
2828
ISitecoreRenderingContext renderingContext = ViewContext?.HttpContext.GetSitecoreRenderingContext() ??
2929
throw new NullReferenceException(Resources.Exception_EditingScriptsTagHelperSitecoreRenderingContextNull);

src/Sitecore.AspNetCore.SDK.RenderingEngine/TagHelpers/Fields/LinkTagHelper.cs

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -75,73 +75,6 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
7575
}
7676
}
7777

78-
private void RenderMarkup(TagHelperOutput output, HyperLinkField field)
79-
{
80-
if (output.TagName == null)
81-
{
82-
output.Content.SetHtmlContent(GenerateLink(field.Value, output));
83-
}
84-
else
85-
{
86-
HyperLink hyperLink = field.Value;
87-
88-
output.Attributes.Add(HrefAttribute, BuildHref(hyperLink));
89-
90-
if (!string.IsNullOrWhiteSpace(hyperLink.Target) && !output.Attributes.ContainsName(TargetAttribute))
91-
{
92-
output.Attributes.Add(TargetAttribute, hyperLink.Target);
93-
}
94-
95-
if (!string.IsNullOrWhiteSpace(hyperLink.Title) && !output.Attributes.ContainsName(TitleAttribute))
96-
{
97-
output.Attributes.Add(TitleAttribute, hyperLink.Title);
98-
}
99-
100-
if (!string.IsNullOrWhiteSpace(hyperLink.Class) && !output.Attributes.ContainsName(ClassAttribute))
101-
{
102-
output.Attributes.Add(ClassAttribute, hyperLink.Class);
103-
}
104-
105-
if (hyperLink.Target == BlankValue && !output.Attributes.ContainsName(RelAttribute))
106-
{
107-
// information disclosure attack prevention keeps target blank site from getting ref to window.opener
108-
output.Attributes.Add(RelAttribute, "noopener noreferrer");
109-
}
110-
111-
string? innerContent = output.GetChildContentAsync()?.Result?.GetContent();
112-
if (string.IsNullOrWhiteSpace(innerContent) && !string.IsNullOrWhiteSpace(hyperLink.Text))
113-
{
114-
output.Content.Append(field.Value.Text);
115-
}
116-
}
117-
}
118-
119-
private void RenderEditableMarkup(TagHelperOutput output, HyperLinkField field)
120-
{
121-
if (field.OpeningChrome != null && field.ClosingChrome != null)
122-
{
123-
output.Content.AppendHtml(chromeRenderer.Render(field.OpeningChrome));
124-
125-
if (field.Value.Href == string.Empty)
126-
{
127-
output.Content.AppendHtml("<span tabindex=\"0\" style=\"cursor: pointer;\">[No text in field]</span>");
128-
}
129-
else
130-
{
131-
output.Content.AppendHtml(GenerateLink(field.Value, output));
132-
}
133-
134-
output.Content.AppendHtml(chromeRenderer.Render(field.ClosingChrome));
135-
}
136-
else
137-
{
138-
DefaultTagHelperContent content = new();
139-
_ = content.AppendHtml(new HtmlString(field.EditableMarkupFirst));
140-
_ = content.AppendHtml(new HtmlString(field.EditableMarkupLast));
141-
output.Content.SetHtmlContent(content);
142-
}
143-
}
144-
14578
/// <summary>
14679
/// Generates anchor HTML tag.
14780
/// </summary>
@@ -221,4 +154,71 @@ private static string BuildHref(HyperLink hyperLink)
221154

222155
return sb.ToString();
223156
}
157+
158+
private void RenderMarkup(TagHelperOutput output, HyperLinkField field)
159+
{
160+
if (output.TagName == null)
161+
{
162+
output.Content.SetHtmlContent(GenerateLink(field.Value, output));
163+
}
164+
else
165+
{
166+
HyperLink hyperLink = field.Value;
167+
168+
output.Attributes.Add(HrefAttribute, BuildHref(hyperLink));
169+
170+
if (!string.IsNullOrWhiteSpace(hyperLink.Target) && !output.Attributes.ContainsName(TargetAttribute))
171+
{
172+
output.Attributes.Add(TargetAttribute, hyperLink.Target);
173+
}
174+
175+
if (!string.IsNullOrWhiteSpace(hyperLink.Title) && !output.Attributes.ContainsName(TitleAttribute))
176+
{
177+
output.Attributes.Add(TitleAttribute, hyperLink.Title);
178+
}
179+
180+
if (!string.IsNullOrWhiteSpace(hyperLink.Class) && !output.Attributes.ContainsName(ClassAttribute))
181+
{
182+
output.Attributes.Add(ClassAttribute, hyperLink.Class);
183+
}
184+
185+
if (hyperLink.Target == BlankValue && !output.Attributes.ContainsName(RelAttribute))
186+
{
187+
// information disclosure attack prevention keeps target blank site from getting ref to window.opener
188+
output.Attributes.Add(RelAttribute, "noopener noreferrer");
189+
}
190+
191+
string? innerContent = output.GetChildContentAsync()?.Result?.GetContent();
192+
if (string.IsNullOrWhiteSpace(innerContent) && !string.IsNullOrWhiteSpace(hyperLink.Text))
193+
{
194+
output.Content.Append(field.Value.Text);
195+
}
196+
}
197+
}
198+
199+
private void RenderEditableMarkup(TagHelperOutput output, HyperLinkField field)
200+
{
201+
if (field.OpeningChrome != null && field.ClosingChrome != null)
202+
{
203+
output.Content.AppendHtml(chromeRenderer.Render(field.OpeningChrome));
204+
205+
if (field.Value.Href == string.Empty)
206+
{
207+
output.Content.AppendHtml("<span tabindex=\"0\" style=\"cursor: pointer;\">[No text in field]</span>");
208+
}
209+
else
210+
{
211+
output.Content.AppendHtml(GenerateLink(field.Value, output));
212+
}
213+
214+
output.Content.AppendHtml(chromeRenderer.Render(field.ClosingChrome));
215+
}
216+
else
217+
{
218+
DefaultTagHelperContent content = new();
219+
_ = content.AppendHtml(new HtmlString(field.EditableMarkupFirst));
220+
_ = content.AppendHtml(new HtmlString(field.EditableMarkupLast));
221+
output.Content.SetHtmlContent(content);
222+
}
223+
}
224224
}

tests/Sitecore.AspNetCore.SDK.GraphQL.Tests/Request/GraphQLHttpRequestWithHeadersFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class GraphQLHttpRequestWithHeadersFixture
1515
[ExcludeFromCodeCoverage]
1616
public static Action<IFixture> AutoSetup => f =>
1717
{
18-
GraphQLHttpClientOptions options = Substitute.For<GraphQLHttpClientOptions> ();
18+
GraphQLHttpClientOptions options = Substitute.For<GraphQLHttpClientOptions>();
1919
f.Inject(options);
2020

2121
IGraphQLJsonSerializer serializer = Substitute.For<IGraphQLJsonSerializer>();

tests/Sitecore.AspNetCore.SDK.Pages.Tests/Controllers/PagesSetupControllerFixture.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ public class PagesSetupControllerFixture
3434
f.Inject(requestDelegate);
3535

3636
IOptions<PagesOptions> pagesOptions = Substitute.For<IOptions<PagesOptions>>();
37-
PagesOptions PagesOptionsValues = new PagesOptions
37+
PagesOptions pagesOptionsValues = new PagesOptions
3838
{
3939
ConfigEndpoint = ValidConfigEndpoint,
4040
RenderEndpoint = ValidRenderEndpoint,
4141
ValidEditingOrigin = ValidEditingOrigin,
4242
ValidOrigins = ValidOrigins,
4343
EditingSecret = ValidEditingSecret
4444
};
45-
pagesOptions.Value.Returns(PagesOptionsValues);
45+
pagesOptions.Value.Returns(pagesOptionsValues);
4646
f.Inject(pagesOptions);
4747

4848
ILogger<PagesSetupController> logger = Substitute.For<ILogger<PagesSetupController>>();
4949
f.Inject(logger);
5050

51-
IOptions<RenderingEngineOptions > renderingEngineOptions = Substitute.For<IOptions<RenderingEngineOptions>>();
51+
IOptions<RenderingEngineOptions> renderingEngineOptions = Substitute.For<IOptions<RenderingEngineOptions>>();
5252
string componentName = "TestComponent";
5353
ComponentRendererDescriptor componentRendererDescriptor = new(name => name == componentName, _ => null!, componentName);
5454
RenderingEngineOptions renderingEngineOptionsValues = new RenderingEngineOptions
@@ -57,7 +57,6 @@ public class PagesSetupControllerFixture
5757
{
5858
{ 1, componentRendererDescriptor }
5959
}
60-
6160
};
6261
renderingEngineOptions.Value.Returns(renderingEngineOptionsValues);
6362
f.Inject(renderingEngineOptions);

tests/Sitecore.AspNetCore.SDK.Pages.Tests/Request/Handlers/GraphQL/GraphQLEditingServiceHandlerFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class GraphQLEditingServiceHandlerFixture
3737
SitecoreLayoutRequest request = new()
3838
{
3939
{
40-
"sc_request_headers_key" , new Dictionary<string, string[]>()
40+
"sc_request_headers_key", new Dictionary<string, string[]>()
4141
{
4242
{ "mode", ["edit"] },
4343
{ "language", ["en"] },
@@ -118,7 +118,7 @@ public async Task Request_NoLanguageSet_ErrorThrown(GraphQLEditingServiceHandler
118118
SitecoreLayoutRequest request = new SitecoreLayoutRequest
119119
{
120120
{
121-
"sc_request_headers_key" , new Dictionary<string, string[]>()
121+
"sc_request_headers_key", new Dictionary<string, string[]>()
122122
{
123123
{ "mode", ["edit"] }
124124
}

tests/Sitecore.AspNetCore.SDK.Pages.Tests/Services/Constants.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,5 @@ public static GraphQLResponse<EditingDictionaryResponse> DictionaryResponseWithP
7474
};
7575
}
7676
}
77-
7877
}
7978
}

tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/LinkTagHelperFixture.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,6 @@ public void Process_AnchorLinkTagWithAnchor_AddsAnchorToHrefAttribute(
784784
}
785785
#endregion
786786

787-
788787
[Theory]
789788
[AutoNSubstituteData]
790789
public void Process_RenderingChromesAreNotNull_ChromesAreOutput(

tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/RichTextTagHelperFixture.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ public void Process_DivTagWithEditableFieldAndEditableSetToFalseAndTextAttribute
708708

709709
#endregion
710710

711-
712711
[Theory]
713712
[AutoNSubstituteData]
714713
public void Process_RenderingChromesAreNotNull_ChromesAreOutput(

0 commit comments

Comments
 (0)