Skip to content

feat(chore): Unique ids. - OEL-3642#663

Closed
enriquelacoma wants to merge 1 commit intodevelopmentfrom
OEL-3642
Closed

feat(chore): Unique ids. - OEL-3642#663
enriquelacoma wants to merge 1 commit intodevelopmentfrom
OEL-3642

Conversation

@enriquelacoma
Copy link
Collaborator

Extend random range and add microtime to id generation.

Fix for issue #642

@github-actions
Copy link

github-actions bot commented Apr 15, 2025

🚀 Deployed on https://preview-663--oelibrary.netlify.app

@github-actions github-actions bot temporarily deployed to pull request April 15, 2025 10:35 Inactive
#}

{% set _id = id|default('dropdown-' ~ random(1000)) %}
{% set _id = id|default('dropdown-' ~ random(10000) ~ "-" ~ "now"|date('u')) %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was going to suggest the use of a Drupal core filter like this: https://www.drupal.org/node/3363551
But the library itself is not tied to Drupal so we cannot rely on that filter.

A probability of 0.0001 should be enough.
An improvement could be to pass the correct values on the templates where this is used.

Remember to update comment above with parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"I was going to suggest the use of a Drupal core filter like this: https://www.drupal.org/node/3363551
But the library itself is not tied to Drupal so we cannot rely on that filter2

This is already commented in the issue #642 and can't really be done without third party libraries

"A probability of 0.0001 should be enough.
An improvement could be to pass the correct values on the templates where this is used."

We also added microtime to the id, I tested adding several dropdowns to the preview content in the same example and the microtimes of each one is different

I updated the doc

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally oe_bootstrap_theme would use the dropdown passing the correct id based on an unique filter.
The component itself is not aware of other possible dropdowns.
You can play with probabilities, but the only safe mode of doing this is excluding used ids.

@tibi2303 tibi2303 changed the title OEL-3642: Extend random range and add microtime to the id. feat(chore): Unique ids. -OEL-3642 Apr 16, 2025
@tibi2303 tibi2303 changed the title feat(chore): Unique ids. -OEL-3642 feat(chore): Unique ids. - OEL-3642 Apr 16, 2025
@tibi2303 tibi2303 closed this Apr 16, 2025
@tibi2303
Copy link
Collaborator

redone this on a different branch because it was needed to add #default# at the end of the branch for netlify deploy only on the default theme.

@drishu drishu deleted the OEL-3642 branch April 24, 2025 06:28
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.

3 participants