Skip to content

Commit

Permalink
fix: addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
onehanddev committed Dec 10, 2024
1 parent f2efe02 commit 332f3bf
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 118 deletions.
48 changes: 0 additions & 48 deletions client/src/app/(overview)/url-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
RESTORATION_ACTIVITY_SUBTYPE,
} from "@shared/entities/activity.enum";
import { ECOSYSTEM } from "@shared/entities/ecosystem.enum";
import { PROJECT_SCORE } from "@shared/entities/project-score.enum";
import {
COST_TYPE_SELECTOR,
PROJECT_PRICE_TYPE,
Expand Down Expand Up @@ -37,18 +36,6 @@ export const filtersSchema = z.object({
[FILTER_KEYS[9]]: z.array(z.number()).length(2),
});

export const scorecardFiltersSchema = z.object({
availabilityOfExperiencedLabor: z.nativeEnum(PROJECT_SCORE).optional(),
availabilityOfAlternatingFunding: z.nativeEnum(PROJECT_SCORE).optional(),
coastalProtectionBenefits: z.nativeEnum(PROJECT_SCORE).optional(),
biodiversityBenefit: z.nativeEnum(PROJECT_SCORE).optional(),
financialFeasibility: z.nativeEnum(PROJECT_SCORE).optional(),
legalFeasibility: z.nativeEnum(PROJECT_SCORE).optional(),
implementationFeasibility: z.nativeEnum(PROJECT_SCORE).optional(),
socialFeasibility: z.nativeEnum(PROJECT_SCORE).optional(),
securityRating: z.nativeEnum(PROJECT_SCORE).optional(),
});

export const INITIAL_FILTERS_STATE: z.infer<typeof filtersSchema> = {
keyword: "",
projectSizeFilter: PROJECT_SIZE_FILTER.MEDIUM,
Expand All @@ -62,20 +49,6 @@ export const INITIAL_FILTERS_STATE: z.infer<typeof filtersSchema> = {
abatementPotentialRange: INITIAL_ABATEMENT_POTENTIAL_RANGE,
};

export const INITIAL_SCORECARD_FILTERS_STATE: z.infer<
typeof scorecardFiltersSchema
> = {
availabilityOfExperiencedLabor: undefined,
availabilityOfAlternatingFunding: undefined,
coastalProtectionBenefits: undefined,
biodiversityBenefit: undefined,
financialFeasibility: undefined,
legalFeasibility: undefined,
implementationFeasibility: undefined,
socialFeasibility: undefined,
securityRating: undefined,
};

export function useGlobalFilters() {
const [popup, setPopup] = useAtom(popupAtom);
const [filters, setFilters] = useQueryState(
Expand All @@ -95,27 +68,6 @@ export function useGlobalFilters() {
return [filters, updateFilters] as const;
}

export function useScorecardFilters() {
const [popup, setPopup] = useAtom(popupAtom);
const [filters, setFilters] = useQueryState(
"scorecardFilters",
parseAsJson(scorecardFiltersSchema.parse).withDefault(
INITIAL_SCORECARD_FILTERS_STATE,
),
);

const updateFilters = async (
updater: (
prev: typeof INITIAL_SCORECARD_FILTERS_STATE,
) => typeof INITIAL_SCORECARD_FILTERS_STATE,
) => {
await setFilters(updater);
if (popup) setPopup(null);
};

return [filters, updateFilters] as const;
}

export function useTableView() {
return useQueryState(
"table",
Expand Down
26 changes: 15 additions & 11 deletions client/src/components/ui/score-card.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
export type Score = "high" | "medium" | "low";
import { PROJECT_SCORE } from "@shared/entities/project-score.enum";

import { cn } from "@/lib/utils";

interface ScoreIndicatorProps {
score: Score;
className?: string;
children?: React.ReactNode;
bgColorClasses?: Record<PROJECT_SCORE, string>;
}

export const DEFAULT_BG_CLASSES = {
high: "bg-high",
medium: "bg-medium",
low: "bg-low",
};

export const ScoreIndicator = ({
score,
children,
className = "",
}: ScoreIndicatorProps) => {
const bgColorClass = {
high: "bg-high",
medium: "bg-medium",
low: "bg-low",
}[score];

return (
<div
className={`flex h-10 items-center justify-center font-medium capitalize text-deep-ocean ${bgColorClass} ${className}`}
className={cn(
"flex h-10 items-center justify-center font-normal capitalize text-deep-ocean",
className,
)}
>
{children ? children : score}
{children}
</div>
);
};
2 changes: 1 addition & 1 deletion client/src/containers/overview/filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function ProjectsFilters() {
setFiltersOpen((prev) => ({ ...prev, filtersOpen: false }));
};

const { queryKey } = queryKeys.projects.countries;
const { queryKey } = queryKeys.tables.countries;
const { data: countryOptions } = client.projects.getProjectCountries.useQuery(
queryKey,
{},
Expand Down
14 changes: 10 additions & 4 deletions client/src/containers/overview/project-details/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Link from "next/link";

import { PROJECT_SCORE } from "@shared/entities/project-score.enum";
import { useAtom } from "jotai";
import { ChevronUp, ChevronDown, NotebookPen } from "lucide-react";

Expand All @@ -8,6 +9,7 @@ import {
formatCurrency,
renderAbatementCurrency,
} from "@/lib/format";
import { cn } from "@/lib/utils";

import { projectDetailsAtom } from "@/app/(overview)/store";

Expand All @@ -27,7 +29,7 @@ import {
DialogTrigger,
} from "@/components/ui/dialog";
import { Label } from "@/components/ui/label";
import { ScoreIndicator } from "@/components/ui/score-card";
import { ScoreIndicator, DEFAULT_BG_CLASSES } from "@/components/ui/score-card";
import {
Sheet,
SheetContent,
Expand Down Expand Up @@ -380,9 +382,13 @@ export default function ProjectDetails() {
<div key={item.name} className="flex">
<div className="w-2/3 content-center py-2">{item.name}</div>
<ScoreIndicator
className="w-1/3"
score={item.rating as "high" | "medium" | "low"}
/>
className={cn(
"w-1/3",
DEFAULT_BG_CLASSES[item.rating as PROJECT_SCORE],
)}
>
{item.rating}
</ScoreIndicator>
</div>
{projectData.scorecard.length !== index + 1 && (
<hr className="m-0" />
Expand Down
16 changes: 7 additions & 9 deletions client/src/containers/overview/table/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { ProjectScorecardView } from "@shared/entities/project-scorecard.view";
import { Project } from "@shared/entities/projects.entity";
import { z } from "zod";

import {
filtersSchema,
scorecardFiltersSchema,
} from "@/app/(overview)/url-store";
import { filtersSchema } from "@/app/(overview)/url-store";

export const NO_DATA: Project[] = [];
export const NO_SCORECARD_DATA: ProjectScorecardView[] = [];
import { scorecardFiltersSchema } from "./view/scorecard-prioritization/schema";

export const NO_DATA = [];

const OMITTED_FIELDS = [
"keyword",
Expand All @@ -20,7 +16,8 @@ const OMITTED_FIELDS = [
export const filtersToQueryParams = (
filters: z.infer<typeof filtersSchema | typeof scorecardFiltersSchema>,
) => {
return Object.keys(filters)
debugger;
const queryParams = Object.keys(filters)
.filter((key) => !OMITTED_FIELDS.includes(key))
.reduce(
(acc, key) => ({
Expand All @@ -31,4 +28,5 @@ export const filtersToQueryParams = (
}),
{},
);
return queryParams;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useState } from "react";

import { ChevronDownIcon, ChevronUpIcon } from "@radix-ui/react-icons";
import { projectsQuerySchema } from "@shared/contracts/projects.contract";
import { keepPreviousData } from "@tanstack/react-query";
import {
flexRender,
Expand Down Expand Up @@ -51,7 +52,7 @@ export function KeyCostsTable() {
pageSize: Number.parseInt(PAGINATION_SIZE_OPTIONS[0]),
});

const queryKey = queryKeys.projects.all(tableView, {
const queryKey = queryKeys.tables.all(tableView, projectsQuerySchema, {
...filters,
sorting,
pagination,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ProjectType } from "@shared/contracts/projects.contract";
import { PROJECT_SCORE } from "@shared/entities/project-score.enum";
import { createColumnHelper } from "@tanstack/react-table";
import { z } from "zod";

import { formatNumber } from "@/lib/format";

import { filtersSchema } from "@/app/(overview)/url-store";

import { ScoreIndicator } from "@/components/ui/score-card";
import { DEFAULT_BG_CLASSES, ScoreIndicator } from "@/components/ui/score-card";

const columnHelper = createColumnHelper<Partial<ProjectType>>();

Expand All @@ -23,7 +24,11 @@ export const columns = (filters: z.infer<typeof filtersSchema>) => [
if (value === undefined) {
return "-";
}
return <ScoreIndicator score={value} />;
return (
<ScoreIndicator className={DEFAULT_BG_CLASSES[value as PROJECT_SCORE]}>
{value}
</ScoreIndicator>
);
},
}),
columnHelper.accessor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function OverviewTable() {
pageSize: Number.parseInt(PAGINATION_SIZE_OPTIONS[0]),
});

const queryKey = queryKeys.projects.all(tableView, {
const queryKey = queryKeys.tables.all(tableView, projectsQuerySchema, {
...filters,
sorting,
pagination,
Expand Down
Loading

0 comments on commit 332f3bf

Please sign in to comment.