Closed mheppner closed 4 years ago
Unfortunately, a blanket LOWER() cannot be added to the ordering due not all order fields being
character fields. What I think I can do is define a generic alphabetize
util function that we can pass 1) the ordering we get from the request and 2) a list of the character fields for the model that would essentially replace any character field orderings with a lower() (and the proper ascend/descend since that changes as well when you apply a lower()).
The UI sorts by the following columns:
Batches:
/api/v6/batches/?order= |
Field | Type |
---|---|---|
title | string | |
recipe_type | int (id) | |
is_creation_done | boolean? | |
jobs_total | int | |
created | datetime | |
last_modified | datetime |
Ingest records:
/api/v6/ingests/?order= |
Field | Type |
---|---|---|
file_name | string | |
status | string | |
file_size | number | |
strike.id | int (id) | |
transfer_started | datetime | |
transfer_ended | datetime | |
ingest_started | datetime | |
ingest_ended | datetime |
Jobs:
/api/v6/jobs/?order= |
Field | Type |
---|---|---|
status | string | |
error.category | string | |
error.title | string | |
job_type | id? name? | |
recipe | id? type name? type title? | |
created | datetime | |
last_modified | datetime | |
node | int (id) |
Recipe:
/api/v6/recipes/?order= |
Field | Type |
---|---|---|
recipe_type.name | string | |
created | datetime | |
last_modified | datetime | |
completed | datetime |
Scans:
/api/v6/scans/?order= |
Field | Type |
---|---|---|
name | string | |
file_count | int? | |
job | int (id) | |
created | datetime | |
last_modified | datetime |
Pain Point? Please describe. See ngageoint/scale-ui#301.
API endpoints returning data sorted alphabetically are using default SQL sorting, which sorts case-sensitive. This can be seen on recipe types page, for example. Add multiple recipe types with lower and upper cases, and you'll see the capitalized ones are alphabetical at the top, followed by lower-case ones at the bottom.
Desired Solution Case-insensitive sorting for REST endpoints.
This can be done by adding an extra
LOWER()
field to the query and sorting on that: https://stackoverflow.com/a/34506461This looks like a good solution for DRF: https://stackoverflow.com/a/47347807
Alternative / Workaround I can sort in some parts of the UI, but anything that returns paged results will obviously not be doable on the frontend.