Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit bbe2a7b

Browse files
committed
cleanup component selection
1 parent ad7a402 commit bbe2a7b

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/Our.Umbraco.DocTypeGridEditor/Helpers/DocTypeGridEditorHelper.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,8 @@ public IHtmlContent RenderDocTypeGridEditorItem(
242242
return new HtmlString($"<pre>could not get viewpath. {editorAlias}, {content.ContentType.Alias}, {viewPath}, {previewViewPath}, {isPreview}, {fullViewPath}</pre>");
243243
}
244244

245-
var renderParams = new { model = content, viewPath = fullViewPath };
246-
var viewComponent = _options.DefaultDocTypeGridEditorViewComponent;
247-
248-
if (!TryGetComponentName(new[] { editorAlias, content.ContentType.Alias }, out string componentName))
249-
{
250-
return new HtmlString($"<pre>could not get componentName. {editorAlias}, {content.ContentType.Alias}, {componentName}</pre>");
251-
252-
}
253-
254-
return helper.InvokeAsync(componentName, renderParams).Result;
245+
var componentName = GetComponentName(new[] { editorAlias, content.ContentType.Alias });
246+
return helper.InvokeAsync(componentName, new { model = content, viewPath = fullViewPath }).Result;
255247
}
256248

257249
private bool TryGetViewPath(ViewContext viewContext, string editorAlias, string contentTypeAlias, string viewPath, string previewViewPath, bool isPreview, out string fullViewPath)
@@ -296,19 +288,19 @@ private bool TryGetViewPath(ViewContext viewContext, string editorAlias, string
296288
return !fullViewPath.IsNullOrWhiteSpace();
297289
}
298290

299-
private bool TryGetComponentName(string[] names, out string componentName)
291+
private string GetComponentName(string[] names)
300292
{
301-
componentName = "";
293+
var componentName = _options.DefaultDocTypeGridEditorViewComponent.Name;
294+
if (componentName.EndsWith("ViewComponent")) componentName = componentName.Substring(0, componentName.LastIndexOf("ViewComponent"));
302295
foreach (var name in names)
303296
{
304-
Console.WriteLine($"getting component name for {name}");
305297
if (_viewComponentSelector.SelectComponent($"{name}DocTypeGridEditor") != null)
306298
{
307-
componentName = $"{name}DocTypeGridEditor";
308-
return true;
299+
return $"{name}DocTypeGridEditor";
309300
}
310301
}
311-
return false;
302+
303+
return componentName;
312304
}
313305

314306
public static bool ViewExists(ViewContext viewContext, string viewName)

0 commit comments

Comments
 (0)