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

Thumnail ordering in collections #370

Closed
seignovert opened this issue Sep 19, 2023 · 4 comments
Closed

Thumnail ordering in collections #370

seignovert opened this issue Sep 19, 2023 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@seignovert
Copy link

Hello,

Thanks for this very nice browser!

I just published my first STAC catalog and I'm experiencing a strange behavior with stac-browser 3.1.0 when multiples thumbnails are attached to an item. The preview displayed in the parent collection is the 1st thumbnail on Firefox and the last one on Chrome. Is there a way to ensure a consistent behavior?

Here is an example: https://radiantearth.github.io/stac-browser/#/external/vims.univ-nantes.fr/stac/titan/030ti/collection.json

On Firefox I get:

Previews on Firefox

Whereas on Chrome I have:

Previews on Chrome

In my case, the would prefer to always display the 1st thumbnail (like on Firefox).

@m-mohr
Copy link
Collaborator

m-mohr commented Sep 20, 2023

Interesting, I assume it depends on how the JS engine deserializes and orders objects. As object properties per the JSON specification don't have an order, I can't fetch "the first one", I can only really order them by key or so. Maybe for this case we can define some kind of best practice that we add another role (e.g. primary) for the thumbnail to be used?

@seignovert
Copy link
Author

I think I have found where the problem is coming from:

thumbnails.sort(a => a.roles.includes(prefer) ? -1 : 1);

The .sort() method is different between the 2 JS engine (see https://stackoverflow.com/q/64396555) when the result of the function return the same value. Here, all the preferred roles are equal to -1, then Firefox keeps the original ordering whereas Chrome is returning the reverse of the original array.

I'm not sure how to change this efficiently but I'm not sure this .sort() method is actually required. It should be a filter method instead.

@m-mohr
Copy link
Collaborator

m-mohr commented Sep 25, 2023

Thanks for the investigation. I'll have a look once I'm back from the STAC sprint or you can go ahead and create a PR for it, too. :)

@m-mohr m-mohr added the bug Something isn't working label Sep 29, 2023
m-mohr added a commit that referenced this issue Oct 2, 2023
m-mohr added a commit that referenced this issue Oct 2, 2023
@m-mohr
Copy link
Collaborator

m-mohr commented Oct 2, 2023

Thanks, this should be fixed now. See b23fb2e

@m-mohr m-mohr closed this as completed Oct 2, 2023
@m-mohr m-mohr added this to the 3.1.1 milestone Oct 2, 2023
@m-mohr m-mohr self-assigned this Oct 2, 2023
@m-mohr m-mohr modified the milestones: 3.1.1, 3.2.0 Mar 7, 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

2 participants