Fix UX issues and improve Docker monitoring user experience

Critical fixes:
1. Monitor type detection on edit
   - When editing a Docker monitor, type is now correctly detected from monitor object
   - Previously defaulted to "hardware" causing incorrect form fields to show
   - Fix: Detect type from query params on create, from monitor.type on edit

2. Default interval for Docker monitors
   - Docker monitors now default to 30 seconds (0.5 minutes) on creation
   - Hardware monitors remain at 15 seconds (0.25 minutes)
   - Pass monitorType to initializeInfrastructureMonitorForCreate

3. Type-aware fallback links
   - Hardware tab empty state: links to /infrastructure/create?type=hardware
   - Docker tab empty state: links to /infrastructure/create?type=docker
   - Ensures correct form is shown when creating from empty state

UX improvements:
4. Enhanced error messaging in Docker container table
   - Differentiate between "No containers" vs "Docker daemon unavailable"
   - Show error details when Capture API fails
   - Display critical errors (docker.client) with red background
   - Show partial error messages when some containers fail to inspect

5. Display Capture metadata
   - Show Capture version in container table header
   - Display error count when errors are present (⚠ N error(s) encountered)
   - Help users identify API issues vs legitimate empty states

6. Improved empty state handling
   - "Docker daemon unavailable" - when Docker socket unreachable on Capture server
   - "No containers found" - when Capture is working but no containers exist
   - "Partial data available" - when some containers failed to inspect
   - Show specific error messages from Capture API

These changes improve the user experience when:
- Editing existing Docker monitors (correct form fields shown)
- Creating Docker monitors (proper default interval)
- Troubleshooting Capture API issues (clear error messages)
- Understanding container availability (version info, error details)
This commit is contained in:
Claude committed 2025-11-15 22:42:02 +00:00
1 parent 0a90a30045
commit fd9d265d23
5 files changed
+81 -17

No files matched your search

@@ -31,14 +31,17 @@ const useInfrastructureMonitorForm = () => {
[event.target.name]: event.target.checked,
});
};
const initializeInfrastructureMonitorForCreate = useCallback((globalSettings) => {
const initializeInfrastructureMonitorForCreate = useCallback((globalSettings, monitorType = "hardware") => {
const gt = globalSettings?.data?.settings?.globalThresholds || {};
// Docker monitors default to 30 seconds (0.5 minutes), hardware to 15 seconds (0.25 minutes)
const defaultInterval = monitorType === "docker" ? 0.5 : 0.25;
setInfrastructureMonitor((prev) => ({
...prev,
url: "",
name: "",
notifications: [],
interval: 0.25,
interval: defaultInterval,
cpu: gt.cpu !== undefined,
usage_cpu: gt.cpu !== undefined ? gt.cpu.toString() : "",
memory: gt.memory !== undefined,
@@ -35,9 +35,6 @@ const CreateInfrastructureMonitor = () => {
const theme = useTheme();
const { t } = useTranslation();
// Get monitor type from query params (default to hardware for backwards compatibility)
const monitorType = searchParams.get("type") || "hardware";
// State
const [https, setHttps] = useState(false);
const [updateTrigger, setUpdateTrigger] = useState(false);
@@ -47,6 +44,11 @@ const CreateInfrastructureMonitor = () => {
monitorId,
updateTrigger,
});
// Determine monitor type: from query params when creating, from monitor object when editing
const monitorType = isCreate
? (searchParams.get("type") || "hardware")
: (monitor?.type || "hardware");
const [deleteMonitor, isDeleting] = useDeleteMonitor();
const [globalSettings, globalSettingsLoading] = useFetchGlobalSettings();
const [notifications, notificationsAreLoading] = useGetNotificationsByTeamId();
@@ -91,7 +93,8 @@ const CreateInfrastructureMonitor = () => {
if (isCreate) {
if (globalSettingsLoading) return;
setHttps(false);
initializeInfrastructureMonitorForCreate(globalSettings);
const typeFromQuery = searchParams.get("type") || "hardware";
initializeInfrastructureMonitorForCreate(globalSettings, typeFromQuery);
} else if (monitor) {
setHttps(monitor.url.startsWith("https"));
initializeInfrastructureMonitorForUpdate(monitor);
@@ -101,6 +104,7 @@ const CreateInfrastructureMonitor = () => {
monitor,
globalSettings,
globalSettingsLoading,
searchParams,
initializeInfrastructureMonitorForCreate,
initializeInfrastructureMonitorForUpdate,
]);
@@ -3,7 +3,7 @@ import { useTheme } from "@emotion/react";
import DataTable from "@/Components/v1/Table/index.jsx";
import { StatusLabel } from "@/Components/v1/Label/index.jsx";
const DockerContainersTable = ({ containers = [] }) => {
const DockerContainersTable = ({ containers = [], errors = [], captureVersion }) => {
const theme = useTheme();
// Helper to format uptime
@@ -136,7 +136,22 @@ const DockerContainersTable = ({ containers = [] }) => {
},
];
// Check if there are critical errors (Docker daemon down)
const dockerClientError = errors.find((e) => e.metric && e.metric.includes("docker.client"));
if (!containers || containers.length === 0) {
// Determine the message based on error type
let message = "No containers found";
let errorDetails = null;
if (dockerClientError) {
message = "Docker daemon unavailable";
errorDetails = dockerClientError.err;
} else if (errors && errors.length > 0) {
message = "Partial data available";
errorDetails = "Some containers could not be inspected";
}
return (
<Box
sx={{
@@ -144,26 +159,66 @@ const DockerContainersTable = ({ containers = [] }) => {
textAlign: "center",
border: `1px solid ${theme.palette.divider}`,
borderRadius: theme.spacing(2),
backgroundColor: dockerClientError ? theme.palette.error.lighter : undefined,
}}
>
<Typography
variant="body1"
color="textSecondary"
color={dockerClientError ? "error.main" : "textSecondary"}
fontWeight={600}
mb={errorDetails ? theme.spacing(2) : 0}
>
No containers found
{message}
</Typography>
{errorDetails && (
<Typography
variant="body2"
color="textSecondary"
>
{errorDetails}
</Typography>
)}
{captureVersion && (
<Typography
variant="caption"
color="textSecondary"
sx={{ display: "block", marginTop: theme.spacing(4) }}
>
Capture version: {captureVersion}
</Typography>
)}
</Box>
);
}
return (
<Stack gap={theme.spacing(4)}>
<Typography
variant="h3"
fontWeight={600}
>
Docker Containers ({containers.length})
</Typography>
<Box>
<Typography
variant="h3"
fontWeight={600}
>
Docker Containers ({containers.length})
</Typography>
{errors && errors.length > 0 && (
<Typography
variant="caption"
color="warning.main"
sx={{ display: "block", marginTop: theme.spacing(1) }}
>
⚠ {errors.length} error(s) encountered while fetching container data
</Typography>
)}
{captureVersion && (
<Typography
variant="caption"
color="textSecondary"
sx={{ display: "block", marginTop: theme.spacing(1) }}
>
Capture version: {captureVersion}
</Typography>
)}
</Box>
<DataTable
headers={headers}
data={containers}
@@ -114,6 +114,8 @@ const InfrastructureDetails = () => {
/>
<DockerContainersTable
containers={monitor?.stats?.aggregateData?.latestCheck?.docker || []}
errors={monitor?.stats?.aggregateData?.latestCheck?.errors || []}
captureVersion={monitor?.stats?.aggregateData?.latestCheck?.capture?.version}
/>
</>
)}
@@ -115,7 +115,7 @@ const InfrastructureMonitors = () => {
isLoading={isLoading}
items={monitors}
type="infrastructureMonitor"
fallbackLink="/infrastructure/create"
fallbackLink="/infrastructure/create?type=hardware"
>
<Stack gap={theme.spacing(10)}>
<Stack direction={"row"}>
@@ -161,7 +161,7 @@ const InfrastructureMonitors = () => {
isLoading={isLoading}
items={monitors}
type="infrastructureMonitor"
fallbackLink="/infrastructure/create"
fallbackLink="/infrastructure/create?type=docker"
>
<Stack gap={theme.spacing(10)}>
<Stack direction={"row"}>