From a1bf2df59d3cc5aed6da1683d2f85601a2b058fe Mon Sep 17 00:00:00 2001 From: tigattack <10629864+tigattack@users.noreply.github.com> Date: Thu, 25 Sep 2025 00:58:12 +0100 Subject: [PATCH] fix(frontend): unused vars/params --- .../src/components/DashboardSettingsModal.jsx | 3 -- frontend/src/components/InlineGroupEdit.jsx | 1 - frontend/src/components/Layout.jsx | 6 +-- frontend/src/contexts/AuthContext.jsx | 6 +-- frontend/src/pages/Dashboard.jsx | 8 +-- frontend/src/pages/HostDetail.jsx | 52 ++----------------- frontend/src/pages/Hosts.jsx | 41 ++------------- frontend/src/pages/Packages.jsx | 1 - frontend/src/pages/Profile.jsx | 9 ++-- frontend/src/pages/Settings.jsx | 14 +---- frontend/src/pages/Users.jsx | 2 +- 11 files changed, 25 insertions(+), 118 deletions(-) diff --git a/frontend/src/components/DashboardSettingsModal.jsx b/frontend/src/components/DashboardSettingsModal.jsx index 5b7b503..4299b56 100644 --- a/frontend/src/components/DashboardSettingsModal.jsx +++ b/frontend/src/components/DashboardSettingsModal.jsx @@ -25,12 +25,10 @@ import { X, } from "lucide-react"; import { useEffect, useState } from "react"; -import { useTheme } from "../contexts/ThemeContext"; import { dashboardPreferencesAPI } from "../utils/api"; // Sortable Card Item Component const SortableCardItem = ({ card, onToggle }) => { - const { isDark } = useTheme(); const { attributes, listeners, @@ -103,7 +101,6 @@ const DashboardSettingsModal = ({ isOpen, onClose }) => { const [cards, setCards] = useState([]); const [hasChanges, setHasChanges] = useState(false); const queryClient = useQueryClient(); - const { isDark } = useTheme(); const sensors = useSensors( useSensor(PointerSensor), diff --git a/frontend/src/components/InlineGroupEdit.jsx b/frontend/src/components/InlineGroupEdit.jsx index 3c1e6ba..15e5491 100644 --- a/frontend/src/components/InlineGroupEdit.jsx +++ b/frontend/src/components/InlineGroupEdit.jsx @@ -8,7 +8,6 @@ const InlineGroupEdit = ({ options = [], className = "", disabled = false, - placeholder = "Select group...", }) => { const [isEditing, setIsEditing] = useState(false); const [selectedValue, setSelectedValue] = useState(value); diff --git a/frontend/src/components/Layout.jsx b/frontend/src/components/Layout.jsx index a57a99a..df84538 100644 --- a/frontend/src/components/Layout.jsx +++ b/frontend/src/components/Layout.jsx @@ -38,7 +38,7 @@ const Layout = ({ children }) => { const saved = localStorage.getItem("sidebarCollapsed"); return saved ? JSON.parse(saved) : false; }); - const [userMenuOpen, setUserMenuOpen] = useState(false); + const [_userMenuOpen, setUserMenuOpen] = useState(false); const [githubStars, setGithubStars] = useState(null); const location = useLocation(); const { @@ -339,7 +339,7 @@ const Layout = ({ children }) => { )} - {navigation.map((item, index) => { + {navigation.map((item) => { if (item.name) { // Single item (Dashboard) return ( @@ -490,7 +490,7 @@ const Layout = ({ children }) => { )} - {navigation.map((item, index) => { + {navigation.map((item) => { if (item.name) { // Single item (Dashboard) return ( diff --git a/frontend/src/contexts/AuthContext.jsx b/frontend/src/contexts/AuthContext.jsx index cbbeb5f..17357e8 100644 --- a/frontend/src/contexts/AuthContext.jsx +++ b/frontend/src/contexts/AuthContext.jsx @@ -123,7 +123,7 @@ export const AuthProvider = ({ children }) => { } else { return { success: false, error: data.error || "Login failed" }; } - } catch (error) { + } catch { return { success: false, error: "Network error occurred" }; } }; @@ -171,7 +171,7 @@ export const AuthProvider = ({ children }) => { } else { return { success: false, error: data.error || "Update failed" }; } - } catch (error) { + } catch { return { success: false, error: "Network error occurred" }; } }; @@ -197,7 +197,7 @@ export const AuthProvider = ({ children }) => { error: data.error || "Password change failed", }; } - } catch (error) { + } catch { return { success: false, error: "Network error occurred" }; } }; diff --git a/frontend/src/pages/Dashboard.jsx b/frontend/src/pages/Dashboard.jsx index 8a59fb9..d57cb53 100644 --- a/frontend/src/pages/Dashboard.jsx +++ b/frontend/src/pages/Dashboard.jsx @@ -104,7 +104,7 @@ const Dashboard = () => { }; // Chart click handlers - const handleOSChartClick = (event, elements) => { + const handleOSChartClick = (_, elements) => { if (elements.length > 0) { const elementIndex = elements[0].index; const osName = @@ -113,7 +113,7 @@ const Dashboard = () => { } }; - const handleUpdateStatusChartClick = (event, elements) => { + const handleUpdateStatusChartClick = (_, elements) => { if (elements.length > 0) { const elementIndex = elements[0].index; const statusName = @@ -135,7 +135,7 @@ const Dashboard = () => { } }; - const handlePackagePriorityChartClick = (event, elements) => { + const handlePackagePriorityChartClick = (_, elements) => { if (elements.length > 0) { const elementIndex = elements[0].index; const priorityName = @@ -210,7 +210,7 @@ const Dashboard = () => { }); // Fetch user's dashboard preferences - const { data: preferences, refetch: refetchPreferences } = useQuery({ + const { data: preferences } = useQuery({ queryKey: ["dashboardPreferences"], queryFn: () => dashboardPreferencesAPI.get().then((res) => res.data), staleTime: 5 * 60 * 1000, // Consider data fresh for 5 minutes diff --git a/frontend/src/pages/HostDetail.jsx b/frontend/src/pages/HostDetail.jsx index 53fddcd..1de9b0d 100644 --- a/frontend/src/pages/HostDetail.jsx +++ b/frontend/src/pages/HostDetail.jsx @@ -43,8 +43,6 @@ const HostDetail = () => { const queryClient = useQueryClient(); const [showCredentialsModal, setShowCredentialsModal] = useState(false); const [showDeleteModal, setShowDeleteModal] = useState(false); - const [isEditingFriendlyName, setIsEditingFriendlyName] = useState(false); - const [editedFriendlyName, setEditedFriendlyName] = useState(""); const [showAllUpdates, setShowAllUpdates] = useState(false); const [activeTab, setActiveTab] = useState(() => { // Restore tab state from localStorage @@ -482,7 +480,7 @@ const HostDetail = () => { DNS Servers

- {host.dns_servers.map((dns, index) => ( + {host.dns_servers.map((dns) => (

{ Network Interfaces

- {host.network_interfaces.map((iface, index) => ( + {host.network_interfaces.map((iface) => (

{ {(showAllUpdates ? host.update_history : host.update_history.slice(0, 5) - ).map((update, index) => ( + ).map((update) => ( { if (!successful) { throw new Error("Copy command failed"); } - } catch (err) { + } catch { // If all else fails, show the text in a prompt prompt("Copy this command:", text); } finally { @@ -1041,50 +1039,8 @@ const CredentialsModal = ({ host, isOpen, onClose }) => { } }; - const getSetupCommands = () => { - // Get current time for crontab scheduling - const now = new Date(); - const currentMinute = now.getMinutes(); - const currentHour = now.getHours(); - - return `# Run this on the target host: ${host?.friendly_name} - -echo "๐Ÿ”„ Setting up PatchMon agent..." - -# Download and install agent -echo "๐Ÿ“ฅ Downloading agent script..." -curl -o /tmp/patchmon-agent.sh ${serverUrl}/api/v1/hosts/agent/download -sudo mkdir -p /etc/patchmon -sudo mv /tmp/patchmon-agent.sh /usr/local/bin/patchmon-agent.sh -sudo chmod +x /usr/local/bin/patchmon-agent.sh - -# Configure credentials -echo "๐Ÿ”‘ Configuring API credentials..." -sudo /usr/local/bin/patchmon-agent.sh configure "${host?.apiId}" "${host?.apiKey}" - -# Test configuration -echo "๐Ÿงช Testing configuration..." -sudo /usr/local/bin/patchmon-agent.sh test - -# Send initial update -echo "๐Ÿ“Š Sending initial package data..." -sudo /usr/local/bin/patchmon-agent.sh update - -# Setup crontab starting at current time -echo "โฐ Setting up hourly crontab starting at ${currentHour.toString().padStart(2, "0")}:${currentMinute.toString().padStart(2, "0")}..." -echo "${currentMinute} * * * * /usr/local/bin/patchmon-agent.sh update >/dev/null 2>&1" | sudo crontab - - -echo "โœ… PatchMon agent setup complete!" -echo " - Agent installed: /usr/local/bin/patchmon-agent.sh" -echo " - Config directory: /etc/patchmon/" -echo " - Updates: Every hour via crontab (starting at ${currentHour.toString().padStart(2, "0")}:${currentMinute.toString().padStart(2, "0")})" -echo " - View logs: tail -f /var/log/patchmon-agent.log"`; - }; - if (!isOpen || !host) return null; - const commands = getSetupCommands(); - return (

diff --git a/frontend/src/pages/Hosts.jsx b/frontend/src/pages/Hosts.jsx index 3406ce1..3a5e49d 100644 --- a/frontend/src/pages/Hosts.jsx +++ b/frontend/src/pages/Hosts.jsx @@ -42,7 +42,6 @@ import { OSIcon } from "../utils/osIcons.jsx"; // Add Host Modal Component const AddHostModal = ({ isOpen, onClose, onSuccess }) => { const friendlyNameId = useId(); - const hostGroupId = useId(); const [formData, setFormData] = useState({ friendly_name: "", hostGroupId: "", @@ -277,7 +276,7 @@ const CredentialsModal = ({ host, isOpen, onClose }) => { } else { throw new Error("Copy command failed"); } - } catch (err) { + } catch { // If all else fails, show the text in a prompt prompt(`Copy this ${label.toLowerCase()}:`, text); } finally { @@ -796,7 +795,6 @@ const Hosts = () => { const hostGroupFilterId = useId(); const statusFilterId = useId(); const osFilterId = useId(); - const bulkHostGroupId = useId(); const [showAddModal, setShowAddModal] = useState(false); const [selectedHosts, setSelectedHosts] = useState([]); const [showBulkAssignModal, setShowBulkAssignModal] = useState(false); @@ -915,7 +913,7 @@ const Hosts = () => { // Use the existing configuration return savedConfig; } - } catch (error) { + } catch { // If there's an error parsing the config, clear it and use default localStorage.removeItem("hosts-column-config"); return defaultConfig; @@ -952,7 +950,7 @@ const Hosts = () => { console.log("bulkUpdateGroupMutation success:", data); // Update the cache with the new host data - if (data && data.hosts) { + if (data?.hosts) { queryClient.setQueryData(["hosts"], (oldData) => { if (!oldData) return oldData; return oldData.map((host) => { @@ -976,17 +974,6 @@ const Hosts = () => { }, }); - // Toggle auto-update mutation - const toggleAutoUpdateMutation = useMutation({ - mutationFn: ({ hostId, auto_update }) => - adminHostsAPI - .toggleAutoUpdate(hostId, auto_update) - .then((res) => res.data), - onSuccess: () => { - queryClient.invalidateQueries(["hosts"]); - }, - }); - const updateFriendlyNameMutation = useMutation({ mutationFn: ({ hostId, friendlyName }) => adminHostsAPI @@ -1522,24 +1509,6 @@ const Hosts = () => { ); } - const getStatusColor = (host) => { - if (host.isStale) return "text-danger-600"; - if (host.updatesCount > 0) return "text-warning-600"; - return "text-success-600"; - }; - - const getStatusIcon = (host) => { - if (host.isStale) return ; - if (host.updatesCount > 0) return ; - return ; - }; - - const getStatusText = (host) => { - if (host.isStale) return "Stale"; - if (host.updatesCount > 0) return "Needs Updates"; - return "Up to Date"; - }; - return (
{/* Page Header */} @@ -2137,7 +2106,7 @@ const BulkAssignModal = ({ {selectedHosts.length !== 1 ? "s" : ""}:

- {selectedHostNames.map((friendlyName, index) => ( + {selectedHostNames.map((friendlyName) => (
โ€ข {friendlyName}
@@ -2247,7 +2216,7 @@ const BulkDeleteModal = ({ Hosts to be deleted:

- {selectedHostNames.map((friendlyName, index) => ( + {selectedHostNames.map((friendlyName) => (
{ const handleAffectedHostsClick = (pkg) => { const affectedHosts = pkg.affectedHosts || []; const hostIds = affectedHosts.map((host) => host.hostId); - const hostNames = affectedHosts.map((host) => host.friendlyName); // Create URL with selected hosts and filter const params = new URLSearchParams(); diff --git a/frontend/src/pages/Profile.jsx b/frontend/src/pages/Profile.jsx index fcedce9..f09e418 100644 --- a/frontend/src/pages/Profile.jsx +++ b/frontend/src/pages/Profile.jsx @@ -73,7 +73,7 @@ const Profile = () => { text: result.error || "Failed to update profile", }); } - } catch (error) { + } catch { setMessage({ type: "error", text: "Network error occurred" }); } finally { setIsLoading(false); @@ -118,7 +118,7 @@ const Profile = () => { text: result.error || "Failed to change password", }); } - } catch (error) { + } catch { setMessage({ type: "error", text: "Network error occurred" }); } finally { setIsLoading(false); @@ -545,7 +545,6 @@ const TfaTab = () => { const [verificationToken, setVerificationToken] = useState(""); const [password, setPassword] = useState(""); const [backupCodes, setBackupCodes] = useState([]); - const [isLoading, setIsLoading] = useState(false); const [message, setMessage] = useState({ type: "", text: "" }); const queryClient = useQueryClient(); @@ -558,7 +557,7 @@ const TfaTab = () => { // Setup TFA mutation const setupMutation = useMutation({ mutationFn: () => tfaAPI.setup().then((res) => res.data), - onSuccess: (data) => { + onSuccess: () => { setSetupStep("setup"); setMessage({ type: "info", @@ -688,7 +687,7 @@ const TfaTab = () => { } else { throw new Error("Copy command failed"); } - } catch (err) { + } catch { // If all else fails, show the text in a prompt prompt("Copy this text:", text); setMessage({ diff --git a/frontend/src/pages/Settings.jsx b/frontend/src/pages/Settings.jsx index cd8b397..355bdb3 100644 --- a/frontend/src/pages/Settings.jsx +++ b/frontend/src/pages/Settings.jsx @@ -29,18 +29,13 @@ const Settings = () => { const repoPublicId = useId(); const repoPrivateId = useId(); const useCustomSshKeyId = useId(); - const isDefaultId = useId(); const protocolId = useId(); const hostId = useId(); const portId = useId(); const updateIntervalId = useId(); const defaultRoleId = useId(); - const repositoryTypeId = useId(); const githubRepoUrlId = useId(); const sshKeyPathId = useId(); - const versionId = useId(); - const releaseNotesId = useId(); - const scriptContentId = useId(); const [formData, setFormData] = useState({ serverProtocol: "http", serverHost: "localhost", @@ -77,13 +72,6 @@ const Settings = () => { // Agent version management state const [showAgentVersionModal, setShowAgentVersionModal] = useState(false); - const [editingAgentVersion, setEditingAgentVersion] = useState(null); - const [agentVersionForm, setAgentVersionForm] = useState({ - version: "", - releaseNotes: "", - scriptContent: "", - isDefault: false, - }); // Version checking state const [versionInfo, setVersionInfo] = useState({ @@ -147,7 +135,7 @@ const Settings = () => { mutationFn: (data) => { return settingsAPI.update(data).then((res) => res.data); }, - onSuccess: (data) => { + onSuccess: () => { queryClient.invalidateQueries(["settings"]); setIsDirty(false); setErrors({}); diff --git a/frontend/src/pages/Users.jsx b/frontend/src/pages/Users.jsx index 84dc9ff..9f9779a 100644 --- a/frontend/src/pages/Users.jsx +++ b/frontend/src/pages/Users.jsx @@ -323,7 +323,7 @@ const AddUserModal = ({ isOpen, onClose, onUserCreated, roles }) => { if (roles && Array.isArray(roles) && roles.length > 0) { payload.role = formData.role; } - const response = await adminUsersAPI.create(payload); + await adminUsersAPI.create(payload); onUserCreated(); } catch (err) { setError(err.response?.data?.error || "Failed to create user");