From 9fd053b0f67286dd70387a9c5732c41c2723aaee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Gonz=C3=A1lez=20Mu=C3=B1oz?= Date: Thu, 19 Dec 2024 09:29:26 +0100 Subject: [PATCH] adds query params to /scorecard endpoint --- .../overview/table/view/key-costs/index.tsx | 5 ----- .../table/view/scorecard-prioritization/index.tsx | 15 ++++++++++++++- shared/contracts/projects.contract.ts | 4 +--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/client/src/containers/overview/table/view/key-costs/index.tsx b/client/src/containers/overview/table/view/key-costs/index.tsx index 82e4a633..9adc09c5 100644 --- a/client/src/containers/overview/table/view/key-costs/index.tsx +++ b/client/src/containers/overview/table/view/key-costs/index.tsx @@ -66,11 +66,6 @@ export function KeyCostsTable() { { query: { ...filtersToQueryParams(filters), - // fields: TABLE_COLUMNS.map((column) => column.accessorKey), - // ...(sorting.length > 0 && { - // sort: sorting.map((sort) => `${sort.desc ? "" : "-"}${sort.id}`), - // }), - // fields: [''], pageNumber: pagination.pageIndex + 1, pageSize: pagination.pageSize, }, diff --git a/client/src/containers/overview/table/view/scorecard-prioritization/index.tsx b/client/src/containers/overview/table/view/scorecard-prioritization/index.tsx index fee28cd2..19ca5bfc 100644 --- a/client/src/containers/overview/table/view/scorecard-prioritization/index.tsx +++ b/client/src/containers/overview/table/view/scorecard-prioritization/index.tsx @@ -3,6 +3,7 @@ import { useState } from "react"; import { ChevronDownIcon, ChevronUpIcon } from "@radix-ui/react-icons"; +import { projectScorecardQuerySchema } from "@shared/contracts/projects.contract"; import { ProjectScorecardView } from "@shared/entities/project-scorecard.view"; import { keepPreviousData } from "@tanstack/react-query"; import { @@ -14,6 +15,7 @@ import { } from "@tanstack/react-table"; import { useAtom } from "jotai"; import { ChevronsUpDownIcon } from "lucide-react"; +import { z } from "zod"; import { client } from "@/lib/query-client"; import { queryKeys } from "@/lib/query-keys"; @@ -45,6 +47,8 @@ import TablePagination, { import { scorecardFiltersSchema } from "./schema"; +type sortFields = z.infer; + export function ScoredCardPrioritizationTable() { const [tableView] = useTableView(); const [filters] = useGlobalFilters(); @@ -70,7 +74,16 @@ export function ScoredCardPrioritizationTable() { queryKey, { query: { - filter: filtersToQueryParams(filters), + ...filtersToQueryParams(filters), + costRange: filters.costRange, + abatementPotentialRange: filters.abatementPotentialRange, + costRangeSelector: filters.costRangeSelector, + partialProjectName: filters.keyword, + ...(sorting.length > 0 && { + sort: sorting.map( + (sort) => `${sort.desc ? "" : "-"}${sort.id}`, + ) as sortFields, + }), pageNumber: pagination.pageIndex + 1, pageSize: pagination.pageSize, }, diff --git a/shared/contracts/projects.contract.ts b/shared/contracts/projects.contract.ts index f5319781..feef86f5 100644 --- a/shared/contracts/projects.contract.ts +++ b/shared/contracts/projects.contract.ts @@ -1,4 +1,3 @@ -import { ProjectScorecard } from "./../entities/project-scorecard.entity"; import { initContract } from "@ts-rest/core"; import { z } from "zod"; import { @@ -17,7 +16,6 @@ import { ProjectScorecardDto } from "@shared/dtos/projects/project-scorecard.dto const contract = initContract(); export type ProjectType = Omit; -export type ProjectScorecardType = Omit; export const otherParams = z.object({ costRange: z.coerce.number().array().optional(), @@ -28,7 +26,7 @@ export const otherParams = z.object({ }); export const projectsQuerySchema = generateEntityQuerySchema(Project); export const projectScorecardQuerySchema = - generateEntityQuerySchema(ProjectScorecard); + generateEntityQuerySchema(ProjectScorecardView); export const getProjectsQuerySchema = projectsQuerySchema.merge(otherParams); export const getProjectScorecardQuerySchema =