Skip to content

docs: Simple example of creating a dashboard filter and applying it to dashboard elements #818

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

Conversation

dunnkevin
Copy link

Wanted to submit an example of creating a dashboard filter and listeners for dashboard tiles that update based on the filter. This is based on a number of support requests that ask how to do this using Looker's API. We have some community posts about what endpoints to use, but no real working examples.

  • 👇 Edit "Developer Checklist" to reflect items relevant to this PR (and try to make sure to check everything off before asking for review)

Developer Checklist ℹ️

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Appropriate docs were updated (if necessary)

Fixes #816 🦕

@google-cla google-cla bot added the cla: yes label Sep 14, 2021
@jkaster jkaster changed the title feat: Simple example of creating a dashboard filter and applying it to dashboard elements docs: Simple example of creating a dashboard filter and applying it to dashboard elements Sep 17, 2021
Copy link
Contributor

@fabio-looker fabio-looker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally was a bit unclear on the purpose of some of the looping where I commented, which if that could be clarified in any way, would be a big win in my opinion. Other than that, they overall organization looks good to me.

"""
# Keep track of the current result_maker and add to it, otherwise listeners for other filters would be removed
current_filterables = element.result_maker.filterables
for filterable in current_filterables:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is surely largely to do with my inexperience with Python, but I'm confused why we are iterating through current filterables twice, once here and then once on line 75. I am sure your code is doing the right and necessary thing, but as far as readability, I've tried to figure it out a few times and I'm not 100% clear on this point. Either some additional comment, or combining these loops somehow might help? Not sure!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch. The code was doing the right thing, just not as efficiently as it could have. Originally when I drew up this process, I used one step to get the current filterables, and a second step to then update them. But, this isn't nearly as efficient as doing that all at once. Consolidated these two loops into one per your suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two loops being consolidated in to one makes this so much clearer, I no longer feel lost :)

On lines 66-68, are you essentially just making a clone of the array? If there is a python method to do that, it might be clearer to use it, otherwise this looks good as is!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh great catch. I've consolidated that down into just the one line in line 66. That loop's definitely unnecessary.

@dunnkevin
Copy link
Author

@fabio-looker - Thanks for the original review, great suggestions. Added a couple small changes described in the above conversations. When you've got a few, would you mind having a look at the new changes?

fabio-looker
fabio-looker previously approved these changes Sep 29, 2021
@dunnkevin
Copy link
Author

Hey @fabio-looker - When you get a chance could I get a quick review? Just one small change to condense the copying of the array.

fabio-looker
fabio-looker previously approved these changes Oct 8, 2021
Copy link
Contributor

@fabio-looker fabio-looker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is now clear enough what's going on, and it will be a valuable example!

@drstrangelooker drstrangelooker force-pushed the main branch 4 times, most recently from 9474788 to 5f9930c Compare February 4, 2022 02:33
@drstrangelooker drstrangelooker changed the base branch from main to example_of_creating_dashboard_filter February 15, 2022 21:48
@drstrangelooker drstrangelooker merged this pull request into looker-open-source:example_of_creating_dashboard_filter Feb 15, 2022
drstrangelooker pushed a commit that referenced this pull request Feb 15, 2022
…o dashboard elements (#818)

* Pushing new_dashboard_filter to remote

* Adding example to create_dashboard_filter, fixes 816

* Rename dashboard_filter file

* add new line at end of file

* Fixing new line at end of file 🤦🏼‍♂️

* Condensing loops

* Consolidating loops, adding check for matching model and explore

* Removing unnecessary loop

Co-authored-by: Kevin Dunn <[email protected]>
drstrangelooker pushed a commit that referenced this pull request Feb 23, 2022
…o dashboard elements (#818)

* Pushing new_dashboard_filter to remote

* Adding example to create_dashboard_filter, fixes 816

* Rename dashboard_filter file

* add new line at end of file

* Fixing new line at end of file 🤦🏼‍♂️

* Condensing loops

* Consolidating loops, adding check for matching model and explore

* Removing unnecessary loop

Co-authored-by: Kevin Dunn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Looker SDK (Python): Create example of how to create dashboard filter
3 participants