Skip to content
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

feat(web-devtools): custom-context-input #1716

Merged
merged 4 commits into from
Oct 28, 2024

Conversation

Harman-singh-waraich
Copy link
Contributor

@Harman-singh-waraich Harman-singh-waraich commented Oct 16, 2024

  • update dispute template presets
  • Add option to provide custom context

PR-Codex overview

This PR introduces enhancements to the DisputeTemplateView by adding a new component CustomContextInputs, which allows for additional context inputs in the dispute process. It also updates some transaction hashes and improves the existing component structure.

Detailed summary

  • Updated txnHash values in FetchDisputeRequestInput.tsx.
  • Changed title from "Trump-Biden" to "Trump-Harris" in FetchDisputeRequestInput.tsx.
  • Added className prop to Container in JSONEditor.tsx.
  • Introduced CustomContextInputs component to manage additional context inputs.
  • Added state for customContext in DisputeTemplateView.
  • Modified initial context setup to include customContext.
  • Updated dependencies in DisputeTemplateView to include customContext.
  • Integrated CustomContextInputs in the form of DisputeTemplateView.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new component, CustomContextInputs, for managing additional context variables.
    • Users can now input custom context data in the DisputeTemplateView.
    • Updated the placeholder for the _templateUri input field for clarity.
  • Enhancements

    • The JSONEditor component now supports custom class names for improved styling.
  • Bug Fixes

    • Updated txnHash values and titles for several presets in the dispute template.
  • Chores

    • Removed a path mapping entry in the TypeScript configuration to streamline module resolution.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes in this pull request involve updates to several components within the dispute template section of the web application. Key modifications include adjustments to the txnHash values and the renaming of presets in FetchDisputeRequestInput.tsx, the introduction of a new state variable and a new component in page.tsx, and the addition of a className prop in JSONEditor.tsx. A new functional component, CustomContextInputs, has also been created to manage custom context inputs. Additionally, a path mapping entry has been removed from the tsconfig.json file.

Changes

File Path Change Summary
web-devtools/src/app/(main)/dispute-template/FetchDisputeRequestInput.tsx Updated txnHash values for presets "Escrow", "Curated Lists", and renamed "Trump-Biden" to "Trump-Harris" with new txnHash.
web-devtools/src/app/(main)/dispute-template/page.tsx Added customContext state variable and updated useEffect to include it. Integrated new component CustomContextInputs for custom context data inputs. Changed placeholder for _templateUri input field.
web-devtools/src/components/JSONEditor.tsx Added className prop to Container component for enhanced styling flexibility.
web-devtools/src/app/(main)/dispute-template/CustomContextInputs.tsx Introduced CustomContextInputs component to manage additional context variables, utilizing hooks for state management and debouncing input updates. Included styled components for layout.
web-devtools/tsconfig.json Removed path mapping entry for "src*" to "../../kleros-sdk/src/*", affecting TypeScript module path resolution.

Possibly related PRs

Suggested labels

Type: Maintenance :construction:, Package: Web

Suggested reviewers

  • alcercu
  • kemuru

🐰 In the land of code where bunnies play,
New inputs and presets hop in today.
With hashes updated and contexts anew,
Our templates are fresh, and styling's in view!
So let’s celebrate, with a jump and a cheer,
For a brighter codebase, we hold so dear! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0e1e8e5 and ff618c0.

📒 Files selected for processing (1)
  • web-devtools/src/app/(main)/dispute-template/CustomContextInputs.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web-devtools/src/app/(main)/dispute-template/CustomContextInputs.tsx

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Oct 16, 2024

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit ff618c0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/671f2805be35d80008042c0a
😎 Deploy Preview https://deploy-preview-1716--kleros-v2-university.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Oct 16, 2024

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit ff618c0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/671f28054b8ac10008af868f
😎 Deploy Preview https://deploy-preview-1716--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Oct 16, 2024

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit ff618c0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/671f28053b0a590008a174a5
😎 Deploy Preview https://deploy-preview-1716--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Harman-singh-waraich Harman-singh-waraich marked this pull request as draft October 16, 2024 11:38
Copy link

netlify bot commented Oct 16, 2024

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit ff618c0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/671f28058084fe0008ea92d1
😎 Deploy Preview https://deploy-preview-1716--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
web-devtools/src/components/JSONEditor.tsx (1)

62-62: LGTM! Consider adding prop typing for improved type safety.

The addition of the className prop to the Container component is a good improvement. It enhances the component's flexibility by allowing custom styles to be applied from the parent component.

To further improve the component, consider adding proper TypeScript typing for the component props. This will provide better type safety and autocompletion. Here's a suggestion:

interface JSONEditorProps {
  className?: string;
  // Add other props here
}

const JSONEditor: React.FC<JSONEditorProps> = (props) => {
  // ... rest of the component
};

This change will make the component more robust and easier to use correctly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3a6d207 and 48a757f.

📒 Files selected for processing (4)
  • kleros-sdk/src/dataMappings/utils/disputeDetailsSchema.ts (2 hunks)
  • web-devtools/src/app/(main)/dispute-template/FetchDisputeRequestInput.tsx (1 hunks)
  • web-devtools/src/app/(main)/dispute-template/page.tsx (6 hunks)
  • web-devtools/src/components/JSONEditor.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (10)
kleros-sdk/src/dataMappings/utils/disputeDetailsSchema.ts (2)

59-59: ⚠️ Potential issue

Removal of validation for policyURI field

The policyURI field in the DisputeDetailsSchema no longer includes validation to ensure it's a valid multi-address. This change has several implications:

  1. Any string can now be used as a policy URI, potentially allowing invalid URIs.
  2. It removes a layer of data validation, which could lead to data integrity issues.
  3. This change might affect other parts of the system that expect the policy URI to be in a specific format.

To address these concerns:

  1. Please clarify the rationale behind removing the validation. Is this intentional to allow for a wider range of URI formats?
  2. Consider adding a custom validation function if the isMultiaddr function is no longer suitable. For example:
policyURI: z.string().refine((value) => {
  // Add custom validation logic here
  return true; // or false if invalid
}, {
  message: "Provided policy URI is invalid."
})
  1. If complete flexibility is required, consider adding a warning in the code comments about the lack of validation and the potential risks.

  2. Ensure that any downstream code that uses the policyURI can handle potentially invalid URI formats.

Run the following script to find usage of the policyURI field across the codebase:

#!/bin/bash
# Description: Find usage of policyURI field
rg --type typescript "policyURI" -C 3

This will help identify areas that might be affected by the change and need additional attention or updates.


8-10: Verify the impact of the simplified isMultiaddr regex pattern

The regex pattern for validating multi-addresses has been significantly simplified. While this change may improve readability and performance, it could have unintended consequences:

  1. It might now accept some previously invalid multi-addresses.
  2. It might reject some previously valid multi-addresses.
  3. The changes could affect the validation of policy URIs and other system components relying on this function.

To ensure the changes don't introduce regressions:

  1. Please clarify the rationale behind simplifying the regex pattern.
  2. Conduct thorough testing with various multi-address formats to ensure all valid use cases are still supported.
  3. Update the unit tests to cover edge cases for both valid and invalid multi-addresses.

Run the following script to find potential usage of isMultiaddr function across the codebase:

This will help identify areas that might be affected by the change and need additional testing or updates.

web-devtools/src/app/(main)/dispute-template/FetchDisputeRequestInput.tsx (4)

54-54: LGTM. Verify the new transaction hash.

The update to the "Curated Lists" preset's transaction hash looks good. However, please ensure that the new hash (0xa7981830bf8144ab2070f3a639bd36b204c4c48ee1fafef66abaf60272418ed4) is correct and corresponds to the intended transaction on the specified chain (421614).

To verify the transaction hash, you can use the following script:

#!/bin/bash
# Description: Verify the transaction hash for the "Curated Lists" preset

# Test: Check if the transaction exists on the specified chain
gh api graphql -f query='
query($hash: String!) {
  transaction(hash: $hash) {
    hash
    blockNumber
  }
}
' -F hash="0xa7981830bf8144ab2070f3a639bd36b204c4c48ee1fafef66abaf60272418ed4" \
--jq '.data.transaction'

# Note: This script assumes that the GitHub GraphQL API has access to the specified chain (421614).
# If it doesn't, you may need to use a chain-specific explorer API instead.

49-59: Summary of changes to preset transaction hashes

The changes in this file are limited to updating the txnHash values for the three presets: "Escrow", "Curated Lists", and "Trump-Biden". These updates don't affect the component's logic or structure, but they do change the example transactions that users can quickly load.

To ensure the integrity of these presets:

  1. Verify that each new transaction hash is valid and exists on the specified chain (421614).
  2. Confirm that these new transactions accurately represent the intended dispute scenarios for each preset.
  3. Update any related documentation or tests that may reference these preset transaction hashes.

To verify all transaction hashes at once, you can use the following script:

#!/bin/bash
# Description: Verify all preset transaction hashes

# Array of transaction hashes to check
hashes=(
  "0x2565b756e500240544f7fc36f938462c7efbbd2e343c57979f81fecdf1054e23"
  "0xa7981830bf8144ab2070f3a639bd36b204c4c48ee1fafef66abaf60272418ed4"
  "0x83934c07f6476b2fd8c43cf856819134a58c007cb6938c6990fb3058b243ba0c"
)

# Loop through each hash and check its validity
for hash in "${hashes[@]}"; do
  echo "Checking transaction: $hash"
  gh api graphql -f query='
  query($hash: String!) {
    transaction(hash: $hash) {
      hash
      blockNumber
    }
  }
  ' -F hash="$hash" \
  --jq '.data.transaction'
  echo "---"
done

# Note: This script assumes that the GitHub GraphQL API has access to the specified chain (421614).
# If it doesn't, you may need to use a chain-specific explorer API instead.

59-59: LGTM. Verify the new transaction hash.

The update to the "Trump-Biden" preset's transaction hash looks good. However, please ensure that the new hash (0x83934c07f6476b2fd8c43cf856819134a58c007cb6938c6990fb3058b243ba0c) is correct and corresponds to the intended transaction on the specified chain (421614).

To verify the transaction hash, you can use the following script:

#!/bin/bash
# Description: Verify the transaction hash for the "Trump-Biden" preset

# Test: Check if the transaction exists on the specified chain
gh api graphql -f query='
query($hash: String!) {
  transaction(hash: $hash) {
    hash
    blockNumber
  }
}
' -F hash="0x83934c07f6476b2fd8c43cf856819134a58c007cb6938c6990fb3058b243ba0c" \
--jq '.data.transaction'

# Note: This script assumes that the GitHub GraphQL API has access to the specified chain (421614).
# If it doesn't, you may need to use a chain-specific explorer API instead.

49-49: LGTM. Verify the new transaction hash.

The update to the "Escrow" preset's transaction hash looks good. However, please ensure that the new hash (0x2565b756e500240544f7fc36f938462c7efbbd2e343c57979f81fecdf1054e23) is correct and corresponds to the intended transaction on the specified chain (421614).

To verify the transaction hash, you can use the following script:

web-devtools/src/app/(main)/dispute-template/page.tsx (4)

108-112: Approved: Definition of StyledJSONEditor component

The StyledJSONEditor component is correctly defined with the desired height and width, ensuring consistent styling across the application.


158-158: Approved: Addition of customContextInput state variable

Initializing customContextInput with an empty JSON object string "{}" is appropriate and sets the correct initial state for user input.


202-203: Approved: Merging custom context into initial context

Merging customContext into initialContext ensures that any additional context provided by the user is included in the data fetching logic. This is correctly implemented.


227-227: Approved: Inclusion of customContextInput in useEffect dependencies

Adding customContextInput to the dependency array of the useEffect hook ensures that changes to the custom context input trigger the data fetching logic. This is appropriate.

@Harman-singh-waraich Harman-singh-waraich force-pushed the chore/update-dispute-template-presets branch from f0298ff to 0e1e8e5 Compare October 25, 2024 12:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (2)
web-devtools/src/app/(main)/dispute-template/CustomContextInputs.tsx (2)

8-14: Consider making the margin configurable via props.

The fixed margin-top: 32px in the Container styled component might limit its reusability. Consider making it configurable through props for better flexibility.

-const Container = styled.div`
+interface ContainerProps {
+  marginTop?: string;
+}
+const Container = styled.div<ContainerProps>`
   width: 100%;
   display: flex;
   flex-direction: column;
   gap: 16px;
-  margin-top: 32px;
+  margin-top: ${props => props.marginTop || '32px'};
 `;

43-80: Consider memoizing rendered inputs for better performance.

For better performance with large variable lists, consider memoizing the rendered inputs using useMemo to prevent unnecessary re-renders.

+  const renderedInputs = useMemo(() => 
+    requiredVariables.map((variable, index) =>
+      DisputeRequestParams.includes(variable) ? null : (
+        <InputContainer key={`${variable}-${index}`}>
+          <VariableName>{variable}:</VariableName>
+          <Field
+            type="text"
+            name={variable}
+            value={customContext?.[variable]}
+            onChange={(e) => {
+              setCustomContextInputs((prev) => ({ ...prev, [variable]: e.target.value }));
+            }}
+            placeholder={`Enter ${variable.toLowerCase()}`}
+          />
+        </InputContainer>
+      )
+    ),
+    [requiredVariables, customContext]
+  );

   return requiredVariables.length ? (
     <Container>
       <WithHelpTooltip tooltipMsg="These are additional variables required by the data mapping to be passed as initial context. Please ignore the variables that will come from the result of the preceeding data mappings">
         <Header>Additional Context</Header>
       </WithHelpTooltip>
-      {requiredVariables.map((variable, index) =>
-        DisputeRequestParams.includes(variable) ? null : (
-          <InputContainer key={`${variable}-${index}`}>
-            <VariableName>{variable}:</VariableName>
-            <Field
-              type="text"
-              name={variable}
-              value={customContext?.[variable]}
-              onChange={(e) => {
-                setCustomContextInputs((prev) => ({ ...prev, [variable]: e.target.value }));
-              }}
-              placeholder={`Enter ${variable.toLowerCase()}`}
-            />
-          </InputContainer>
-        )
-      )}
+      {renderedInputs}
     </Container>
   ) : null;
🧰 Tools
🪛 Biome

[error] 64-64: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 48a757f and 0e1e8e5.

📒 Files selected for processing (5)
  • web-devtools/src/app/(main)/dispute-template/CustomContextInputs.tsx (1 hunks)
  • web-devtools/src/app/(main)/dispute-template/FetchDisputeRequestInput.tsx (1 hunks)
  • web-devtools/src/app/(main)/dispute-template/page.tsx (7 hunks)
  • web-devtools/src/components/JSONEditor.tsx (1 hunks)
  • web-devtools/tsconfig.json (0 hunks)
💤 Files with no reviewable changes (1)
  • web-devtools/tsconfig.json
🚧 Files skipped from review as they are similar to previous changes (3)
  • web-devtools/src/app/(main)/dispute-template/FetchDisputeRequestInput.tsx
  • web-devtools/src/app/(main)/dispute-template/page.tsx
  • web-devtools/src/components/JSONEditor.tsx
🧰 Additional context used
🪛 Biome
web-devtools/src/app/(main)/dispute-template/CustomContextInputs.tsx

[error] 64-64: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

Copy link

codeclimate bot commented Oct 28, 2024

Code Climate has analyzed commit ff618c0 and detected 22 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 8
Duplication 6
Style 8

View more on Code Climate.

Copy link

@Harman-singh-waraich Harman-singh-waraich marked this pull request as ready for review October 28, 2024 06:21
Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@alcercu alcercu added this pull request to the merge queue Oct 28, 2024
@jaybuidl jaybuidl linked an issue Oct 28, 2024 that may be closed by this pull request
Merged via the queue into dev with commit 7a00ce6 Oct 28, 2024
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DevTools template preview: provide the graphApiKey variable in input
4 participants