-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/removal challenge justification display #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jaybuidl
merged 6 commits into
master
from
feat/removal-challenge-justification-display
Jun 20, 2024
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4c83305
feat(web): removal-and-challenge-justifications-display
tractorss 16e4324
refactor(web): update-list-and-item-info-card-ui
tractorss 3942a7d
fix(web): show-requester-address-for-removal-requests
tractorss e6b162d
refactor(web): style-refactors
tractorss d24382e
refactor(web): update-info-cards-style
tractorss 9b02617
Merge branch 'master' into feat/removal-challenge-justification-display
kemuru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Do not enter sensitive information here. | ||
export REACT_APP_DEPLOYMENT=devnet | ||
export REACT_APP_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/71663/curate-test/version/latest | ||
export REACT_APP_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/curate-v2-devnet/version/latest | ||
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-core-devnet/version/latest | ||
export REACT_APP_STATUS_URL=https://curate-v2-devnet.betteruptime.com/badge | ||
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=24725439 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
const StyledHeader = styled.h1` | ||
margin: 0; | ||
`; | ||
|
||
interface IHeader { | ||
text: string; | ||
} | ||
|
||
const Header: React.FC<IHeader> = ({ text }) => { | ||
return <StyledHeader>{text}</StyledHeader>; | ||
}; | ||
|
||
export default Header; |
58 changes: 58 additions & 0 deletions
58
web/src/components/HistoryDisplay/Party/JustificationDetails.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from "react"; | ||
import ReactMarkdown from "react-markdown"; | ||
import styled from "styled-components"; | ||
import { getIpfsUrl } from "utils/getIpfsUrl"; | ||
import AttachmentIcon from "svgs/icons/attachment.svg"; | ||
import { customScrollbar } from "styles/customScrollbar"; | ||
|
||
const Container = styled.div` | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
|
||
const JustificationTitle = styled.h3` | ||
margin: 0px; | ||
font-weight: 600; | ||
`; | ||
|
||
const DescriptionContainer = styled.div` | ||
max-height: 400px; | ||
width: 100%; | ||
overflow-y: scroll; | ||
${customScrollbar} | ||
`; | ||
|
||
const StyledA = styled.a` | ||
display: flex; | ||
gap: 6px; | ||
> svg { | ||
width: 16px; | ||
fill: ${({ theme }) => theme.primaryBlue}; | ||
} | ||
`; | ||
|
||
export type Justification = { | ||
name: string; | ||
description: string; | ||
fileURI?: string; | ||
}; | ||
|
||
const JustificationDetails: React.FC<{ justification: Justification }> = ({ justification }) => { | ||
return ( | ||
<Container> | ||
<JustificationTitle>{justification.name}</JustificationTitle> | ||
<DescriptionContainer> | ||
<ReactMarkdown>{justification.description}</ReactMarkdown> | ||
</DescriptionContainer> | ||
{justification?.fileURI && ( | ||
<StyledA href={getIpfsUrl(justification.fileURI)}> | ||
<AttachmentIcon /> | ||
View attached file | ||
</StyledA> | ||
)} | ||
</Container> | ||
); | ||
}; | ||
|
||
export default JustificationDetails; |
127 changes: 127 additions & 0 deletions
127
web/src/components/HistoryDisplay/Party/JustificationModal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import styled from "styled-components"; | ||
import { Button } from "@kleros/ui-components-library"; | ||
|
||
import Modal from "components/Modal"; | ||
import ActionButton from "components/ActionButton"; | ||
import { SkeletonJustificationCard } from "components/StyledSkeleton"; | ||
import { mapFromSubgraphStatus } from "components/RegistryCard/StatusBanner"; | ||
|
||
import { EvidencesQuery, RequestDetailsFragment } from "src/graphql/graphql"; | ||
import { isUndefined } from "src/utils"; | ||
import { getIpfsUrl } from "utils/getIpfsUrl"; | ||
import fetchJsonIpfs from "utils/fetchJsonIpfs"; | ||
import { useEvidences } from "queries/useEvidences"; | ||
|
||
import Header from "./Header"; | ||
import JustificationDetails, { Justification } from "./JustificationDetails"; | ||
|
||
const StyledModal = styled(Modal)` | ||
gap: 30px; | ||
`; | ||
|
||
const ButtonsContainer = styled.div` | ||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
flex-wrap: wrap; | ||
margin-top: 38px; | ||
row-gap: 8px; | ||
`; | ||
|
||
const StyledLabel = styled.label` | ||
width: 100%; | ||
`; | ||
|
||
const JustificationText = styled.h3` | ||
width: 100%; | ||
margin: 0px; | ||
margin-bottom: 4px; | ||
text-align: center; | ||
`; | ||
|
||
interface IJustificationModal { | ||
request: RequestDetailsFragment; | ||
isRemoval: boolean; | ||
toggleModal: () => void; | ||
} | ||
|
||
const JustificationModal: React.FC<IJustificationModal> = ({ request, toggleModal, isRemoval }) => { | ||
const { data: evidenceData, isLoading: isLoadingEvidences } = useEvidences(request.externalDisputeID); | ||
const [justification, setJustification] = useState<Justification>(); | ||
const [isLoadingJustification, setIsLoadingJustification] = useState(false); | ||
|
||
useEffect(() => { | ||
if (isUndefined(evidenceData)) return; | ||
setIsLoadingJustification(true); | ||
|
||
const uri = getEvidenceUriForRequest(request, evidenceData.evidences, isRemoval); | ||
|
||
if (!uri) { | ||
setIsLoadingJustification(false); | ||
return; | ||
} | ||
|
||
fetchJsonIpfs(getIpfsUrl(uri)) | ||
.then((res) => { | ||
setJustification(res as Justification); | ||
}) | ||
.finally(() => setIsLoadingJustification(false)); | ||
}, [evidenceData, isRemoval, request]); | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<StyledModal {...{ toggleModal }}> | ||
<Header text={isRemoval ? "Removal Requested" : "Request Challenged"} /> | ||
<JustificationText>Justification</JustificationText> | ||
{isLoadingEvidences || isLoadingJustification ? ( | ||
<SkeletonJustificationCard /> | ||
) : justification ? ( | ||
<JustificationDetails {...{ justification }} /> | ||
) : ( | ||
<StyledLabel>No Justification provided</StyledLabel> | ||
)} | ||
<ButtonsContainer> | ||
<Button variant="secondary" text="Return" onClick={toggleModal} /> | ||
{!request.resolved && ( | ||
<ActionButton | ||
isItem | ||
itemId={request.item.itemID} | ||
status={mapFromSubgraphStatus(request.item.status, request.disputed)} | ||
registryAddress={request.item.registryAddress} | ||
/> | ||
)} | ||
</ButtonsContainer> | ||
</StyledModal> | ||
); | ||
}; | ||
|
||
/** | ||
* @description returns the correct evidence relating to the request | ||
* @need this is needed since the removal request might not have the evidence, same for challenge request. | ||
* to get the correct evidence for the request, we match the timestamp of the request and evidence, | ||
* if both are same , it means the evidence was created in the same block as that request and belongs to the request | ||
* @returns the evidence uri for the request if it exists, otherwise null | ||
*/ | ||
const getEvidenceUriForRequest = ( | ||
request: RequestDetailsFragment, | ||
evidences: EvidencesQuery["evidences"], | ||
isRemoval: boolean | ||
) => { | ||
if (isRemoval) { | ||
if (evidences.length > 0 && evidences[0].timestamp === request.submissionTime) { | ||
return evidences[0].evidence; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
// in case of challenge either the first or the second one can be the challenge evidence, | ||
// in case of registration challenge, the 1st one is the challenge evidence, | ||
// or if the removal request did not have any justification, the 1st one could be the challenge justification | ||
if (evidences.length > 0 && evidences[0].timestamp === request.challengeTime) return evidences[0].evidence; | ||
if (evidences.length > 1 && evidences[1].timestamp === request.challengeTime) return evidences[1].evidence; | ||
|
||
return null; | ||
}; | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export default JustificationModal; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import AliasDisplay from "components/RegistryInfo/AliasDisplay"; | ||
import { RequestDetailsFragment } from "src/graphql/graphql"; | ||
import DocIcon from "svgs/icons/doc.svg"; | ||
import { useToggle } from "react-use"; | ||
import JustificationModal from "./JustificationModal"; | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
gap: 8px; | ||
`; | ||
|
||
const StyledLabel = styled.label` | ||
display: flex; | ||
align-items: center; | ||
gap: 4px; | ||
color: ${({ theme }) => theme.primaryBlue}; | ||
cursor: pointer; | ||
`; | ||
|
||
const StyledDoc = styled(DocIcon)` | ||
width: 16px; | ||
height: 16px; | ||
fill: ${({ theme }) => theme.primaryBlue}; | ||
`; | ||
|
||
interface IParty { | ||
request: RequestDetailsFragment; | ||
isRemoval?: boolean; | ||
} | ||
|
||
const Party: React.FC<IParty> = ({ request, isRemoval = false }) => { | ||
const [isOpen, toggleModal] = useToggle(false); | ||
const aliasAddress = isRemoval ? request.requester.id : request?.challenger?.id; | ||
|
||
return ( | ||
<Container> | ||
<label>by</label> | ||
<AliasDisplay address={aliasAddress ?? ""} /> | ||
<label>-</label> | ||
<StyledLabel onClick={toggleModal}> | ||
<StyledDoc /> Justification | ||
</StyledLabel> | ||
{isOpen && <JustificationModal {...{ request, toggleModal, isRemoval }} />} | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Party; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.