Skip to content

Commit 7f027c6

Browse files
committed
Support RelativeTopicBase with new topics
Previously, the `TopicList`'s `RelativeTopicBase` would work incorrectly with new topics since `ITopicRepository.Load()` would load the _parent_ context's `UniqueKey`, and thus it would return content relative to the _parent_, not the new topic. This is mitigated by temporarily creating a placeholder topic in the topic graph that can be used as the relative base. This placeholder topic must be removed from the parent's `Children` collection, as otherwise it will persist in memory, interfere with future attempts to create new children, and potentially even end up getting persisted to the database under certain circumstances (such as a recursive `Save()` triggered by an `Import()`).
1 parent 9ecf880 commit 7f027c6

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

OnTopic.Editor.AspNetCore/Components/TopicListViewComponent.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public IViewComponentResult Invoke(
9494
if (attribute.RelativeTopicBase != null) {
9595
var baseTopic = _topicRepository.Load(currentTopic.UniqueKey);
9696
var rootTopic = attribute.RelativeTopicBase switch {
97+
if (String.IsNullOrEmpty(currentTopic.Key)) {
98+
baseTopic = TopicFactory.Create("NewTopic", currentTopic.ContentType, baseTopic);
99+
baseTopic.Parent.Children.Remove(baseTopic);
100+
}
97101
"CurrentTopic" => baseTopic,
98102
"ParentTopic" => baseTopic.Parent,
99103
"GrandparentTopic" => (Topic)baseTopic.Parent?.Parent,

0 commit comments

Comments
 (0)