Skip to content

Commit

Permalink
Add descriptive name on mapping list
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Jul 15, 2023
1 parent 78028ef commit 317d84f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/WireMockInspector/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using DynamicData;
using Newtonsoft.Json;
Expand Down Expand Up @@ -149,6 +150,7 @@ public MainWindowViewModel()
Raw = model,
Id = model.Guid?.ToString(),
Title = model.Title,
DescriptiveName = GetDescriptiveName(model),
Description = model.Title != model.Description? model.Description: null,
UpdatedOn = model.UpdatedAt,
Content = AsMarkdownCode("json", JsonConvert.SerializeObject(model, Formatting.Indented)).AsMarkdownSyntax(),
Expand Down Expand Up @@ -288,6 +290,54 @@ await _settingsManager.UpdateSettings(settings =>
});
}

private string GetDescriptiveName(MappingModel model)
{
var sb = new StringBuilder();

if (model.Request.Methods is {Length: > 0} methods)
{
sb.Append(string.Join(" | ", methods));

}
else
{
sb.Append("<any method>");
}
sb.Append(": ");

var pathDefined = false;

{
if (model.Request.Url is JObject jo)
{
if (jo.TryGetValue("Matchers", out var matchers) && matchers is JArray arr)
{
var patterns = arr.OfType<JObject>().Select(x => x.TryGetValue("Pattern", out var p) ? p.ToString() : null)
.OfType<string>();
sb.Append(string.Join(" | ", patterns));
pathDefined = true;
}
}
}
{
if (model.Request.Path is JObject jo)
{
if (jo.TryGetValue("Matchers", out var matchers) && matchers is JArray arr)
{
var patterns = arr.OfType<JObject>().Select(x => x.TryGetValue("Pattern", out var p) ? p.ToString() : null)
.OfType<string>();
sb.Append(string.Join(" | ", patterns));
pathDefined = true;
}
}
}
if (pathDefined == false)
{
sb.Append("<any path>");
}
return sb.ToString();
}

public ReactiveCommand<Unit, Unit> SaveServerSettings { get; set; }

private static IEnumerable<SettingsWrapper> MapToSettingsWrappers(object serverSettings, string? namePrefix = null)
Expand Down Expand Up @@ -659,6 +709,7 @@ public class MappingViewModel: ViewModelBase
{
public MappingModel Raw { get; set; }
public string Id { get; set; }
public string DescriptiveName { get; set; }
public DateTime? UpdatedOn { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/WireMockInspector/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
</Grid>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Title}" IsVisible="{Binding Title, Converter={x:Static ObjectConverters.IsNotNull}}" Foreground="white" VerticalAlignment="Center" Margin="5,5"></TextBlock>
<TextBlock Text="{Binding DescriptiveName}" IsVisible="{Binding DescriptiveName, Converter={x:Static ObjectConverters.IsNotNull}}" Foreground="white" VerticalAlignment="Center" Margin="5,5"></TextBlock>
<TextBlock Text="{Binding Description}" IsVisible="{Binding Description, Converter={x:Static ObjectConverters.IsNotNull}}" Foreground="white" VerticalAlignment="Center" Margin="5,5"></TextBlock>
</StackPanel>
</StackPanel>
Expand Down

0 comments on commit 317d84f

Please sign in to comment.