Skip to content

Commit

Permalink
supported custom field name for dashboard filter connections
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlagunas committed Sep 6, 2024
1 parent d401970 commit 69eb41e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ public sealed class DashboardDataFilterBinding : Binding<FieldBindingSource, Das
internal DashboardDataFilterBinding() : this(null) { }

public DashboardDataFilterBinding(DashboardDataFilter dataFilter)
: this(dataFilter, dataFilter.FieldName) { }

public DashboardDataFilterBinding(DashboardDataFilter dataFilter, string fieldName)
{
Source = new FieldBindingSource() { FieldName = dataFilter?.FieldName };
Source = new FieldBindingSource() { FieldName = fieldName };
Operator = BindingOperatorType.Equals;
Target = new DashboardDataFilterBindingTarget()
{
DashboardFilterId = dataFilter?.Id,
DashboardFilterFieldName = dataFilter?.FieldName
DashboardFilterId = dataFilter.Id,
DashboardFilterFieldName = dataFilter.FieldName
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Reveal.Sdk.Dom.Filters
public sealed class DashboardDateFilterBindingTarget : BindingTarget
{
[JsonProperty("GlobalFilterId")]
public string DashboardFilterId { get; set; }
public string DashboardFilterId { get; set; } = "_date";

[JsonProperty("GlobalFilterFieldName")]
public string DashboardFilterFieldName { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Reveal.Sdk.Dom/Filters/DashboardDataFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public DashboardDataFilter(string fieldName, string title, DataSourceItem dataSo
{
SchemaTypeName = SchemaTypeNames.TabularGlobalFilterType;
FieldName = fieldName;
Title = title;
Title = title ?? fieldName;
DataDefinition.DataSourceItem = dataSourceItem;
DataDefinition.Fields = dataSourceItem?.Fields.Clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ public static class IFilterBindingsExtensions
{
public static T ConnectDashboardFilter<T>(this T visualization, DashboardFilter dashboardFilter)
where T : IFilterBindings
{
return visualization.ConnectDashboardFilter(dashboardFilter, null);
}

public static T ConnectDashboardFilter<T>(this T visualization, DashboardFilter dashboardFilter, string fieldName)
where T : IFilterBindings
{
if (dashboardFilter is DashboardDateFilter)
{
visualization.FilterBindings.Add(new DashboardDateFilterBinding("Date"));
visualization.FilterBindings.Add(new DashboardDateFilterBinding(fieldName ?? "Date"));
}
else
else if (dashboardFilter is DashboardDataFilter dataFilter)
{
visualization.FilterBindings.Add(new DashboardDataFilterBinding(dashboardFilter as DashboardDataFilter));
var binding = fieldName == null ? new DashboardDataFilterBinding(dataFilter) : new DashboardDataFilterBinding(dataFilter, fieldName);
visualization.FilterBindings.Add(binding);
}
return visualization;
}
Expand Down

0 comments on commit 69eb41e

Please sign in to comment.