feat(centralui): TemplatePathFormatter — folder-path label for template pickers
Claude-Session: https://claude.ai/code/session_01G2GHPnbbKGvyyfbr2XBRVH
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Renders a template's location as "Folder / Subfolder / Name" for the Create
|
||||
/// Instance template field and the picker footer. Pure; tolerates dangling or
|
||||
/// cyclic folder ids (stops after 32 hops) so a half-migrated catalogue never
|
||||
/// breaks the create page.
|
||||
/// </summary>
|
||||
public static class TemplatePathFormatter
|
||||
{
|
||||
/// <summary>Separator placed between each folder segment and the template name.</summary>
|
||||
public const string Separator = " / ";
|
||||
|
||||
/// <summary>
|
||||
/// Builds the display path for <paramref name="template"/> by walking its
|
||||
/// folder chain upward through <paramref name="foldersById"/>.
|
||||
/// </summary>
|
||||
public static string Format(Template template, IReadOnlyDictionary<int, TemplateFolder> foldersById)
|
||||
{
|
||||
var parts = new List<string> { template.Name };
|
||||
var next = template.FolderId;
|
||||
var hops = 0;
|
||||
while (next is int id && foldersById.TryGetValue(id, out var folder) && hops++ < 32)
|
||||
{
|
||||
parts.Add(folder.Name);
|
||||
next = folder.ParentFolderId;
|
||||
}
|
||||
parts.Reverse();
|
||||
return string.Join(Separator, parts);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user