Maintenance: Extract parseFilterParam shared helper from tags and statuses modules#34436
Conversation
…rseTagsParam and parseStatusesParam
📝 WalkthroughWalkthroughA new generic utility function Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
code/core/src/manager-api/lib/filter-param.ts (1)
24-26: Skip empty token after removing!to avoid empty filter values.At Line 25, a token of just
!becomes''and is passed totransform; for tags this can currently add an empty tag. Consider guarding the stripped token before transform.♻️ Suggested hardening
param.split(';').forEach((raw) => { if (!raw) { return; } const isExcluded = raw.startsWith('!'); - const value = transform(isExcluded ? raw.slice(1) : raw); + const token = isExcluded ? raw.slice(1) : raw; + if (!token) { + return; + } + const value = transform(token);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/core/src/manager-api/lib/filter-param.ts` around lines 24 - 26, The code currently marks tokens starting with '!' via isExcluded and then calls transform on raw.slice(1), but if raw === '!' this yields an empty string which can create empty filter values; update the logic in the filter-token handling (use isExcluded, raw and transform) to detect and skip empty stripped tokens before calling transform (e.g., only compute value = transform(raw.slice(1)) when raw.slice(1).length > 0, otherwise treat as an empty/ignored token or return early) so no empty tag/value is produced.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@code/core/src/manager-api/lib/filter-param.ts`:
- Around line 24-26: The code currently marks tokens starting with '!' via
isExcluded and then calls transform on raw.slice(1), but if raw === '!' this
yields an empty string which can create empty filter values; update the logic in
the filter-token handling (use isExcluded, raw and transform) to detect and skip
empty stripped tokens before calling transform (e.g., only compute value =
transform(raw.slice(1)) when raw.slice(1).length > 0, otherwise treat as an
empty/ignored token or return early) so no empty tag/value is produced.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3bebfc5b-a9c6-4aaa-b24d-d68b401c5006
📒 Files selected for processing (3)
code/core/src/manager-api/lib/filter-param.tscode/core/src/manager-api/modules/statuses.tscode/core/src/manager-api/modules/tags.ts
Closes #34426
What I did
parseTagsParam(tags.ts) andparseStatusesParam(statuses.ts) had identical structure for parsing semicolon-separated URL filter parameters with!-negation support — ~25-30 lines each, ~55 lines total of near-duplicate logic.Extracted a generic
parseFilterParam<T>(param, transform)helper tocode/core/src/manager-api/lib/filter-param.ts:;splitting, empty-string guard, and!prefix detectiontransform(rawValue)to convert the string to the target typenull/undefinedfrom transform to silently skip unknown values (used by statuses)Both
parseTagsParamandparseStatusesParamare reduced to one-liners that pass their respective transforms. Public API is unchanged.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
No manual testing required — this is a pure refactor with no behavior changes. Existing unit tests verify correctness.
Summary by CodeRabbit