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

Sort formatted values in vector API response (ordering + fformatter params) #806

Closed
1 task done
Raruto opened this issue Apr 9, 2024 · 0 comments · Fixed by #807
Closed
1 task done

Sort formatted values in vector API response (ordering + fformatter params) #806

Raruto opened this issue Apr 9, 2024 · 0 comments · Fixed by #807
Assignees
Labels
feature New feature or request

Comments

@Raruto
Copy link
Contributor

Raruto commented Apr 9, 2024

Checklist

  • I've searched through the current issues to make sure this feature hasn't been requested already.

Motivation

Be able to sort the the following values by "formatted" field value instead of by field key:

https://v37.g3wsuite.it/vector/api/data/qdjango/97/buildings_2f43dc1d_6725_42d2_a09b_dd446220104a/?fformatter=address&ordering=address

// current behavior

"data": [
  [ "A101", "Via Sallustio Bandini" ],
  [ "A102", "Via Atto Vannucci" ],
  [ "A103", "Via Alfredo Oriani gia' Via Vecchia" ],
  [ "A106", "Piazza Pietro Leopoldo" ],
  [ "A107", "Via Ubaldo Montelatici" ],
  [ "A108", "Via Giandomenico Romagnosi" ],
  [ "B002", "Via Giovanni Lampredi" ],
  [ "C106", "Via Pietro Cironi" ],
  [ "C107", "Via Pietro Corridoni" ]
],

Suggested solution

Introduce a new parameter or change the ordering behavior so that response can be like following:

// desired behavior

"data": [
  [ "A106", "Piazza Pietro Leopoldo" ],
  [ "A103", "Via Alfredo Oriani gia' Via Vecchia" ],
  [ "A102", "Via Atto Vannucci" ],
  [ "A108", "Via Giandomenico Romagnosi" ],
  [ "B002", "Via Giovanni Lampredi" ],
  [ "C106", "Via Pietro Cironi" ],
  [ "C107", "Via Pietro Corridoni" ],
  [ "A101", "Via Sallustio Bandini" ],
  [ "A107", "Via Ubaldo Montelatici" ]
],

NB the sorting algo must also take into account numeric, null and boolean values (see below)

Alternatives considered

Formatted values can be sorted on client-side, but this make every API calls code even more complex/unreliable:

fetch('https://v37.g3wsuite.it/vector/api/data/qdjango/97/buildings_2f43dc1d_6725_42d2_a09b_dd446220104a/?fformatter=address' /* + '&ordering=address' */)
  .then(d => d.json())
  // sorted by fformatter
  .then(d => d.data.sort((a, b) => `${a[1]}`.localeCompare(b[1], undefined, 'number' === typeof a[1] ? { numeric: true } : { sensitivity: 'base' })))
@Raruto Raruto added the feature New feature or request label Apr 9, 2024
wlorenzetti pushed a commit that referenced this issue Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants