Skip to content

Commit

Permalink
fix(web): wrong count and bad filter encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
alcercu committed Oct 6, 2023
1 parent 9a09569 commit 2048cff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
20 changes: 14 additions & 6 deletions web/src/components/CasesDisplay/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDebounce } from "react-use";
import styled from "styled-components";
import Skeleton from "react-loading-skeleton";
import { Searchbar, DropdownCascader } from "@kleros/ui-components-library";
import { rootCourtToItems, useCourtTree } from "hooks/queries/useCourtTree";
import { rootCourtToItems, useCourtTree } from "queries/useCourtTree";
import { isUndefined } from "utils/index";
import { decodeURIFilter, encodeURIFilter, useRootPath } from "utils/uri";

Expand Down Expand Up @@ -44,10 +44,14 @@ const Search: React.FC = () => {
[search]
);
const { data: courtTreeData } = useCourtTree();
const items = useMemo(
() => !isUndefined(courtTreeData) && [rootCourtToItems(courtTreeData.court, "id")],
[courtTreeData]
);
const items = useMemo(() => {
if (!isUndefined(courtTreeData)) {
const items = [rootCourtToItems(courtTreeData.court!, "id")];
items.push({ label: "All Courts", value: "all" });
return items;
}
return undefined;
}, [courtTreeData]);

return (
<div>
Expand All @@ -63,7 +67,11 @@ const Search: React.FC = () => {
<DropdownCascader
items={items}
placeholder={"Select Court"}
onSelect={(value) => navigate(`${location}/${page}/${order}/${{ ...filterObject, court: value }}`)}
onSelect={(value) => {
const { court: _, ...filterWithoutCourt } = decodedFilter;
const newFilter = value === "all" ? filterWithoutCourt : { ...decodedFilter, court: value.toString() };
navigate(`${location}/${page}/${order}/${encodeURIFilter(newFilter)}`);
}}
/>
) : (
<Skeleton width={240} height={42} />
Expand Down
7 changes: 5 additions & 2 deletions web/src/hooks/queries/useCourtTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ interface IItem {
children?: IItem[];
}

export const rootCourtToItems = (court: NonNullable<CourtTreeQuery["court"]>, value?: "id" | "path"): IItem => ({
export const rootCourtToItems = (
court: NonNullable<CourtTreeQuery["court"]>,
value: "id" | "path" = "path"
): IItem => ({
label: court.name ? court.name : "Unnamed Court",
value: value === "id" ? court.id : `/courts/${court.id}`,
children: court.children.length > 0 ? court.children.map((child) => rootCourtToItems(child)) : undefined,
children: court.children.length > 0 ? court.children.map((child) => rootCourtToItems(child, value)) : undefined,
});
12 changes: 5 additions & 7 deletions web/src/pages/Cases/CasesFetcher.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useMemo } from "react";
import { useWindowSize } from "react-use";
import { useParams, useNavigate } from "react-router-dom";
import { DisputeDetailsFragment, Dispute_Filter, OrderDirection } from "src/graphql/graphql";
Expand All @@ -24,7 +24,7 @@ const calculateStats = (
totalCases = isCourtFilter ? courtData?.numberDisputes : counters?.cases;
ruledCases = isCourtFilter ? courtData?.numberClosedDisputes : counters?.casesRuled;
} else if (filter?.ruled) {
totalCases = isCourtFilter ? courtData?.numberClosedDisputes : counters?.casesAppealing;
totalCases = isCourtFilter ? courtData?.numberClosedDisputes : counters?.casesRuled;
ruledCases = totalCases;
} else {
totalCases = isCourtFilter
Expand Down Expand Up @@ -57,11 +57,9 @@ const CasesFetcher: React.FC = () => {
decodedFilter,
order === "asc" ? OrderDirection.Asc : OrderDirection.Desc
);
const { totalCases, ruledCases } = calculateStats(
isCourtFilter,
courtData?.court,
counterData?.counter,
decodedFilter
const { totalCases, ruledCases } = useMemo(
() => calculateStats(isCourtFilter, courtData?.court, counterData?.counter, decodedFilter),
[isCourtFilter, courtData?.court, counterData?.counter, decodedFilter]
);

return (
Expand Down

0 comments on commit 2048cff

Please sign in to comment.