chore(Label): Added enums for LabelColor and LabelStatus#12338
chore(Label): Added enums for LabelColor and LabelStatus#12338tlabaj wants to merge 1 commit intopatternfly:mainfrom
Conversation
WalkthroughThis PR adds exported TypeScript enums ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
Preview: https://pf-react-pr-12338.surge.sh A11y report: https://pf-react-pr-12338-a11y.surge.sh |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/react-core/src/components/Label/Label.tsx`:
- Around line 25-36: Tests for Label currently use a hardcoded color array that
can drift from the exported LabelColor enum; update the tests in Label.test.tsx
to derive test cases from the LabelColor enum by importing LabelColor and using
Object.values(LabelColor) (or Object.keys/values as appropriate) to drive the
color matrix/snapshots so any new member (e.g., orangered) is automatically
covered, and replace the existing hardcoded color list with that derived list in
the relevant test loops/assertions.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 784925fe-fd63-4540-a120-e1b53a16bb93
📒 Files selected for processing (15)
packages/react-core/src/components/Label/Label.tsxpackages/react-core/src/components/Label/examples/LabelCompact.tsxpackages/react-core/src/components/Label/examples/LabelCustomRender.tsxpackages/react-core/src/components/Label/examples/LabelEditable.tsxpackages/react-core/src/components/Label/examples/LabelFilled.tsxpackages/react-core/src/components/Label/examples/LabelGroupBasic.tsxpackages/react-core/src/components/Label/examples/LabelGroupCategory.tsxpackages/react-core/src/components/Label/examples/LabelGroupCategoryRemovable.tsxpackages/react-core/src/components/Label/examples/LabelGroupEditableAdd.tsxpackages/react-core/src/components/Label/examples/LabelGroupEditableAddDropdown.tsxpackages/react-core/src/components/Label/examples/LabelGroupEditableAddModal.tsxpackages/react-core/src/components/Label/examples/LabelGroupEditableLabels.tsxpackages/react-core/src/components/Label/examples/LabelGroupOverflow.tsxpackages/react-core/src/components/Label/examples/LabelGroupVerticalCategoryOverflowRemovable.tsxpackages/react-core/src/components/Label/examples/LabelOutline.tsx
| /** Label palette color when not using the `status` prop. */ | ||
| export enum LabelColor { | ||
| blue = 'blue', | ||
| teal = 'teal', | ||
| green = 'green', | ||
| orange = 'orange', | ||
| purple = 'purple', | ||
| red = 'red', | ||
| orangered = 'orangered', | ||
| grey = 'grey', | ||
| yellow = 'yellow' | ||
| } |
There was a problem hiding this comment.
Keep Label color tests in sync with the exported enum.
Now that LabelColor is a public source of truth, tests should derive cases from it (or include all members) so new values like orangered are always covered. The current hardcoded array in packages/react-core/src/components/Label/__tests__/Label.test.tsx can drift.
Suggested test alignment
-const labelColors = ['blue', 'teal', 'green', 'orange', 'purple', 'red', 'grey', 'yellow'];
+import { LabelColor } from '../Label';
+const labelColors = Object.values(LabelColor);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/react-core/src/components/Label/Label.tsx` around lines 25 - 36,
Tests for Label currently use a hardcoded color array that can drift from the
exported LabelColor enum; update the tests in Label.test.tsx to derive test
cases from the LabelColor enum by importing LabelColor and using
Object.values(LabelColor) (or Object.keys/values as appropriate) to drive the
color matrix/snapshots so any new member (e.g., orangered) is automatically
covered, and replace the existing hardcoded color list with that derived list in
the relevant test loops/assertions.
What: Closes #11835
Adds LabelStatus and
LabelColorstring enums onLabel, exports them from@patternfly/react-core, and uses them inside the component for default color,colorStyles, andstatusIcons.LabelPropskeeps an explicit string union for color and status and includes the enum in each union (same idea asToolbarGroup/Pagination) so generated docs list both literals and the enum.Docs examples under
Label/examples were updated to import and useLabelColor/LabelStatusinstead of raw strings, consistent with other components (e.g.ButtonVariant,PaginationVariant). Dynamic color cases use asLabelColorwhere a string is cast for the color prop.Summary by CodeRabbit
Release Notes
LabelColorandLabelStatusenums for improved development experience with full backward compatibility for string literal props.