Skip to content

Commit 2048cff

Browse files
committed
fix(web): wrong count and bad filter encoding
1 parent 9a09569 commit 2048cff

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

web/src/components/CasesDisplay/Search.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useDebounce } from "react-use";
44
import styled from "styled-components";
55
import Skeleton from "react-loading-skeleton";
66
import { Searchbar, DropdownCascader } from "@kleros/ui-components-library";
7-
import { rootCourtToItems, useCourtTree } from "hooks/queries/useCourtTree";
7+
import { rootCourtToItems, useCourtTree } from "queries/useCourtTree";
88
import { isUndefined } from "utils/index";
99
import { decodeURIFilter, encodeURIFilter, useRootPath } from "utils/uri";
1010

@@ -44,10 +44,14 @@ const Search: React.FC = () => {
4444
[search]
4545
);
4646
const { data: courtTreeData } = useCourtTree();
47-
const items = useMemo(
48-
() => !isUndefined(courtTreeData) && [rootCourtToItems(courtTreeData.court, "id")],
49-
[courtTreeData]
50-
);
47+
const items = useMemo(() => {
48+
if (!isUndefined(courtTreeData)) {
49+
const items = [rootCourtToItems(courtTreeData.court!, "id")];
50+
items.push({ label: "All Courts", value: "all" });
51+
return items;
52+
}
53+
return undefined;
54+
}, [courtTreeData]);
5155

5256
return (
5357
<div>
@@ -63,7 +67,11 @@ const Search: React.FC = () => {
6367
<DropdownCascader
6468
items={items}
6569
placeholder={"Select Court"}
66-
onSelect={(value) => navigate(`${location}/${page}/${order}/${{ ...filterObject, court: value }}`)}
70+
onSelect={(value) => {
71+
const { court: _, ...filterWithoutCourt } = decodedFilter;
72+
const newFilter = value === "all" ? filterWithoutCourt : { ...decodedFilter, court: value.toString() };
73+
navigate(`${location}/${page}/${order}/${encodeURIFilter(newFilter)}`);
74+
}}
6775
/>
6876
) : (
6977
<Skeleton width={240} height={42} />

web/src/hooks/queries/useCourtTree.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ interface IItem {
4646
children?: IItem[];
4747
}
4848

49-
export const rootCourtToItems = (court: NonNullable<CourtTreeQuery["court"]>, value?: "id" | "path"): IItem => ({
49+
export const rootCourtToItems = (
50+
court: NonNullable<CourtTreeQuery["court"]>,
51+
value: "id" | "path" = "path"
52+
): IItem => ({
5053
label: court.name ? court.name : "Unnamed Court",
5154
value: value === "id" ? court.id : `/courts/${court.id}`,
52-
children: court.children.length > 0 ? court.children.map((child) => rootCourtToItems(child)) : undefined,
55+
children: court.children.length > 0 ? court.children.map((child) => rootCourtToItems(child, value)) : undefined,
5356
});

web/src/pages/Cases/CasesFetcher.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useMemo } from "react";
22
import { useWindowSize } from "react-use";
33
import { useParams, useNavigate } from "react-router-dom";
44
import { DisputeDetailsFragment, Dispute_Filter, OrderDirection } from "src/graphql/graphql";
@@ -24,7 +24,7 @@ const calculateStats = (
2424
totalCases = isCourtFilter ? courtData?.numberDisputes : counters?.cases;
2525
ruledCases = isCourtFilter ? courtData?.numberClosedDisputes : counters?.casesRuled;
2626
} else if (filter?.ruled) {
27-
totalCases = isCourtFilter ? courtData?.numberClosedDisputes : counters?.casesAppealing;
27+
totalCases = isCourtFilter ? courtData?.numberClosedDisputes : counters?.casesRuled;
2828
ruledCases = totalCases;
2929
} else {
3030
totalCases = isCourtFilter
@@ -57,11 +57,9 @@ const CasesFetcher: React.FC = () => {
5757
decodedFilter,
5858
order === "asc" ? OrderDirection.Asc : OrderDirection.Desc
5959
);
60-
const { totalCases, ruledCases } = calculateStats(
61-
isCourtFilter,
62-
courtData?.court,
63-
counterData?.counter,
64-
decodedFilter
60+
const { totalCases, ruledCases } = useMemo(
61+
() => calculateStats(isCourtFilter, courtData?.court, counterData?.counter, decodedFilter),
62+
[isCourtFilter, courtData?.court, counterData?.counter, decodedFilter]
6563
);
6664

6765
return (

0 commit comments

Comments
 (0)