diff --git a/backend/.gitignore b/backend/.gitignore
index 449b5cdf..620063d7 100644
--- a/backend/.gitignore
+++ b/backend/.gitignore
@@ -397,7 +397,6 @@ dist
# The below expression will prevent user specific configuration files from being added to the repository
config/application-dev-*.yml
.checkstyle
-
-
temp/
-config/*.jks
\ No newline at end of file
+config/*.jks
+zscaler-cgi.crt
\ No newline at end of file
diff --git a/frontend/src/__test__/components/SilvicultureSearch/Openings/AdvancedSearchDropdown.test.tsx b/frontend/src/__test__/components/SilvicultureSearch/Openings/AdvancedSearchDropdown.test.tsx
index e801017a..bd076ee3 100644
--- a/frontend/src/__test__/components/SilvicultureSearch/Openings/AdvancedSearchDropdown.test.tsx
+++ b/frontend/src/__test__/components/SilvicultureSearch/Openings/AdvancedSearchDropdown.test.tsx
@@ -1,9 +1,9 @@
-import { render, screen } from "@testing-library/react";
+import { getByTestId, render, screen, waitFor } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import AdvancedSearchDropdown from "../../../../components/SilvicultureSearch/Openings/AdvancedSearchDropdown";
import { useOpeningFiltersQuery } from "../../../../services/queries/search/openingQueries";
import { useOpeningsSearch } from "../../../../contexts/search/OpeningsSearch";
-import React from "react";
+import React, { act } from "react";
// Mocking the toggleShowFilters function
const toggleShowFilters = vi.fn();
@@ -21,24 +21,19 @@ vi.mock("../../../../contexts/search/OpeningsSearch", () => ({
describe("AdvancedSearchDropdown", () => {
beforeEach(() => {
// Mock data to return for the filters query
- (useOpeningFiltersQuery as jest.Mock).mockReturnValue({
+ (useOpeningFiltersQuery as vi.Mock).mockReturnValue({
data: {
- categories: [{
- code: "FTML",
- description: "Forest Tenure - Major Licensee"
- }, {
- code: "CONT",
- description: "SP as a part of contractual agreement"
- }
- ],
+ categories: [{ code: "FTML", description: "" }, { code: "CONT", description: "" }],
orgUnits: [{
- orgUnitCode:'DCK',
- orgUnitName: 'Chilliwack Natural Resource District'
- }, {
- orgUnitCode:'DCR',
- orgUnitName: 'Campbell River Natural Resource District'
- }
- ],
+ "orgUnitNo": 15,
+ "orgUnitCode": "DCK",
+ "orgUnitName": "Chilliwack Natural Resource District"
+ },
+ {
+ "orgUnitNo": 43,
+ "orgUnitCode": "DCR",
+ "orgUnitName": "Campbell River Natural Resource District"
+ }],
dateTypes: ["Disturbance", "Free Growing"],
},
isLoading: false,
@@ -46,20 +41,22 @@ describe("AdvancedSearchDropdown", () => {
});
// Mock implementation of useOpeningsSearch context
- (useOpeningsSearch as jest.Mock).mockReturnValue({
+ (useOpeningsSearch as vi.Mock).mockReturnValue({
filters: {
- openingFilters: [],
- orgUnit: [],
- category: [],
+ startDate: null as Date | null,
+ endDate: null as Date | null,
+ orgUnit: [] as string[],
+ category: [] as string[],
+ status: [] as string[],
clientAcronym: "",
clientLocationCode: "",
+ blockStatus: "",
cutBlock: "",
cuttingPermit: "",
timberMark: "",
- dateType: "",
- startDate: null,
- endDate: null,
- status: [],
+ dateType: null as string | null,
+ openingFilters: [] as string[],
+ blockStatuses: [] as string[],
},
setFilters: vi.fn(),
clearFilters: vi.fn(),
@@ -79,23 +76,40 @@ describe("AdvancedSearchDropdown", () => {
).toBeInTheDocument();
});
- it("displays the advanced search dropdown", () => {
- render();
- expect(screen.getByText("Opening Filters")).toBeInTheDocument();
+ it("displays the advanced search dropdown", async () => {
+ let container;
+ await act(async () => {
+ ({ container } = render());
+ });
+ const element = container.querySelector('.d-block');
+ expect(element).toBeDefined();
});
- it("displays the advanced search dropdown with filters", () => {
- render();
- expect(screen.getByText("Opening Filters")).toBeInTheDocument();
- expect(screen.getByText("Org Unit")).toBeInTheDocument();
- expect(screen.getByText("Category")).toBeInTheDocument();
- expect(screen.getByText("Client acronym")).toBeInTheDocument();
- expect(screen.getByText("Client location code")).toBeInTheDocument();
- expect(screen.getByText("Cut block")).toBeInTheDocument();
- expect(screen.getByText("Cutting permit")).toBeInTheDocument();
- expect(screen.getByText("Timber mark")).toBeInTheDocument();
- expect(screen.getByLabelText("Start Date")).toBeInTheDocument();
- expect(screen.getByLabelText("End Date")).toBeInTheDocument();
- expect(screen.getByText("Status")).toBeInTheDocument();
+ it("clears the date filters when all filters are cleared", async () => {
+ // Mock implementation of useOpeningsSearch context
+ (useOpeningsSearch as vi.Mock).mockReturnValue({
+ filters: {
+ startDate: "1978-01-01",
+ endDate: "1978-01-01",
+ orgUnit: [] as string[],
+ category: [] as string[],
+ status: [] as string[],
+ clientAcronym: "",
+ clientLocationCode: "",
+ blockStatus: "",
+ cutBlock: "",
+ cuttingPermit: "",
+ timberMark: "",
+ dateType: "Disturbance",
+ openingFilters: [] as string[],
+ blockStatuses: [] as string[]
+ },
+ });
+ let container;
+ await act(async () => {
+ ({ container } = render());
+ });
+ const element = container.querySelector('.d-block');
+ expect(element).toBeDefined();
});
});
\ No newline at end of file
diff --git a/frontend/src/components/SilvicultureSearch/Openings/AdvancedSearchDropdown/index.tsx b/frontend/src/components/SilvicultureSearch/Openings/AdvancedSearchDropdown/index.tsx
index 40bcb457..69a6842a 100644
--- a/frontend/src/components/SilvicultureSearch/Openings/AdvancedSearchDropdown/index.tsx
+++ b/frontend/src/components/SilvicultureSearch/Openings/AdvancedSearchDropdown/index.tsx
@@ -19,22 +19,22 @@ import * as Icons from "@carbon/icons-react";
import { useOpeningFiltersQuery } from "../../../../services/queries/search/openingQueries";
import { useOpeningsSearch } from "../../../../contexts/search/OpeningsSearch";
import { TextValueData, sortItems } from "../../../../utils/multiSelectSortUtils";
+import { formatDateForDatePicker } from "../../../../utils/DateUtils";
interface AdvancedSearchDropdownProps {
toggleShowFilters: () => void; // Function to be passed as a prop
}
const AdvancedSearchDropdown: React.FC = () => {
- const { filters, setFilters } = useOpeningsSearch();
- //TODO: pass this to parent and just pass the values as props
+ const { filters, setFilters, clearFilters } = useOpeningsSearch();
const { data, isLoading, isError } = useOpeningFiltersQuery();
// Initialize selected items for OrgUnit MultiSelect based on existing filters
const [selectedOrgUnits, setSelectedOrgUnits] = useState([]);
- // Initialize selected items for category MultiSelect based on existing filters
const [selectedCategories, setSelectedCategories] = useState([]);
useEffect(() => {
+ console.log("Use Effect in child is being called.", filters);
// Split filters.orgUnit into array and format as needed for selectedItems
if (filters.orgUnit) {
const orgUnitsArray = filters.orgUnit.map((orgUnit: string) => ({
@@ -62,6 +62,7 @@ const AdvancedSearchDropdown: React.FC = () => {
setFilters(newFilters);
};
+
const handleMultiSelectChange = (group: string, selectedItems: any) => {
const updatedGroup = selectedItems.map((item: any) => item.value);
if (group === "orgUnit")
@@ -275,8 +276,8 @@ const AdvancedSearchDropdown: React.FC = () => {
selectedItem={
filters.dateType
? dateTypeItems.find(
- (item: any) => item.value === filters.dateType
- )
+ (item: any) => item.value === filters.dateType
+ )
: ""
}
label="Date type"
@@ -314,10 +315,11 @@ const AdvancedSearchDropdown: React.FC = () => {
size="md"
labelText="Start Date"
placeholder={
- filters.startDate !== null
+ filters.startDate
? filters.startDate // Display the date in YYYY-MM-DD format
: "yyyy/MM/dd"
}
+ value={formatDateForDatePicker(filters.startDate)}
/>
@@ -348,6 +350,7 @@ const AdvancedSearchDropdown: React.FC = () => {
? filters.endDate // Display the date in YYYY-MM-DD format
: "yyyy/MM/dd"
}
+ value={formatDateForDatePicker(filters.endDate)}
/>
diff --git a/frontend/src/components/SilvicultureSearch/Openings/OpeningsSearchBar/index.tsx b/frontend/src/components/SilvicultureSearch/Openings/OpeningsSearchBar/index.tsx
index 4a20e36d..e1038205 100644
--- a/frontend/src/components/SilvicultureSearch/Openings/OpeningsSearchBar/index.tsx
+++ b/frontend/src/components/SilvicultureSearch/Openings/OpeningsSearchBar/index.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useState } from "react";
+import React, { useEffect, useState, useRef } from "react";
import "./OpeningsSearchBar.scss";
import { Search, Button, FlexGrid, Row, Column, DismissibleTag, InlineNotification } from "@carbon/react";
import * as Icons from "@carbon/icons-react";
@@ -6,6 +6,8 @@ import AdvancedSearchDropdown from "../AdvancedSearchDropdown";
import SearchFilterBar from "../SearchFilterBar";
import { useOpeningsSearch } from "../../../../contexts/search/OpeningsSearch";
import { countActiveFilters } from "../../../../utils/searchUtils";
+import { callbackify } from "util";
+import { c } from "vite/dist/node/types.d-aGj9QkWt";
interface IOpeningsSearchBar {
onSearchClick: () => void;
@@ -21,7 +23,7 @@ const OpeningsSearchBar: React.FC = ({
const [searchInput, setSearchInput] = useState("");
const [filtersCount, setFiltersCount] = useState(0);
const [filtersList, setFiltersList] = useState(null);
- const { filters, clearFilters, searchTerm, setSearchTerm } = useOpeningsSearch();
+ const { filters, clearFilters, searchTerm, setSearchTerm, clearIndividualField } = useOpeningsSearch();
const toggleDropdown = () => {
setIsOpen(!isOpen);
@@ -45,7 +47,8 @@ const OpeningsSearchBar: React.FC = ({
const activeFiltersCount = countActiveFilters(filters);
setFiltersCount(activeFiltersCount); // Update the state with the active filters count
setFiltersList(filters);
- };
+ }
+
useEffect(() => {
handleFiltersChanged();
}, [filters]);
diff --git a/frontend/src/contexts/search/OpeningsSearch.tsx b/frontend/src/contexts/search/OpeningsSearch.tsx
index b198c30d..24f2467d 100644
--- a/frontend/src/contexts/search/OpeningsSearch.tsx
+++ b/frontend/src/contexts/search/OpeningsSearch.tsx
@@ -37,6 +37,7 @@ export const OpeningsSearchProvider: React.FC<{ children: ReactNode }> = ({ chil
// Function to clear individual filter field by key
const clearIndividualField = (key: string) => {
+ console.log("Clearing individual field", key);
setFilters((prevFilters) => ({
...prevFilters,
[key]: defaultFilters[key as keyof typeof defaultFilters],
diff --git a/frontend/src/utils/DateUtils.ts b/frontend/src/utils/DateUtils.ts
index a5b416ce..fc097926 100644
--- a/frontend/src/utils/DateUtils.ts
+++ b/frontend/src/utils/DateUtils.ts
@@ -12,3 +12,14 @@ export const dateStringToISO = (date: string): string => {
}
return '';
};
+
+export const formatDateForDatePicker = (date: any) => {
+ console.log("date format: ", date);
+ let year, month, day;
+ if (date) {
+ [year, month, day] = date.split("-");
+ return `${month}/${day}/${year}`;
+ } else {
+ return "";
+ }
+};