Skip to content

Commit

Permalink
improved dashboard filter API
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlagunas committed Sep 5, 2024
1 parent 80e9fc0 commit 6366c10
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion e2e/Sandbox/Factories/CampaignsDashboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static RdashDocument CreateDashboard()
var campaignIdFilter = new DashboardDataFilter(excelDataSourceItem)
{
Title = "CampaignID",
SelectedFieldName = "CampaignID",
FieldName = "CampaignID",
AllowMultipleSelection = true,
AllowEmptySelection = true
};
Expand Down
13 changes: 2 additions & 11 deletions e2e/Sandbox/Factories/SalesDashboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/Reveal.Sdk.Dom/Filters/DashboardDataFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Reveal.Sdk.Dom/Filters/DashboardDataFilterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FilterItem> SelectedItems { get; set; } = new List<FilterItem>();
}
Expand Down
6 changes: 4 additions & 2 deletions src/Reveal.Sdk.Dom/Filters/DashboardDateFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 6366c10

Please sign in to comment.