EightfoldAI / octuple

The Octuple component library
MIT License
16 stars 45 forks source link

fix: table: ensure boolean types in react render when expandable row #834

Closed dkilgore-eightfold closed 1 month ago

dkilgore-eightfold commented 1 month ago

SUMMARY:

In JavaScript and TypeScript, the && operator is used for logical AND operations, but it can also be used for conditional rendering in React. The expression A && B will return B if A is truthy, and A otherwise.

In this case, rowSupportExpand && expanded && expandRowNode will render expandRowNode if both rowSupportExpand and expanded are truthy. If either of them is falsy, it will render that falsy value.

The reason we're seeing a "0" in some upstream bundles could be that either rowSupportExpand or expanded is 0. In JavaScript, 0 is considered a falsy value, so if rowSupportExpand or expanded is 0, the whole expression will evaluate to 0.

To fix this, we ensure that rowSupportExpand and expanded are always boolean values. If they're not, we convert them to booleans using !!value.

Hence the quick fix is:

{!!rowSupportExpand && !!expanded && expandRowNode}

This will render expandRowNode if both rowSupportExpand and expanded are truthy, and nothing otherwise.

JIRA TASK (Eightfold Employees Only):

ENG-90186

CHANGE TYPE:

TEST COVERAGE:

TEST PLAN:

Pull the PR branch and run yarn and yarn storybook. Verify the Table Expandable Row stories behave as expected.

codesandbox-ci[bot] commented 1 month ago

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.