From 6366c106c9c3726928326215ef4f6cb67d73642b Mon Sep 17 00:00:00 2001 From: Brian Lagunas <835562+brianlagunas@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:59:58 -0600 Subject: [PATCH] improved dashboard filter API --- e2e/Sandbox/Factories/CampaignsDashboard.cs | 2 +- e2e/Sandbox/Factories/SalesDashboard.cs | 13 ++----------- .../Bindings/DashboardDataFilterBinding.cs | 4 ++-- src/Reveal.Sdk.Dom/Filters/DashboardDataFilter.cs | 15 ++++++++++++--- .../Filters/DashboardDataFilterBase.cs | 4 ++-- src/Reveal.Sdk.Dom/Filters/DashboardDateFilter.cs | 6 ++++-- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/e2e/Sandbox/Factories/CampaignsDashboard.cs b/e2e/Sandbox/Factories/CampaignsDashboard.cs index 87be6ae8..781ecb8a 100644 --- a/e2e/Sandbox/Factories/CampaignsDashboard.cs +++ b/e2e/Sandbox/Factories/CampaignsDashboard.cs @@ -31,7 +31,7 @@ internal static RdashDocument CreateDashboard() var campaignIdFilter = new DashboardDataFilter(excelDataSourceItem) { Title = "CampaignID", - SelectedFieldName = "CampaignID", + FieldName = "CampaignID", AllowMultipleSelection = true, AllowEmptySelection = true }; diff --git a/e2e/Sandbox/Factories/SalesDashboard.cs b/e2e/Sandbox/Factories/SalesDashboard.cs index ae6c88ab..c28d13ee 100644 --- a/e2e/Sandbox/Factories/SalesDashboard.cs +++ b/e2e/Sandbox/Factories/SalesDashboard.cs @@ -21,19 +21,10 @@ internal static RdashDocument CreateDashboard() UseAutoLayout = false, }; - var dateFilter = new DashboardDateFilter() - { - Title = "My Date Filter" - }; + var dateFilter = new DashboardDateFilter("My Date Filter"); document.Filters.Add(dateFilter); - var territoryFilter = new DashboardDataFilter(excelDataSourceItem) - { - Title = "Territory", - SelectedFieldName = "Territory", - AllowMultipleSelection = true, - AllowEmptySelection = true - }; + var territoryFilter = new DashboardDataFilter("Territory", excelDataSourceItem); document.Filters.Add(territoryFilter); document.Visualizations.Add(CreateKpiTargetVisualization(excelDataSourceItem, territoryFilter)); diff --git a/src/Reveal.Sdk.Dom/Filters/Bindings/DashboardDataFilterBinding.cs b/src/Reveal.Sdk.Dom/Filters/Bindings/DashboardDataFilterBinding.cs index a145040a..75e05dd9 100644 --- a/src/Reveal.Sdk.Dom/Filters/Bindings/DashboardDataFilterBinding.cs +++ b/src/Reveal.Sdk.Dom/Filters/Bindings/DashboardDataFilterBinding.cs @@ -6,12 +6,12 @@ internal DashboardDataFilterBinding() : this(null) { } public DashboardDataFilterBinding(DashboardDataFilter dataFilter) { - Source = new FieldBindingSource() { FieldName = dataFilter?.SelectedFieldName }; + Source = new FieldBindingSource() { FieldName = dataFilter?.FieldName }; Operator = BindingOperatorType.Equals; Target = new DashboardDataFilterBindingTarget() { DashboardFilterId = dataFilter?.Id, - DashboardFilterFieldName = dataFilter?.SelectedFieldName + DashboardFilterFieldName = dataFilter?.FieldName }; } } diff --git a/src/Reveal.Sdk.Dom/Filters/DashboardDataFilter.cs b/src/Reveal.Sdk.Dom/Filters/DashboardDataFilter.cs index 72921006..a0b70d53 100644 --- a/src/Reveal.Sdk.Dom/Filters/DashboardDataFilter.cs +++ b/src/Reveal.Sdk.Dom/Filters/DashboardDataFilter.cs @@ -9,15 +9,24 @@ namespace Reveal.Sdk.Dom.Filters public sealed class DashboardDataFilter : DashboardDataFilterBase { [JsonProperty("DataSpec")] - public TabularDataDefinition DataDefinition { get; internal set; } = new TabularDataDefinition(); + internal TabularDataDefinition DataDefinition { get; set; } = new TabularDataDefinition(); - public string SelectedFieldName { get; set; } + [JsonProperty("SelectedFieldName")] + public string FieldName { get; set; } internal DashboardDataFilter() : this(null) { } public DashboardDataFilter(DataSourceItem dataSourceItem) + : this (null, dataSourceItem) { } + + public DashboardDataFilter(string fieldName, DataSourceItem dataSourceItem) + : this (fieldName, null, dataSourceItem) { } + + public DashboardDataFilter(string fieldName, string title, DataSourceItem dataSourceItem) { SchemaTypeName = SchemaTypeNames.TabularGlobalFilterType; + FieldName = fieldName; + Title = title; DataDefinition.DataSourceItem = dataSourceItem; DataDefinition.Fields = dataSourceItem?.Fields.Clone(); } @@ -27,7 +36,7 @@ public void SelectValues(params object[] values) SelectedItems.Clear(); foreach (var value in values) { - SelectedItems.Add(new FilterItem(SelectedFieldName, value)); + SelectedItems.Add(new FilterItem(FieldName, value)); } } } diff --git a/src/Reveal.Sdk.Dom/Filters/DashboardDataFilterBase.cs b/src/Reveal.Sdk.Dom/Filters/DashboardDataFilterBase.cs index e8b920eb..22b62264 100644 --- a/src/Reveal.Sdk.Dom/Filters/DashboardDataFilterBase.cs +++ b/src/Reveal.Sdk.Dom/Filters/DashboardDataFilterBase.cs @@ -5,8 +5,8 @@ namespace Reveal.Sdk.Dom.Filters public abstract class DashboardDataFilterBase : DashboardFilter { public bool IsDynamic { get; set; } = true; - public bool AllowMultipleSelection { get; set; } - public bool AllowEmptySelection { get; set; } + public bool AllowMultipleSelection { get; set; } = true; + public bool AllowEmptySelection { get; set; } = true; public bool SortByLabel { get; set; } = true; public List SelectedItems { get; set; } = new List(); } diff --git a/src/Reveal.Sdk.Dom/Filters/DashboardDateFilter.cs b/src/Reveal.Sdk.Dom/Filters/DashboardDateFilter.cs index b963e7cf..e3469dd8 100644 --- a/src/Reveal.Sdk.Dom/Filters/DashboardDateFilter.cs +++ b/src/Reveal.Sdk.Dom/Filters/DashboardDateFilter.cs @@ -13,10 +13,12 @@ public sealed class DashboardDateFilter : DashboardFilter [JsonConverter(typeof(StringEnumConverter))] public DateRuleType RuleType { get; set; } = DateRuleType.LastYear; - public DashboardDateFilter() + public DashboardDateFilter() : this("Date Filter") { } + + public DashboardDateFilter(string title) { SchemaTypeName = SchemaTypeNames.DateGlobalFilterType; - Title = "Date Filter"; + Title = title; } } }