Skip to content

Derive ComplaintStatus from the status array instead of duplicating it - #151

Merged
hasithakn merged 1 commit into
wso2:mainfrom
anjuchamantha:ci/complaint-status-derive-from-array
Sep 7, 2026
Merged

Derive ComplaintStatus from the status array instead of duplicating it#151
hasithakn merged 1 commit into
wso2:mainfrom
anjuchamantha:ci/complaint-status-derive-from-array

Conversation

@anjuchamantha

Copy link
Copy Markdown
Contributor

Why

Frontend quality fails on #103, the frontend-npm group bump, on one file:

[warn] src/types/complaint.ts
[warn] Code style issues found in the above file.

That bump raises Prettier from 3.8.1 to 3.9.6, and 3.9 changed how it formats union types — a union that fits inside printWidth is now collapsed rather than kept one member per line:

-export type ComplaintStatus =
-  | 'OPEN'
-  | 'IN_PROGRESS'
-  | 'WAITING_ON_CLIENT'
-  | 'AWAITING_INTERNAL_REVIEW'
-  | 'RESOLVED'
+export type ComplaintStatus =
+  'OPEN' | 'IN_PROGRESS' | 'WAITING_ON_CLIENT' | 'AWAITING_INTERNAL_REVIEW' | 'RESOLVED'

The two versions are mutually incompatible on this file — each rejects the other's output. Verified by running both against main's copy with main's .prettierrc:

Prettier Result on main as-is
3.8.1 clean
3.9.6 fails

So simply reformatting the file in a separate PR would not work: that PR's own Frontend quality job runs main's Prettier 3.8.1, which would reject 3.9-formatted output. The reformat can only ride along inside #103 itself.

What this does instead

The file already listed those five values twice — once as the union, once as the array the complaint filter dropdowns iterate:

export type ComplaintStatus = 'OPEN' | 'IN_PROGRESS' | ...
export const COMPLAINT_STATUSES: ComplaintStatus[] = ['OPEN', 'IN_PROGRESS', ...]

Adding or renaming a status meant editing both, with nothing to catch it if only one changed. Deriving the union from the array removes the duplication:

export const COMPLAINT_STATUSES = [...] as const
export type ComplaintStatus = (typeof COMPLAINT_STATUSES)[number]

The resulting type is identical. COMPLAINT_STATUSES is only ever read — two .map() calls, in ComplaintListFilters.tsx and ComplaintQueueFilters.tsx — so becoming readonly costs nothing.

Because the multi-line union is gone, neither Prettier version has an opinion about this file any more, which is what lets this merge on its own and unblocks #103 without touching it.

Verified

Check Result
prettier@3.8.1 --check (what main runs today) clean
prettier@3.9.6 --check (what #103 upgrades to) clean
tsc -b exit 0
eslint src/types/complaint.ts exit 0
Vitest, full suite 297 passed

Sequencing

This is safe to merge on its own — it passes today's Prettier. Once it is on main, #103 needs a rebase and should then go green with no changes of its own.

Worth noting for later: this only removes the current collision. Any future Prettier minor can reformat something else, and Dependabot cannot fix that itself. If that churn becomes tiresome, pinning Prettier via a dependabot.yml ignore is the alternative — deliberate upgrades instead of surprise ones.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N5BHH7V3eMp8RYgXP79TCL

The five status values were written out twice - once as a union type, once as the
array the filter dropdowns iterate - so adding or renaming a status meant editing
both, with nothing to catch it if only one changed. Deriving the union from the
array with `as const` leaves a single source of truth; the resulting type is
identical, and the array is only ever read (two `.map()` calls in the complaint
filters), so becoming readonly costs nothing.

It also settles a formatting disagreement. Prettier 3.9 collapses a union that
fits inside printWidth, where 3.8 kept one member per line, so this file could not
satisfy both versions at once and the frontend-npm group bump raising Prettier to
3.9.6 failed the format check on it. With the union gone, neither version has an
opinion about the file and the bump can land unchanged.

Verified against both: 3.8.1 and 3.9.6 each report the file clean. tsc, eslint and
the full 297-test Vitest suite pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N5BHH7V3eMp8RYgXP79TCL
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 91a04873-18fd-4f6d-b42a-6e7a1a514084


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

@anjuchamantha anjuchamantha added the Action/trigger-e2e Runs the E2E test suite, including the PR changes label Sep 5, 2026
@hasithakn
hasithakn merged commit 10ab937 into wso2:main Sep 7, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Action/trigger-e2e Runs the E2E test suite, including the PR changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants