Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

[Issue #1957]: sortby posted date desc default #4

Merged
merged 8 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions frontend/src/app/api/SearchOpportunityAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions frontend/src/components/search/SearchSortBy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/types/search/searchRequestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions frontend/tests/components/search/SearchSortBy.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jest.mock("../../../src/hooks/useSearchParamUpdater", () => ({
}));

describe("SearchSortBy", () => {
const initialQueryParams = "opportunityNumberAsc";
const initialQueryParams = "postedDateDesc";
const mockFormRef = React.createRef<HTMLFormElement>();

it("should not have basic accessibility issues", async () => {
Expand All @@ -36,7 +36,7 @@ describe("SearchSortBy", () => {
);

expect(
screen.getByDisplayValue("Opportunity Number (Ascending)"),
screen.getByDisplayValue("Posted Date (newest)"),
).toBeInTheDocument();
});

Expand All @@ -57,7 +57,7 @@ describe("SearchSortBy", () => {
});

expect(
screen.getByDisplayValue("Opportunity Title (Descending)"),
screen.getByDisplayValue("Opportunity Title (Z to A)"),
).toBeInTheDocument();

expect(requestSubmitMock).toHaveBeenCalled();
Expand Down
Loading