Closed cheton closed 2 months ago
Open the branch in Web Editor • VS Code • Insiders
Open Preview
Latest commit: 8c645885ddfcf66124203ee4ec87a91cd68e0763
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
โฑ๏ธ Estimated effort to review: 3 ๐ต๐ต๐ตโชโช |
๐งช PR contains tests |
๐ No security concerns identified |
โก Key issues to review Possible Bug The `disabled` prop is being set using nullish coalescing, which might not work as expected if `disabled` is explicitly set to `false`. Possible Bug The `disabled` prop is being set using nullish coalescing, which might not work as expected if `disabled` is explicitly set to `false`. Code Smell The `disabled` prop is being set using nullish coalescing, which might not work as expected if `disabled` is explicitly set to `false`. |
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Attention: Patch coverage is 83.33333%
with 3 lines
in your changes missing coverage. Please review.
Project coverage is 77.80%. Comparing base (
da62c8c
) to head (8c64588
). Report is 1 commits behind head on v2.
Files with missing lines | Patch % | Lines |
---|---|---|
packages/react/src/button/Button.js | 33.33% | 2 Missing :warning: |
packages/react/src/button/ButtonGroup.js | 0.00% | 1 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
On 2024-09-24 07:37:56 +0000, PR #930 (8c645885ddfcf66124203ee4ec87a91cd68e0763) was successfully deployed. You can view it at the following link: https://trendmicro-frontend.github.io/tonic-ui-demo/react/pr-930/
/describe
PR Description updated to latest commit (https://github.com/trendmicro-frontend/tonic-ui/commit/5162afc4d6a6e4610c0b510fc6f8fb72fb845d8f)
/review
/improve
/improve
Latest suggestions up to 8c64588
Category | Suggestion | Score |
Enhancement |
Move the name conflict check outside the conditional block for consistent execution___ **Consider moving the name conflict check and warning outside of theif (checkboxGroupContext) block to ensure it's always performed, regardless of whether a checkbox group context exists.** [packages/react/src/checkbox/Checkbox.js [60-67]](https://github.com/trendmicro-frontend/tonic-ui/pull/930/files#diff-d5ae55a366f7b950201c3eed96f52580aac6a13b4d1ff587e33bc597a67a5c51R60-R67) ```diff const isNameConflict = (!isNullish(name) && !isNullish(checkboxGroupName) && (name !== checkboxGroupName)); -if (process.env.NODE_ENV !== 'production' && isNameConflict && !isNameConflict.current) { +if (process.env.NODE_ENV !== 'production' && isNameConflict && !isNameConflictRef.current) { // Log the warning message only once console.error( `Warning: The \`Checkbox\` has a \`name\` prop ("${name}") that conflicts with the \`CheckboxGroup\`'s \`name\` prop ("${checkboxGroupName}")` ); isNameConflictRef.current = true; } +if (checkboxGroupContext) { + // ... existing code ... +} + ``` Suggestion importance[1-10]: 8Why: Moving the name conflict check outside the conditional block ensures that the check is always performed, which is a significant improvement for consistency and reliability in the code. | 8 |
Maintainability |
Add a comment explaining the purpose of the getMemoizedState function___ **Consider adding a comment to explain the purpose of thegetMemoizedState function and how it's used in the context of the ButtonGroup component.**
[packages/react/src/button/ButtonGroup.js [25-30]](https://github.com/trendmicro-frontend/tonic-ui/pull/930/files#diff-7eb5a03e77d6ee9639b58e062a8f452133274079a68e68b495303d15d3f96393R25-R30)
```diff
+// Create a memoized context object to prevent unnecessary re-renders
+// when the ButtonGroup props haven't changed
const context = getMemoizedState({
disabled,
orientation,
size,
variant,
});
```
- [ ] **Apply this suggestion**
Suggestion importance[1-10]: 5Why: Adding a comment improves code readability and maintainability by clarifying the purpose of the `getMemoizedState` function, though it is not crucial for functionality. | 5 |
Category | Suggestion | Score |
Enhancement |
Simplify null checks using modern JavaScript features___ **Replace theisNullish function calls with the more concise and commonly used nullish coalescing operator (??) for checking if name and radioGroupName are not null or undefined.** [packages/react/src/radio/Radio.js [58]](https://github.com/trendmicro-frontend/tonic-ui/pull/930/files#diff-902e8001f5f749a8725aa09ca99a7020fb3923fca8861a8478b575090d353573R58-R58) ```diff -const isNameConflict = (!isNullish(name) && !isNullish(radioGroupName) && (name !== radioGroupName)); +const isNameConflict = (name != null && radioGroupName != null && name !== radioGroupName); ``` Suggestion importance[1-10]: 8Why: The suggestion correctly simplifies the null checks using modern JavaScript syntax, improving code readability and maintainability. | 8 |
Performance |
Move console.error to useEffect for better performance___ **Consider moving the console.error statement outside of the component's render cycleto improve performance. You could use a custom hook or a useEffect with appropriate dependencies to log the warning only when necessary.** [packages/react/src/checkbox/Checkbox.js [60-64]](https://github.com/trendmicro-frontend/tonic-ui/pull/930/files#diff-d5ae55a366f7b950201c3eed96f52580aac6a13b4d1ff587e33bc597a67a5c51R60-R64) ```diff -if (process.env.NODE_ENV !== 'production' && isNameConflict) { - console.error( - `Warning: The \`Checkbox\` has a \`name\` prop ("${name}") that conflicts with the \`CheckboxGroup\`'s \`name\` prop ("${checkboxGroupName}")` - ); -} +useEffect(() => { + if (process.env.NODE_ENV !== 'production' && isNameConflict) { + console.error( + `Warning: The \`Checkbox\` has a \`name\` prop ("${name}") that conflicts with the \`CheckboxGroup\`'s \`name\` prop ("${checkboxGroupName}")` + ); + } +}, [isNameConflict, name, checkboxGroupName]); ``` Suggestion importance[1-10]: 7Why: The suggestion improves performance by moving the console.error statement to a useEffect hook, ensuring it only runs when necessary, which is a good practice for optimizing component rendering. | 7 |
Category | Suggestion | Score |
Enhancement |
โ Use nullish coalescing operator for more precise boolean handling___Suggestion Impact:The suggestion to use the nullish coalescing operator (??) instead of the logical OR operator (||) for the variable 'disabled' was implemented. code diff: ```diff - disabled = buttonGroupDisabled || disabled; + disabled = buttonGroupDisabled ?? disabled; ```operator (||) when checking for buttonGroupDisabled . This ensures that false values are not treated as falsy.** [packages/react/src/button/Button.js [34]](https://github.com/trendmicro-frontend/tonic-ui/pull/930/files#diff-37592a959e1ed17e0fa9b850e25ae31a73268d7cddb4c47cb5567d1d87307b3bR34-R34) ```diff -disabled = buttonGroupDisabled || disabled; +disabled = buttonGroupDisabled ?? disabled; ``` Suggestion importance[1-10]: 7Why: | 7 |
Use object property shorthand for more concise code___ **Consider using object property shorthand for thecontext object creation to make the code more concise and easier to read.** [packages/react/src/button/ButtonGroup.js [25-30]](https://github.com/trendmicro-frontend/tonic-ui/pull/930/files#diff-7eb5a03e77d6ee9639b58e062a8f452133274079a68e68b495303d15d3f96393R25-R30) ```diff -const context = getMemoizedState({ - disabled, - orientation, - size, - variant, -}); +const context = getMemoizedState({ disabled, orientation, size, variant }); ``` Suggestion importance[1-10]: 7Why: | 7 | |
Best practice |
Simplify object destructuring by removing unnecessary spread operator___ **Consider destructuringbuttonGroupDisabled and buttonGroupOrientation directly in the object destructuring statement to improve code readability and reduce the number of lines.** [packages/react/src/button/Button.js [28-33]](https://github.com/trendmicro-frontend/tonic-ui/pull/930/files#diff-37592a959e1ed17e0fa9b850e25ae31a73268d7cddb4c47cb5567d1d87307b3bR28-R33) ```diff const { disabled: buttonGroupDisabled, orientation: buttonGroupOrientation, size: buttonGroupSize, variant: buttonGroupVariant, -} = { ...buttonGroupContext }; +} = buttonGroupContext; ``` Suggestion importance[1-10]: 7Why: | 7 |
Maintainability |
Add a description comment for the new build script___ **Consider adding a description for the newbuild-public script to improve maintainability and help other developers understand its purpose.** [package.json [10]](https://github.com/trendmicro-frontend/tonic-ui/pull/930/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R10-R10) ```diff -"build-public": "lerna exec --no-private -- yarn build", +"build-public": "lerna exec --no-private -- yarn build # Builds only public packages", ``` Suggestion importance[1-10]: 7Why: | 7 |
/review
PR Type
Enhancement, Documentation
Description
disabled
prop inButton
,ButtonGroup
,Checkbox
, andRadio
components.disabled
and other props.disabled
prop forButtonGroup
,CheckboxGroup
, andRadioGroup
.build-public
script topackage.json
.Changes walkthrough ๐
4 files
Button.js
Add support for `disabled` prop in `Button`
packages/react/src/button/Button.js
disabled
prop inButton
.disabled
andorientation
.ButtonGroup
context.ButtonGroup.js
Add `disabled` prop to `ButtonGroup`
packages/react/src/button/ButtonGroup.js
disabled
prop toButtonGroup
.disabled
.Checkbox.js
Update `Checkbox` to use nullish coalescing
packages/react/src/checkbox/Checkbox.js
disabled
andname
.CheckboxGroup
context.Radio.js
Update `Radio` to use nullish coalescing
packages/react/src/radio/Radio.js
disabled
andname
.RadioGroup
context.4 files
tonic-ui-927.md
Add changeset for disabled button group support
.changeset/tonic-ui-927.md - Added changeset for supporting disabled button group.
index.page.mdx
Document `disabled` prop for `ButtonGroup`
packages/react-docs/pages/components/button-group/index.page.mdx - Documented `disabled` prop for `ButtonGroup`.
index.page.mdx
Update `disabled` prop documentation for `CheckboxGroup`
packages/react-docs/pages/components/checkbox-group/index.page.mdx - Updated default value of `disabled` prop for `CheckboxGroup`.
index.page.mdx
Update `disabled` prop documentation for `RadioGroup`
packages/react-docs/pages/components/radio-group/index.page.mdx - Updated default value of `disabled` prop for `RadioGroup`.
1 files
package.json
Add `build-public` script to package.json
package.json - Added `build-public` script to package.json.