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

OSOE-867: Addressing analyzer warnings #76

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 22 additions & 20 deletions Lombiq.ChartJs.Samples/Controllers/SampleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ public SampleController(
public async Task<IActionResult> Balance() =>
View(new BalanceViewModel
{
Labels = new[] { Labels.Balance },
DataSets = new[]
{
Labels = [Labels.Balance],
DataSets =
[
// You can find more detailed description about dataset here:
// https://www.chartjs.org/docs/2.9.4/charts/bar.html#dataset-properties
new ChartJsDataSet
{
Label = Labels.Incomes,
BackgroundColor = new[] { ChartColors.IncomesBarChartBackgroundColor },
Data = new double?[]
{
BackgroundColor = [ChartColors.IncomesBarChartBackgroundColor],
Data =
[
(await _session.QueryIndex<NumericFieldIndex>(
index =>
index.Published &&
Expand All @@ -68,14 +68,14 @@ public async Task<IActionResult> Balance() =>
.ListAsync())
.Select(index => decimal.ToDouble(index.Numeric ?? 0m))
.Sum(),
},
],
},
new ChartJsDataSet
{
Label = Labels.Expenses,
BackgroundColor = new[] { ChartColors.ExpensesBarChartBackgroundColor },
Data = new double?[]
{
BackgroundColor = [ChartColors.ExpensesBarChartBackgroundColor],
Data =
[
(await _session.QueryIndex<NumericFieldIndex>(
index =>
index.Published &&
Expand All @@ -87,9 +87,9 @@ public async Task<IActionResult> Balance() =>
.ListAsync())
.Select(index => decimal.ToDouble(index.Numeric ?? 0m))
.Sum(),
},
],
},
},
],
Options = new
{
// These options below are to simplify UI testing.
Expand All @@ -114,6 +114,8 @@ public async Task<IActionResult> Balance() =>
// /Lombiq.ChartJs.Samples/Sample/History
public async Task<IActionResult> History(string incomeTag = null, string expenseTag = null)
{
if (!ModelState.IsValid) return BadRequest(ModelState);

var transactions = await GetMonthlyTransactionsAsync(incomeTag, expenseTag);

return View(new HistoryViewModel
Expand All @@ -123,27 +125,27 @@ public async Task<IActionResult> History(string incomeTag = null, string expense
.Select(item => item.ToString("MMMM yyyy", CultureInfo.InvariantCulture)),
// You can find more detailed description about dataset here:
// https://www.chartjs.org/docs/2.9.4/charts/line.html#dataset-properties
DataSets = new[]
{
DataSets =
[
new ChartJsDataSet
{
Label = Labels.Incomes,
BackgroundColor = new[] { ChartColors.Transparent },
BorderColor = new[] { ChartColors.IncomesLineChartBorderColor },
BackgroundColor = [ChartColors.Transparent],
BorderColor = [ChartColors.IncomesLineChartBorderColor],
Data = transactions
.OrderBy(item => item.Key)
.Select(item => item.Value.Income),
},
new ChartJsDataSet
{
Label = Labels.Expenses,
BackgroundColor = new[] { ChartColors.Transparent },
BorderColor = new[] { ChartColors.ExpensesLineChartBorderColor },
BackgroundColor = [ChartColors.Transparent],
BorderColor = [ChartColors.ExpensesLineChartBorderColor],
Data = transactions
.OrderBy(item => item.Key)
.Select(item => item.Value.Expense),
},
},
],
Options = new
{
// These options below are to simplify UI testing.
Expand Down Expand Up @@ -203,7 +205,7 @@ await FindDateFieldIndexesByTagsFilterAsync(incomeTag, incomeTagsFilter, expense

private async Task<IEnumerable<string>> GetItemIdsByTermIdAsync(string taxonomyId, string termId) =>
string.IsNullOrEmpty(termId)
? Array.Empty<string>()
? []
: (await _orchardHelper.QueryCategorizedContentItemsAsync(query => query
.Where(taxIndex => taxIndex.TaxonomyContentItemId == taxonomyId)
.Where(taxIndex => taxIndex.TermContentItemId == termId)))
Expand Down
5 changes: 2 additions & 3 deletions Lombiq.ChartJs/TagHelpers/ChartTagHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Lombiq.ChartJs.Models;
using Microsoft.AspNetCore.Razor.TagHelpers;
using OrchardCore.DisplayManagement;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand All @@ -17,10 +16,10 @@ public class ChartTagHelper : TagHelper
public string ChartType { get; set; } = "bar";

[HtmlAttributeName("labels")]
public IEnumerable<string> Labels { get; set; } = Array.Empty<string>();
public IEnumerable<string> Labels { get; set; } = [];

[HtmlAttributeName("datasets")]
public IEnumerable<ChartJsDataSet> DataSets { get; set; } = Array.Empty<ChartJsDataSet>();
public IEnumerable<ChartJsDataSet> DataSets { get; set; } = [];

[HtmlAttributeName("options")]
public object Options { get; set; } = new();
Expand Down