From 7c911d2397d130683159396192da0e16947f4e92 Mon Sep 17 00:00:00 2001 From: Ryan Lewis Date: Wed, 8 May 2024 19:57:04 -0700 Subject: [PATCH 1/6] default sort by to posted date descending --- frontend/src/app/api/SearchOpportunityAPI.ts | 11 +++++++---- frontend/src/components/search/SearchSortBy.tsx | 12 ++++++------ frontend/src/types/search/searchRequestTypes.ts | 8 +++++++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/api/SearchOpportunityAPI.ts b/frontend/src/app/api/SearchOpportunityAPI.ts index 4e4f321b3..a9a3b4df1 100644 --- a/frontend/src/app/api/SearchOpportunityAPI.ts +++ b/frontend/src/app/api/SearchOpportunityAPI.ts @@ -44,6 +44,7 @@ export default class SearchOpportunityAPI extends BaseApi { } const subPath = "search"; + console.log("requestBody => ", requestBody); const response = await this.request( "POST", this.basePath, @@ -113,7 +114,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)) { @@ -123,9 +124,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..4bf61b795 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: "Posted Date (Descending)", value: "postedDateDesc" }, + { label: "Posted Date (Ascending)", value: "postedDateAsc" }, { label: "Opportunity Number (Descending)", value: "opportunityNumberDesc" }, - { label: "Opportunity Title (Ascending)", value: "opportunityTitleAsc" }, + { label: "Opportunity Number (Ascending)", value: "opportunityNumberAsc" }, { label: "Opportunity Title (Descending)", value: "opportunityTitleDesc" }, - { label: "Agency (Ascending)", value: "agencyAsc" }, + { label: "Opportunity Title (Ascending)", value: "opportunityTitleAsc" }, { label: "Agency (Descending)", value: "agencyDesc" }, - { label: "Posted Date (Ascending)", value: "postedDateAsc" }, - { label: "Posted Date (Descending)", value: "postedDateDesc" }, - { label: "Close Date (Ascending)", value: "closeDateAsc" }, + { label: "Agency (Ascending)", value: "agencyAsc" }, { label: "Close Date (Descending)", value: "closeDateDesc" }, + { label: "Close Date (Ascending)", value: "closeDateAsc" }, ]; 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; From af98e14fc031c5da78631642a1f4a926e6c77f7d Mon Sep 17 00:00:00 2001 From: Ryan Lewis Date: Thu, 9 May 2024 11:48:14 -0700 Subject: [PATCH 2/6] remove console log --- frontend/src/app/api/SearchOpportunityAPI.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/app/api/SearchOpportunityAPI.ts b/frontend/src/app/api/SearchOpportunityAPI.ts index a9a3b4df1..f8dfc53cc 100644 --- a/frontend/src/app/api/SearchOpportunityAPI.ts +++ b/frontend/src/app/api/SearchOpportunityAPI.ts @@ -44,7 +44,6 @@ export default class SearchOpportunityAPI extends BaseApi { } const subPath = "search"; - console.log("requestBody => ", requestBody); const response = await this.request( "POST", this.basePath, From 90e0ba66f8897a3eed8e2cc3741a1da28af9070b Mon Sep 17 00:00:00 2001 From: Ryan Lewis Date: Mon, 13 May 2024 12:55:55 -0700 Subject: [PATCH 3/6] update search sort by --- .../src/components/search/SearchSortBy.tsx | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/search/SearchSortBy.tsx b/frontend/src/components/search/SearchSortBy.tsx index 4bf61b795..7a9154c0a 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: "Posted Date (Descending)", value: "postedDateDesc" }, - { label: "Posted Date (Ascending)", value: "postedDateAsc" }, - { label: "Opportunity Number (Descending)", value: "opportunityNumberDesc" }, - { label: "Opportunity Number (Ascending)", value: "opportunityNumberAsc" }, - { label: "Opportunity Title (Descending)", value: "opportunityTitleDesc" }, - { label: "Opportunity Title (Ascending)", value: "opportunityTitleAsc" }, - { label: "Agency (Descending)", value: "agencyDesc" }, - { label: "Agency (Ascending)", value: "agencyAsc" }, - { label: "Close Date (Descending)", value: "closeDateDesc" }, - { label: "Close Date (Ascending)", value: "closeDateAsc" }, + { label: "Posted Date (newest)", value: "postedDateDesc" }, + { label: "Posted Date (oldest)", value: "postedDateAsc" }, + { label: "Opportunity Number (newest)", value: "opportunityNumberDesc" }, + { label: "Opportunity Number (oldest)", value: "opportunityNumberAsc" }, + { 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: "Close Date (descending)", value: "closeDateDesc" }, + { label: "Close Date (ascending)", value: "closeDateAsc" }, ]; interface SearchSortByProps { From cd8574874acbadaa05851836770a360d20e6e596 Mon Sep 17 00:00:00 2001 From: Ryan Lewis Date: Mon, 13 May 2024 13:05:19 -0700 Subject: [PATCH 4/6] fix sortby test --- frontend/tests/components/search/SearchSortBy.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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(); From 643c5a9da34701471ae80bca122c647b79e6dd05 Mon Sep 17 00:00:00 2001 From: Ryan Lewis Date: Tue, 14 May 2024 13:45:07 -0700 Subject: [PATCH 5/6] update order --- frontend/src/components/search/SearchSortBy.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/search/SearchSortBy.tsx b/frontend/src/components/search/SearchSortBy.tsx index 7a9154c0a..97ff6e36d 100644 --- a/frontend/src/components/search/SearchSortBy.tsx +++ b/frontend/src/components/search/SearchSortBy.tsx @@ -9,14 +9,14 @@ type SortOption = { const SORT_OPTIONS: SortOption[] = [ { label: "Posted Date (newest)", value: "postedDateDesc" }, { label: "Posted Date (oldest)", value: "postedDateAsc" }, - { label: "Opportunity Number (newest)", value: "opportunityNumberDesc" }, - { label: "Opportunity Number (oldest)", value: "opportunityNumberAsc" }, + { label: "Close Date (descending)", value: "closeDateDesc" }, + { label: "Close Date (ascending)", 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: "Close Date (descending)", value: "closeDateDesc" }, - { label: "Close Date (ascending)", value: "closeDateAsc" }, + { label: "Opportunity Number (newest)", value: "opportunityNumberDesc" }, + { label: "Opportunity Number (oldest)", value: "opportunityNumberAsc" }, ]; interface SearchSortByProps { From 39754c70b3ef8742fe6506261999302f1d15276b Mon Sep 17 00:00:00 2001 From: Ryan Lewis Date: Tue, 14 May 2024 13:47:27 -0700 Subject: [PATCH 6/6] update parenthesis --- frontend/src/components/search/SearchSortBy.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/search/SearchSortBy.tsx b/frontend/src/components/search/SearchSortBy.tsx index 97ff6e36d..5c5475534 100644 --- a/frontend/src/components/search/SearchSortBy.tsx +++ b/frontend/src/components/search/SearchSortBy.tsx @@ -9,14 +9,14 @@ type SortOption = { const SORT_OPTIONS: SortOption[] = [ { label: "Posted Date (newest)", value: "postedDateDesc" }, { label: "Posted Date (oldest)", value: "postedDateAsc" }, - { label: "Close Date (descending)", value: "closeDateDesc" }, - { label: "Close Date (ascending)", value: "closeDateAsc" }, + { 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 (newest)", value: "opportunityNumberDesc" }, - { label: "Opportunity Number (oldest)", value: "opportunityNumberAsc" }, + { label: "Opportunity Number (descending)", value: "opportunityNumberDesc" }, + { label: "Opportunity Number (ascending)", value: "opportunityNumberAsc" }, ]; interface SearchSortByProps {