-
Notifications
You must be signed in to change notification settings - Fork 4k
Add step parameter to st.time_input #6071
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
36009e6 to
9f2fa46
Compare
sfc-gh-mnowotka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should implement some type checking.
| *, # keyword-only arguments: | ||
| disabled: bool = False, | ||
| label_visibility: LabelVisibility = "visible", | ||
| step: Union[int, timedelta] = timedelta(minutes=15), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd extract 15 to the constant, for example DEFAULT_STEP_MINUTES=15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, it was repeated in two places, so I've extracted it to constants 👍
| def test_st_time_input_with_step(self): | ||
| """Test st.time_input with step.""" | ||
| value = datetime.time(9, 00) | ||
| st.time_input("Set an alarm for", value, step=datetime.timedelta(minutes=5)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen if I do step=True or step="foo" or step=(90,) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any part of code that would actually check the type in runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most of our components we don't do such checking and just rely on Type Hints and runtime exceptions, in my opinion it'd be a bit of over engineering, however I can add some type checking if you insist. But in such case I guess we need some approval for further messages send to user from product, since this is outside of the spec.
I'm leaving this as is for now and waiting for a response from you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say that all I'm asking boils down to changing your code from:
if isinstance(step, timedelta):
step = step.seconds
if step < 60 or step > timedelta(hours=23).seconds:
raise StreamlitAPIException(
f"`step` must be between 60 seconds and 23 hours but is currently set to {step} seconds."
)
to:
if isinstance(step, timedelta):
step = step.seconds
elif not isinstance(step, int):
raise StreamlitAPIException(f"`step` can only be `int` or `timedelta` but {type(step)} is provided")
if step < 60 or step > timedelta(hours=23).seconds:
raise StreamlitAPIException(
f"`step` must be between 60 seconds and 23 hours but is currently set to {step} seconds."
)
So we are talking about adding two lines of code :) IMO pretty cheap stuff to check, even if not done elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's cheap and as I wrote I'm not going to insist on that, thank you for the example and the message, I've updated it with a small change
if not isinstance(step, (int, timedelta)):
raise StreamlitAPIException(
f"`step` can only be `int` or `timedelta` but {type(step)} is provided."
)
this is called before any step conversion
sfc-gh-mnowotka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| }) | ||
|
|
||
| it("has step parameter which defaults to 900 seconds (15 minutes)", () => { | ||
| const props = getProps() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get these tests to use the new react testing library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thank you for noticing this 🙇 , I've just updated the tests to use RTL instead of Enzyme, can you please re-review it? 👍
6440deb to
ebb3158
Compare
| props.element, | ||
| "12:08", | ||
| { fromUi: true } | ||
| "12:45", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test is specifically to test for ui changes. I am thinking that you can maybe call fireEvent here (https://testing-library.com/docs/dom-testing-library/api-events/) to test this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this suggestion, I'm a bit stuck, because I'm firing change event on baseui time input and seems like its not triggering setStringValue method, however when testing manually the timepicker works good 🤔
| props.element, | ||
| "12:08", | ||
| { fromUi: true } | ||
| "12:45", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
willhuang1997
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 of the tests are not properly testing what I would expect. Need them to call onChange in order to actually test the functionality.
|
Everything else LGTM though |
82b7979 to
5a3ba73
Compare
|
@willhuang1997 I have reverted these 2 tests back to Enzyme, so this PR can get merge after QA, can you please accept it? And we will fix these 2 cases in separate PR |
|
Hey @sfc-gh-tszerszen 👋🏼 |
sfc-gh-wihuang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Giving approval but would be great to look if we could look into a better way of selecting certain divs.
willhuang1997
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Giving approval but would be great to look if we could look into a better way of selecting certain divs.
|
Took another pass at it after adding className to the proper div through BaseWeb - think RTL translation is much cleaner now 👍🏼 |
5a3ba73 to
ba3a9e5
Compare
6aac008 to
2cbc822
Compare
1f66c0a to
c46e1b3
Compare
|
Thank you @mayagbarnes I allowed myself to re-use your work so in this PR TimeInput.test.tsx is completely rewritten to RTL 👍 |
c46e1b3 to
c0d1ee4
Compare
c0d1ee4 to
88363e9
Compare
* develop: Allow control of st.pyplot() width (streamlit#6067) `withMapboxToken`: add types (streamlit#6275) Add step parameter to st.time_input (streamlit#6071) Enable no-else-return rule in ESLint (streamlit#6205) Fix `make tstypecheck` (streamlit#6273)
# By Kamil Breguła (2) and others # Via GitHub * develop: Allow control of st.pyplot() width (streamlit#6067) `withMapboxToken`: add types (streamlit#6275) Add step parameter to st.time_input (streamlit#6071) Enable no-else-return rule in ESLint (streamlit#6205) Fix `make tstypecheck` (streamlit#6273) # Conflicts: # frontend/src/hocs/withMapboxToken/withMapboxToken.test.tsx # frontend/src/hocs/withMapboxToken/withMapboxToken.tsx
📚 Context
Please describe the project or issue background here
This PR adds
stepparameter tost.time_inputas a keyword only optional param.🧠 Description of Changes
Add bullet points summarizing your changes here
Revised:
Insert screenshot of your updated UI/code here
Current:
Insert screenshot of existing UI/code here
🧪 Testing Done
🌐 References
Does this depend on other work, documents, or tickets?
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.