Skip to content

Commit

Permalink
Do not convert IShape to dynamic (#15622)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Mar 29, 2024
1 parent 8fba42a commit 42a2e0a
Show file tree
Hide file tree
Showing 35 changed files with 165 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ private async Task<AdminNodeListViewModel> BuildDisplayViewModel(Models.AdminMen
foreach (var factory in _factories)
{
var treeNode = factory.Create();
dynamic thumbnail = await _displayManager.BuildDisplayAsync(treeNode, _updateModelAccessor.ModelUpdater, "TreeThumbnail");
thumbnail.TreeNode = treeNode;
var thumbnail = await _displayManager.BuildDisplayAsync(treeNode, _updateModelAccessor.ModelUpdater, "TreeThumbnail");
thumbnail.Properties["TreeNode"] = treeNode;
thumbnails.Add(factory.Name, thumbnail);
}

Expand Down Expand Up @@ -138,8 +138,8 @@ public async Task<IActionResult> Create(AdminNodeEditViewModel model)
return NotFound();
}

dynamic editor = await _displayManager.UpdateEditorAsync(treeNode, updater: _updateModelAccessor.ModelUpdater, isNew: true, "", "");
editor.TreeNode = treeNode;
var editor = await _displayManager.UpdateEditorAsync(treeNode, updater: _updateModelAccessor.ModelUpdater, isNew: true, "", "");
editor.Properties["TreeNode"] = treeNode;

if (ModelState.IsValid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@

@foreach (var child in children)
{
dynamic adminNodeShape = await MenuItemDisplayManager.BuildDisplayAsync(child, updater, "TreeSummary");
adminNodeShape.AdminMenuId = Model.AdminMenuId;
adminNodeShape.MenuItem = child;
adminNodeShape.Index = Model.Index + "-" + index++;
var adminNodeShape = await MenuItemDisplayManager.BuildDisplayAsync(child, updater, "TreeSummary");
adminNodeShape.Properties["AdminMenuId"] = Model.AdminMenuId;
adminNodeShape.Properties["MenuItem"] = child;
adminNodeShape.Properties["Index"] = Model.Index + "-" + index++;
@await DisplayAsync(adminNodeShape);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
{
if (menuItem != null)
{
dynamic adminNodeShape = await MenuItemDisplayManager.BuildDisplayAsync(menuItem, updater, "TreeSummary");
adminNodeShape.AdminMenuId = Model.AdminMenu.Id;
adminNodeShape.MenuItem = menuItem;
adminNodeShape.Index = index++;
var adminNodeShape = await MenuItemDisplayManager.BuildDisplayAsync(menuItem, updater, "TreeSummary");
adminNodeShape.Properties["AdminMenuId"] = Model.AdminMenu.Id;
adminNodeShape.Properties["MenuItem"] = menuItem;
adminNodeShape.Properties["Index"] = index++;

@await DisplayAsync(adminNodeShape)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public async Task<dynamic> BuildTypeEditorAsync(ContentTypeDefinition contentTyp
{
ArgumentNullException.ThrowIfNull(contentTypeDefinition);

dynamic contentTypeDefinitionShape = await CreateContentShapeAsync("ContentTypeDefinition_Edit");
contentTypeDefinitionShape.ContentTypeDefinition = contentTypeDefinition;
var contentTypeDefinitionShape = await CreateContentShapeAsync("ContentTypeDefinition_Edit");
contentTypeDefinitionShape.Properties["ContentTypeDefinition"] = contentTypeDefinition;

var typeContext = new BuildEditorContext(
contentTypeDefinitionShape,
Expand All @@ -68,8 +68,8 @@ public async Task<dynamic> UpdateTypeEditorAsync(ContentTypeDefinition contentTy
{
ArgumentNullException.ThrowIfNull(contentTypeDefinition);

dynamic contentTypeDefinitionShape = await CreateContentShapeAsync("ContentTypeDefinition_Edit");
contentTypeDefinitionShape.ContentTypeDefinition = contentTypeDefinition;
var contentTypeDefinitionShape = await CreateContentShapeAsync("ContentTypeDefinition_Edit");
contentTypeDefinitionShape.Properties["ContentTypeDefinition"] = contentTypeDefinition;

var layout = await _layoutAccessor.GetLayoutAsync();

Expand Down Expand Up @@ -149,8 +149,8 @@ public async Task<dynamic> BuildTypePartEditorAsync(ContentTypePartDefinition co
{
ArgumentNullException.ThrowIfNull(contentTypePartDefinition);

dynamic typePartDefinitionShape = await CreateContentShapeAsync("ContentTypePartDefinition_Edit");
typePartDefinitionShape.ContentPart = contentTypePartDefinition;
var typePartDefinitionShape = await CreateContentShapeAsync("ContentTypePartDefinition_Edit");
typePartDefinitionShape.Properties["ContentPart"] = contentTypePartDefinition;

var partContext = new BuildEditorContext(
typePartDefinitionShape,
Expand All @@ -173,14 +173,14 @@ public async Task<dynamic> UpdateTypePartEditorAsync(ContentTypePartDefinition c
{
ArgumentNullException.ThrowIfNull(contentTypePartDefinition);

dynamic typePartDefinitionShape = await CreateContentShapeAsync("ContentTypePartDefinition_Edit");
var typePartDefinitionShape = await CreateContentShapeAsync("ContentTypePartDefinition_Edit");
var layout = await _layoutAccessor.GetLayoutAsync();

await _contentDefinitionManager.AlterTypeDefinitionAsync(contentTypePartDefinition.ContentTypeDefinition.Name, typeBuilder =>
{
return typeBuilder.WithPartAsync(contentTypePartDefinition.Name, async typePartBuilder =>
{
typePartDefinitionShape.ContentPart = contentTypePartDefinition;
typePartDefinitionShape.Properties["ContentPart"] = contentTypePartDefinition;

var partContext = new UpdateTypePartEditorContext(
typePartBuilder,
Expand All @@ -205,8 +205,8 @@ public async Task<dynamic> BuildPartFieldEditorAsync(ContentPartFieldDefinition
{
ArgumentNullException.ThrowIfNull(contentPartFieldDefinition);

dynamic partFieldDefinitionShape = await CreateContentShapeAsync("ContentPartFieldDefinition_Edit");
partFieldDefinitionShape.ContentField = contentPartFieldDefinition;
var partFieldDefinitionShape = await CreateContentShapeAsync("ContentPartFieldDefinition_Edit");
partFieldDefinitionShape.Properties["ContentField"] = contentPartFieldDefinition;

var fieldContext = new BuildEditorContext(
partFieldDefinitionShape,
Expand All @@ -230,15 +230,15 @@ public async Task<dynamic> UpdatePartFieldEditorAsync(ContentPartFieldDefinition
ArgumentNullException.ThrowIfNull(contentPartFieldDefinition);

var contentPartDefinition = contentPartFieldDefinition.PartDefinition;
dynamic partFieldDefinitionShape = await CreateContentShapeAsync("ContentPartFieldDefinition_Edit");
var partFieldDefinitionShape = await CreateContentShapeAsync("ContentPartFieldDefinition_Edit");

var layout = await _layoutAccessor.GetLayoutAsync();

await _contentDefinitionManager.AlterPartDefinitionAsync(contentPartDefinition.Name, partBuilder =>
{
return partBuilder.WithFieldAsync(contentPartFieldDefinition.Name, async partFieldBuilder =>
{
partFieldDefinitionShape.ContentField = contentPartFieldDefinition;
partFieldDefinitionShape.Properties["ContentField"] = contentPartFieldDefinition;

var fieldContext = new UpdatePartFieldEditorContext(
partFieldBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
<select asp-for="Editor" class="form-select" id="field-editor-select">
@foreach (var editorShape in editorShapes)
{
dynamic shape = await Factory.CreateAsync(editorShape);
shape.Editor = Model.Editor;
var shape = await Factory.CreateAsync(editorShape);
shape.Properties["Editor"] = Model.Editor;
@await DisplayAsync(shape)
}
</select>
Expand All @@ -75,8 +75,8 @@
<select asp-for="DisplayMode" class="form-select" id="field-display-select">
@foreach (var displayShape in displayShapes)
{
dynamic shape = await Factory.CreateAsync(displayShape);
shape.DisplayMode = Model.DisplayMode;
var shape = await Factory.CreateAsync(displayShape);
shape.Properties["DisplayMode"] = Model.DisplayMode;
@await DisplayAsync(shape)
}
</select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
<select asp-for="Editor" class="form-select" id="type-part-editor-select">
@foreach (var editorShape in editorShapes)
{
dynamic shape = await Factory.CreateAsync(editorShape);
shape.Editor = Model.Editor;
var shape = await Factory.CreateAsync(editorShape);
shape.Properties["Editor"] = Model.Editor;
@await DisplayAsync(shape)
}
</select>
Expand All @@ -80,8 +80,8 @@
<select asp-for="DisplayMode" class="form-select" id="type-part-display-select">
@foreach (var displayShape in displayShapes)
{
dynamic shape = await Factory.CreateAsync(displayShape);
shape.DisplayMode = Model.DisplayMode;
var shape = await Factory.CreateAsync(displayShape);
shape.Properties["DisplayMode"] = Model.DisplayMode;
@await DisplayAsync(shape)
}
</select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public async Task<IActionResult> List(
? pagerOptions.Value.MaxPagedCount
: await query.CountAsync();

dynamic pagerShape = await shapeFactory.PagerAsync(pager, itemsPerPage, options.RouteValues);
var pagerShape = await shapeFactory.PagerAsync(pager, itemsPerPage, options.RouteValues);

// Load items so that loading handlers are invoked.
var pageOfContentItems = await query.Skip(pager.GetStartIndex())
Expand All @@ -207,11 +207,11 @@ public async Task<IActionResult> List(
}

// Populate options pager summary values.
var startIndex = (pagerShape.Page - 1) * pagerShape.PageSize + 1;
var startIndex = (pager.Page - 1) * pager.PageSize + 1;
options.StartIndex = startIndex;
options.EndIndex = startIndex + contentItemSummaries.Count - 1;
options.ContentItemsCount = contentItemSummaries.Count;
options.TotalItemCount = pagerShape.TotalItemCount;
options.TotalItemCount = itemsPerPage;

var header = await _contentOptionsDisplayManager.BuildEditorAsync(options, this, false, string.Empty, string.Empty);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
</button>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="bulk-action-menu-button">
@{
dynamic bulkActions = await ContentOptionsDisplayManager.BuildDisplayAsync(Model, null, "BulkActions");
@await DisplayAsync(bulkActions.Content)
var bulkActions = await ContentOptionsDisplayManager.BuildDisplayAsync(Model, null, "BulkActions");
if (bulkActions.TryGetProperty<IShape>("Content", out var content))
{
@await DisplayAsync(content)
}
}
</ul>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public override IDisplayResult Display(ContentItem contentItem, IUpdateModel upd
async ctx => (await ctx.New.TestContentPartA()).Creating(_creating++),
shape =>
{
((dynamic)shape).Processing = _processing++;
shape.Properties["Processing"] = _processing++;

return Task.CompletedTask;
})
.Location("Detail", "Content")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@await DisplayAsync(Model)

@*
We can still call the DisplHelper with methods
We can still call the DisplayHelper with methods
*@
@await New.Bar()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ public async Task<IActionResult> Display(long id)
var items = new List<dynamic>();
foreach (var step in deploymentPlan.DeploymentSteps)
{
dynamic item = await _displayManager.BuildDisplayAsync(step, _updateModelAccessor.ModelUpdater, "Summary");
item.DeploymentStep = step;
var item = await _displayManager.BuildDisplayAsync(step, _updateModelAccessor.ModelUpdater, "Summary");
item.Properties["DeploymentStep"] = step;
items.Add(item);
}

var thumbnails = new Dictionary<string, dynamic>();
foreach (var factory in _factories)
{
var step = factory.Create();
dynamic thumbnail = await _displayManager.BuildDisplayAsync(step, _updateModelAccessor.ModelUpdater, "Thumbnail");
thumbnail.DeploymentStep = step;
var thumbnail = await _displayManager.BuildDisplayAsync(step, _updateModelAccessor.ModelUpdater, "Thumbnail");
thumbnail.Properties["DeploymentStep"] = step;
thumbnails.Add(factory.Name, thumbnail);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public async Task<IActionResult> Create(EditDeploymentPlanStepViewModel model)
return NotFound();
}

dynamic editor = await _displayManager.UpdateEditorAsync(step, updater: _updateModelAccessor.ModelUpdater, isNew: true, "", "");
editor.DeploymentStep = step;
var editor = await _displayManager.UpdateEditorAsync(step, updater: _updateModelAccessor.ModelUpdater, isNew: true, string.Empty, string.Empty);
editor.Properties["DeploymentStep"] = step;

if (ModelState.IsValid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task<IActionResult> BuildEditor(string id, string prefix, string pr
}

// Create a Card Shape
dynamic contentCard = await _shapeFactory.New.ContentCard(
var contentCard = await _shapeFactory.New.ContentCard(
// Updater is the controller for AJAX Requests
Updater: _updateModelAccessor.ModelUpdater,
// Shape Specific
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,16 @@ public async Task<IActionResult> Edit(string name)
return NotFound();
}

dynamic rule = await _ruleDisplayManager.BuildDisplayAsync(layer.LayerRule, _updateModelAccessor.ModelUpdater, "Summary");
rule.ConditionId = layer.LayerRule.ConditionId;
var rule = await _ruleDisplayManager.BuildDisplayAsync(layer.LayerRule, _updateModelAccessor.ModelUpdater, "Summary");
rule.Properties["ConditionId"] = layer.LayerRule.ConditionId;

var thumbnails = new Dictionary<string, dynamic>();
foreach (var factory in _conditionFactories)
{
var condition = factory.Create();
dynamic thumbnail = await _conditionDisplayManager.BuildDisplayAsync(condition, _updateModelAccessor.ModelUpdater, "Thumbnail");
thumbnail.Condition = condition;
thumbnail.TargetUrl = Url.ActionLink("Create", "LayerRule", new { name, type = factory.Name });
var thumbnail = await _conditionDisplayManager.BuildDisplayAsync(condition, _updateModelAccessor.ModelUpdater, "Thumbnail");
thumbnail.Properties["Condition"] = condition;
thumbnail.Properties["TargetUrl"] = Url.ActionLink("Create", "LayerRule", new { name, type = factory.Name });
thumbnails.Add(factory.Name, thumbnail);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public async Task<IActionResult> Create(string id, string menuContentItemId, str

var contentItem = await _contentManager.NewAsync(id);

dynamic model = await _contentItemDisplayManager.BuildEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, true);
var model = await _contentItemDisplayManager.BuildEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, true);

model.MenuContentItemId = menuContentItemId;
model.MenuItemId = menuItemId;
model.Properties["MenuContentItemId"] = menuContentItemId;
model.Properties["MenuItemId"] = menuItemId;

return View(model);
}
Expand Down Expand Up @@ -100,12 +100,12 @@ public async Task<IActionResult> CreatePost(string id, string menuContentItemId,

var contentItem = await _contentManager.NewAsync(id);

dynamic model = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, true);
var model = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, true);

if (!ModelState.IsValid)
{
model.MenuContentItemId = menuContentItemId;
model.MenuItemId = menuItemId;
model.Properties["MenuContentItemId"] = menuContentItemId;
model.Properties["MenuItemId"] = menuItemId;

return View(model);
}
Expand Down Expand Up @@ -169,10 +169,10 @@ public async Task<IActionResult> Edit(string menuContentItemId, string menuItemI

var contentItem = menuItem.ToObject<ContentItem>();

dynamic model = await _contentItemDisplayManager.BuildEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false);
var model = await _contentItemDisplayManager.BuildEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false);

model.MenuContentItemId = menuContentItemId;
model.MenuItemId = menuItemId;
model.Properties["MenuContentItemId"] = menuContentItemId;
model.Properties["MenuItemId"] = menuItemId;

return View(model);
}
Expand Down Expand Up @@ -220,12 +220,12 @@ public async Task<IActionResult> EditPost(string menuContentItemId, string menuI

contentItem.Merge(existing);

dynamic model = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false);
var model = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false);

if (!ModelState.IsValid)
{
model.MenuContentItemId = menuContentItemId;
model.MenuItemId = menuItemId;
model.Properties["MenuContentItemId"] = menuContentItemId;
model.Properties["MenuItemId"] = menuItemId;

return View(model);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@
<ol class="menu-item menu-item-links">
@foreach (var menuItem in menuItems.MenuItems)
{

dynamic menuItemShape = await ContentItemDisplayManager.BuildDisplayAsync(menuItem, updater, "Admin");
menuItemShape.MenuPart = Model.MenuPart;
menuItemShape.Index = Model.Index + "-" + index++;
var menuItemShape = await ContentItemDisplayManager.BuildDisplayAsync(menuItem, updater, "Admin");
menuItemShape.Properties["MenuPart"] = Model.MenuPart;
menuItemShape.Properties["Index"] = Model.Index + "-" + index++;
@await DisplayAsync(menuItemShape)
}
</ol>
Expand Down
Loading

0 comments on commit 42a2e0a

Please sign in to comment.