Skip to content
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

Add a disabled_options parameter to a custom Select widget #3067

Merged
merged 11 commits into from
Jan 13, 2022

Conversation

maximlt
Copy link
Member

@maximlt maximlt commented Jan 6, 2022

This PR adds a disabled_options parameter to the Select widget which allows to disable some options, which in practice makes them unusable and un-clickable.

image

I've extended the base Select widget of Bokeh to implement this option on the client-side. I've called the model CustomSelect instead of something more specific, but I'm open for a better name.

disabled_options is a List Parameter (default to []) that accepts a subset of the options values, i.e. if options is a dictionary then disabled_options must list some dictionary values, not keys. I've had the feeling this would be more intuitive, but since dictionary options have been confusing people I'd also be fine implementing the "labels" alternative if that's clearer.

I've added some validation in a dedicated callback but I observed that it's called after _process_param_change which means that the bokeh model and then the UI still gets updated before an error is raised on the Python side. I wasn't sure implementing the validation/error part in _process_param_change was the right thing to do either.

@codecov
Copy link

codecov bot commented Jan 6, 2022

Codecov Report

Merging #3067 (a784bae) into master (c0c765b) will increase coverage by 0.08%.
The diff coverage is 98.79%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3067      +/-   ##
==========================================
+ Coverage   83.42%   83.51%   +0.08%     
==========================================
  Files         190      190              
  Lines       25134    25282     +148     
==========================================
+ Hits        20969    21113     +144     
- Misses       4165     4169       +4     
Impacted Files Coverage Δ
panel/models/__init__.py 100.00% <ø> (ø)
panel/widgets/select.py 94.37% <95.23%> (+<0.01%) ⬆️
panel/models/widgets.py 100.00% <100.00%> (ø)
panel/tests/widgets/test_select.py 100.00% <100.00%> (ø)
panel/tests/conftest.py 94.85% <0.00%> (-1.48%) ⬇️
panel/links.py 78.00% <0.00%> (-0.49%) ⬇️
panel/command/serve.py 39.26% <0.00%> (-0.42%) ⬇️
panel/io/server.py 73.75% <0.00%> (-0.34%) ⬇️
panel/widgets/tables.py 85.53% <0.00%> (-0.02%) ⬇️
panel/layout/tabs.py 88.18% <0.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c0c765b...a784bae. Read the comment docs.

Copy link
Member

@philippjfr philippjfr left a comment

Choose a reason for hiding this comment

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

Congrats on your first custom Bokeh model! Only have one comment which is that we use 2-space indentation for TypeScript files. If you could resolve that I'll merge.

@maximlt
Copy link
Member Author

maximlt commented Jan 12, 2022

@philippjfr I've made the changes you requested. Sorry for the indentation, I had noticed the difference but then forgot about it. VSCode wasn't also playing nicely (which is quite rare), I did set the indentation to be of 2 spaces by default for typescript files but this setting was overridden by an indentation auto-detection feature.

I noticed that this PR was actually breaking the SingleSelect widget by passing it disabled_options while this was not a property of the Bokeh model. So I've implemented the possibility to disable options of this widget too (which is used under the hood by Select when size is set to a value greater than 1).

And made three other changes (plus a few minor ones):

  • Raise an error when groups is set and size is greater than 1, since the SingleSelect widget doesn't support options grouping
  • Raise an error when on initialization the value is one the disabled options (shouldn't have missed this one!)
  • Refactored the tests

@philippjfr philippjfr merged commit ba40613 into master Jan 13, 2022
@philippjfr philippjfr deleted the select_disabled branch January 13, 2022 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants