From 4f6a4fd5e88f28197e3a8a2fe7dccba63c7ed567 Mon Sep 17 00:00:00 2001 From: Ryan Lewis <93001277+rylew1@users.noreply.github.com> Date: Wed, 22 May 2024 10:48:20 -0700 Subject: [PATCH] [Issue #]: sortby posted date desc default (navapbc/simpler-grants-gov#4) Fixes # - Update sortby labels and ordering --- frontend/src/app/api/SearchOpportunityAPI.ts | 10 ++++++---- .../src/components/search/SearchSortBy.tsx | 20 +++++++++---------- .../src/types/search/searchRequestTypes.ts | 8 +++++++- .../components/search/SearchSortBy.test.tsx | 6 +++--- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/frontend/src/app/api/SearchOpportunityAPI.ts b/frontend/src/app/api/SearchOpportunityAPI.ts index c515bb7bc..36fdb31ac 100644 --- a/frontend/src/app/api/SearchOpportunityAPI.ts +++ b/frontend/src/app/api/SearchOpportunityAPI.ts @@ -109,7 +109,7 @@ export default class SearchOpportunityAPI extends BaseApi { closeDate: "close_date", }; - let order_by: PaginationOrderBy = "opportunity_id"; + let order_by: PaginationOrderBy = "post_date"; if (sortby) { for (const [key, value] of Object.entries(orderByFieldLookup)) { if (sortby.startsWith(key)) { @@ -119,9 +119,11 @@ export default class SearchOpportunityAPI extends BaseApi { } } - const sort_direction: PaginationSortDirection = sortby?.endsWith("Desc") - ? "descending" - : "ascending"; + // default to descending + let sort_direction: PaginationSortDirection = "descending"; + if (sortby) { + sort_direction = sortby?.endsWith("Desc") ? "descending" : "ascending"; + } return { order_by, diff --git a/frontend/src/components/search/SearchSortBy.tsx b/frontend/src/components/search/SearchSortBy.tsx index ebd706898..5c5475534 100644 --- a/frontend/src/components/search/SearchSortBy.tsx +++ b/frontend/src/components/search/SearchSortBy.tsx @@ -7,16 +7,16 @@ type SortOption = { }; const SORT_OPTIONS: SortOption[] = [ - { label: "Opportunity Number (Ascending)", value: "opportunityNumberAsc" }, - { label: "Opportunity Number (Descending)", value: "opportunityNumberDesc" }, - { label: "Opportunity Title (Ascending)", value: "opportunityTitleAsc" }, - { label: "Opportunity Title (Descending)", value: "opportunityTitleDesc" }, - { label: "Agency (Ascending)", value: "agencyAsc" }, - { label: "Agency (Descending)", value: "agencyDesc" }, - { label: "Posted Date (Ascending)", value: "postedDateAsc" }, - { label: "Posted Date (Descending)", value: "postedDateDesc" }, - { label: "Close Date (Ascending)", value: "closeDateAsc" }, - { label: "Close Date (Descending)", value: "closeDateDesc" }, + { label: "Posted Date (newest)", value: "postedDateDesc" }, + { label: "Posted Date (oldest)", value: "postedDateAsc" }, + { label: "Close Date (newest)", value: "closeDateDesc" }, + { label: "Close Date (oldest)", value: "closeDateAsc" }, + { label: "Opportunity Title (A to Z)", value: "opportunityTitleAsc" }, + { label: "Opportunity Title (Z to A)", value: "opportunityTitleDesc" }, + { label: "Agency (A to Z)", value: "agencyAsc" }, + { label: "Agency (Z to A)", value: "agencyDesc" }, + { label: "Opportunity Number (descending)", value: "opportunityNumberDesc" }, + { label: "Opportunity Number (ascending)", value: "opportunityNumberAsc" }, ]; interface SearchSortByProps { diff --git a/frontend/src/types/search/searchRequestTypes.ts b/frontend/src/types/search/searchRequestTypes.ts index 83afcad5c..94e78635f 100644 --- a/frontend/src/types/search/searchRequestTypes.ts +++ b/frontend/src/types/search/searchRequestTypes.ts @@ -6,7 +6,13 @@ export interface SearchFilterRequestBody { funding_category?: { one_of: string[] }; } -export type PaginationOrderBy = "opportunity_id" | "opportunity_number"; +export type PaginationOrderBy = + | "opportunity_id" + | "opportunity_number" + | "opportunity_title" + | "agency_code" + | "post_date" + | "close_date"; export type PaginationSortDirection = "ascending" | "descending"; export interface PaginationRequestBody { order_by: PaginationOrderBy; diff --git a/frontend/tests/components/search/SearchSortBy.test.tsx b/frontend/tests/components/search/SearchSortBy.test.tsx index 3dff473bd..17b6f732e 100644 --- a/frontend/tests/components/search/SearchSortBy.test.tsx +++ b/frontend/tests/components/search/SearchSortBy.test.tsx @@ -12,7 +12,7 @@ jest.mock("../../../src/hooks/useSearchParamUpdater", () => ({ })); describe("SearchSortBy", () => { - const initialQueryParams = "opportunityNumberAsc"; + const initialQueryParams = "postedDateDesc"; const mockFormRef = React.createRef(); it("should not have basic accessibility issues", async () => { @@ -36,7 +36,7 @@ describe("SearchSortBy", () => { ); expect( - screen.getByDisplayValue("Opportunity Number (Ascending)"), + screen.getByDisplayValue("Posted Date (newest)"), ).toBeInTheDocument(); }); @@ -57,7 +57,7 @@ describe("SearchSortBy", () => { }); expect( - screen.getByDisplayValue("Opportunity Title (Descending)"), + screen.getByDisplayValue("Opportunity Title (Z to A)"), ).toBeInTheDocument(); expect(requestSubmitMock).toHaveBeenCalled();