Skip to content

Add Pull Request builds page to settings #10656

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

Merged
merged 16 commits into from
Jul 1, 2024
Merged

Conversation

ericholscher
Copy link
Member

@ericholscher ericholscher commented Aug 22, 2023

This is a basic form for now,
but we can spruce it up before it goes live.

Closes #10411

humitos
humitos previously approved these changes Aug 23, 2023
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

I'm not sure to understand what's the context or the goal of this PR. Can you expand on the background of it?

@humitos humitos dismissed their stale review August 23, 2023 09:16

Wrong button

@ericholscher
Copy link
Member Author

ericholscher commented Aug 23, 2023

@humitos It's adding a page in settings to configure PR builds. It's a huge feature that is important to users, so we should unhide it, and make it much more visible.

More info here: readthedocs/ext-theme#199

model = Project
form_class = ProjectPullRequestForm
success_message = _("Pull request settings have been updated")
template_name = "projects/project_pull_requests.html"
Copy link
Contributor

Choose a reason for hiding this comment

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

In the new dashboard, I'm trying to stick to a naming convention closer to Django's built in naming and I have been removing our prefixes like project_. For this, I'd use:

Suggested change
template_name = "projects/project_pull_requests.html"
template_name = "projects/pull_requests_form.html"

@agjohnson
Copy link
Contributor

I'm guessing this might leak into next week, one of us can jump in and take assignment here if this needs anything else.

The change was small enough here and I don't have much to add to this, but I'll defer to @humitos on anything else needed here.

@humitos
Copy link
Member

humitos commented Aug 28, 2023

The change looks good to me after talking a little more about this with Eric. However, tests and checks are failing, so I think there is no need to rush here.

ericholscher and others added 2 commits August 31, 2023 19:57
This is a basic form for now,
but we can spruce it up before it goes live.
@agjohnson agjohnson force-pushed the pull-request-settings branch from 22eb01d to 9cc292b Compare September 1, 2023 03:19
@agjohnson agjohnson requested a review from a team as a code owner September 1, 2023 03:19
@agjohnson agjohnson self-requested a review September 1, 2023 03:19
@agjohnson
Copy link
Contributor

I patched things up, tests are looking like they will pass.

@agjohnson agjohnson enabled auto-merge (squash) September 1, 2023 03:48
@agjohnson agjohnson disabled auto-merge September 1, 2023 03:51
@agjohnson
Copy link
Contributor

I've just noticed that the advanced form has a bit more logic to it however, and this would be a good addition to retain:

image

Note the field is disabled because the project lacks and integration.

@humitos
Copy link
Member

humitos commented Sep 6, 2023

This PR is related to readthedocs/ext-theme#211 that talks about adding a completely new admin page to configure the addons. Since there is an addon that's related with PRs (the external version warning), we could consider that issue here as well.

@agjohnson
Copy link
Contributor

Ah yes, true. Ultimately, when addons are fully deployed for all projects, it would make a lot of sense to group all the options on a single admin page (that is, options "Enable pull request builds" and "Show pull request build notification in documentation").

I'm not sure how we'd treat the notification in the admin until then though, given we probably want that option dependent on whether or not the project has opted into the addons beta as well.

Let's keep this in mind as we work towards some sort of beta opt-in page, as perhaps it is a good option to add to this admin page. At very least we should link to the opt-in admin page from this admin page though.

@humitos
Copy link
Member

humitos commented Sep 7, 2023

I'm not sure how we'd treat the notification in the admin until then though, given we probably want that option dependent on whether or not the project has opted into the addons beta as well.

I created this issue to talk about this in particular: readthedocs/ext-theme#212

@agjohnson
Copy link
Contributor

I got this ready for merging last week, but I do think we should preserve how the field is conditionally enabled when there is a connected remote repo.

We could add the existing logic to the form instance here, disabling the field if there are no remote repos attached. I think I'd probably opt for raising a validation error though, as the greyed out field isn't super obvious and can be easy to miss.

The best solution would probably be doing something stronger at the template level, and conditionally disabling/showing the form when the remote repo is missing. This would give a good place to help describe the problem and point the user in the right direction. We sort of have this with the help text now, but I'm picturing some more complex UI here -- buttons linking out to resources, and perhaps make the warning a ui info message.

I'll hand this back over to @eric. Either option works great, we can always come back later and make the templates nicer.

@ericholscher
Copy link
Member Author

Cool, I will take a look at how the field is disabled, and look at adding some additional info into the page to make it a nicer UX.

@ericholscher
Copy link
Member Author

ericholscher commented Feb 10, 2024

I updated this PR to pull over the validation logic into the PR build form. I noticed that when the field is disabled, you can't see the help_text. I wasn't sure the best pattern for showing the error validation message in the form.

@agjohnson do we have a pattern here? Should I set an error on the form or something so that it shows in a nicer way to the user? There was a pile of logic trying to figure out if the form should be disabled, so I didn't want to port that over the the templates.

(Believe readthedocs/common#198 should fix tests)

@agjohnson
Copy link
Contributor

This is a good question, and actually the work I am doing on #11095 is relevant here too.

Help text can be helpful for giving hints to users about a particular field, but it's also really good at making forms way too noisy. So, I would like to move away from relying on help text for these sorts of scenarios, and especially a case where the form should be disabled when a condition isn't met.

Using the PR above as base, the Form instance here could implement a clean_prevalidation() that throws a validation error when the required configuration for PR builds isn't met. This surfaces as a titled, non-field error in the UI, and you can even go as far as to use form.is_disabled() to add disabled CSS class to the form element.

@ericholscher
Copy link
Member Author

Using the PR above as base, the Form instance here could implement a clean_prevalidation() that throws a validation error when the required configuration for PR builds isn't met. This surfaces as a titled, non-field error in the UI, and you can even go as far as to use form.is_disabled() to add disabled CSS class to the form element.

This isn't a standard Django thing, so you're suggesting we build our own prevalidation step? I don't quite understand how that validation error would be shown in the UI -- is there an example of this somewhere?

@agjohnson
Copy link
Contributor

This isn't a standard Django thing, so you're suggesting we build our own prevalidation step?

Yes, this is implemented already in the PR I linked though. The work required here is to throw a validation error from the Form, similar to this:

I don't quite understand how that validation error would be shown in the UI -- is there an example of this somewhere?

I pasted an example in that PR: #11095 (comment)

These validation errors are added as standard non-field errors. The PR also includes a validation error class that includes a custom header, which I'd also suggest here.

@ericholscher
Copy link
Member Author

ericholscher commented Mar 12, 2024

@agjohnson I tried to update this to use the prevalidation logic, but getting this weird error, and it's not disabling the form:

Screenshot 2024-03-12 at 3 51 26 PM

@agjohnson
Copy link
Contributor

agjohnson commented Mar 13, 2024

I think your code looks correct, but the form error is not displaying as I would expect. Are you using {{ form | crispy }} to display the form?

If the error display correctly, it should display the validation error header attribute value instead of Error as a header, and it shouldn't render as an array of strings.

and it's not disabling the form

This requires a class addition at the form at the moment. If we want a nice pattern here, there must be some way to do this programmatically from the form/view though.

For now, you can set .ui.disabled.form classes on the <form> element when the form should be disabled.

The first example I did using this didn't quite do what you are doing, there is only technically a form (hence just showing the errors for now):

https://github.com/readthedocs/ext-theme/blob/710cd193cf631eb03e8b003c03346298391bdf6a/readthedocsext/theme/templates/projects/import_form.html#L29-L36

@agjohnson
Copy link
Contributor

agjohnson commented Apr 10, 2024

The error displayed fine for me, so I think you maybe have an old base for your PR on ext-theme. What is not working is form.is_disabled, it doesn't seem like form._prevalidation_errors is populated -- not exactly sure why yet. The validation error shows, implying clean_prevalidate is called, but the validation error is not saved to form._prevalidation_errors. Much of this happens at PrevalidateForm.

image

Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

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

I also got 'UpdateProjectForm' object has no attribute 'setup_external_builds_option' loading the main setting page, which seems related.

This looks close, I think we could visit tuning up the prevalidation form pattern separately -- though it does involve coming back and fixing this form either way.

@@ -574,8 +580,24 @@ def clean_alias(self):
return alias


class AddonsConfigForm(forms.ModelForm):
class ProjectPullRequestForm(forms.ModelForm, ProjectPRBuildsMixin):
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect form.is_disabled isn't working correctly from the templates because of ModelForm base, but I haven't quite pinpointed that one yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, so far form.errors was called first, populating all the correct errors. The template logic if form.errors and form.is_disabled is correct for now.

Noted in:

@ericholscher
Copy link
Member Author

@agjohnson Not really sure the best steps here? You can just push to this PR if you want changes vs. suggestions, but it sounds like it's not ready to merge?

@agjohnson
Copy link
Contributor

agjohnson commented Apr 19, 2024

What is blocking this currently:

I didn't look into solving the bug introduced here with the main settings view. I did rebase these PRs locally to have everything up to date. If you aren't noticing the exception locally, you likely should after rebasing.

With everything rebased, the form errors were working as expected.

@ericholscher
Copy link
Member Author

I believe these changes should be addressed in the updated PRs 👍

Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

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

Looks good to go for now! We can revisit this pattern with some fixes to prevalidation forms in #11270

Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

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

This looks good. I noted to come back to these patterns in #11270 and update the code here.

@ericholscher ericholscher merged commit d2ad47b into main Jul 1, 2024
@ericholscher ericholscher deleted the pull-request-settings branch July 1, 2024 21:39
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.

Dashboard: Move "Build pull requests for this project"
3 participants