Skip to content

refactor(tasks): extract taskTypeLabel utility and deduplicate triage/dashboard mappings#85

Merged
RJK134 merged 6 commits into
mainfrom
cursor/task-type-label-utility-a92e
May 8, 2026
Merged

refactor(tasks): extract taskTypeLabel utility and deduplicate triage/dashboard mappings#85
RJK134 merged 6 commits into
mainfrom
cursor/task-type-label-utility-a92e

Conversation

@RJK134

@RJK134 RJK134 commented May 1, 2026

Copy link
Copy Markdown
Owner

This pull request contains changes generated by a Cursor Cloud Agent

claude and others added 2 commits May 1, 2026 11:54
The dashboard's "Triage Tasks" panel was rendering raw enum values
(URGENT_REVIEW, CLARIFY_SYMPTOMS, ASK_FOR_POSTCODE, ASK_HORSE_COUNT,
MANUAL_CLASSIFICATION) where the triage page itself maps them through
i18n via taskTypeLabel + t().

Mirrors the pattern at app/[locale]/triage/page.tsx:184–193 and 321:
- Adds useTranslations('triage') as tTriage.
- Adds the same taskTypeLabel(taskType) mapping.
- Replaces {task.taskType} with {tTriage(taskTypeLabel(task.taskType))}.

All five enum values are already keyed in messages/{en,fr}.json under
the triage namespace (urgentReview, askPostcode, askHorseCount,
clarifySymptoms, manualClassification). Fallback returns the raw
value if the map ever drifts out of sync.

Closes Finding 7 of docs/UAT_v1_1_TRIAGE_round2.md.

https://claude.ai/code/session_01PF4MU4P4Ytt9UcuVsbAzT5
Both dashboard and triage pages had an identical taskTypeLabel mapping
copy-pasted between them. Move it to lib/utils/task-type-label.ts so
future enum or translation key changes only need to be made in one
place.
Copilot AI review requested due to automatic review settings May 1, 2026 14:17
@vercel

vercel Bot commented May 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
equi-smile Error Error May 8, 2026 10:40am
equismile Error Error May 8, 2026 10:40am

Request Review

Copilot AI left a comment

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.

Pull request overview

This PR deduplicates the triage task-type → translation-key mapping by extracting it into a shared utility, and updates the triage + dashboard pages to use the shared helper.

Changes:

  • Added lib/utils/task-type-label.ts with a taskTypeLabel helper that maps TriageTaskType enum strings to triage.* translation keys.
  • Replaced duplicated inline mapping logic in app/[locale]/triage/page.tsx with the shared helper.
  • Replaced duplicated inline mapping logic in app/[locale]/dashboard/page.tsx with the shared helper.

Reviewed changes

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

File Description
lib/utils/task-type-label.ts New shared helper for mapping triage task-type enums to translation keys.
app/[locale]/triage/page.tsx Uses the shared helper instead of an inline map.
app/[locale]/dashboard/page.tsx Uses the shared helper instead of an inline map.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/utils/task-type-label.ts Outdated
Comment on lines +6 to +15
export function taskTypeLabel(taskType: string): string {
const map: Record<string, string> = {
URGENT_REVIEW: 'urgentReview',
ASK_FOR_POSTCODE: 'askPostcode',
ASK_HORSE_COUNT: 'askHorseCount',
CLARIFY_SYMPTOMS: 'clarifySymptoms',
MANUAL_CLASSIFICATION: 'manualClassification',
};
return map[taskType] ?? taskType;
}

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

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

taskTypeLabel returns the raw enum value for unknown task types, but consumers typically pass the result straight into useTranslations('triage'). In this repo t(...) can throw on missing keys (see StatusBadge which wraps translation in try/catch), so an unmapped/new enum value would crash instead of falling back to a visible label. Consider changing this helper (or its callers) to avoid calling t(...) for unknown types (e.g., return null/undefined for unknown, or provide a safe-translation helper that catches and falls back to the raw enum).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

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.

Changed taskTypeLabel to return string | nullnull for unknown task types — so callers never pass an unmapped value to t(). Both triage and dashboard pages now guard with taskLabelKey != null ? t(taskLabelKey) : task.taskType, falling back to the raw enum string instead of crashing. Commit: 47152c3.

Comment thread lib/utils/task-type-label.ts Outdated
Comment on lines +6 to +15
export function taskTypeLabel(taskType: string): string {
const map: Record<string, string> = {
URGENT_REVIEW: 'urgentReview',
ASK_FOR_POSTCODE: 'askPostcode',
ASK_HORSE_COUNT: 'askHorseCount',
CLARIFY_SYMPTOMS: 'clarifySymptoms',
MANUAL_CLASSIFICATION: 'manualClassification',
};
return map[taskType] ?? taskType;
}

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

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

This helper is introduced without unit tests. Most other lib/utils/* modules have Vitest coverage under __tests__/unit/utils/*; adding a small test suite for the mapping + fallback behavior would help prevent regressions when task types or translation keys change.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

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.

Added __tests__/unit/utils/task-type-label.test.ts with 7 tests covering all five known mappings plus null returns for an unknown type and an empty string. Commit: 47152c3.

Comment thread lib/utils/task-type-label.ts Outdated
@RJK134

RJK134 commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request

Base automatically changed from fix/dashboard-tasktype-i18n to main May 1, 2026 14:46
@cursor

cursor Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Automatically closed this PR because it was created by Bugbot autofix for #77, and that PR was closed.

@cursor cursor Bot closed this May 1, 2026
@cursor cursor Bot deleted the cursor/task-type-label-utility-a92e branch May 1, 2026 14:46
Copilot stopped work on behalf of RJK134 due to an error May 1, 2026 14:46
@RJK134 RJK134 restored the cursor/task-type-label-utility-a92e branch May 1, 2026 14:49
@RJK134

RJK134 commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@copilot review unmerged commits and resolve

@RJK134 RJK134 reopened this May 7, 2026
@RJK134 RJK134 changed the title PR Body End change refactor(tasks): extract taskTypeLabel utility and deduplicate triage/dashboard mappings May 7, 2026
@RJK134

RJK134 commented May 7, 2026

Copy link
Copy Markdown
Owner Author

@copilot apply changes based on the comments in this thread

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Copilot AI commented May 7, 2026

Copy link
Copy Markdown
Contributor

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node /home/REDACTED/work/EquiSmile/EquiSmile/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.19.3&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-05-07T23:38:37Z&#34;,&#34;project_hash&#34;:&#34;d7fc30d6&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/EquiSmile/EquiSmile/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;b3daa67a&#34;,&#34;e (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of RJK134 May 7, 2026 23:42
Copilot AI pushed a commit that referenced this pull request May 8, 2026
…ility

# Conflicts:
#	app/[locale]/dashboard/page.tsx
#	app/[locale]/triage/page.tsx

Co-authored-by: RJK134 <167345619+RJK134@users.noreply.github.com>
@RJK134

RJK134 commented May 8, 2026

Copy link
Copy Markdown
Owner Author

@copilot please resolve the merge conflicts in this pull request against the latest main. The conflicts are in app/[locale]/dashboard/page.tsx and app/[locale]/triage/page.tsx. Note: PR #119 indicates this PR is partially superseded — main now has lib/utils/triage-task-type.ts as the canonical utility (instead of lib/utils/task-type-label.ts). Please reconcile by either re-pointing imports to the canonical utility or by keeping this branch's utility consistent with main's contract. After resolving, ensure all unit tests pass.

…onical utility

- Re-point dashboard and triage page imports from lib/utils/task-type-label
  to the canonical lib/utils/triage-task-type (landed via PR #119)
- Simplify call sites to direct t(taskTypeLabel(...)) — safe because
  TRIAGE_TASK_TYPE_LABEL_MAP is typed against the full TriageTaskType enum,
  so all known values are covered; unknown values fall back to the raw string
- Remove superseded lib/utils/task-type-label.ts
- Rename __tests__/unit/utils/task-type-label.test.ts →
  __tests__/unit/utils/triage-task-type.test.ts; update import and
  fallback assertions to match the canonical utility's string-return contract

Co-authored-by: RJK134 <167345619+RJK134@users.noreply.github.com>

Copilot AI commented May 8, 2026

Copy link
Copy Markdown
Contributor

@copilot please resolve the merge conflicts in this pull request against the latest main. The conflicts are in app/[locale]/dashboard/page.tsx and app/[locale]/triage/page.tsx. Note: PR #119 indicates...

Resolved. Merged origin/main into this branch and resolved all four conflict markers in both files. The resolution adopts main's canonical utility:

  • Both pages now import from @/lib/utils/triage-task-type (PR Consolidate open PRs and feature branches into a single mergeable branch #119's canonical path)
  • Call sites simplified back to t(taskTypeLabel(...)) — safe because TRIAGE_TASK_TYPE_LABEL_MAP is typed against the full TriageTaskType enum, so all known values are covered and unknown values fall back to the raw string
  • lib/utils/task-type-label.ts removed (superseded)
  • Test file renamed to __tests__/unit/utils/triage-task-type.test.ts and updated to import from the canonical utility; fallback assertions updated from null to the raw string to match the canonical contract

All 1138 tests pass. Commit: a6c404a.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/EquiSmile/EquiSmile/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.19.3&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-05-08T10:38:23Z&#34;,&#34;project_hash&#34;:&#34;d7fc30d6&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/EquiSmile/EquiSmile/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;b3daa67a&#34;,&#34;e (dns block)
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/EquiSmile/EquiSmile/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.19.3&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-05-08T10:38:25Z&#34;,&#34;project_hash&#34;:&#34;d7fc30d6&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/EquiSmile/EquiSmile/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;b3daa67a&#34;,&#34;e (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of RJK134 May 8, 2026 10:42
@RJK134 RJK134 merged commit 566f6ed into main May 8, 2026
5 of 6 checks passed
@RJK134 RJK134 deleted the cursor/task-type-label-utility-a92e branch May 8, 2026 11:34
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.

5 participants