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

Added dropdown selector to show incomplete channels #211

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

mvpoyatt
Copy link
Collaborator

@mvpoyatt mvpoyatt commented Sep 4, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced channel details display with creation time and transaction hash.
    • Added pagination and filter visibility management in the Channels component.
    • Introduced a new FilterButton component for improved filter toggling.
    • Added LinkAndCopy component for better link and copy functionality.
  • Bug Fixes

    • Improved error handling in API channel retrieval.
  • Refactor

    • Simplified imports across components for better organization.
    • Replaced standalone functions with dedicated components for better maintainability.
  • Style

    • Adjusted visual spacing in the Clients component for improved layout.
    • Enhanced readability of chain names in the ChainCell component.

Copy link

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes across various components and API files enhance state management, improve data handling, and introduce new UI elements. Key modifications include the addition of new state variables, the restructuring of imports, and the implementation of new components for better code organization. The API has been updated to support pagination and enhanced error handling, while several components have been refactored for improved readability and maintainability.

Changes

Files Change Summary
app/(routes)/channels/channel-details.tsx Introduced state management for sourceChain, added creation time and transaction hash display, and updated rendering logic.
app/(routes)/channels/page.tsx Expanded state management with new variables for filters and pagination, added new column accessors for timestamps and transaction hashes, and improved rendering logic.
app/(routes)/clients/page.tsx Adjusted margin-left style for a <div> element containing the ChainCell component.
app/(routes)/packets/packet-details.tsx Replaced linkAndCopy function with a new LinkAndCopy component for rendering links and copy functionality.
app/(routes)/packets/page.tsx Consolidated imports and replaced manual button implementation with a new FilterButton component.
app/api/channels/helpers.ts Renamed getChannels to getIncompleteChannels, added pagination support, and included additional properties in the IdentifiedChannel object.
app/api/channels/route.ts Enhanced GET function to handle additional query parameters and improved error handling.
app/components/chain-cell.tsx Modified chain name display logic to shorten long names using shortenHex.
app/components/filter-button.tsx Introduced a new FilterButton component for toggling filters with animations.
app/components/index.ts Created a centralized export module for various components to streamline imports.
app/components/link-and-copy.tsx Introduced a LinkAndCopy component for hyperlink and copy functionality with formatted hex values.
app/components/state-cell.tsx Expanded background color logic to include 'Initialized' state.
app/utils/types/channel.ts Modified IdentifiedChannel interface to extend from BaseIdentifiedChannel and added optional properties for createTime and transactionHash.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChannelsAPI
    participant ChannelsPage
    participant ChannelDetails

    User->>ChannelsPage: Request channel data
    ChannelsPage->>ChannelsAPI: Fetch channels
    ChannelsAPI->>ChannelsPage: Return channel data
    ChannelsPage->>ChannelDetails: Display channel details
    ChannelDetails->>ChannelsAPI: Fetch additional channel info
    ChannelsAPI->>ChannelDetails: Return additional info
Loading

🐰 In the meadow, I hop with glee,
New changes bring joy, just wait and see!
With buttons that toggle and links that shine,
Our channels are better, oh how divine!
So let’s dance and play, with a hop and a skip,
For code that is tidy makes my heart flip! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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

@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, codebase verification and nitpick comments (1)
app/components/chain-cell.tsx (1)

14-16: LGTM!

The code changes are approved.

Nitpick: Extract the magic number 25 into a constant.

Consider extracting the magic number 25 into a constant for better maintainability.

Apply this diff to extract the magic number into a constant:

+const MAX_CHAIN_NAME_LENGTH = 25;

export function ChainCell({chain}: {chain: string}) {
  const size = 32;

  if (!chain) {
    return UnknownIcon(size);
  }

  const sim: boolean = chain.toLowerCase().includes('sim');
  const chainName = chain.split('-')[0];
  let icon: JSX.Element = <span>{
-    chain.length > 25 ? shortenHex(chain) : chain
+    chain.length > MAX_CHAIN_NAME_LENGTH ? shortenHex(chain) : chain
  }</span>;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3215328 and 050fc64.

Files selected for processing (14)
  • app/(routes)/channels/channel-details.tsx (3 hunks)
  • app/(routes)/channels/page.tsx (8 hunks)
  • app/(routes)/clients/page.tsx (1 hunks)
  • app/(routes)/packets/packet-details.tsx (4 hunks)
  • app/(routes)/packets/page.tsx (2 hunks)
  • app/api/channels/helpers.ts (4 hunks)
  • app/api/channels/route.ts (1 hunks)
  • app/components/chain-cell.tsx (2 hunks)
  • app/components/filter-button.tsx (1 hunks)
  • app/components/format-strings.tsx (1 hunks)
  • app/components/index.ts (1 hunks)
  • app/components/link-and-copy.tsx (1 hunks)
  • app/components/state-cell.tsx (1 hunks)
  • app/utils/types/channel.ts (1 hunks)
Files skipped from review due to trivial changes (3)
  • app/(routes)/clients/page.tsx
  • app/components/format-strings.tsx
  • app/components/index.ts
Additional comments not posted (35)
app/components/state-cell.tsx (1)

6-6: LGTM!

The code changes are approved. The change enhances the component's responsiveness to different states and is consistent with the existing logic.

app/utils/types/channel.ts (4)

1-1: LGTM!

The code changes are approved.


2-2: LGTM!

The code changes are approved.


4-7: LGTM!

The code changes are approved.


14-14: LGTM!

The code changes are approved.

app/components/filter-button.tsx (1)

1-27: LGTM!

The FilterButton component is well-structured and follows best practices:

  • It uses Tailwind CSS classes for styling, which is consistent with the rest of the codebase.
  • It uses the classNames utility function to conditionally apply classes.
  • It uses the onClick event to toggle the open state.
  • It uses the transition-transform and duration-200 classes to animate the horizontal lines when the button is clicked.
  • It uses the ease-in-out class to apply an easing function to the animation.
  • It uses the relative class to position the horizontal lines relative to the button.
  • It uses the ml-3.5, pt-2.5, pb-3, and px-2 classes to apply margin and padding to the button.
  • It uses the grid, justify-items-center, and items-center classes to center the horizontal lines within the button.
  • It uses the h-0.5 and w-6 classes to set the height and width of the horizontal lines.
  • It uses the bg-vapor class to set the background color of the horizontal lines.
  • It uses the translate-y-4 and -translate-y-4 classes to translate the horizontal lines vertically when the button is clicked.

The code changes are approved.

app/components/link-and-copy.tsx (1)

1-2: LGTM!

The code changes are approved.

app/components/chain-cell.tsx (1)

3-3: LGTM!

The code changes are approved.

app/api/channels/route.ts (4)

2-2: LGTM!

The code changes are approved.


13-21: LGTM!

The code changes are approved.


22-29: LGTM!

The code changes are approved.


Line range hint 32-39: LGTM!

The code changes are approved.

app/(routes)/channels/channel-details.tsx (3)

1-5: LGTM!

The code changes are approved.


39-43: LGTM!

The code changes are approved.


63-67: LGTM!

The code changes are approved.

app/api/channels/helpers.ts (2)

Line range hint 45-63: LGTM!

The code changes are approved. The changes enhance the API's ability to manage channel data by allowing for pagination and filtering.


93-124: LGTM!

The code changes are approved. The changes expand the information available for each channel, thus improving the functionality and usability of the API.

app/(routes)/packets/packet-details.tsx (4)

5-5: LGTM!

The code changes are approved.


147-147: LGTM!

The code changes are approved.


152-152: LGTM!

The code changes are approved.


157-157: LGTM!

The code changes are approved.

app/(routes)/channels/page.tsx (12)

14-25: LGTM!

The restructuring of imports to use a single components module is a good change that reduces redundancy.


27-28: LGTM!

The imports are necessary for the functionality of the component.


Line range hint 50-62: LGTM!

The addition of ChainCell components to display the source and destination chains is a good change. The margin classes are used appropriately for spacing.


86-97: LGTM!

The new column accessors for createTime and transactionHash enhance the data presented to users by providing more context about each channel.


109-111: LGTM!

The new state variables showFilters, showInProgressChannels, and pageNumber are used appropriately to manage filter visibility, toggle the display of in-progress channels, and handle pagination.


119-120: LGTM!

Adding createTime and transactionHash to the columnVisibility state and setting their visibility to false by default is consistent with the addition of the new column accessors.


129-137: LGTM!

The changes to the useEffect hook enhance the component's behavior by loading data, updating the header, and handling a default channelId from the URL.


139-142: LGTM!

The new useEffect hook is used appropriately to load data based on the current page number, which is necessary for pagination.


Line range hint 144-166: LGTM!

The updateChannelType function is implemented correctly to manage the loading of data based on the selected channel type and update the header accordingly.


Line range hint 168-188: LGTM!

The modifications to the loadData function enable loading data for in-progress channels with pagination support. The offset and limit query parameters are used correctly to fetch the appropriate data based on the current page.


285-320: LGTM!

The addition of the FilterButton component and the animated filter container enhances the user experience by providing a clean and interactive way to manage filters. The Select component is used appropriately to allow switching between "Universal" and "In-Progress" channels, triggering the necessary data loading and header update.


322-331: LGTM!

The conditional rendering of the Table component based on showInProgressChannels is implemented correctly. It allows for different pagination behavior depending on the selected channel type, enabling server-side pagination for in-progress channels and rendering the table without pagination for universal channels.

app/(routes)/packets/page.tsx (2)

14-22: LGTM!

The consolidation of imports from the components directory into a single import statement enhances code readability and organization.


327-327: LGTM!

The replacement of the manual filter toggle button implementation with the FilterButton component simplifies the code and improves maintainability by encapsulating the filter toggle logic within a dedicated component.

Comment on lines +4 to +27
export function LinkAndCopy({url, path, hex}: {url?: string, path: string, hex?: string}) {
if (!hex) {
return <p className="font-mono animate-pulse">...</p>;
}

hex = hex.toLowerCase();
if (hex[0] != '0' || hex[1] != 'x') {
let split = hex.split('.');
if (split.length > 0) {
hex = split.pop();
}
hex = '0x' + hex;
}

return (
<div className="whitespace-nowrap flex flex-row">
<Link href={url + path + '/' + hex} target="_blank"
className="text-light-blue dark:text-light-blue font-mono text-[17px]/[24px] hover:underline underline-offset-2">
{hex}
</Link>
<CopyButton str={hex} />
</div>
);
}
Copy link

Choose a reason for hiding this comment

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

Refactor the hex normalization logic into a separate function.

Consider extracting the hex normalization logic into a separate function for better readability and reusability.

Apply this diff to refactor the function:

+function normalizeHex(hex: string): string {
+  hex = hex.toLowerCase();
+  if (hex[0] != '0' || hex[1] != 'x') {
+    let split = hex.split('.');
+    if (split.length > 0) {
+      hex = split.pop();
+    }
+    hex = '0x' + hex;
+  }
+  return hex;
+}
+
 export function LinkAndCopy({url, path, hex}: {url?: string, path: string, hex?: string}) {
   if (!hex) {
     return <p className="font-mono animate-pulse">...</p>;
   }
 
-  hex = hex.toLowerCase();
-  if (hex[0] != '0' || hex[1] != 'x') {
-    let split = hex.split('.');
-    if (split.length > 0) {
-      hex = split.pop();
-    }
-    hex = '0x' + hex;
-  }
+  hex = normalizeHex(hex);
 
   return (
     <div className="whitespace-nowrap flex flex-row">
       <Link href={url + path + '/' + hex} target="_blank"
         className="text-light-blue dark:text-light-blue font-mono text-[17px]/[24px] hover:underline underline-offset-2">
         {hex}
       </Link>
       <CopyButton str={hex} />
     </div>
   );
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function LinkAndCopy({url, path, hex}: {url?: string, path: string, hex?: string}) {
if (!hex) {
return <p className="font-mono animate-pulse">...</p>;
}
hex = hex.toLowerCase();
if (hex[0] != '0' || hex[1] != 'x') {
let split = hex.split('.');
if (split.length > 0) {
hex = split.pop();
}
hex = '0x' + hex;
}
return (
<div className="whitespace-nowrap flex flex-row">
<Link href={url + path + '/' + hex} target="_blank"
className="text-light-blue dark:text-light-blue font-mono text-[17px]/[24px] hover:underline underline-offset-2">
{hex}
</Link>
<CopyButton str={hex} />
</div>
);
}
function normalizeHex(hex: string): string {
hex = hex.toLowerCase();
if (hex[0] != '0' || hex[1] != 'x') {
let split = hex.split('.');
if (split.length > 0) {
hex = split.pop();
}
hex = '0x' + hex;
}
return hex;
}
export function LinkAndCopy({url, path, hex}: {url?: string, path: string, hex?: string}) {
if (!hex) {
return <p className="font-mono animate-pulse">...</p>;
}
hex = normalizeHex(hex);
return (
<div className="whitespace-nowrap flex flex-row">
<Link href={url + path + '/' + hex} target="_blank"
className="text-light-blue dark:text-light-blue font-mono text-[17px]/[24px] hover:underline underline-offset-2">
{hex}
</Link>
<CopyButton str={hex} />
</div>
);
}

Comment on lines +8 to +18
const [sourceChain, setSourceChain] = useState<Chain | undefined>();

useEffect(() => {
for (const chain of Object.keys(CHAIN_CONFIGS)) {
const chainName = chain as CHAIN;
const chainVals = CHAIN_CONFIGS[chainName];
if (channel?.portId?.toLowerCase().includes(chain)) {
setSourceChain(chainVals);
}
}
}, [channel]);
Copy link

Choose a reason for hiding this comment

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

Add CHAIN_CONFIGS to the dependency array of useEffect.

The useEffect hook has a missing dependency on CHAIN_CONFIGS.

Add CHAIN_CONFIGS to the dependency array to fix the issue:

-  useEffect(() => {
+  useEffect(() => {
     for (const chain of Object.keys(CHAIN_CONFIGS)) {
       const chainName = chain as CHAIN;
       const chainVals = CHAIN_CONFIGS[chainName];
       if (channel?.portId?.toLowerCase().includes(chain)) {
         setSourceChain(chainVals);
       }
     }
-  }, [channel]);
+  }, [channel, CHAIN_CONFIGS]);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [sourceChain, setSourceChain] = useState<Chain | undefined>();
useEffect(() => {
for (const chain of Object.keys(CHAIN_CONFIGS)) {
const chainName = chain as CHAIN;
const chainVals = CHAIN_CONFIGS[chainName];
if (channel?.portId?.toLowerCase().includes(chain)) {
setSourceChain(chainVals);
}
}
}, [channel]);
const [sourceChain, setSourceChain] = useState<Chain | undefined>();
useEffect(() => {
for (const chain of Object.keys(CHAIN_CONFIGS)) {
const chainName = chain as CHAIN;
const chainVals = CHAIN_CONFIGS[chainName];
if (channel?.portId?.toLowerCase().includes(chain)) {
setSourceChain(chainVals);
}
}
}, [channel, CHAIN_CONFIGS]);

Copy link
Member

@dshiell dshiell left a comment

Choose a reason for hiding this comment

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

hard to tell without testing in staging

@mvpoyatt mvpoyatt merged commit 26829f0 into main Sep 4, 2024
5 checks passed
@mvpoyatt mvpoyatt deleted the mp/in-progress-channels branch September 4, 2024 20:39
@coderabbitai coderabbitai bot mentioned this pull request Sep 13, 2024
@coderabbitai coderabbitai bot mentioned this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants