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

ComboBox - New methods + bullet proofing #479

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mohsinhijazee
Copy link

@mohsinhijazee mohsinhijazee commented Oct 10, 2024

This PR proposes few additions to the ComboBox.

I have tested this with SvelteKit and wrapped the Combox as a Svelte Component with full events and multiple instances of the component on the same page fetching data from difference sources so many copies/instances work seemlessly.

Few fixes/improvements:

  • Constructor does not rely on window.$hsComboBoxCollection being initialised. Thus users for bundlers (vite etc) don't have to load all of preline.js.
  • Fixed an error about invalid nullish statement
  • Fetching and rendering items is now bit more bullet proof, ensures that the returned response is iterable.

Additions to the CombBox:

  • apiSearchQueryTransformer to allow transforming query before fetch. This is required in case some APIs use more advanced filtering DSL such as Google's AIP-160 for example filter=prefix('name', 'sh') OR contains('lastName', 'sh') etc.
  • selectedItem() returns elemnent that was selected
  • selectedValue() returns the value.
  • selectedAttr(attr) returns the custom attribute.

Few other changes to the package.json (required dependencies added, deprecated type definitions replaced with updated packages), few scripts/watch/commands and generation scripts added.

Don't have full context on design choices so some things might seem absurd and I am here to revise as per your feedback FYI @jahaganiev and @olegpix

@mohsinhijazee mohsinhijazee force-pushed the combobox-enhancements branch 3 times, most recently from e6ea55b to 1664ee2 Compare October 10, 2024 17:25
Copy link
Collaborator

@olegpix olegpix left a comment

Choose a reason for hiding this comment

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

@mohsinhijazee Hi!
Thank you for your work! Please read the comments left. Correct the PR according to the comments and push changes.
Best regards!

pnpm-lock.yaml Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this file from the PR. We don't use PNPM.

Copy link
Author

Choose a reason for hiding this comment

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

Sure!

package.json Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please focus on TS files (src/plugins/combobox/*.ts).
You can create a separate PR in which you will provide your vision of bundling. But again, we do not use PNPM.
Please remove this file from the PR.

Copy link
Author

Choose a reason for hiding this comment

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

I don't have clear idea on bundling, I thought that maybe there's some off line step that only maintainers have or similar. I'll remove them.

index.d.ts Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please focus on TS files (src/plugins/combobox/*.ts). You should not generate output files on your side. Please remove this file from the PR.

preline.d.ts Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please focus on TS files (src/plugins/combobox/*.ts). You should not generate output files on your side. Please remove this file from the PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please focus on TS files (src/plugins/combobox/*.ts). You should not generate output files on your side. Please remove this file from the PR.

src/index.ts Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

We fixed this issue through another PR request from another user. Please remove this file from PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please create a separate PR for the select. We will be grateful if you will separate PRs by making them separate for each plugin.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do not use this as a separate helper. This check can be done with the standard Array method Array.isArray

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that's kinda pointless. 😄

@@ -13,12 +13,14 @@ import {
afterTransition,
htmlToElement,
isParentOrElementHidden,
isArray,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use Array.isArray instead.

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense. Will do.

@@ -376,6 +396,12 @@ class HSComboBox extends HSBasePlugin<IComboBoxOptions> implements IComboBox {
}

private jsonItemsRender(items: any) {

// Bullet proofing.
if (!isArray(items)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use Array.isArray instead.

Changes to the Combobox
 - Constructor does not rely on `window.$hsComboBoxCollection` being initalised. Thus
   users for bundlers (vite etc) don't have to load all of `preline.js`
 - Fixed an error about invalid nullish statement

Public methods selectValue() and selectAttribute
 - selectedItem() returns elemnent that was selected
 - selectedValue() returns the value.
 - selectedAttr() returns the custom attribute.

One option to the ComboBox options:
 - apiSearchQueryTransformer to allow transforming query before fetch

package.json:
   Few watch commands and generation scripts added.
@mohsinhijazee
Copy link
Author

@olegpix Thank you for your feedback!

I have removed everything that was not relevant (package.json scripts, generated dist/ and other d.ts files including the change related to select plugin) so I hope it is easier to review now.

Also, about packaging and bundling, I think some scripts or steps should be documented within the package.json etc. Not so sure about it. What steps/process do you guys follow for that?

@olegpix
Copy link
Collaborator

olegpix commented Nov 4, 2024

@olegpix Thank you for your feedback!

I have removed everything that was not relevant (package.json scripts, generated dist/ and other d.ts files including the change related to select plugin) so I hope it is easier to review now.

Also, about packaging and bundling, I think some scripts or steps should be documented within the package.json etc. Not so sure about it. What steps/process do you guys follow for that?

Hi,
The process is quite simple, you need to run 3 tasks from the Preline root (consistently):

  1. npm run build
  2. npm run build:mjs (optional)
  3. npm run generate-dts
    That's it.

We'll check and approve your PR after the next update, now we are focused on some other tasks.
Thank you for your work!

@jahaganiev
Copy link
Member

Hey @mohsinhijazee - thanks a lot for the PR, we will try to include this PR in v2.7.0 update. Thanks!

private init() {
// So that not to dpeendon preloading whole library.
Copy link

Choose a reason for hiding this comment

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

Small typo in the comment.

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

Successfully merging this pull request may close these issues.

4 participants