Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add tags to patches #69

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 25 commits into from
Jun 16, 2025
Merged

Add tags to patches #69

merged 25 commits into from
Jun 16, 2025

Conversation

jchampio
Copy link
Contributor

@jchampio jchampio commented Jun 2, 2025

A Tag is an arbitrary label for a patch in the Commitfest UI. Other than helping users identify patches of interest, it has no other semantic meaning to the CF application. This addresses #11 and #67.

Tags are created using the administrator interface. They consist of a unique name and a background color. The color should be sent from compliant browsers in #rrggbb format, which is stored without backend validation; to avoid later CSS injection, any non-conforming values are replaced with black during rendering.

It also includes some javascript to help admins pick colors that aren't completely eye-gouging, by putting up an (ignorable) warning if we don't meet baseline WCAG recommendations on text contrast.

Notes

  • To avoid putting a separate name+color copy of every tag into each row of the patchlist query, I instead grab the tag IDs and look them up in a map at render time. I think this requires @transaction.atomic to tie the map and patches together, which I've added across the entire view for simplicity.
  • Backend validation for the color didn't make a whole lot of sense to me, since only admins can create tags and we escape at time-of-use anyway.

Screenshots

Admin interface:
image
User interface:
image

jchampio added 2 commits June 2, 2025 10:48
A Tag is an arbitrary label for a patch in the Commitfest UI. Other than
helping users identify patches of interest, it has no other semantic
meaning to the CF application.

Tags are created using the administrator interface. They consist of a
unique name and a background color. The color should be sent from
compliant browsers in #rrggbb format, which is stored without backend
validation; to avoid CSS injection, any non-conforming values are
replaced with black during templating.
Add front-end soft validation to the TagAdmin form. This uses WCAG 2.2
guidelines to warn the administrator if a color choice is going to be
low-contrast when compared to our text/background color of white. (The
warning may be ignored.)
@@ -531,6 +533,7 @@ def patchlist(request, cf, personalized=False):
)


@transaction.atomic # tie the patchlist() query to Tag.objects.all()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be inclined to define Tag as an append/update-only table - soft deletes only. Think PostgreSQL enums in recommended usage (but with a soft delete capability). No real point enforcing a transaction to read its contents in that case. Even if we got an overly fresh read the attributes of Tag that would be valid data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Until tag usage settles, I think it should be easy for CFMs to add and remove them. (Easily worth a transaction wrap IMO, and the more I look at the complexity of patchlist() the more I think that perhaps it should have been wrapped already...)

Is there some hidden cost to @transaction.atomic that's not in the documentation, that I should be aware of?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there some hidden cost to @transaction.atomic that's not in the documentation, that I should be aware of?

Not that I know of. The goal of using soft deletes still stands. Don't show "hidden/deleted" tags in the UI but they are still there and can be re-enabled. With name/description separated from label so long as the purpose is deemed valid the label can be changed to better match community expectations - which I suspect would happen if we removed and then reinstated a tag. It doesn't have to a hard-and-fast rule; especially if we don't functionally depend on it.

class Patch(models.Model, DiffableModel):
name = models.CharField(
max_length=500, blank=False, null=False, verbose_name="Description"
)
topic = models.ForeignKey(Topic, blank=False, null=False, on_delete=models.CASCADE)
tags = models.ManyToManyField(Tag, related_name="patches", blank=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe also pre-mature, and likely reasonably added later, but I envisioned an ability for annotations to be added to the tag-patch mapping. Maybe the commit message and email threads are enough places to write stuff but, especially for something like 'Good First Issue', some commentary as to why would be expected to exist somewhere, and a tag annotation seems like a good place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also thinking we'll use the mailing list for primary discussion while this shakes out, but I think this would be a good thing to add eventually.

@polobo
Copy link
Contributor

polobo commented Jun 5, 2025

For the CSS I've a couple of thoughts.

Can we use "LCH" as the color specifier instead of RGB?

Python has cssutils to dynamically build stylesheets. Not sure we can fully delegate value validation but keeping the legibility check in place is nice which naturally checks the inputs.

I'd be more inclined to add data-* attributes to the html markup and build a dynamic stylesheet served from an assets URL. Solving cache busting/invalidation (version code in the virtual file name) should be straight-forward - tags aren't going to be frequently changing. I'm considering whether they should just be compiled in; do away with the creation UI altogether. Point users to an external color picker and just tell them where to copy the value. Need to do more research here though - just some thoughts for now.

@jchampio
Copy link
Contributor Author

jchampio commented Jun 5, 2025

Can we use "LCH" as the color specifier instead of RGB?

I like the technical details of LCH, but does it give users something? It's hard to beat "click the button, pick a color, move on" for the price of an <input>. If the system eventually gets the smarts to pick colors for you, then I think LCH starts to make more sense.

@polobo
Copy link
Contributor

polobo commented Jun 5, 2025

Can we use "LCH" as the color specifier instead of RGB?

I like the technical details of LCH, but does it give users something? It's hard to beat "click the button, pick a color, move on" for the price of an <input>. If the system eventually gets the smarts to pick colors for you, then I think LCH starts to make more sense.

I would say the people using this form are designers - our users are the people seeing the results on the webpage. It should be generally easier to produce a consistent set of colors for them to see if those colors are specified in LCH, in particular with a agreed-upon "Luminosity component. Also hoping to figure out dark mode at some point which seems easier to do if using LCH. People invented it and got in into the browsers for a reason.

@jchampio
Copy link
Contributor Author

jchampio commented Jun 5, 2025

Is it hard to migrate RGB to LCH later, if we eventually get to a place where we'd like to make better use of color?

@polobo
Copy link
Contributor

polobo commented Jun 5, 2025

I don’t have any immediate concerns about trying to migrate away from RGB in the future. This is stuff I would need to experiment with myself anyway.

@JelteF
Copy link
Collaborator

JelteF commented Jun 5, 2025

I think storing RGB is fine for now. One thing that would be nice is a "randomize color button" like github has for labels.

super().__init__(*args, **kwargs)


class Tag(models.Model):
Copy link
Collaborator

@JelteF JelteF Jun 5, 2025

Choose a reason for hiding this comment

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

Can you add some entries for this to the dummy database dump: https://github.com/postgres/pgcommitfest#regenerating-the-database-dump-files Or maybe even add a few to that we know we definitely want to the migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll add some to the dummy data. (I'm hoping the initial tags will come from the mailing list during the preview.)

Copy link
Collaborator

@JelteF JelteF Jun 6, 2025

Choose a reason for hiding this comment

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

I think "bug", "needs-user-testing", "needs-bikeshedding", "good-first-review", "mising-docs", "missing-tests" would be a good start.

@JelteF
Copy link
Collaborator

JelteF commented Jun 9, 2025

I played around with this PR just now. I committed a few quality of life improvements on this branch for usability issues I ran into. I think now the only thing it needs is some default tags for people to start with, and then we can merge this.

@polobo
Copy link
Contributor

polobo commented Jun 10, 2025

PG Tags

The attached picture contains my current thinking regarding how tags would be setup in the medium-to-long term. The colors are approximate - as I noted above all tag values in a category simply inherit the color for the category (no borders though, too hard to see and not needed). Bugs gets its own tag, then today's sections get broken out into 4 tag categories that we can fully populate as desired with specific tags. The "Needs Request" category then covers the things authors might want to signal they need help with. I've included a "Development" tag for features either previously abandoned by their author or those that exist because they are deemed "Good First Issue". The "Reviewer Type" likewise is present to handle the expressed desire to communicate the amount of expertise the author (or whomever can edit a patch) deems needed to move it forward. I've included CFBot as an initial placeholder for communicating with the CFBot besides adding directives to the commit message. Lastly, I've included the existing statuses and suggestions for how to color them in line with the tag coloring. In particular, I've reserved Green for In Progress/Committer. I was going to reserve Red for the "failure" statuses but figured Bug Fix made sense. Blue is (for me...I know color is cultural but not sure how to act on that knowledge) neutral in nature so server feature tags and reviewing - the normal/high-volume stuff - gets that. Special/Needs/Reviewer try to draw attention. Both Bug Fix and CFBot really need something besides tags, that exist in the linking record between tag and patch, to store information. Both pre-defined as shown here, and free-form text for stuff like Reviewer Type or Needs Request.

Here is a link to the source document. It is presently editable until I regret that choice or we find a better mechanism.

@polobo
Copy link
Contributor

polobo commented Jun 16, 2025

Strongly believe tag names should be written like; "Help - Docs" instead of "help-docs"; "Good First Review", etc...

@JelteF
Copy link
Collaborator

JelteF commented Jun 16, 2025

Strongly believe tag names should be written like; "Help - Docs" instead of "help-docs"; "Good First Review", etc...

Curious if you have any reason why you prefer that, but changed now.

@JelteF
Copy link
Collaborator

JelteF commented Jun 16, 2025

I couldn't find a way to push the background color into a safer data-* attribute, but maybe someone knows of a way to do that? That would get rid of the CSS injection problem altogether.

I looked into this, and afaict it's impossible to do this. Even with the attr css attribute, because that doesn't support colors: https://developer.mozilla.org/en-US/docs/Web/CSS/attr

@JelteF JelteF merged commit a0ae045 into postgres:main Jun 16, 2025
1 check passed
@polobo
Copy link
Contributor

polobo commented Jun 16, 2025

Strongly believe tag names should be written like; "Help - Docs" instead of "help-docs"; "Good First Review", etc...

Curious if you have any reason why you prefer that, but changed now.

The things people read day after day basically have the form “word word word” etc…so our brains have the least amount of work on syntax, and can hone in on content and remembering/association, when reading stuff in that form. Stuff like “word_word_word” and “word-word-word” look more like code (which given the audience suggests it wouldn’t be terrible) than something intended for polished user interface presentation. Capitalization of the first letter aids in this as well for title/label content for much the same reason.

JelteF added a commit that referenced this pull request Jun 22, 2025
A Tag is an arbitrary label for a patch in the Commitfest UI. Other than
helping users identify patches of interest, it has no other semantic
meaning to the CF application. This addresses #11 and #67.

Tags are created using the administrator interface. They consist of a
unique name and a background color. The color should be sent from
compliant browsers in `#rrggbb` format, which is stored without backend
validation; to avoid later CSS injection, any non-conforming values are
replaced with black during rendering.

It also includes some javascript to help admins pick colors that aren't
completely eye-gouging, by putting up an (ignorable) warning if we don't
meet baseline [WCAG
recommendations](https://www.w3.org/WAI/WCAG22/Techniques/general/G18.html)
on text contrast.

## Notes

- To avoid putting a separate name+color copy of every tag into each row
of the `patchlist` query, I instead grab the tag IDs and look them up in
a map at render time. I think this requires `@transaction.atomic` to tie
the map and patches together, which I've added across the entire view
for simplicity.
- Backend validation for the color didn't make a whole lot of sense to
me, since only admins can create tags and we escape at time-of-use
anyway.

## Screenshots
Admin interface:

![image](https://github.com/user-attachments/assets/8061a2d1-1d5b-456b-99bb-4af5d6dc79fc)
User interface:

![image](https://github.com/user-attachments/assets/9c95b307-c6e2-48c8-bd65-881c08429a96)

---------

Co-authored-by: Jelte Fennema-Nio <[email protected]>
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.

3 participants