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

Adds validation: parameter name must be specified if value is specified #65

Merged
merged 11 commits into from
Sep 30, 2022

Conversation

JasonWeill
Copy link
Collaborator

In the create form, if the parameter value is nonblank, the parameter name must not be blank.

If the parameter name and value are both blank, there is no error.

If the parameter name is nonblank and the value is blank, there is no error.

Errors are displayed on name or value blur.

There is no validation for the value.

parameter-validation.mov

@github-actions
Copy link
Contributor

Binder 👈 Launch a Binder on branch jweill-aws/jupyter-scheduler/parameter-validation

@3coins
Copy link
Collaborator

3coins commented Sep 30, 2022

@jweill-aws
I am not sure about allowing a parameter name with blank value. It would seem that in most cases this is likely an oversight by the user and they probably missed providing a value; prompting user to add a value in this case is likely the right intent. What do you think?

Comment on lines 26 to 32
const useForceUpdate = () => {
const [, setTick] = useState(0);
const update = useCallback(() => {
setTick(tick => tick + 1);
}, []);
return update;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Without useForceUpdate, although the model is updated, the parameters component does not automatically rerender. This function is meant to update a nominal state to force a rerender.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we know why this behavior is happening?
That seems like a hack to support a refresh that React supports by design; this is likely an issue with our code. If ParametersPicker is a functional component, any update to props is supposed to re-render it. If you need internal state in the ParametersPicker to trigger changes, then that's the way to go. In either case, there shouldn't be a pattern of adding an unused state to force updates.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A parameter with a name and an empty-string value is not inherently an error; there might be a reasonable reason for that. (The errors variable uses an empty-string value to mean "no error" for a particular input name, for example.) @ellisonbg had suggested the specific case of "empty parameter name, non-empty parameter value" being an error, but I don't consider the other three cases to be problematic:

Empty name Name
Empty value ✅ ✅
Value ❌ ✅

From a user's perspective, there is a very low chance they would want to pass an empty string for a parameter; for other cases (number, boolean) this will cause an exception. On the other hand, blocking users to pass an empty value will hinder some users, I don't feel that we will have a lot of users who would want this. Ok to submit this as-is and revisit after some user feedback.

Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW, the async update was fixed in #63.

@JasonWeill
Copy link
Collaborator Author

@jweill-aws I am not sure about allowing a parameter name with blank value. It would seem that in most cases this is likely an oversight by the user and they probably missed providing a value; prompting user to add a value in this case is likely the right intent. What do you think?

A parameter with a name and an empty-string value is not inherently an error; there might be a reasonable reason for that. (The errors variable uses an empty-string value to mean "no error" for a particular input name, for example.) @ellisonbg had suggested the specific case of "empty parameter name, non-empty parameter value" being an error, but I don't consider the other three cases to be problematic:

Empty name Name
Empty value
Value

@dlqqq
Copy link
Collaborator

dlqqq commented Sep 30, 2022

A parameter with a name and an empty-string value is not inherently an error; there might be a reasonable reason for that.

I believe this is to preserve parity with shell environment variables, which can be defined without values. A common example is just to define export DEBUG in your local shell and have an application dispatch additional logging based on that.

src/components/parameters-picker.tsx Outdated Show resolved Hide resolved
@dlqqq
Copy link
Collaborator

dlqqq commented Sep 30, 2022

Let me rebase off of main and include a change to fix that bug.

@dlqqq
Copy link
Collaborator

dlqqq commented Sep 30, 2022

Other bugs I found while playing around:

Screen.Recording.2022-09-30.at.10.44.14.AM.mov

Deleting param should clear the corresponding errors.

Screen.Recording.2022-09-30.at.10.47.03.AM.mov

Error state is not being correctly re-calculated upon deleting a param in the middle.

@dlqqq
Copy link
Collaborator

dlqqq commented Sep 30, 2022

@jweill-aws @3coins I rebased off of main, removed the useForceUpdate() hook, and fixed the aforementioned error state bugs.

src/mainviews/create-job.tsx Show resolved Hide resolved
dlqqq and others added 5 commits September 30, 2022 14:52
updates:
- [github.com/pre-commit/pre-commit-hooks: v4.2.0 → v4.3.0](pre-commit/pre-commit-hooks@v4.2.0...v4.3.0)
- [github.com/psf/black: 22.3.0 → 22.8.0](psf/black@22.3.0...22.8.0)
- [github.com/asottile/pyupgrade: v2.32.1 → v2.38.2](asottile/pyupgrade@v2.32.1...v2.38.2)
- [github.com/pycqa/flake8: 4.0.1 → 5.0.4](PyCQA/flake8@4.0.1...5.0.4)
- [github.com/sirosen/check-jsonschema: 0.15.0 → 0.18.3](python-jsonschema/check-jsonschema@0.15.0...0.18.3)
…erver#61)

* Improvements to the MUI theme for JupyterLab.

* Additional theme improvements.

Co-authored-by: Brian E. Granger <brgrange@amazon.com>
@dlqqq dlqqq merged commit df78aa7 into jupyter-server:main Sep 30, 2022
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

4 participants