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

Add labeling opportunity to <Filter> component #2892

Merged
merged 5 commits into from
Aug 14, 2024
Merged

Add labeling opportunity to <Filter> component #2892

merged 5 commits into from
Aug 14, 2024

Conversation

balanza
Copy link
Member

@balanza balanza commented Aug 12, 2024

Description

The <Filter> component now allows options as key/value pairs. This is to cope with cases in which the value of the element must be different than the one shown.
Also, it enables a single value to be selected using a simple string, being more permissive on the allowed input.

This PR introduces no breaking changes.

Usage

// normal usage
<Filter 
     value={["Mario Rossi"]}
     options={["Mario Rossi", "Giuseppe Verdi"]} />

// using string as value
<Filter 
     value="Mario Rossi"
     options={["Mario Rossi", "Giuseppe Verdi"]} />

// with key/value
<Filter 
     value={["mario_rossi"}
     options={[
       ["mario_rossi", "Mario Rossi"], 
       ["giuseppe_verdi", "Giuseppe Verdi"]
     ]} />

@balanza balanza requested a review from dottorblaster August 12, 2024 15:56
@balanza balanza enabled auto-merge (squash) August 12, 2024 15:58
@balanza balanza disabled auto-merge August 12, 2024 15:59
Copy link
Contributor

@dottorblaster dottorblaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one tiny change but overall:

immagine

const parsedValue = typeof value === 'string' ? [value] : value;

const selectedLabels = parsedValue.reduce((acc, key) => {
const e = labeledOptions.find(([optionKey]) => optionKey === key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

immagine

@balanza balanza requested a review from dottorblaster August 14, 2024 10:30
Copy link
Contributor

@dottorblaster dottorblaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d039a74: --pedantic mode

Yes I am

@balanza balanza merged commit 9c92e45 into main Aug 14, 2024
27 checks passed
@balanza balanza deleted the enhance-filter branch August 14, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants