-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DCAT-2: Ensure that sort query parameters are normalized (#6)
* DCAT-2: Normalize incoming sort value so that the order is consistent and invalid sort orders return user to default sort order
- Loading branch information
1 parent
b78f202
commit 6995cc0
Showing
13 changed files
with
132 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
#### Running Data-Catalog locally | ||
|
||
```bash | ||
npm run dev | ||
npm run start | ||
``` | ||
|
||
#### Local Testing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* The default sort key used for sorting collections. | ||
*/ | ||
export const defaultSortKey = 'relevance' | ||
|
||
/** | ||
* An array of objects representing the available sort keys for collections. | ||
* Each object contains a `key` which is used for sorting and a `value` which is the display name. | ||
*/ | ||
export const collectionSortKeys = [ | ||
{ | ||
key: 'relevance', | ||
value: 'Relevance' | ||
}, | ||
{ | ||
key: '-usage_score', | ||
value: 'Usage' | ||
}, | ||
{ | ||
key: 'start_date', | ||
value: 'Start Date' | ||
}, | ||
{ | ||
key: '-ongoing', | ||
value: 'End Date' | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getValidSortkey } from '../getValidSortkey' | ||
|
||
describe('getCollectionSortKeys returns valid sort key configuration', () => { | ||
test('should return the correct value for a valid sort key', () => { | ||
expect(getValidSortkey('relevance')).toBe('Relevance') | ||
expect(getValidSortkey('-usage_score')).toBe('Usage') | ||
expect(getValidSortkey('start_date')).toBe('Start Date') | ||
expect(getValidSortkey('-ongoing')).toBe('End Date') | ||
}) | ||
|
||
test('should return null for an invalid sort key', () => { | ||
expect(getValidSortkey('invalid_key')).toBeNull() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { collectionSortKeys } from '../constants/sortKeys' | ||
/** | ||
* Query the list of valid collection sort keys and return the value for the key | ||
* @param {string} sortKey The sort key to check | ||
* @returns {string|null} The valid sort key or null | ||
*/ | ||
export const getValidSortkey = (sortKey: string) => { | ||
const found = collectionSortKeys.find((validSortKey) => validSortKey.key === sortKey) | ||
|
||
return found ? found.value : null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters