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

Show dialog errors at the top #17221

Merged
merged 4 commits into from Dec 3, 2022
Merged

Conversation

martinpitt
Copy link
Member

@martinpitt martinpitt commented Apr 5, 2022

See @garrett's review in #17214 (review) . This makes our dialogs comply with PatternFly form validation design.

On main they look like this:

kdump-main
motd-edit-main
timer-main
crypto-policies-main

With this PR they look like this:
kdump-pr
motd-edit-pr
timer-pr
crypto-policies-pr png

Initial draft which just converts cockpit-components-dialog and a few <ModalError> instances.

  • Builds on top of systemd: Show timer creation errors #17220 (spotted during this conversion)
  • tuned
  • shell superuser
  • shell host dialog
  • shell credentials
  • Software Updates
  • Firewall
  • NetworkManager dialogs-common
  • Metrics

@martinpitt
Copy link
Member Author

@garrett : Is this the direction that you had in mind? I can't say I like it (it makes the dialog contents jump around), but PF makes this rather clear. So I'm mostly asking whether I am missing something in general, before I spend more time to fix the rest. They all need to be tested individually, e.g. one dialog didn't have a <Form> so the spacing was wrong. And the timer dialog had completely broken error reporting.

@jelly
Copy link
Member

jelly commented Apr 5, 2022

Just had this with kpatches, it is shown at the top but it's missing some spacing in my opinion.
image

Does this PR handle that too?

@martinpitt
Copy link
Member Author

@jelly : Thanks for spotting -- I suppose that's another case of missing a <Form> wrapper. As this is an utterly complex endeavour, I'll split up the cockpit-components-dialog PR from the <ModalError> PR -- even individually they are hard enough.

@jelly
Copy link
Member

jelly commented Apr 5, 2022

@jelly : Thanks for spotting -- I suppose that's another case of missing a <Form> wrapper. As this is an utterly complex endeavour, I'll split up the cockpit-components-dialog PR from the <ModalError> PR -- even individually they are hard enough.

Yup, it's missing a <Form> shall I make it a part of the my install kpatches update branch?

This looks fine now
image

@martinpitt
Copy link
Member Author

@jelly : Sure, why not -- then let's block this PR on your's as well.

@garrett
Copy link
Member

garrett commented Apr 6, 2022

@garrett : Is this the direction that you had in mind? I can't say I like it (it makes the dialog contents jump around), but PF makes this rather clear.

Yes. And I agree about not liking the contents jump around; I don't like that either and it's probably why it was on the bottom.

But, yes, PF is very clear about this.

And this is why we should, in most cases, have errors situated at the origin of error (as in: the widget that has problematic data, such as inputs with invalid entries) whenever possible.

However, in every single example above, there's no amount of changing the values that can affect the outcome. There's no permission or something going wrong when saving, so there's really no problem pushing down the form which cannot fix the problem anyway... at least in these examples.

So I'm mostly asking whether I am missing something in general, before I spend more time to fix the rest. They all need to be tested individually, e.g. one dialog didn't have a <Form> so the spacing was wrong. And the timer dialog had completely broken error reporting.

Yeah, thankfully we caught that. Forms really should have a <Form> of some type; the HTML specs are pretty clear about <form> being needed for widgets to be useful (at least without sprinkling in JavaScript to do something not necessarily related to a form). If it happened to work before, then that's just browsers trying to deal with invalid HTML and doing something that approximates what is expected.

If an element is not nested within in a form, then a form association can be attached. Otherwise, its form association is null (which was the case here):

https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#association-of-controls-and-forms

(This is about browser implementations and fallbacks.)

Here's MDN specifically pointing out <input form="formID">: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-form

It's best to just nest within a <form> instead of using the form attribute to point to a <form>, as the attribute just makes things confusing and loses context of other form elements. It exists as a fallback mechanism:

The form attribute lets you place an input anywhere in the document but have it included with a form elsewhere in the document.

But then note:

Note: An input can only be associated with one form.

(But it should be associated with a form. Ideally nested within. But rare circumstances require the use of the form attribute instead.)

@garrett
Copy link
Member

garrett commented Apr 7, 2022

FWIW: We would ideally have this PR, #17221, and PRs similar to the machines one for modals in Cockpit, Cockpit-Podman, etc. all land in the same release.

@jelly
Copy link
Member

jelly commented Apr 8, 2022

Found out that cockpit-machines needs fixing:

image

@garrett
Copy link
Member

garrett commented Apr 21, 2022

Just checking in: What's the status of this PR? Is it waiting on anything or anyone? (It's still marked as draft, FWIW.)

The screenshots look good to me, so I'm happy with what I see so far. Triggering all the errors might be a bit difficult to see it aside from the screenshots, however.

@martinpitt
Copy link
Member Author

@garrett : Not blocked, I just didn't find the time to look into this again. This is a huge piece of work, but splitting it up into several independent PRs runs the risk of being inconsistent in a release.

@garrett
Copy link
Member

garrett commented Apr 25, 2022

Not blocked

Whew. I was worried that I was blocking it. 😅 👍

This is a huge piece of work, but splitting it up into several independent PRs runs the risk of being inconsistent in a release.

Yep. This is definitely one of those massive PRs that touches a lot of the codebase and needs to be all-in-one.

@garrett
Copy link
Member

garrett commented Nov 7, 2022

Can we get this looked at again and merged soon, please? Thanks! ✨

@KKoukiou KKoukiou removed the blocked label Nov 30, 2022
@KKoukiou KKoukiou self-assigned this Nov 30, 2022
@KKoukiou KKoukiou temporarily deployed to cockpit-dist November 30, 2022 12:06 Inactive
@KKoukiou
Copy link
Contributor

Updated all dialogs I could find with alerts in modal. All affected dialogs seen in the screenshots below.

border-border-Screen Shot 2022-11-30 at 12 24 42
border-border-Screen Shot 2022-11-30 at 12 27 03
border-border-Screen Shot 2022-11-30 at 12 29 24
border-border-Screen Shot 2022-11-30 at 12 32 06
border-border-Screen Shot 2022-11-30 at 12 35 10
border-border-Screen Shot 2022-11-30 at 12 35 24
border-border-Screen Shot 2022-11-30 at 12 38 01
border-border-Screen Shot 2022-11-30 at 12 45 05
border-border-Screen Shot 2022-11-30 at 12 45 28
border-border-Screen Shot 2022-11-30 at 12 49 22
border-border-Screen Shot 2022-11-30 at 12 52 11
border-border-Screen Shot 2022-11-30 at 12 55 04
border-border-Screen Shot 2022-11-30 at 12 56 26

@KKoukiou KKoukiou marked this pull request as ready for review November 30, 2022 12:18
@KKoukiou KKoukiou temporarily deployed to cockpit-dist November 30, 2022 12:23 Inactive
@martinpitt
Copy link
Member Author

@KKoukiou : Thank you! This may also affect some pixel tests, or don't we have any errors there?

@KKoukiou
Copy link
Contributor

@KKoukiou : Thank you! This may also affect some pixel tests, or don't we have any errors there?

I will wait for the test results and see :)

@KKoukiou KKoukiou temporarily deployed to cockpit-dist November 30, 2022 14:04 Inactive
@KKoukiou KKoukiou temporarily deployed to cockpit-dist November 30, 2022 15:18 Inactive
@KKoukiou KKoukiou temporarily deployed to cockpit-dist November 30, 2022 17:41 Inactive
@KKoukiou KKoukiou temporarily deployed to cockpit-dist December 1, 2022 10:33 Inactive
KKoukiou
KKoukiou previously approved these changes Dec 1, 2022
Copy link
Contributor

@KKoukiou KKoukiou left a comment

Choose a reason for hiding this comment

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

Self approving - but I would love someone else to take a look as well :)

@martinpitt
Copy link
Member Author

Thanks @KKoukiou for finishing this! The first few changes in the pixel test comparison look like acceptable noise. However, the "Switch to administrative access" dialog got a lot of extra space now, which looks sad. Is this easy to fix?

@garrett
Copy link
Member

garrett commented Dec 1, 2022

Thanks for the comparison screenshots!

It's not the only one with extra space, for example:

image

And there's extra space here, too (also above "these changes"; the differentiating space below is due to the scroll region content being different):

image

(And there are a bunch of others, but I think most are variants.)


Additionally, there's a bug in the dark theme as seen here:

image

(The white in the table becomes black, whereas the white in the modal becomes dark grey.)

...but it's not a problem in this PR itself; it's just visible here. This one particular bug with the dark theme lists should be fixed elsewhere.

Nothing uses the footer outside of the Dialog class, and it's not an API
that makes much sense on its own.

Likewise, the Dialog class is very hard to use standalone without
`show_modal_dialog()`, and nothing imports it.

Make these private, so that we can change their implementation.
@KKoukiou KKoukiou temporarily deployed to cockpit-dist December 1, 2022 17:51 Inactive
@KKoukiou KKoukiou marked this pull request as ready for review December 1, 2022 18:52
@KKoukiou KKoukiou temporarily deployed to cockpit-dist December 1, 2022 18:56 Inactive
@KKoukiou KKoukiou temporarily deployed to cockpit-dist December 2, 2022 00:17 Inactive
@martinpitt
Copy link
Member Author

Thanks @KKoukiou ! LGTM, but I can't approve as it's my PR

@jelly
Copy link
Member

jelly commented Dec 2, 2022

Thanks @KKoukiou ! LGTM, but I can't approve as it's my PR

Approved!

isDisabled={ !dialogLoggerValue }
onChange={enable => setDialogProxyValue(enable)} />
<Stack hasGutter>
{ dialogError && <ModalError dialogError={ _("Failed to configure PCP") } dialogErrorDetail={dialogError} /> }
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test. Details

@@ -71,10 +71,11 @@ const onDialogDone = function(success) {
document.getElementById("demo-dialog-result").textContent = "Dialog closed: " + result + "(" + action + ")";
};

const onStandardDemoClicked = function(staticError) {
const onStandardDemoClicked = (staticError) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test. Details

const dialogProps = {
title: "This shouldn't be seen",
body: React.createElement(PatternDialogBody, { clickNested: onStandardDemoClicked }),
static_error: staticError,
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test. Details

@@ -316,14 +316,12 @@ const UnlockKey = ({ keyName, load, onClose }) => {
<Button variant='link' onClick={onClose}>{_("Cancel")}</Button>
</>
}>
<>
<Form onSubmit={e => { e.preventDefault(); return false }} isHorizontal>
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test. Details

@@ -278,7 +280,10 @@ class AddMachine extends React.Component {
</Button>
</>}
>
{body}
<Stack hasGutter>
{ this.props.dialogError && <ModalError dialogError={this.props.dialogError} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test. Details

<p>{_("Your browser will remember your access level across sessions.")}</p>
</>
<Stack hasGutter>
{error && <ModalError dialogError={error} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test. Details

@@ -183,6 +182,7 @@ const CryptoPolicyDialog = ({
</>
}
>
{error && <ModalError dialogError={typeof error == 'string' ? error : error.message} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test. Details

Comment on lines +74 to +75
<ModalError dialogError={error}
dialogErrorDetail={errorDetail} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 added lines are not executed by any test. Details

{dialogError && <ModalError dialogError={_("Timer deletion failed")} dialogErrorDetail={dialogError} />}
{reason}
<Stack hasGutter>
{dialogError && <ModalError dialogError={_("Timer deletion failed")} dialogErrorDetail={dialogError} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test. Details

@@ -314,6 +313,7 @@ const TunedDialog = ({
</>
}
>
{error && <ModalError dialogError={typeof error == 'string' ? error : error.message} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test. Details

@KKoukiou KKoukiou merged commit 4a7a40f into cockpit-project:main Dec 3, 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

5 participants