Skip to content

Commit dd0b936

Browse files
committed
feat(web): cases search by disputeId
1 parent 72e0ede commit dd0b936

File tree

5 files changed

+151
-67
lines changed

5 files changed

+151
-67
lines changed

web/src/components/CasesDisplay/CasesGrid.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import styled from "styled-components";
33
import { StandardPagination } from "@kleros/ui-components-library";
44
import { CasesPageQuery } from "queries/useCasesQuery";
5+
import { CasesPageQueryId } from "queries/useCasesQuerybyId";
56
import DisputeCard from "components/DisputeCard";
67

78
const Container = styled.div`
@@ -20,6 +21,7 @@ const StyledPagination = styled(StandardPagination)`
2021

2122
export interface ICasesGrid {
2223
disputes: CasesPageQuery["disputes"];
24+
CaseIdData?: CasesPageQueryId["dispute"];
2325
currentPage: number;
2426
setCurrentPage: (newPage: number) => void;
2527
numberDisputes: number;
@@ -32,13 +34,24 @@ const CasesGrid: React.FC<ICasesGrid> = ({
3234
setCurrentPage,
3335
numberDisputes,
3436
casesPerPage,
37+
CaseIdData,
3538
}) => {
3639
return (
3740
<>
3841
<Container>
39-
{disputes.map((dispute, i) => {
40-
return <DisputeCard key={i} {...dispute} />;
41-
})}
42+
{CaseIdData ? (
43+
<>
44+
{[CaseIdData].map((dispute, i) => {
45+
return <DisputeCard key={i} {...dispute} />;
46+
})}
47+
</>
48+
) : (
49+
<>
50+
{disputes.map((dispute, i) => {
51+
return <DisputeCard key={i} {...dispute} />;
52+
})}
53+
</>
54+
)}
4255
</Container>
4356
<StyledPagination
4457
{...{ currentPage }}

web/src/components/CasesDisplay/Search.tsx

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,51 @@ const StyledSearchbar = styled(Searchbar)`
1919
}
2020
`;
2121

22-
const Search: React.FC = () => (
23-
<Container>
24-
<StyledSearchbar />
25-
<DropdownCascader
26-
placeholder={"Select Court"}
27-
onSelect={() => {
28-
// Called with the item value when select is clicked
29-
}}
30-
items={[
31-
{
32-
label: "General Court",
33-
value: 0,
34-
children: [
35-
{
36-
label: "Blockchain",
37-
value: 1,
38-
children: [
39-
{
40-
label: "Technical",
41-
value: 2,
42-
},
43-
{
44-
label: "Non-technical",
45-
value: 3,
46-
},
47-
{
48-
label: "Other",
49-
value: 4,
50-
},
51-
],
52-
},
53-
{
54-
label: "Marketing Services",
55-
value: 5,
56-
},
57-
],
58-
},
59-
]}
60-
/>
61-
</Container>
62-
);
22+
const Search = ({ getDisputeId }: any) => {
23+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
24+
getDisputeId(e.target.value);
25+
};
26+
return (
27+
<Container>
28+
<StyledSearchbar onChange={handleChange} />
29+
<DropdownCascader
30+
placeholder={"Select Court"}
31+
onSelect={() => {
32+
// Called with the item value when select is clicked
33+
}}
34+
items={[
35+
{
36+
label: "General Court",
37+
value: 0,
38+
children: [
39+
{
40+
label: "Blockchain",
41+
value: 1,
42+
children: [
43+
{
44+
label: "Technical",
45+
value: 2,
46+
},
47+
{
48+
label: "Non-technical",
49+
value: 3,
50+
},
51+
{
52+
label: "Other",
53+
value: 4,
54+
},
55+
],
56+
},
57+
{
58+
label: "Marketing Services",
59+
value: 5,
60+
},
61+
],
62+
},
63+
]}
64+
/>
65+
</Container>
66+
);
67+
};
6368

6469
export default Search;
Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
import styled from "styled-components";
33
import Search from "./Search";
44
import StatsAndFilters from "./StatsAndFilters";
55
import CasesGrid, { ICasesGrid } from "./CasesGrid";
6-
6+
import { useCasesQueryById } from "hooks/queries/useCasesQuerybyId";
7+
// import { CasesPageQueryId } from "queries/useCasesQuerybyId";
78
const StyledHR = styled.hr`
89
margin-top: 24px;
910
margin-bottom: 24px;
@@ -22,26 +23,32 @@ const CasesDisplay: React.FC<ICasesDisplay> = ({
2223
casesPerPage,
2324
title = "Cases",
2425
className,
25-
}) => (
26-
<div {...{ className }}>
27-
<h1>{title}</h1>
28-
<Search />
29-
<StatsAndFilters />
30-
<StyledHR />
31-
{disputes.length > 0 ? (
32-
<CasesGrid
33-
{...{
34-
disputes,
35-
currentPage,
36-
setCurrentPage,
37-
numberDisputes,
38-
casesPerPage,
39-
}}
40-
/>
41-
) : (
42-
<h1>wow no cases</h1>
43-
)}
44-
</div>
45-
);
26+
}) => {
27+
const [query, setQuery] = useState<string>("");
28+
const { data } = useCasesQueryById(query);
29+
const CaseIdData = data?.dispute;
30+
return (
31+
<div {...{ className }}>
32+
<h1>{title}</h1>
33+
<Search getDisputeId={setQuery} />
34+
<StatsAndFilters />
35+
<StyledHR />
36+
{disputes.length > 0 ? (
37+
<CasesGrid
38+
{...{
39+
CaseIdData,
40+
disputes,
41+
currentPage,
42+
setCurrentPage,
43+
numberDisputes,
44+
casesPerPage,
45+
}}
46+
/>
47+
) : (
48+
<h1>wow no cases</h1>
49+
)}
50+
</div>
51+
);
52+
};
4653

4754
export default CasesDisplay;

web/src/graphql/generated.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,6 +3064,25 @@ export type CasesPageQuery = {
30643064
counter?: { __typename?: "Counter"; cases: any } | null;
30653065
};
30663066

3067+
export type CasesPageQueryId = {
3068+
__typename?: "Query";
3069+
dispute: {
3070+
__typename?: "Dispute";
3071+
id: string;
3072+
period: Period;
3073+
lastPeriodChange: any;
3074+
arbitrated: { __typename?: "Arbitrable"; id: string };
3075+
court: {
3076+
__typename?: "Court";
3077+
id: string;
3078+
policy?: string | null;
3079+
feeForJuror: any;
3080+
timesPerPeriod: Array<any>;
3081+
};
3082+
};
3083+
counter?: { __typename?: "Counter"; cases: any } | null;
3084+
};
3085+
30673086
export type ClassicAppealQueryVariables = Exact<{
30683087
disputeID: Scalars["ID"];
30693088
}>;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* eslint-disable prettier/prettier */
2+
import useSWR from "swr";
3+
import { gql } from "graphql-request";
4+
import { CasesPageQueryId } from "src/graphql/generated";
5+
export type { CasesPageQueryId };
6+
7+
const casesQuery = gql`
8+
query DisputeById($disputeID: ID!) {
9+
dispute(id: $disputeID) {
10+
id
11+
arbitrated {
12+
id
13+
}
14+
court {
15+
id
16+
policy
17+
feeForJuror
18+
timesPerPeriod
19+
}
20+
period
21+
lastPeriodChange
22+
}
23+
counter(id: "0") {
24+
cases
25+
}
26+
}
27+
`;
28+
29+
export const useCasesQueryById = (id?: string | number) => {
30+
const { data, error, isValidating } = useSWR(() =>
31+
typeof id !== "undefined"
32+
? {
33+
query: casesQuery,
34+
variables: { disputeID: id?.toString() },
35+
}
36+
: false
37+
);
38+
const result = data ? (data as CasesPageQueryId) : undefined;
39+
return { data: result, error, isValidating };
40+
};

0 commit comments

Comments
 (0)