Skip to content

Commit 3ebe8ca

Browse files
Kevin Dunndrstrangelooker
authored andcommitted
Consolidating loops, adding check for matching model and explore
1 parent b4f0353 commit 3ebe8ca

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

examples/python/create_dashboard_filter.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def main():
1818
filter_model = '<model_name>'
1919
filter_explore = '<explore_name>'
2020
filter_dimension = '<view_name.field_name>' # Requires a fully-scoped dimension
21-
21+
2222
filter = create_filter(dash_id, filter_name, filter_model, filter_explore, filter_dimension)
2323
elements = sdk.dashboard_dashboard_elements(dash_id)
2424
for element in elements:
@@ -27,7 +27,6 @@ def main():
2727
if element.type != 'text':
2828
update_elements_filters(element, filter)
2929

30-
3130
def create_filter(dash_id: str, filter_name: str, filter_model: str, filter_explore: str , filter_dimension: str ) -> DashboardFilter:
3231
"""Creates a dashboard filter object on the specified dashboard. Filters must be tied to a specific LookML Dimension.
3332
@@ -67,9 +66,13 @@ def update_elements_filters(element: DashboardElement, filter: DashboardFilter)
6766
new_listens = []
6867
for each in filterable.listen:
6968
new_listens.append(each)
70-
# Add listener for new filter
71-
new_listens.append(models.ResultMakerFilterablesListen(dashboard_filter_name=filter.name, field=filter.dimension))
72-
filterable.listen = new_listens
69+
70+
# Add listener for new filter, if model and explore is the same
71+
# You can easily add further restrictions to what tiles or queries within merged results will listen to the new tile
72+
# If you don't want to restrict what tiles or queries this listen to this filter, just remove this if
73+
if filter.model == filterable.model and filter.explore == filterable.view:
74+
new_listens.append(models.ResultMakerFilterablesListen(dashboard_filter_name=filter.name, field=filter.dimension))
75+
filterable.listen = new_listens
7376
# Append the new filterables to a result maker that we can use for the dashboard element
7477
element.result_maker.filterables.append(
7578
models.ResultMakerFilterables(

0 commit comments

Comments
 (0)