Skip to content

Commit

Permalink
Added pretty printing of type names for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
leosperry committed Oct 26, 2024
1 parent de2c1d9 commit 8dc5f31
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public virtual AutomationMetaData GetMetaData()
Name = thisType.Name,
Description = thisType.FullName,
Enabled = true,
UnderlyingType = thisType.Name
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

using System.Text;

namespace HaKafkaNet;

[ExcludeFromDiscovery]
Expand Down Expand Up @@ -88,13 +90,10 @@ AutomationMetaData GetOrMakeMeta(string source)
Description = underlyingType.FullName,
Enabled = true,
KeyRequest = GenerateKey(source, underlyingType.Name),
UnderlyingType = underlyingType.Name
};
}
if (meta.UnderlyingType is null)
{
meta.UnderlyingType = underlyingType.Name;
}

meta.UnderlyingType = underlyingType.PrettyPrint();

if (string.IsNullOrEmpty(meta.KeyRequest))
{
Expand Down Expand Up @@ -138,4 +137,24 @@ private string GenerateKey(string source, string name)
}

public IEnumerable<string> TriggerEntityIds() => _triggers;

}

static class PrettyPrintTypeNameExtensions
{
public static string PrettyPrint(this Type type)
{
if (!type.IsGenericType)
{
return type.Name;
}
StringBuilder builder = new();
builder.Append(type.Name.Substring(0, type.Name.IndexOf('`')));
builder.Append('<');
builder.Append(string.Join(", ", type.GetGenericArguments().Select(t => t.PrettyPrint())));
builder.Append('>');

return builder.ToString();
}
}

1 change: 0 additions & 1 deletion src/HaKafkaNet/Models/AutomationMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ internal static AutomationMetaData Create(object automation)
Name = automation.GetType().Name,
Description = automation.GetType().Name,
Enabled = true,
UnderlyingType = automation.GetType().Name
};
}
}
Expand Down

0 comments on commit 8dc5f31

Please sign in to comment.