Skip to content

Add configurable tag style rules - #1640

Closed
killecaptron wants to merge 1 commit into
Part-DB:masterfrom
killecaptron:tag-styles
Closed

killecaptron wants to merge 1 commit into
Part-DB:masterfrom
killecaptron:tag-styles

Conversation

@killecaptron

Copy link
Copy Markdown
Contributor

Tags are a free-form, flat list, and every tag looks the same, so a list of parts with a dozen tags per row
gives no visual grouping at all - even though tags are usually used in namespaces like Risk:High or
Project:Foo.

An administrator can now define an ordered list of rules under System settings → Tag styles, which map a tag
(exactly, or by prefix) to one of the semantic Bootstrap colors. Tags which do not match any rule keep their
previous appearance, and only the color of a tag changes - filtering and searching by tags are untouched.

At most one rule is applied per tag: an exact rule wins over a prefix rule, the longest matching prefix wins
among prefix rules, and the first configured rule wins any remaining tie. The rules are resolved in one place,
so tags look the same in the part tables and on the part page.

Each rule row previews itself while it is edited. The rules only take effect once the settings are saved, so a
row which showed a fixed word in the stored color gave no feedback about what is being typed: the badge now
shows the entered tag in the chosen color, a prefix rule marks itself with an ellipsis, and the badge explains
what the selected match type will match. That is also the answer to "exact or prefix?", which the two words
alone do not explain.

Documented in docs/usage/tag_styles.md.

🤖 Generated with Claude Code

Tags are a free-form, flat list, and every tag looked the same, so a
list of parts with a dozen tags per row gave no visual grouping at all -
even though tags are usually used in namespaces like "Risk:High" or
"Project:Foo".

An administrator can now define an ordered list of rules in the system
settings, which map a tag (exactly, or by prefix) to one of the semantic
Bootstrap colors. Tags which do not match any rule keep their previous
appearance, and only the color of a tag changes - filtering and
searching by tags are untouched.

At most one rule is applied per tag: an exact rule wins over a prefix
rule, the longest matching prefix wins among prefix rules, and the first
configured rule wins any remaining tie. The rules are resolved in one
place, so tags look the same in the part tables and on the part page.

Each rule row previews itself while it is edited. The rules only take
effect once the settings are saved, so a row which showed a fixed word
in the stored color gave no feedback about what is being typed: the
badge now shows the entered tag in the chosen color, a prefix rule marks
itself with an ellipsis, and a sentence below the row spells out what
the selected match type will match. That sentence is also the answer to
"exact or prefix?", which the two words alone do not explain.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jbtronics

Copy link
Copy Markdown
Member

@greptileai Review

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: plus

[Medium impact] The PR changes tag badge colors across several part views and adds an administrator settings workflow.

Fix the rule-number collision before merging; it can overwrite a remaining rule after saving.

Fix All in Claude CodeFindings

  1. P1 New rules overwrite existing rules ▶
  2. P2 Selected tags become unreadable ▶
  3. P2 Default preview shows wrong color ▶
  4. P2 Rule controls lack accessible names ▶
Fix with agent prompt
### Issue 1
templates/form/tag_style_rules_collection.html.twig:43
After removing a middle rule and saving, the page renders the same submitted form, whose remaining child names can be `0` and `2`. Using `form|length` resets the next index to `2`. Clicking “Add rule” creates another row with the same field names, so the next save can overwrite the existing rule.

Start above the largest rendered child index, or redirect after saving and handle sparse indexes after invalid submissions.

### Issue 2
src/DataTables/Column/TagsColumn.php:66
The new `text-bg-light`, `text-bg-warning`, and `text-bg-info` classes need dark text. But `tables.css` forces white text on every direct link in a selected row with a stronger `!important` rule. Selecting a part makes these tags hard to read; `light` becomes almost white on white.

Exclude badges with their own text color from the selected-row override.

### Issue 3
assets/controllers/pages/tag_style_rule_controller.js:75-76
Choosing `default` previews a gray badge, but saved tags do not use gray: `TagsColumn` keeps `bg-primary`, and `string_to_tags` keeps `bg-info`. Administrators therefore see a color they will not get after saving.

Make the preview explain that `default` keeps each page’s existing color instead of presenting `bg-secondary` as the result.

### Issue 4
src/Form/Settings/TagStyleRuleType.php:55-57
All three rule fields use `label: false`, but the column headings are plain `<strong>` elements and are not linked to the controls. The trash button also contains only an unnamed icon. Screen-reader users cannot tell what each field or button does.

Add translated accessible names using visually hidden labels or `aria-label`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds saved tag-color rules with exact and prefix matching.

  • Part tags can use saved exact and prefix color rules.
  • Rule previews update as an administrator edits each row.

All 24 added translation unit IDs were checked and match their keys. PHP tests and browser checks were not run: PHP, installed dependencies, and built frontend assets are absent.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    E[Rule edits] --> P[Live preview]
    E -->|Save| S[Saved rules]
    S --> R[TagStyleResolver]
    T[Part table tags] --> R
    D[Part details and tag-page header] --> R
    R --> M{Winning rule}
    M -->|Exact first, then longest prefix| C[Configured badge color]
    M -->|No match or default| F[Keep caller color]
Loading

Reviews (1) · Last reviewed commit: "Add configurable tag style rules" · Reviewed by Greptile

{% endset %}
{% set _proto_html = __proto|e('html_attr') %}
{% set _proto_name = form.vars.prototype_name|default('__name__') %}
{% set _index = form|length %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 New rules overwrite existing rules

After removing a middle rule and saving, the page renders the same submitted form, whose remaining child names can be 0 and 2. Using form|length resets the next index to 2. Clicking “Add rule” creates another row with the same field names, so the next save can overwrite the existing rule.

Start above the largest rendered child index, or redirect after saving and handle sparse indexes after invalid submissions.

Prompt To Fix With AI
This is a comment left during a code review.
Path: templates/form/tag_style_rules_collection.html.twig
Line: 43

Comment:
**New rules overwrite existing rules**

After removing a middle rule and saving, the page renders the same submitted form, whose remaining child names can be `0` and `2`. Using `form|length` resets the next index to `2`. Clicking “Add rule” creates another row with the same field names, so the next save can overwrite the existing rule.

Start above the largest rendered child index, or redirect after saving and handle sparse indexes after invalid submissions.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

'<a href="%s" class="badge bg-primary badge-table">%s</a>',
'<a href="%s" class="%s">%s</a>',
$this->urlGenerator->generate('part_list_tags', ['tag' => $tag]),
htmlspecialchars($this->tagStyleResolver->resolve((string) $tag, 'badge bg-primary badge-table')),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Selected tags become unreadable

The new text-bg-light, text-bg-warning, and text-bg-info classes need dark text. But tables.css forces white text on every direct link in a selected row with a stronger !important rule. Selecting a part makes these tags hard to read; light becomes almost white on white.

Exclude badges with their own text color from the selected-row override.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/DataTables/Column/TagsColumn.php
Line: 66

Comment:
**Selected tags become unreadable**

The new `text-bg-light`, `text-bg-warning`, and `text-bg-info` classes need dark text. But `tables.css` forces white text on every direct link in a selected row with a stronger `!important` rule. Selecting a part makes these tags hard to read; `light` becomes almost white on white.

Exclude badges with their own text color from the selected-row override.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

Comment on lines +75 to +76
//"default" means the rule does not force a colour, which is how an unmatched tag looks
const badgeClass = color === '' || color === 'default' ? 'bg-secondary' : `text-bg-${color}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Default preview shows wrong color

Choosing default previews a gray badge, but saved tags do not use gray: TagsColumn keeps bg-primary, and string_to_tags keeps bg-info. Administrators therefore see a color they will not get after saving.

Make the preview explain that default keeps each page’s existing color instead of presenting bg-secondary as the result.

Prompt To Fix With AI
This is a comment left during a code review.
Path: assets/controllers/pages/tag_style_rule_controller.js
Line: 75-76

Comment:
**Default preview shows wrong color**

Choosing `default` previews a gray badge, but saved tags do not use gray: `TagsColumn` keeps `bg-primary`, and `string_to_tags` keeps `bg-info`. Administrators therefore see a color they will not get after saving.

Make the preview explain that `default` keeps each page’s existing color instead of presenting `bg-secondary` as the result.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

Comment on lines +55 to +57
->add('pattern', TextType::class, [
'label' => false,
'required' => true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Rule controls lack accessible names

All three rule fields use label: false, but the column headings are plain <strong> elements and are not linked to the controls. The trash button also contains only an unnamed icon. Screen-reader users cannot tell what each field or button does.

Add translated accessible names using visually hidden labels or aria-label.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Form/Settings/TagStyleRuleType.php
Line: 55-57

Comment:
**Rule controls lack accessible names**

All three rule fields use `label: false`, but the column headings are plain `<strong>` elements and are not linked to the controls. The trash button also contains only an unnamed icon. Screen-reader users cannot tell what each field or button does.

Add translated accessible names using visually hidden labels or `aria-label`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

@jbtronics

Copy link
Copy Markdown
Member

I am planning to move the tag system to a way, where parts refer to a common global tag entities.
That makes sorting and grouping much easier, and will also allow to apply such styling rules directly onto tags instead of doing this quite indirect styling like here.

@killecaptron

Copy link
Copy Markdown
Contributor Author

Superseded by #1672, which stores tags as entities of their own (with colors, nesting and the other data structure features), as you suggested above. Closing this one.

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.

2 participants