-
Notifications
You must be signed in to change notification settings - Fork 36
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
Conversation
WalkthroughThe 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
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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
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 theopen
state.- It uses the
transition-transform
andduration-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
, andpx-2
classes to apply margin and padding to the button.- It uses the
grid
,justify-items-center
, anditems-center
classes to center the horizontal lines within the button.- It uses the
h-0.5
andw-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
andtransactionHash
enhance the data presented to users by providing more context about each channel.
109-111
: LGTM!The new state variables
showFilters
,showInProgressChannels
, andpageNumber
are used appropriately to manage filter visibility, toggle the display of in-progress channels, and handle pagination.
119-120
: LGTM!Adding
createTime
andtransactionHash
to thecolumnVisibility
state and setting their visibility tofalse
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 defaultchannelId
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. Theoffset
andlimit
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. TheSelect
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 onshowInProgressChannels
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.
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> | ||
); | ||
} |
There was a problem hiding this comment.
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.
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> | |
); | |
} |
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]); |
There was a problem hiding this comment.
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.
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]); |
There was a problem hiding this 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
Summary by CodeRabbit
New Features
FilterButton
component for improved filter toggling.LinkAndCopy
component for better link and copy functionality.Bug Fixes
Refactor
Style