Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE]: Move "project size" filter to sidebar #201

Merged
merged 1 commit into from
Dec 26, 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
4 changes: 2 additions & 2 deletions client/src/app/(overview)/url-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface Parameter<T = keyof z.infer<typeof filtersSchema>> {

export const filtersSchema = z.object({
[FILTER_KEYS[0]]: z.string().optional(),
[FILTER_KEYS[1]]: z.nativeEnum(PROJECT_SIZE_FILTER),
[FILTER_KEYS[1]]: z.array(z.nativeEnum(PROJECT_SIZE_FILTER)),
[FILTER_KEYS[2]]: z.nativeEnum(PROJECT_PRICE_TYPE),
[FILTER_KEYS[3]]: z.nativeEnum(COST_TYPE_SELECTOR),
[FILTER_KEYS[4]]: z.string().optional(),
Expand All @@ -50,7 +50,7 @@ export const filtersSchema = z.object({

export const INITIAL_FILTERS_STATE: z.infer<typeof filtersSchema> = {
keyword: "",
projectSizeFilter: PROJECT_SIZE_FILTER.MEDIUM,
projectSizeFilter: [],
priceType: PROJECT_PRICE_TYPE.MARKET_PRICE,
costRangeSelector: COST_TYPE_SELECTOR.NPV,
countryCode: "",
Expand Down
40 changes: 40 additions & 0 deletions client/src/containers/overview/filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState, useEffect } from "react";
import { CheckedState } from "@radix-ui/react-checkbox";
import { ACTIVITY } from "@shared/entities/activity.enum";
import { ECOSYSTEM } from "@shared/entities/ecosystem.enum";
import { PROJECT_SIZE_FILTER } from "@shared/entities/projects.entity";
import { useSetAtom } from "jotai/index";
import { XIcon } from "lucide-react";
import { useDebounce } from "rooks";
Expand All @@ -18,6 +19,8 @@ import {
useProjectOverviewFilters,
} from "@/app/(overview)/url-store";

import { FILTERS } from "@/constants/tooltip";

import { Button } from "@/components/ui/button";
import { CheckboxWrapper } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
Expand Down Expand Up @@ -123,6 +126,18 @@ export default function ProjectsFilters() {
}));
};

const handleProjectSizeChange = async (
isChecked: CheckedState,
size: PROJECT_SIZE_FILTER,
) => {
await setFilters((prev) => ({
...prev,
projectSizeFilter: isChecked
? [...prev.projectSizeFilter, size]
: prev.projectSizeFilter.filter((e) => e !== size),
}));
};

const debouncedCostChange = useDebounce(async (cost: number[]) => {
await setFilters((prev) => ({
...prev,
Expand Down Expand Up @@ -350,6 +365,31 @@ export default function ProjectsFilters() {
max={formatNumber(INITIAL_ABATEMENT_POTENTIAL_RANGE[1])}
/>
</div>

<div className="space-y-2">
<Label
tooltip={{
title: "Project size",
content: FILTERS.PROJECT_SIZE,
}}
>
Project size
</Label>
<ul className="flex gap-2">
{Object.values(PROJECT_SIZE_FILTER).map((size) => (
<li key={size}>
<CheckboxWrapper
label={size}
id={size}
checked={filters.projectSizeFilter.includes(size)}
onCheckedChange={async (isChecked) => {
await handleProjectSizeChange(isChecked, size);
}}
/>
</li>
))}
</ul>
</div>
</section>
);
}
21 changes: 0 additions & 21 deletions client/src/containers/overview/header/parameters/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
PROJECT_SIZE_FILTER,
COST_TYPE_SELECTOR,
PROJECT_PRICE_TYPE,
} from "@shared/entities/projects.entity";
Expand All @@ -25,26 +24,6 @@ import {
} from "@/components/ui/select";

export const PROJECT_PARAMETERS: Parameter[] = [
{
key: FILTER_KEYS[1],
label: "Project size",
className: "w-[125px]",
tooltipContent: FILTERS.PROJECT_SIZE,
options: [
{
label: PROJECT_SIZE_FILTER.SMALL,
value: PROJECT_SIZE_FILTER.SMALL,
},
{
label: PROJECT_SIZE_FILTER.MEDIUM,
value: PROJECT_SIZE_FILTER.MEDIUM,
},
{
label: PROJECT_SIZE_FILTER.LARGE,
value: PROJECT_SIZE_FILTER.LARGE,
},
],
},
{
key: FILTER_KEYS[2],
label: "Carbon pricing type",
Expand Down
Loading