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

Propagate changes of md-rendered checkboxes to the server #14258

Closed
wants to merge 5 commits into from

Conversation

j2L4e
Copy link

@j2L4e j2L4e commented Jan 5, 2021

Markdown rendered checkboxes are now enabled/clickable in comment blocks, markdown is changed accordingly and the raw comment is updated on the server.

Attaches change handlers to the markdown rendered checkboxes.
When a checkbox value changes, the corresponding [ ] or [x] in the markdown string is set accordingly and sent to the server.
On success it updates the raw-content on error it resets the checkbox to its original value.
While a request is in-flight, all checkboxes within the same markdown block are disabled.

#7097

@j2L4e j2L4e changed the title handle changes of md-rendered checkboxes on an issue page to the s… Propagate changes of md-rendered checkboxes on issue pages to the server Jan 5, 2021
@techknowlogick techknowlogick added type/enhancement An improvement of existing functionality topic/ui Change the appearance of the Gitea UI labels Jan 5, 2021
@j2L4e j2L4e changed the title Propagate changes of md-rendered checkboxes on issue pages to the server Propagate changes of md-rendered checkboxes to the server Jan 5, 2021
@codecov-io
Copy link

codecov-io commented Jan 5, 2021

Codecov Report

Merging #14258 (4ac7ad5) into master (126c933) will decrease coverage by 0.10%.
The diff coverage is 26.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14258      +/-   ##
==========================================
- Coverage   41.97%   41.87%   -0.11%     
==========================================
  Files         735      742       +7     
  Lines       78933    79324     +391     
==========================================
+ Hits        33132    33214      +82     
- Misses      40346    40647     +301     
- Partials     5455     5463       +8     
Impacted Files Coverage Δ
modules/auth/admin.go 0.00% <ø> (ø)
modules/auth/auth.go 61.53% <ø> (-2.51%) ⬇️
modules/auth/sso/reverseproxy.go 9.52% <0.00%> (ø)
modules/middlewares/cookie.go 0.00% <0.00%> (ø)
modules/middlewares/locale.go 0.00% <0.00%> (ø)
modules/middlewares/redis.go 2.15% <2.15%> (ø)
routers/admin/users.go 27.77% <26.66%> (-0.08%) ⬇️
modules/templates/base.go 28.57% <28.57%> (ø)
routers/routes/recovery.go 29.41% <29.41%> (ø)
modules/middlewares/virtual.go 32.29% <32.29%> (ø)
... and 24 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 4ef5f17...4ac7ad5. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 5, 2021
@j2L4e j2L4e requested review from 6543 and zeripath January 8, 2021 14:14
@j2L4e j2L4e mentioned this pull request Jan 12, 2021
7 tasks
Copy link
Member

@noerw noerw left a comment

Choose a reason for hiding this comment

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

Thank you! 🎉

Two edge cases to consider:

  1. Your markdown <-> checkbox matching fails for pathologic markdown like the following:

    [x]
    - [ ] foobar

    This should be fixable with a stricter regex like ^- \[[ x]\]

  2. The checkboxes are still interactive when user can't edit a comment. For accessibility I'd prefer if these checkboxes remain disabled. You could check if a sibling matching .comment-container .comment-header-right .menu .item.edit-content exists, or (cleaner) add a data-attr to the comment indicating if it is editable. For the cleaner solution, edit templates/repo/issue/view_content/comments.tmpl with a similar check to

    {{if or .ctx.Permission.IsAdmin .IsCommentPoster .ctx.HasIssuesOrPullsWritePermission}}

@zeripath
Copy link
Contributor

Thank you!

Two edge cases to consider:

  1. Your markdown <-> checkbox matching fails for pathologic markdown like the following:

    [x]
    - [ ] foobar
    

    This should be fixable with a stricter regex like ^- \[[ x]\]

as I showed in #14258 (comment) the regexp route cannot work - we need to store the index in the raw markdown of the checkbox as described here: #14258 (comment) (and some kind of hash of the raw markdown too to ensure it hasn't changed in the intervening period) then switch the checkbox that way.

  1. The checkboxes are still interactive when user can't edit a comment. For accessibility I'd prefer if these checkboxes remain disabled. You could check if a sibling matching .comment-container .comment-header-right .menu .item.edit-content exists, or (cleaner) add a data-attr to the comment indicating if it is editable. For the cleaner solution, edit templates/repo/issue/view_content/comments.tmpl with a similar check to
    {{if or .ctx.Permission.IsAdmin .IsCommentPoster .ctx.HasIssuesOrPullsWritePermission}}

Agreed - these should be disabled if the user does not have permission to edit.

We can pass in the permission check as part of render config to goldmark to get it to render actual forms for the checkboxes - although getting that past the sanitizer as currently constituted could be difficult - or just get javascript to enable them - by passing in the permission flag as part of the render.

@lunny
Copy link
Member

lunny commented Jan 25, 2021

  • The markdown or orgmode renderer should give the line number of the checkbox on original document.
  • All checkboxes should accept an event to request backend to update the markdown/orgmode and then update the frontend document via ajax .

@j2L4e
Copy link
Author

j2L4e commented Jan 29, 2021

I'm still up for this, but having a lot on my plate right now. I'll get it done when I find the time to read up on go a little, so I don't just blindly apply zeripath's diff (thanks for that) but know how it works. Shouldn't be that long.

If anyone's willing to do it right away, go ahead. Will report back here once I start working on it again

@6543 6543 added this to the 1.15.0 milestone Feb 13, 2021
@go-gitea go-gitea locked and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. topic/ui Change the appearance of the Gitea UI type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants