Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Backward incompatibility on use of label in CollectionPreferences. #2857

Open
2 tasks done
nicklera1 opened this issue Oct 11, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@nicklera1
Copy link

Browser

Chrome, Safari, Firefox, Edge

Package version

v3.0.782

React version

18.1

Description

Resent change to a5defd9#diff-9a4626222e43ed6f71fb6aa5a4fc8bff1727c66603314abd4888c51c55025741R65 have broke rendering of Preference panel due to new filtering logic where it assumes that label is string which is based on the interface (my assumption)

export interface ContentDisplayOption {
       id: string;
       label: string;
       alwaysVisible?: boolean;
   }

The issue is that we had use ReactNode as label before and since the current code assumes it's string it throws and error.

TypeError: e.label.toLowerCase is not a function
    at index.tsx:65:22
    at Array.filter (<anonymous>)
    at index.tsx:64:60

Source code

a5defd9#diff-9a4626222e43ed6f71fb6aa5a4fc8bff1727c66603314abd4888c51c55025741R65

const sortedAndFilteredOptions = useMemo(
   () =>
     getSortedOptions({ options, contentDisplay: value }).filter(option =>
       option.label.toLowerCase().trim().includes(columnFilteringText.toLowerCase().trim())
     ),
   [columnFilteringText, options, value]
 );

Reproduction

import styled from "styled-components";
// Example of ContentDisplayOption
export interface ContentDisplayOption {
  id: string;
  label: string;
  alwaysVisible?: boolean;
}

function App() {
  const options = [
    {
      id: "first",
      label: "First Label",
      alwaysVisible: true,
    },
    {
      id: "first",
      label: (
        // ReactNode passed here
        <div>
          <strong>ALSO LABEL</strong>
        </div>
      ) as React.ReactNode,
      alwaysVisible: true,
    },
  ] as ContentDisplayOption[];
  return (
    <div style={{ padding: "30px" }}>
      {options.map((opt) => {
        return (
          <ul>
            <li> Id: {opt.id} </li>
            <li> Label: {opt.label}</li>
            <li> Visible: {opt.alwaysVisible ? "Yes" : "no"} </li>
          </ul>
        );
      })}
    </div>
  );
}

export default App;

Edit React@18-Typescript (forked)

Code of Conduct

@nicklera1 nicklera1 added the bug Something isn't working label Oct 11, 2024
@nicklera1 nicklera1 changed the title [Bug]: Backword incompatibility on use of label in CollectionPreferences. [Bug]: Backward incompatibility on use of label in CollectionPreferences. Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant