Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue with .order files not being applied if the path containing a hyphen #35

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions TRENZ.Docs.API/Services/NavNodeOrderingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public NavNodeOrderingService(ISourcesProvider sourcesProvider,

public async Task ReorderTreeAsync(NavTree tree, CancellationToken cancellationToken = default)
{
_logger.LogDebug("Reordering tree...");

var orderFiles = _sourcesProvider.GetSources()
.SelectMany(source => source.FindFiles(new("\\.order")))
.ToDictionary(sf => sf.RelativePath.Split(Path.DirectorySeparatorChar)[..^1],
.ToDictionary(sf => NavNode.PathToLocation(sf.RelativePath).Split(NavNode.Separator)[..^1],
sf => sf);

var i = 0;
Expand All @@ -31,6 +33,8 @@ public async Task ReorderTreeAsync(NavTree tree, CancellationToken cancellationT
}

await SetChildrenOrderByOrderFile(Array.Empty<string>(), tree.Root.Values, orderFiles, cancellationToken);

_logger.LogDebug("Reordering done");
}

private async Task SetOrderByParent(NavNode node, Dictionary<string[], ISourceFile> orderFiles, int index, CancellationToken cancellationToken)
Expand All @@ -49,7 +53,7 @@ private async Task SetOrderByParent(NavNode node, Dictionary<string[], ISourceFi
await SetChildrenOrderByOrderFile(node.LocationParts, node.Children.Values, orderFiles, cancellationToken);
}

private async Task SetChildrenOrderByOrderFile(IEnumerable<string> pathParts,
private async Task SetChildrenOrderByOrderFile(IEnumerable<string> locationParts,
IEnumerable<NavNode> children,
chucker marked this conversation as resolved.
Show resolved Hide resolved
Dictionary<string[], ISourceFile> orderFiles,
CancellationToken cancellationToken = default)
Expand All @@ -58,7 +62,7 @@ private async Task SetChildrenOrderByOrderFile(IEnumerable<string> pathParts,
return;

// if this particular folder has a .order, override the order
var orderFile = orderFiles.SingleOrDefault(of => of.Key.SequenceEqual(pathParts));
var orderFile = orderFiles.SingleOrDefault(of => of.Key.SequenceEqual(locationParts));

if (orderFile.Value == null)
return;
Expand Down
12 changes: 11 additions & 1 deletion TRENZ.Docs.API/Services/NavTreeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ namespace TRENZ.Docs.API.Services;

public class NavTreeProvider : INavTreeProvider
{
private readonly ILogger<NavTreeProvider> _logger;
private readonly INavNodeFlaggingService _flaggingService;
private readonly INavNodeOrderingService _orderingService;
private readonly INavNodeAuthorizationService _authorizationService;

public NavTreeProvider(INavNodeFlaggingService flaggingService, INavNodeOrderingService orderingService, INavNodeAuthorizationService authorizationService)
public NavTreeProvider(INavNodeFlaggingService flaggingService, INavNodeOrderingService orderingService, INavNodeAuthorizationService authorizationService, ILogger<NavTreeProvider> logger)
{
_flaggingService = flaggingService;
_orderingService = orderingService;
_authorizationService = authorizationService;
_logger = logger;
}

/// <inheritdoc />
public async Task<NavTree> RebuildAsync(List<ISourceFile> files, CancellationToken cancellationToken = default)
{
_logger.LogDebug("Rebuilding tree using {Count} files", files.Count);

var root = new Dictionary<string, NavNode>();

foreach (var file in files)
Expand Down Expand Up @@ -47,17 +51,23 @@ public async Task<NavTree> RebuildAsync(List<ISourceFile> files, CancellationTok
node = node[nodeName].Children ??= new();
}
}

_logger.LogTrace("Added file to tree: {Location}", string.Join(NavNode.Separator, currentLocation));
}

Tree = new(root);

await PostProcessTree(files, cancellationToken);

_logger.LogDebug("Tree rebuilt");

return Tree;
}

private async Task PostProcessTree(List<ISourceFile> files, CancellationToken cancellationToken)
{
_logger.LogDebug("Post processing tree...");

await _flaggingService.UpdateHasContentFlagAsync(Tree.Root, files, cancellationToken);
await _orderingService.ReorderTreeAsync(Tree, cancellationToken);
await _authorizationService.UpdateGroupsAsync(Tree, cancellationToken);
Expand Down
Loading