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

Copy custom group properties in group-utils copyGroup function #1843

Merged
merged 7 commits into from
Jul 26, 2024

Conversation

lukasnys
Copy link
Contributor

Why?

In our use case of ember-power-select we add custom properties onto the groups to conditionally render those groups in a different way (in the @groupComponent that we pass to PowerSelectMultiple).

However, because the copyGroup function strips those custom properties, our styling is broken as soon as a user enters a search term.

What?

Change the copyGroup function to include all fields.

@lukasnys lukasnys changed the title fix: copy all properties of the group Fix group-utils' copyGroup function behaviour Jul 12, 2024
@mkszepp
Copy link
Collaborator

mkszepp commented Jul 14, 2024

Not sure if this works in your case, but we have a @extra paramenter to pass additional option to any place... maybe this helps you already to fix your issue?

If it isn't working with @extra, can you add any test for this changes, so there is always save for future updates

@lukasnys
Copy link
Contributor Author

lukasnys commented Jul 15, 2024

@mkszepp thanks for the suggestion! I don't believe the @extra works for our use case though.
As we'd need to pass the the custom properties as @extra to the @groupComponent and those custom properties can be unique per group object.

How do you suggest I should test these changes? Should I export the copyGroup function and then write a unit test for it?

EDIT: I took a stab at writing tests for this

@mkszepp
Copy link
Collaborator

mkszepp commented Jul 16, 2024

@lukasnys for test i would like you add a test like a real usecase... for example creating a component in which you are passing this property... so we don't need to export the function right?
Its always better to make real example...

With @extra you need maybe to create the object with more dimensions to get run, but it works without override of any component... Passing custom parameter works atm fine, but when you will move any day to glint (which will be recommended in near future to every app and is also already usabel) your use-case could be more configuration inside your app, because glint validates if every parameter you pass, exists on component and has correct type. So you need also to override component signature... inside your app to get run.

@lukasnys
Copy link
Contributor Author

Hey @mkszepp, that makes sense! I removed the unit tests and added an integration test for my change.

@lukasnys
Copy link
Contributor Author

I also created #1844 where I add the same test to showcase that it's currently failing.

@mkszepp
Copy link
Collaborator

mkszepp commented Jul 26, 2024

Thanks looks already good! Can you add als a test for single select? Than i think we test everything

Can you fix also the embroider test?

@lukasnys
Copy link
Contributor Author

Added the single select test case and fixed the Embroider test!

Copy link
Collaborator

@mkszepp mkszepp left a comment

Choose a reason for hiding this comment

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

Thank you! LGTM!

Copy link
Collaborator

@mkszepp mkszepp left a comment

Choose a reason for hiding this comment

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

Ah one thing.. for TS i think we need to extend the Group with [key: string]: unknown otherwise its not possibile to use inside TS project... can you maybe add also this one?

Line 120 in group-utils

@mkszepp mkszepp changed the title Fix group-utils' copyGroup function behaviour Copy custom group options in group-utils copyGroup function Jul 26, 2024
@mkszepp mkszepp changed the title Copy custom group options in group-utils copyGroup function Copy custom group properties in group-utils copyGroup function Jul 26, 2024
@lukasnys
Copy link
Contributor Author

Will do 👀

In the implementation of the copyGroup function, do you think it makes sense to keep the explicit check for the disabled property. Or do you think I can remove it since we have the ...group?

Implementation below as reference

function copyGroup(group: Group, suboptions: any[]): Group {
  const groupCopy: Group = { ...group, options: suboptions };
  if (Object.prototype.hasOwnProperty.call(group, 'disabled')) {
    groupCopy.disabled = group.disabled;
  }
  return groupCopy;
}

@mkszepp
Copy link
Collaborator

mkszepp commented Jul 26, 2024

Will do 👀

In the implementation of the copyGroup function, do you think it makes sense to keep the explicit check for the disabled property. Or do you think I can remove it since we have the ...group?

Implementation below as reference

function copyGroup(group: Group, suboptions: any[]): Group {
  const groupCopy: Group = { ...group, options: suboptions };
  if (Object.prototype.hasOwnProperty.call(group, 'disabled')) {
    groupCopy.disabled = group.disabled;
  }
  return groupCopy;
}

I think, we can hold like it is, so the autocomplete is better

@lukasnys
Copy link
Contributor Author

Added [key: string]: unknown to the Group interface 👍

@mkszepp mkszepp merged commit 4b1cf5b into cibernox:master Jul 26, 2024
18 checks passed
@mkszepp
Copy link
Collaborator

mkszepp commented Jul 26, 2024

Thank you... i will release it on begin of next week

@lukasnys
Copy link
Contributor Author

Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants