Skip to content

Add colour support for tag configs#16109

Draft
bodhish wants to merge 1 commit intodevelopfrom
feature/tag-config-color-support
Draft

Add colour support for tag configs#16109
bodhish wants to merge 1 commit intodevelopfrom
feature/tag-config-color-support

Conversation

@bodhish
Copy link
Member

@bodhish bodhish commented Mar 14, 2026

Summary

  • Adds optional meta field to TagConfigRequest so color can be sent to the API
  • Adds a shuffle button to TagConfigForm that randomly assigns from 10 WCAG-accessible colors
  • Shows a live tag badge preview with the selected color
  • Populates color when editing an existing tag config
  • TagBadge already renders meta.color, so tags display their chosen color automatically

Closes #16104

Test plan

  • Create a new tag config — verify "Assign Color" button appears
  • Click shuffle — verify color changes and badge preview updates
  • Clear color with ✕ button — verify it resets to no color
  • Save tag with a color — verify it persists and displays in tag badges across the app
  • Edit an existing tag with a color — verify the color is populated in the form
  • Verify all 10 colors have sufficient contrast against their tinted backgrounds

🤖 Generated with Claude Code

Summary by CodeRabbit

New Features

  • Tags can now be assigned custom colors
  • Added shuffle button to randomly select from available color options
  • Color selections display as visual badge previews
  • Clear button to remove assigned colors
  • Color assignments persist when editing tags

Allow setting a color on tag configs via the meta field. Adds a shuffle
button to the TagConfigForm that randomly assigns from 10 WCAG-accessible
colors. The TagBadge component already renders meta.color, so tags display
their chosen color automatically.

Closes #16104

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bodhish bodhish requested review from a team March 14, 2026 06:57
@bodhish bodhish requested a review from a team as a code owner March 14, 2026 06:57
Copilot AI review requested due to automatic review settings March 14, 2026 06:57
@netlify
Copy link

netlify bot commented Mar 14, 2026

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit d30e69d
🔍 Latest deploy log https://app.netlify.com/projects/care-ohc/deploys/69b506c14984500008aeba12
😎 Deploy Preview https://deploy-preview-16109.preview.ohc.network
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2026

Walkthrough

Color support is added to the tag configuration system. Localization strings for the color feature are introduced, a color picker with shuffle button is implemented in the tag form, and the TagConfigRequest type is extended to include optional color metadata.

Changes

Cohort / File(s) Summary
Localization
public/locale/en.json
Added two new keys: assign_color and shuffle_color for the color assignment UI.
Tag Config Form
src/pages/Admin/TagConfig/TagConfigForm.tsx
Implemented color feature with a TAG_COLORS constant, new color form field, color control with shuffle button (randomly selects from TAG_COLORS), and colored Badge preview. Color is persisted through form state and included in payload when provided.
Type Definitions
src/types/emr/tagConfig/tagConfig.ts
Extended TagConfigRequest interface with optional meta?: TagConfigMeta field to support color metadata in request payloads.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add colour support for tag configs' clearly and concisely summarizes the main change: introducing color functionality to tag configurations.
Description check ✅ Passed The description includes a comprehensive summary of changes, test plan with specific steps, and closes a linked issue. It adequately covers the main objectives and implementation details.
Linked Issues check ✅ Passed All coding requirements from issue #16104 are met: optional meta field added to TagConfigRequest, color persistence implemented, and visual display through TagBadge is supported.
Out of Scope Changes check ✅ Passed All changes directly support the color feature objective: localization keys for UI, form field additions, type updates, and schema modifications are all scoped to tag config color support.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/tag-config-color-support
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

Migrating from UI to YAML configuration.

Use the @coderabbitai configuration command in a PR comment to get a dump of all your UI settings in YAML format. You can then edit this YAML file and upload it to the root of your repository to configure CodeRabbit programmatically.

@bodhish
Copy link
Member Author

bodhish commented Mar 14, 2026

@gigincg backend doesn't allow you to set the meta; :(

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds optional color support for Tag Configs by persisting a meta.color value to the API and exposing simple UI controls (shuffle/clear + live preview) in the Admin Tag Config form.

Changes:

  • Extends TagConfigRequest to allow sending meta (used for meta.color) to the API.
  • Adds color assignment UI in TagConfigForm (shuffle from a fixed palette, clear, and live badge preview; also populates color on edit).
  • Adds new i18n strings for the color actions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/types/emr/tagConfig/tagConfig.ts Adds optional meta to the request type to support sending color metadata.
src/pages/Admin/TagConfig/TagConfigForm.tsx Implements color selection/shuffle/clear UI and includes meta.color in create/update payloads.
public/locale/en.json Adds assign_color and shuffle_color translation strings used by the form.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +45 to 48
] as const;

import useBreakpoints from "@/hooks/useBreakpoints";
import { cn } from "@/lib/utils";
Comment on lines 204 to 208
priority: data.priority,
status: data.status,
resource: data.resource,
meta: data.color ? { color: data.color } : {},
...(parentId && { parent: parentId }),
Comment on lines 92 to 95
facility_organization: z.string().optional(),
organization: z.string().optional(),
color: z.string().optional(),
});
size="icon"
className="size-7 text-muted-foreground"
onClick={() => field.onChange("")}
disabled={isLoading}
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d30e69d9e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

priority: data.priority,
status: data.status,
resource: data.resource,
meta: data.color ? { color: data.color } : {},

Choose a reason for hiding this comment

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

P1 Badge Preserve existing metadata when building meta payload

onSubmit now always sends meta as either { color: ... } or {}; when editing a tag that already has other metadata keys in meta, this overwrites them and silently drops those values on save. This regression is introduced here because updates previously omitted meta entirely, so non-color metadata could be retained by the API. Please merge with existing metadata (or omit meta when unchanged) instead of replacing it wholesale.

Useful? React with 👍 / 👎.

@cloudflare-workers-and-pages
Copy link

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: d30e69d
Status: ✅  Deploy successful!
Preview URL: https://31adceaa.care-preview-a7w.pages.dev
Branch Preview URL: https://feature-tag-config-color-sup.care-preview-a7w.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/types/emr/tagConfig/tagConfig.ts (1)

4-6: 🧹 Nitpick | 🔵 Trivial

Consider adding explicit color property to TagConfigMeta for type safety.

Since the PR introduces color support via meta.color, you could enhance type safety by defining the known color field explicitly while retaining extensibility:

♻️ Proposed enhancement
 export interface TagConfigMeta {
+  color?: string;
   [key: string]: unknown;
 }

This would provide autocomplete and type checking for the color field across the codebase while still allowing arbitrary additional metadata properties.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/types/emr/tagConfig/tagConfig.ts` around lines 4 - 6, The TagConfigMeta
interface should explicitly declare the known color field while preserving
arbitrary metadata; update the TagConfigMeta declaration in tagConfig.ts to
include a color?: string property alongside the existing index signature so
usages of meta.color across the codebase get compile-time type safety and IDE
autocompletion without losing extensibility.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@public/locale/en.json`:
- Line 781: The i18n key "assign_color" was inserted inline; move this new key
(and any other newly added keys such as the one around lines flagged 5509) to
the very end of the en.json file instead of inserting them mid-file, ensuring
keys are appended in a single group at the file's end so the repository's
guideline (append new i18n keys to the end) is followed; locate occurrences of
"assign_color" and any other recently added keys and cut/paste them to the
file's end in the same JSON object order.

In `@src/pages/Admin/TagConfig/TagConfigForm.tsx`:
- Around line 421-430: The clear Button (the icon-only button rendering CareIcon
inside) lacks an accessible label; update the Button in TagConfigForm.tsx to
include an aria-label (or aria-labelledby) using the translation key (e.g.,
"clear_color") and ensure the translation key is added to locale files; keep
existing props (type, variant, size, onClick, disabled) and retain CareIcon for
visual display while providing the aria-label so screen readers announce the
button purpose.
- Around line 412-416: The tag preview in TagConfigForm uses inconsistent
opacity suffixes (background: "18", border: "40") compared to TagBadge; update
the inline style in the preview (where style is set using field.value) to use
the same opacity pattern as TagBadge—set backgroundColor to field.value + "40"
and borderColor to field.value + "60" so the preview matches the TagBadge
component's rendering.
- Around line 34-46: The TAG_COLORS constant is currently placed among the
import statements; move the complete TAG_COLORS definition (the const TAG_COLORS
= [...] as const;) out of the import block and place it after all imports are
finished and before the file's first type/interface or component definition
(i.e., right before the interface definition in this file), removing the
original lines from the import area so the file imports remain grouped at the
top.
- Around line 34-45: TAG_COLORS in TagConfigForm.tsx contains hues that fail
WCAG AA 4.5:1 contrast when used as text on their 40% opacity backgrounds;
either replace the hex values in TAG_COLORS with colors validated to meet 4.5:1
on a 40% background or keep the existing palette but update the rendering logic
(e.g., in the Tag component / label renderer) to compute and use an accessible
foreground color (black or white) per color using a contrast check function;
ensure the chosen approach is applied where TAG_COLORS is consumed so all tag
text meets 4.5:1 on the 40% opacity background.
- Line 207: The current update payload sets meta to data.color ? { color:
data.color } : {}, which overwrites any existing TagConfigMeta fields; when
building the payload in the TagConfigForm submit/update handler (where meta is
constructed), merge the existing tag.meta (or the fetched tag object) with the
new color instead of replacing it — e.g., use a spread of existingMeta || {}
combined with color only when data.color is present so other meta keys are
preserved; reference the meta property, TagConfigMeta type, and data.color when
making this change.

---

Outside diff comments:
In `@src/types/emr/tagConfig/tagConfig.ts`:
- Around line 4-6: The TagConfigMeta interface should explicitly declare the
known color field while preserving arbitrary metadata; update the TagConfigMeta
declaration in tagConfig.ts to include a color?: string property alongside the
existing index signature so usages of meta.color across the codebase get
compile-time type safety and IDE autocompletion without losing extensibility.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fb350d99-fc92-4675-bd2e-1e6d38e3c4fb

📥 Commits

Reviewing files that changed from the base of the PR and between 2447c3d and d30e69d.

📒 Files selected for processing (3)
  • public/locale/en.json
  • src/pages/Admin/TagConfig/TagConfigForm.tsx
  • src/types/emr/tagConfig/tagConfig.ts

"assign_a_volunteer_to": "Assign a volunteer to {{name}}",
"assign_bed": "Assign Bed",
"assign_bed_now": "Assign Bed Now",
"assign_color": "Assign Color",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Move newly added i18n keys to the end of en.json.

Both keys were inserted inline; this repository requires new keys in public/locale/en.json to be appended at the end of the file.

🔧 Proposed fix
-  "assign_bed_now": "Assign Bed Now",
-  "assign_color": "Assign Color",
+  "assign_bed_now": "Assign Bed Now",
   "assign_location": "Assign Location",
-  "showing_x_of_y": "Showing <strong>{{x}}</strong> of <strong>{{y}}</strong>",
-  "shuffle_color": "Shuffle Color",
+  "showing_x_of_y": "Showing <strong>{{x}}</strong> of <strong>{{y}}</strong>",
   "sidebar": "sidebar",
-  "zoom_out": "Zoom Out",
-  "℞": "℞"
+  "zoom_out": "Zoom Out",
+  "℞": "℞",
+  "assign_color": "Assign Color",
+  "shuffle_color": "Shuffle Color"
 }

As per coding guidelines: "Append missing i18n keys directly to the end of the public/locale/en.json file without reading i18n files".

Also applies to: 5509-5509

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@public/locale/en.json` at line 781, The i18n key "assign_color" was inserted
inline; move this new key (and any other newly added keys such as the one around
lines flagged 5509) to the very end of the en.json file instead of inserting
them mid-file, ensuring keys are appended in a single group at the file's end so
the repository's guideline (append new i18n keys to the end) is followed; locate
occurrences of "assign_color" and any other recently added keys and cut/paste
them to the file's end in the same JSON object order.

Comment on lines +34 to +46
const TAG_COLORS = [
"#B91C1C", // Red
"#C2410C", // Orange
"#A16207", // Amber
"#15803D", // Green
"#0F766E", // Teal
"#1D4ED8", // Blue
"#7E22CE", // Purple
"#BE185D", // Pink
"#0E7490", // Cyan
"#4D7C0F", // Lime
] as const;

Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Move constant definition after all imports.

The TAG_COLORS constant is defined in the middle of the import statements, breaking the file's organization. Constants should be defined after all imports are complete.

♻️ Suggested fix

Move lines 34-46 to after line 58 (after all imports), before the interface definition:

 import { isIOSDevice } from "@/Utils/utils";
 
+const TAG_COLORS = [
+  "#B91C1C", // Red
+  "#C2410C", // Orange
+  "#A16207", // Amber
+  "#15803D", // Green
+  "#0F766E", // Teal
+  "#1D4ED8", // Blue
+  "#7E22CE", // Purple
+  "#BE185D", // Pink
+  "#0E7490", // Cyan
+  "#4D7C0F", // Lime
+] as const;
+
 interface TagConfigFormProps {

And remove lines 34-46 from their current location.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const TAG_COLORS = [
"#B91C1C", // Red
"#C2410C", // Orange
"#A16207", // Amber
"#15803D", // Green
"#0F766E", // Teal
"#1D4ED8", // Blue
"#7E22CE", // Purple
"#BE185D", // Pink
"#0E7490", // Cyan
"#4D7C0F", // Lime
] as const;
const TAG_COLORS = [
"#B91C1C", // Red
"#C2410C", // Orange
"#A16207", // Amber
"#15803D", // Green
"#0F766E", // Teal
"#1D4ED8", // Blue
"#7E22CE", // Purple
"#BE185D", // Pink
"#0E7490", // Cyan
"#4D7C0F", // Lime
] as const;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/Admin/TagConfig/TagConfigForm.tsx` around lines 34 - 46, The
TAG_COLORS constant is currently placed among the import statements; move the
complete TAG_COLORS definition (the const TAG_COLORS = [...] as const;) out of
the import block and place it after all imports are finished and before the
file's first type/interface or component definition (i.e., right before the
interface definition in this file), removing the original lines from the import
area so the file imports remain grouped at the top.

Comment on lines +34 to +45
const TAG_COLORS = [
"#B91C1C", // Red
"#C2410C", // Orange
"#A16207", // Amber
"#15803D", // Green
"#0F766E", // Teal
"#1D4ED8", // Blue
"#7E22CE", // Purple
"#BE185D", // Pink
"#0E7490", // Cyan
"#4D7C0F", // Lime
] as const;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the contrast ratios using a simple Python script
pip install wcag-contrast-ratio 2>/dev/null

python3 << 'EOF'
# Calculate contrast ratios for TAG_COLORS against their tinted backgrounds
# The background is the color with 40% opacity (25% actual due to hex)
# approximated by blending with white

def hex_to_rgb(hex_color):
    hex_color = hex_color.lstrip('#')
    return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))

def blend_with_white(rgb, alpha):
    """Blend color with white background at given alpha"""
    return tuple(int(c * alpha + 255 * (1 - alpha)) for c in rgb)

def relative_luminance(rgb):
    """Calculate relative luminance per WCAG"""
    def adjust(c):
        c = c / 255
        return c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4
    r, g, b = [adjust(c) for c in rgb]
    return 0.2126 * r + 0.7152 * g + 0.0722 * b

def contrast_ratio(l1, l2):
    lighter = max(l1, l2)
    darker = min(l1, l2)
    return (lighter + 0.05) / (darker + 0.05)

TAG_COLORS = [
    ("#B91C1C", "Red"),
    ("#C2410C", "Orange"),
    ("#A16207", "Amber"),
    ("#15803D", "Green"),
    ("#0F766E", "Teal"),
    ("#1D4ED8", "Blue"),
    ("#7E22CE", "Purple"),
    ("#BE185D", "Pink"),
    ("#0E7490", "Cyan"),
    ("#4D7C0F", "Lime"),
]

print("Color Contrast Analysis (text color vs 40% opacity background on white):")
print("=" * 70)
for color, name in TAG_COLORS:
    fg_rgb = hex_to_rgb(color)
    # 0x40 = 64 in decimal, 64/255 ≈ 0.25 alpha
    bg_rgb = blend_with_white(fg_rgb, 0.25)
    
    fg_lum = relative_luminance(fg_rgb)
    bg_lum = relative_luminance(bg_rgb)
    ratio = contrast_ratio(fg_lum, bg_lum)
    
    status = "✓ PASS" if ratio >= 4.5 else "✗ FAIL"
    print(f"{name:8} {color}: {ratio:.2f}:1 {status} (AA requires 4.5:1)")

EOF

Repository: ohcnetwork/care_fe

Length of output: 1618


🏁 Script executed:

fd "TagBadge" --type f

Repository: ohcnetwork/care_fe

Length of output: 94


🏁 Script executed:

cat -n src/components/Tags/TagBadge.tsx

Repository: ohcnetwork/care_fe

Length of output: 1548


Most colors fail WCAG AA contrast requirements and must be adjusted.

Verification confirms that 9 out of 10 colors fail to meet WCAG AA 4.5:1 contrast ratio when used as text on their 40% opacity backgrounds:

  • Red (#B91C1C): 4.16:1 ✗
  • Orange (#C2410C): 3.54:1 ✗
  • Amber (#A16207): 3.49:1 ✗
  • Green (#15803D): 3.53:1 ✗
  • Teal (#0F766E): 3.80:1 ✗
  • Blue (#1D4ED8): 4.45:1 ✗
  • Purple (#7E22CE): 4.51:1 ✓
  • Pink (#BE185D): 3.91:1 ✗
  • Cyan (#0E7490): 3.74:1 ✗
  • Lime (#4D7C0F): 3.56:1 ✗

This violates accessibility requirements for clinical environments. Consider using lighter or darker colors to achieve sufficient contrast, or implement an alternative approach such as using white/black text with these colored backgrounds instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/Admin/TagConfig/TagConfigForm.tsx` around lines 34 - 45, TAG_COLORS
in TagConfigForm.tsx contains hues that fail WCAG AA 4.5:1 contrast when used as
text on their 40% opacity backgrounds; either replace the hex values in
TAG_COLORS with colors validated to meet 4.5:1 on a 40% background or keep the
existing palette but update the rendering logic (e.g., in the Tag component /
label renderer) to compute and use an accessible foreground color (black or
white) per color using a contrast check function; ensure the chosen approach is
applied where TAG_COLORS is consumed so all tag text meets 4.5:1 on the 40%
opacity background.

priority: data.priority,
status: data.status,
resource: data.resource,
meta: data.color ? { color: data.color } : {},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check what fields TagConfigMeta interface contains
ast-grep --pattern 'interface TagConfigMeta {
  $$$
}'

# Also check for type definition
rg -n "TagConfigMeta" --type=ts -A 5

Repository: ohcnetwork/care_fe

Length of output: 1320


🏁 Script executed:

sed -n '190,230p' src/pages/Admin/TagConfig/TagConfigForm.tsx

Repository: ohcnetwork/care_fe

Length of output: 1284


🏁 Script executed:

sed -n '1,210p' src/pages/Admin/TagConfig/TagConfigForm.tsx | head -100

Repository: ohcnetwork/care_fe

Length of output: 2925


🏁 Script executed:

sed -n '100,160p' src/pages/Admin/TagConfig/TagConfigForm.tsx

Repository: ohcnetwork/care_fe

Length of output: 2095


🏁 Script executed:

rg "meta\s*:\s*\{" --type=ts -B 2 -A 2 src/pages/Admin/TagConfig src/types/emr/tagConfig

Repository: ohcnetwork/care_fe

Length of output: 373


🏁 Script executed:

rg "\.meta\?" --type=ts src/pages/Admin/TagConfig src/types/emr/tagConfig -B 1 -A 1

Repository: ohcnetwork/care_fe

Length of output: 305


🏁 Script executed:

rg "meta:" --type=ts -A 3 src/types/emr/tagConfig/ | head -40

Repository: ohcnetwork/care_fe

Length of output: 510


🏁 Script executed:

rg "color" --type=ts src/pages/Admin/TagConfig -B 2 -A 2

Repository: ohcnetwork/care_fe

Length of output: 3606


Preserve existing meta fields when updating tags to prevent future data loss.

While currently only the color field is managed in meta, the open-ended TagConfigMeta type ([key: string]: unknown) could accommodate additional properties. The current payload construction at line 207 overwrites the entire meta object during updates, which would lose any other meta fields if they are added in the future.

Although this isn't causing data loss today, consider preserving existing meta fields for robustness:

Proposed fix to preserve existing meta
-      meta: data.color ? { color: data.color } : {},
+      meta: {
+        ...(isEditing && existingConfig?.meta ? existingConfig.meta : {}),
+        ...(data.color ? { color: data.color } : {}),
+      },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/Admin/TagConfig/TagConfigForm.tsx` at line 207, The current update
payload sets meta to data.color ? { color: data.color } : {}, which overwrites
any existing TagConfigMeta fields; when building the payload in the
TagConfigForm submit/update handler (where meta is constructed), merge the
existing tag.meta (or the fetched tag object) with the new color instead of
replacing it — e.g., use a spread of existingMeta || {} combined with color only
when data.color is present so other meta keys are preserved; reference the meta
property, TagConfigMeta type, and data.color when making this change.

Comment on lines +412 to +416
style={{
color: field.value,
backgroundColor: field.value + "18",
borderColor: field.value + "40",
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent opacity values with TagBadge component.

The badge preview uses different opacity suffixes (18 for background, 40 for border) compared to TagBadge which uses 40 for background and 60 for border. This creates a visual inconsistency between the preview and the actual rendered tag.

Based on the relevant code snippet from TagBadge.tsx, the color styling should match:

🔧 Proposed fix for consistency
                     <Badge
                       style={{
                         color: field.value,
-                        backgroundColor: field.value + "18",
-                        borderColor: field.value + "40",
+                        backgroundColor: field.value + "40",
+                        borderColor: field.value + "60",
                       }}
                       className="capitalize"
                     >
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
style={{
color: field.value,
backgroundColor: field.value + "18",
borderColor: field.value + "40",
}}
<Badge
style={{
color: field.value,
backgroundColor: field.value + "40",
borderColor: field.value + "60",
}}
className="capitalize"
>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/Admin/TagConfig/TagConfigForm.tsx` around lines 412 - 416, The tag
preview in TagConfigForm uses inconsistent opacity suffixes (background: "18",
border: "40") compared to TagBadge; update the inline style in the preview
(where style is set using field.value) to use the same opacity pattern as
TagBadge—set backgroundColor to field.value + "40" and borderColor to
field.value + "60" so the preview matches the TagBadge component's rendering.

Comment on lines +421 to +430
<Button
type="button"
variant="ghost"
size="icon"
className="size-7 text-muted-foreground"
onClick={() => field.onChange("")}
disabled={isLoading}
>
<CareIcon icon="l-times" className="size-4" />
</Button>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add accessible label to icon-only clear button.

The clear button uses only an icon without visible text or an accessible label, making it inaccessible to screen reader users. As per coding guidelines, proper ARIA labels should be implemented for accessibility.

♿ Proposed fix
                     <Button
                       type="button"
                       variant="ghost"
                       size="icon"
                       className="size-7 text-muted-foreground"
                       onClick={() => field.onChange("")}
                       disabled={isLoading}
+                      aria-label={t("clear_color")}
                     >
                       <CareIcon icon="l-times" className="size-4" />
                     </Button>

Note: You may need to add the clear_color translation key to the locale files.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/Admin/TagConfig/TagConfigForm.tsx` around lines 421 - 430, The
clear Button (the icon-only button rendering CareIcon inside) lacks an
accessible label; update the Button in TagConfigForm.tsx to include an
aria-label (or aria-labelledby) using the translation key (e.g., "clear_color")
and ensure the translation key is added to locale files; keep existing props
(type, variant, size, onClick, disabled) and retain CareIcon for visual display
while providing the aria-label so screen readers announce the button purpose.

@github-actions
Copy link

🎭 Playwright Test Results

Status: ✅ Passed
Test Shards: 3

Metric Count
Total Tests 271
✅ Passed 271
❌ Failed 0
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #7397

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type Changes Contains changes in typescript types Work in Progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Colour Support for Tags

2 participants