Skip to content

Commit

Permalink
234 available filter (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathildehaugum authored Nov 2, 2023
1 parent e76126f commit 207d4ff
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions frontend/mockdata/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const MockConsultants: Consultant[] = [
},
],
yearsOfExperience: 23,
isOccupied: true,
},
];

Expand Down
21 changes: 21 additions & 0 deletions frontend/src/components/AvailabilityFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use client";
import FilterButton from "./FilterButton";
import { useFilteredConsultants } from "@/hooks/useFilteredConsultants";

export default function AvailabilityFilter() {
const { availabilityFilterOn, toggleAvailabilityFilter } =
useFilteredConsultants();

return (
<div className="flex flex-col gap-2">
<p className="body-small">Status</p>
<div className="flex flex-col gap-2 w-52">
<FilterButton
label={"Ledig tid"}
onClick={() => toggleAvailabilityFilter(!availabilityFilterOn)}
checked={availabilityFilterOn}
/>
</div>
</div>
);
}
2 changes: 2 additions & 0 deletions frontend/src/components/StaffingSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import { useState } from "react";
import DepartmentFilter from "./DepartmentFilter";
import AvailabilityFilter from "./AvailabilityFilter";
import SearchBarComponent from "./SearchBarComponent";
import { ArrowLeft, Filter } from "react-feather";
import ExperienceFilter from "./ExperienceFilter";
Expand All @@ -22,6 +23,7 @@ export default function StaffingSidebar() {
</button>
</div>
<SearchBarComponent />
<AvailabilityFilter />
<DepartmentFilter />
<ExperienceFilter />
</div>
Expand Down
26 changes: 24 additions & 2 deletions frontend/src/hooks/useFilteredConsultants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface UpdateFilterParams {
departments?: string;
years?: string;
week?: Week;
availability?: Boolean;
}

export function useFilteredConsultants() {
Expand All @@ -24,6 +25,7 @@ export function useFilteredConsultants() {
const searchFilter = searchParams.get("search") || "";
const departmentFilter = searchParams.get("depFilter") || "";
const yearFilter = searchParams.get("yearFilter") || "";
const availabilityFilter = searchParams.get("availabilityFilter") || "";
const selectedWeek = stringToWeek(
searchParams.get("selectedWeek") || undefined,
);
Expand All @@ -40,11 +42,12 @@ export function useFilteredConsultants() {
const { departments = departmentFilter } = updateParams;
const { years = yearFilter } = updateParams;
const { week = selectedWeek } = updateParams;
const { availability = availabilityFilter } = updateParams;

router.push(
`${pathname}?search=${search}&depFilter=${departments}&yearFilter=${years}${
week ? `&selectedWeek=${weekToString(week)}` : ""
}`,
}&availabilityFilter=${availability}`,
);
},
[
Expand All @@ -54,6 +57,7 @@ export function useFilteredConsultants() {
searchFilter,
selectedWeek,
yearFilter,
availabilityFilter,
],
);

Expand Down Expand Up @@ -87,7 +91,7 @@ export function useFilteredConsultants() {

function resetSelectedWeek() {
router.push(
`${pathname}?search=${searchFilter}&depFilter=${departmentFilter}&yearFilter=${yearFilter}`,
`${pathname}?search=${searchFilter}&depFilter=${departmentFilter}&yearFilter=${yearFilter}&availabilityFilter=${availabilityFilter}`,
);
}

Expand Down Expand Up @@ -119,11 +123,14 @@ export function useFilteredConsultants() {
.map((urlString) => yearRanges.find((y) => y.urlString === urlString))
.filter((year) => year !== undefined) as YearRange[];

const availabilityFilterOn = availabilityFilter === "true";

const filteredConsultants = filterConsultants(
searchFilter,
departmentFilter,
filteredYears,
consultants,
availabilityFilterOn,
);

function setNameSearch(newSearch: string) {
Expand All @@ -147,6 +154,13 @@ export function useFilteredConsultants() {
[updateRoute, yearFilter],
);

const toggleAvailabilityFilter = useCallback(
(availabelFilterOn: Boolean) => {
updateRoute({ availability: availabelFilterOn });
},
[updateRoute],
);

useEffect(() => {
function handleDepartmentHotkey(keyCode: string) {
departments
Expand Down Expand Up @@ -181,11 +195,13 @@ export function useFilteredConsultants() {
departments,
filteredDepartments,
filteredYears,
availabilityFilterOn,
currentNameSearch: activeNameSearch,
searchFilter,
setNameSearch,
toggleDepartmentFilter,
toggleYearFilter,
toggleAvailabilityFilter,
selectedWeek,
incrementSelectedWeek,
decrementSelectedWeek,
Expand Down Expand Up @@ -236,6 +252,7 @@ function filterConsultants(
departmentFilter: string,
yearFilter: YearRange[],
consultants: Consultant[],
availabilityFilterOn: Boolean,
) {
let newFilteredConsultants = consultants;
if (search && search.length > 0) {
Expand All @@ -255,6 +272,11 @@ function filterConsultants(
inYearRanges(consultant, yearFilter),
);
}
if (availabilityFilterOn) {
newFilteredConsultants = newFilteredConsultants.filter(
(consultant) => !consultant.isOccupied,
);
}
return newFilteredConsultants;
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type Consultant = {
department: string;
yearsOfExperience: number;
bookings?: BookedHoursPerWeek[] | null;
isOccupied: Boolean;
};

export type Department = {
Expand Down

0 comments on commit 207d4ff

Please sign in to comment.