Copilot commented on code in PR #314:
URL:
https://github.com/apache/kvrocks-controller/pull/314#discussion_r2125405764
##########
webui/src/app/ui/nav-links.tsx:
##########
@@ -50,12 +52,51 @@ export default function NavLinks({
>
<Button
color="inherit"
- className={`mx-1 rounded-full px-4 py-1
transition-colors ${
- isActive
- ? "bg-primary-light/10 text-primary
dark:text-primary-light"
- : "hover:bg-gray-100
dark:hover:bg-dark-border"
- }`}
+ sx={{
+ textTransform: "none",
+ borderRadius: "20px",
+ paddingLeft: scrolled ? 2 : 2.5,
+ paddingRight: scrolled ? 2 : 2.5,
+ paddingTop: scrolled ? 0.6 : 0.8,
+ paddingBottom: scrolled ? 0.6 : 0.8,
+ fontSize: scrolled ? "0.875rem" : "0.9rem",
+ letterSpacing: "0.01em",
+ fontWeight: 500,
+ marginX: 0.5,
+ transition: "all 0.3s ease",
+ backgroundColor: isActive
+ ? (theme) =>
+ theme.palette.mode === "dark"
+ ? "rgba(255, 255, 255, 0.15)"
+ : "rgba(25, 118, 210, 0.08)"
+ : "transparent",
+ color: (theme) => {
+ if (theme.palette.mode === "dark") {
+ return isActive ? "#fff" : "rgba(255,
255, 255, 0.9)";
+ }
+ return isActive ? "#1976d2" : "rgba(0, 0,
0, 0.7)";
+ },
+ "&:hover": {
+ backgroundColor: (theme) =>
+ theme.palette.mode === "dark"
+ ? "rgba(255, 255, 255, 0.2)"
+ : "rgba(25, 118, 210, 0.12)",
+ boxShadow: isActive
+ ? (theme) =>
+ theme.palette.mode === "dark"
+ ? "0 2px 8px rgba(0, 0, 0,
0.3)"
+ : "0 2px 8px rgba(25, 118,
210, 0.2)"
+ : "none",
+ },
+ boxShadow: isActive
+ ? (theme) =>
+ theme.palette.mode === "dark"
+ ? "0 2px 5px rgba(0, 0, 0, 0.2)"
+ : "0 2px 5px rgba(25, 118, 210,
0.15)"
+ : "none",
+ }}
Review Comment:
[nitpick] The inline style object for the Button is quite complex; consider
extracting it into a separate variable or styled component to improve
readability and maintainability.
```suggestion
sx={getButtonStyles(scrolled, isActive)}
```
##########
webui/src/app/ui/banner.tsx:
##########
@@ -65,80 +67,179 @@ export default function Banner() {
document.getElementById("navbar")?.classList.add("navbar-dark-mode");
}
+ const handleScroll = () => {
Review Comment:
[nitpick] Consider debouncing the scroll event handler to reduce the
frequency of state updates during fast scrolling, which could improve
performance.
##########
webui/src/app/ui/breadcrumb.tsx:
##########
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+"use client";
+
+import { Box, Typography, Chip, Paper } from "@mui/material";
+import { usePathname } from "next/navigation";
+import Link from "next/link";
+import { useState, useEffect } from "react";
+import HomeIcon from "@mui/icons-material/Home";
+import ChevronRightIcon from "@mui/icons-material/ChevronRight";
+import FolderIcon from "@mui/icons-material/Folder";
+import StorageIcon from "@mui/icons-material/Storage";
+import DnsIcon from "@mui/icons-material/Dns";
+import DeviceHubIcon from "@mui/icons-material/DeviceHub";
+import { fetchClusters, listShards, listNodes } from "@/app/lib/api";
+
+interface BreadcrumbItem {
+ name: string;
+ displayName: string;
+ url: string;
+ icon: React.ReactNode | null;
+ isNumeric: boolean;
+ isLast: boolean;
+}
+
+export default function Breadcrumb() {
+ const pathname = usePathname();
+ const [breadcrumbItems, setBreadcrumbItems] =
useState<BreadcrumbItem[]>([]);
+ const [loading, setLoading] = useState(false);
+
+ useEffect(() => {
+ if (pathname === "/") {
+ setBreadcrumbItems([]);
+ setLoading(false);
+ return;
+ }
+
+ const generateBreadcrumbs = async () => {
+ setLoading(true);
+ const pathSegments = pathname.split("/").filter(Boolean);
+
+ if (pathSegments.length === 0) {
+ setBreadcrumbItems([]);
+ setLoading(false);
+ return;
+ }
+
+ const items: BreadcrumbItem[] = [];
+
+ for (let index = 0; index < pathSegments.length; index++) {
+ const segment = pathSegments[index];
+ const url = `/${pathSegments.slice(0, index + 1).join("/")}`;
+ const isLast = index === pathSegments.length - 1;
+ const isNumeric = !isNaN(Number(segment));
+
+ let icon = null;
+ let displayName = segment;
+
+ if (index === 0 && segment === "namespaces") {
+ icon = <FolderIcon fontSize="small"
className="text-primary/70" />;
+ displayName = "Namespaces";
+ } else if (segment === "clusters") {
+ icon = <StorageIcon fontSize="small"
className="text-primary/70" />;
+ displayName = "Clusters";
+ } else if (segment === "shards") {
+ icon = <DnsIcon fontSize="small"
className="text-primary/70" />;
+ displayName = "Shards";
+ } else if (segment === "nodes") {
+ icon = <DeviceHubIcon fontSize="small"
className="text-primary/70" />;
+ displayName = "Nodes";
+ } else if (isNumeric) {
+ const prevSegment = pathSegments[index - 1];
+ if (prevSegment === "shards") {
+ displayName = `Shard ${parseInt(segment) + 1}`;
+ icon = null;
+ } else if (prevSegment === "nodes") {
+ displayName = `Node ${parseInt(segment) + 1}`;
+ icon = null;
+ } else {
+ displayName = `ID: ${segment}`;
+ icon = null;
+ }
+ } else {
+ // For namespace and cluster names, capitalize first letter
+ displayName = segment.charAt(0).toUpperCase() +
segment.slice(1);
+
+ const prevSegment = pathSegments[index - 1];
+ if (prevSegment === "namespaces") {
+ icon = null;
+ } else if (prevSegment === "clusters") {
+ icon = null;
+ }
+ }
+
+ items.push({
+ name: segment,
+ displayName,
+ url,
+ icon,
+ isNumeric,
+ isLast,
+ });
+ }
+
+ setBreadcrumbItems(items);
+ setLoading(false);
+ };
+
+ generateBreadcrumbs();
+ }, [pathname]);
+
+ if (pathname === "/" || breadcrumbItems.length === 0) return null;
+
+ return (
+ <Paper elevation={0} className="mt-4 w-full border-0 bg-white px-6
py-3 dark:bg-dark-paper">
+ <Box className="flex items-center overflow-x-auto py-1 pt-2">
+ <Link
+ href="/"
+ className="flex items-center text-gray-600
transition-colors hover:text-primary dark:text-gray-300
dark:hover:text-primary-light"
+ >
+ <HomeIcon fontSize="small" className="mr-2" />
+ <Typography variant="body2" className="font-medium">
+ Home
+ </Typography>
+ </Link>
+
+ {breadcrumbItems.map((item, index) => (
+ <Box key={index} className="flex items-center">
Review Comment:
Using index as a key in a list render may lead to issues with component
identity; consider using a unique identifier if available.
```suggestion
{breadcrumbItems.map((item) => (
<Box key={item.name} className="flex items-center">
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]