Skip to content

Commit

Permalink
Merge pull request #1594 from pkuehnel/feat/DoNotShowOccurrenceCountI…
Browse files Browse the repository at this point in the history
…fNotNeeded

feat(ErrorHandlingService): do not show occurrence count if not needed
  • Loading branch information
pkuehnel authored Oct 31, 2024
2 parents 2303099 + 9ea60c7 commit a31643d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ else
NoIcon="true"
ContentAlignment="HorizontalAlignment.Left"
ShowCloseIcon="false">
<h4>@(error.Headline + $" occured {error.Occurrences.Count} time(s)")</h4>
<h4>@(error.Headline + $"{(error.HideOccurrenceCount ? string.Empty : $" occured {error.OccurrenceCount} time(s)")}")</h4>
<div>
Hidden reason: @(error.HideReason == LoggedErrorHideReason.NotEnoughOccurrences ? "Not Enough occurrences" : "Dismissed")
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ else
ContentAlignment="HorizontalAlignment.Left"
ShowCloseIcon="true"
CloseIconClicked="@(_ => DismissError(error.Id))">
<h4>@(error.Headline + $" occured {error.Occurrences.Count} time(s)")</h4>
<h4>@(error.Headline + $"{(error.HideOccurrenceCount ? string.Empty : $" occured {error.OccurrenceCount} time(s)")}")</h4>
@((MarkupString)error.Message)
</MudAlert>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class PossibleIssues(IIssueKeys issueKeys) : IPossibleIssues
IsTelegramEnabled = false,
ShowErrorAfterOccurrences = 1,
HasPlaceHolderIssueKey = false,
HideOccurrenceCount = true,
}
},
{ issueKeys.FleetApiTokenNotRequested, new DtoIssue
Expand All @@ -23,6 +24,7 @@ public class PossibleIssues(IIssueKeys issueKeys) : IPossibleIssues
IsTelegramEnabled = false,
ShowErrorAfterOccurrences = 1,
HasPlaceHolderIssueKey = false,
HideOccurrenceCount = true,
}
},
{ issueKeys.FleetApiTokenUnauthorized, new DtoIssue
Expand All @@ -47,6 +49,7 @@ public class PossibleIssues(IIssueKeys issueKeys) : IPossibleIssues
IsTelegramEnabled = false,
ShowErrorAfterOccurrences = 1,
HasPlaceHolderIssueKey = false,
HideOccurrenceCount = true,
}
},
{ issueKeys.FleetApiTokenNotReceived, new DtoIssue
Expand All @@ -55,6 +58,7 @@ public class PossibleIssues(IIssueKeys issueKeys) : IPossibleIssues
IsTelegramEnabled = false,
ShowErrorAfterOccurrences = 1,
HasPlaceHolderIssueKey = false,
HideOccurrenceCount = true,
}
},
{ issueKeys.FleetApiTokenExpired, new DtoIssue
Expand All @@ -63,6 +67,7 @@ public class PossibleIssues(IIssueKeys issueKeys) : IPossibleIssues
IsTelegramEnabled = true,
ShowErrorAfterOccurrences = 1,
HasPlaceHolderIssueKey = false,
HideOccurrenceCount = true,
}
},
{ issueKeys.FleetApiTokenNoApiRequestsAllowed, new DtoIssue
Expand All @@ -71,6 +76,7 @@ public class PossibleIssues(IIssueKeys issueKeys) : IPossibleIssues
IsTelegramEnabled = true,
ShowErrorAfterOccurrences = 2,
HasPlaceHolderIssueKey = false,
HideOccurrenceCount = true,
}
},
{ issueKeys.CrashedOnStartup, new DtoIssue
Expand All @@ -79,6 +85,7 @@ public class PossibleIssues(IIssueKeys issueKeys) : IPossibleIssues
IsTelegramEnabled = true,
ShowErrorAfterOccurrences = 1,
HasPlaceHolderIssueKey = false,
HideOccurrenceCount = true,
}
},
{ issueKeys.RestartNeeded, new DtoIssue
Expand All @@ -87,6 +94,7 @@ public class PossibleIssues(IIssueKeys issueKeys) : IPossibleIssues
IsTelegramEnabled = false,
ShowErrorAfterOccurrences = 1,
HasPlaceHolderIssueKey = false,
HideOccurrenceCount = true,
}
},
{ issueKeys.GetVehicle, new DtoIssue
Expand Down Expand Up @@ -191,6 +199,7 @@ public class PossibleIssues(IIssueKeys issueKeys) : IPossibleIssues
IsTelegramEnabled = true,
ShowErrorAfterOccurrences = 2,
HasPlaceHolderIssueKey = false,
HideOccurrenceCount = true,
}
},
};
Expand Down
8 changes: 5 additions & 3 deletions TeslaSolarCharger/Server/Services/ErrorHandlingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public async Task<Fin<List<DtoLoggedError>>> GetActiveLoggedErrors()
var mappingConfiguration = mapperConfigurationFactory.Create(cfg =>
{
cfg.CreateMap<LoggedError, DtoLoggedError>()
.ForMember(d => d.Occurrences, opt => opt.MapFrom(s => new List<DateTime>() { s.StartTimeStamp }.Concat(s.FurtherOccurrences)))
.ForMember(d => d.OccurrenceCount, opt => opt.MapFrom(s => s.FurtherOccurrences.Count() + 1))
.ForMember(d => d.Severity, opt => opt.MapFrom(s => possibleIssues.GetIssueByKey(s.IssueKey).IssueSeverity))
.ForMember(d => d.HideOccurrenceCount, opt => opt.MapFrom(s => possibleIssues.GetIssueByKey(s.IssueKey).HideOccurrenceCount))
;
});
var mapper = mappingConfiguration.CreateMapper();
Expand All @@ -50,7 +51,7 @@ public async Task<Fin<List<DtoLoggedError>>> GetActiveLoggedErrors()
.Select(e => mapper.Map<DtoLoggedError>(e))
.ToList();

var removedErrorCount = errors.RemoveAll(e => e.Occurrences.Count < possibleIssues.GetIssueByKey(e.IssueKey).ShowErrorAfterOccurrences);
var removedErrorCount = errors.RemoveAll(e => e.OccurrenceCount < possibleIssues.GetIssueByKey(e.IssueKey).ShowErrorAfterOccurrences);
logger.LogDebug("{removedErrorsCount} errors removed as did not reach minimum error count", removedErrorCount);
return Fin<List<DtoLoggedError>>.Succ(errors);
},
Expand All @@ -71,8 +72,9 @@ public async Task<Fin<List<DtoHiddenError>>> GetHiddenErrors()
var mappingConfiguration = mapperConfigurationFactory.Create(cfg =>
{
cfg.CreateMap<LoggedError, DtoHiddenError>()
.ForMember(d => d.Occurrences, opt => opt.MapFrom(s => new List<DateTime>() { s.StartTimeStamp }.Concat(s.FurtherOccurrences)))
.ForMember(d => d.OccurrenceCount, opt => opt.MapFrom(s => s.FurtherOccurrences.Count() + 1))
.ForMember(d => d.Severity, opt => opt.MapFrom(s => possibleIssues.GetIssueByKey(s.IssueKey).IssueSeverity))
.ForMember(d => d.HideOccurrenceCount, opt => opt.MapFrom(s => possibleIssues.GetIssueByKey(s.IssueKey).HideOccurrenceCount))
;
});
var mapper2 = mappingConfiguration.CreateMapper();
Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Shared/Dtos/DtoIssue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class DtoIssue
/// If true the issue Starts with the specified issue key and can have multiple variations separated from the main issue key by _
/// </summary>
public bool HasPlaceHolderIssueKey { get; set; }
public bool HideOccurrenceCount { get; set; }
}
3 changes: 2 additions & 1 deletion TeslaSolarCharger/Shared/Dtos/LoggedError/DtoLoggedError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class DtoLoggedError
public IssueSeverity Severity { get; set; }
public string Headline { get; set; }
public string IssueKey { get; set; }
public List<DateTime> Occurrences { get; set; } = new();
public int OccurrenceCount { get; set; }
public string? Vin { get; set; }
public string Message { get; set; }
public bool HideOccurrenceCount { get; set; }
}

0 comments on commit a31643d

Please sign in to comment.