fix(frontend): unused vars/params

This commit is contained in:
tigattack
2025-09-25 00:58:12 +01:00
parent 67a5462a25
commit a1bf2df59d
11 changed files with 25 additions and 118 deletions

View File

@@ -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),

View File

@@ -8,7 +8,6 @@ const InlineGroupEdit = ({
options = [],
className = "",
disabled = false,
placeholder = "Select group...",
}) => {
const [isEditing, setIsEditing] = useState(false);
const [selectedValue, setSelectedValue] = useState(value);

View File

@@ -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 }) => {
</div>
</div>
)}
{navigation.map((item, index) => {
{navigation.map((item) => {
if (item.name) {
// Single item (Dashboard)
return (
@@ -490,7 +490,7 @@ const Layout = ({ children }) => {
</div>
</li>
)}
{navigation.map((item, index) => {
{navigation.map((item) => {
if (item.name) {
// Single item (Dashboard)
return (

View File

@@ -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" };
}
};

View File

@@ -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

View File

@@ -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
</p>
<div className="space-y-1">
{host.dns_servers.map((dns, index) => (
{host.dns_servers.map((dns) => (
<p
key={dns}
className="font-medium text-secondary-900 dark:text-white font-mono text-sm"
@@ -502,7 +500,7 @@ const HostDetail = () => {
Network Interfaces
</p>
<div className="space-y-1">
{host.network_interfaces.map((iface, index) => (
{host.network_interfaces.map((iface) => (
<p
key={iface.name}
className="font-medium text-secondary-900 dark:text-white text-sm"
@@ -815,7 +813,7 @@ const HostDetail = () => {
{(showAllUpdates
? host.update_history
: host.update_history.slice(0, 5)
).map((update, index) => (
).map((update) => (
<tr
key={update.id}
className="hover:bg-secondary-50 dark:hover:bg-secondary-700"
@@ -1028,7 +1026,7 @@ const CredentialsModal = ({ host, isOpen, onClose }) => {
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 (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
<div className="bg-white dark:bg-secondary-800 rounded-lg p-6 w-full max-w-4xl max-h-[90vh] overflow-y-auto">

View File

@@ -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 <AlertTriangle className="h-5 w-5" />;
if (host.updatesCount > 0) return <Clock className="h-5 w-5" />;
return <CheckCircle className="h-5 w-5" />;
};
const getStatusText = (host) => {
if (host.isStale) return "Stale";
if (host.updatesCount > 0) return "Needs Updates";
return "Up to Date";
};
return (
<div className="h-[calc(100vh-7rem)] flex flex-col overflow-hidden">
{/* Page Header */}
@@ -2137,7 +2106,7 @@ const BulkAssignModal = ({
{selectedHosts.length !== 1 ? "s" : ""}:
</p>
<div className="max-h-32 overflow-y-auto bg-secondary-50 rounded-md p-3">
{selectedHostNames.map((friendlyName, index) => (
{selectedHostNames.map((friendlyName) => (
<div key={friendlyName} className="text-sm text-secondary-700">
{friendlyName}
</div>
@@ -2247,7 +2216,7 @@ const BulkDeleteModal = ({
Hosts to be deleted:
</p>
<div className="max-h-32 overflow-y-auto bg-secondary-50 dark:bg-secondary-700 rounded-md p-3">
{selectedHostNames.map((friendlyName, index) => (
{selectedHostNames.map((friendlyName) => (
<div
key={friendlyName}
className="text-sm text-secondary-700 dark:text-secondary-300"

View File

@@ -69,7 +69,6 @@ const Packages = () => {
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();

View File

@@ -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({

View File

@@ -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({});

View File

@@ -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");