Fix: Add regional_status to Service type
- Improved the regional monitoring agent assign to service type
This commit is contained in:
@@ -74,8 +74,9 @@ export function ServiceForm({
|
|||||||
urlValue = initialData.url || "";
|
urlValue = initialData.url || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle regional monitoring data - ensure proper assignment display
|
// Handle regional monitoring data - check regional_status field
|
||||||
const regionalAgent = initialData.region_name && initialData.agent_id
|
const isRegionalEnabled = initialData.regional_status === "enabled";
|
||||||
|
const regionalAgent = isRegionalEnabled && initialData.region_name && initialData.agent_id
|
||||||
? `${initialData.region_name}|${initialData.agent_id}`
|
? `${initialData.region_name}|${initialData.agent_id}`
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ export function ServiceForm({
|
|||||||
retries: String(initialData.retries || 3),
|
retries: String(initialData.retries || 3),
|
||||||
notificationChannel: initialData.notificationChannel === "none" ? "" : initialData.notificationChannel || "",
|
notificationChannel: initialData.notificationChannel === "none" ? "" : initialData.notificationChannel || "",
|
||||||
alertTemplate: initialData.alertTemplate === "default" ? "" : initialData.alertTemplate || "",
|
alertTemplate: initialData.alertTemplate === "default" ? "" : initialData.alertTemplate || "",
|
||||||
regionalMonitoringEnabled: Boolean(initialData.regional_monitoring_enabled),
|
regionalMonitoringEnabled: isRegionalEnabled,
|
||||||
regionalAgent: regionalAgent,
|
regionalAgent: regionalAgent,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -99,7 +100,8 @@ export function ServiceForm({
|
|||||||
url: urlValue,
|
url: urlValue,
|
||||||
port: portValue,
|
port: portValue,
|
||||||
regionalAgent,
|
regionalAgent,
|
||||||
regionalMonitoringEnabled: Boolean(initialData.regional_monitoring_enabled),
|
regionalMonitoringEnabled: isRegionalEnabled,
|
||||||
|
regional_status: initialData.regional_status,
|
||||||
region_name: initialData.region_name,
|
region_name: initialData.region_name,
|
||||||
agent_id: initialData.agent_id
|
agent_id: initialData.agent_id
|
||||||
});
|
});
|
||||||
@@ -118,13 +120,17 @@ export function ServiceForm({
|
|||||||
// Parse regional agent selection
|
// Parse regional agent selection
|
||||||
let regionName = "";
|
let regionName = "";
|
||||||
let agentId = "";
|
let agentId = "";
|
||||||
|
let regionalStatus: "enabled" | "disabled" = "disabled";
|
||||||
|
|
||||||
// Only set region and agent if regional monitoring is enabled AND an agent is selected (not unassign)
|
// Set regional status and agent data based on form values
|
||||||
if (data.regionalMonitoringEnabled && data.regionalAgent && data.regionalAgent !== "") {
|
if (data.regionalMonitoringEnabled) {
|
||||||
|
regionalStatus = "enabled";
|
||||||
|
if (data.regionalAgent && data.regionalAgent !== "") {
|
||||||
const [parsedRegionName, parsedAgentId] = data.regionalAgent.split("|");
|
const [parsedRegionName, parsedAgentId] = data.regionalAgent.split("|");
|
||||||
regionName = parsedRegionName || "";
|
regionName = parsedRegionName || "";
|
||||||
agentId = parsedAgentId || "";
|
agentId = parsedAgentId || "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare service data with proper field mapping
|
// Prepare service data with proper field mapping
|
||||||
const serviceData = {
|
const serviceData = {
|
||||||
@@ -134,8 +140,8 @@ export function ServiceForm({
|
|||||||
retries: parseInt(data.retries),
|
retries: parseInt(data.retries),
|
||||||
notificationChannel: data.notificationChannel === "none" ? "" : data.notificationChannel,
|
notificationChannel: data.notificationChannel === "none" ? "" : data.notificationChannel,
|
||||||
alertTemplate: data.alertTemplate === "default" ? "" : data.alertTemplate,
|
alertTemplate: data.alertTemplate === "default" ? "" : data.alertTemplate,
|
||||||
regionalMonitoringEnabled: data.regionalMonitoringEnabled || false,
|
// Use regional_status field instead of regionalMonitoringEnabled
|
||||||
// Always set region_name and agent_id - empty strings when unassigned
|
regionalStatus: regionalStatus,
|
||||||
regionName: regionName,
|
regionName: regionName,
|
||||||
agentId: agentId,
|
agentId: agentId,
|
||||||
// Map the URL field to appropriate database field based on service type
|
// Map the URL field to appropriate database field based on service type
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ export function ServiceRegionalFields({ form }: ServiceRegionalFieldsProps) {
|
|||||||
enabled: regionalMonitoringEnabled,
|
enabled: regionalMonitoringEnabled,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Filter only online agents
|
// Filter only online agents and exclude the default localhost agent (ID 1)
|
||||||
const onlineAgents = regionalAgents.filter(agent => agent.connection === 'online');
|
const onlineAgents = regionalAgents.filter(agent =>
|
||||||
|
agent.connection === 'online' && agent.agent_id !== "1"
|
||||||
|
);
|
||||||
|
|
||||||
// Find the current agent name for display
|
// Find the current agent name for display
|
||||||
const getCurrentAgentDisplay = () => {
|
const getCurrentAgentDisplay = () => {
|
||||||
@@ -31,7 +33,7 @@ export function ServiceRegionalFields({ form }: ServiceRegionalFieldsProps) {
|
|||||||
return "Select a regional agent or unassign";
|
return "Select a regional agent or unassign";
|
||||||
}
|
}
|
||||||
|
|
||||||
const [regionName] = currentRegionalAgent.split("|");
|
const [regionName, agentId] = currentRegionalAgent.split("|");
|
||||||
const agent = onlineAgents.find(agent =>
|
const agent = onlineAgents.find(agent =>
|
||||||
`${agent.region_name}|${agent.agent_id}` === currentRegionalAgent
|
`${agent.region_name}|${agent.agent_id}` === currentRegionalAgent
|
||||||
);
|
);
|
||||||
@@ -41,7 +43,25 @@ export function ServiceRegionalFields({ form }: ServiceRegionalFieldsProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If agent is not found in online agents, it might be offline but still assigned
|
// If agent is not found in online agents, it might be offline but still assigned
|
||||||
return regionName || "Select a regional agent or unassign";
|
// Show the region name from the stored value
|
||||||
|
if (regionName && agentId) {
|
||||||
|
return `${regionName} (Agent ${agentId}) - Offline`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Select a regional agent or unassign";
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the proper select value - handle both assigned and unassigned cases
|
||||||
|
const getSelectValue = () => {
|
||||||
|
if (!regionalMonitoringEnabled) {
|
||||||
|
return "unassign";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!currentRegionalAgent || currentRegionalAgent === "") {
|
||||||
|
return "unassign";
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentRegionalAgent;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -82,7 +102,7 @@ export function ServiceRegionalFields({ form }: ServiceRegionalFieldsProps) {
|
|||||||
// Handle the unassign case by setting to empty string
|
// Handle the unassign case by setting to empty string
|
||||||
field.onChange(value === "unassign" ? "" : value);
|
field.onChange(value === "unassign" ? "" : value);
|
||||||
}}
|
}}
|
||||||
value={field.value || "unassign"}
|
value={getSelectValue()}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
>
|
>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
@@ -135,12 +155,12 @@ export function ServiceRegionalFields({ form }: ServiceRegionalFieldsProps) {
|
|||||||
No online regional agents found. Services will use default monitoring.
|
No online regional agents found. Services will use default monitoring.
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
{currentRegionalAgent && currentRegionalAgent !== "" && currentRegionalAgent !== "unassign" && (
|
{currentRegionalAgent && currentRegionalAgent !== "" && (
|
||||||
<p className="text-sm text-green-600">
|
<p className="text-sm text-green-600">
|
||||||
Currently assigned to: {getCurrentAgentDisplay()}
|
Currently assigned to: {getCurrentAgentDisplay()}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
{(!currentRegionalAgent || currentRegionalAgent === "" || currentRegionalAgent === "unassign") && (
|
{(!currentRegionalAgent || currentRegionalAgent === "") && regionalMonitoringEnabled && (
|
||||||
<p className="text-sm text-orange-600">
|
<p className="text-sm text-orange-600">
|
||||||
Service is unassigned and will use default monitoring.
|
Service is unassigned and will use default monitoring.
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -32,10 +32,11 @@ export const serviceService = {
|
|||||||
muteAlerts: item.alerts === "muted", // Convert string to boolean for compatibility
|
muteAlerts: item.alerts === "muted", // Convert string to boolean for compatibility
|
||||||
alerts: item.alerts || "unmuted", // Store actual database field
|
alerts: item.alerts || "unmuted", // Store actual database field
|
||||||
muteChangedAt: item.mute_changed_at,
|
muteChangedAt: item.mute_changed_at,
|
||||||
// Regional monitoring fields
|
// Regional monitoring fields - use regional_status
|
||||||
region_name: item.region_name || "",
|
region_name: item.region_name || "",
|
||||||
agent_id: item.agent_id || "",
|
agent_id: item.agent_id || "",
|
||||||
regional_monitoring_enabled: item.regional_monitoring_enabled || false,
|
regional_status: item.regional_status || "disabled",
|
||||||
|
regional_monitoring_enabled: item.regional_status === "enabled", // Backward compatibility
|
||||||
}));
|
}));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching services:", error);
|
console.error("Error fetching services:", error);
|
||||||
@@ -62,8 +63,8 @@ export const serviceService = {
|
|||||||
max_retries: params.retries,
|
max_retries: params.retries,
|
||||||
notification_id: params.notificationChannel,
|
notification_id: params.notificationChannel,
|
||||||
template_id: params.alertTemplate,
|
template_id: params.alertTemplate,
|
||||||
// Regional monitoring fields
|
// Regional monitoring fields - use regional_status
|
||||||
regional_monitoring_enabled: params.regionalMonitoringEnabled || false,
|
regional_status: params.regionalStatus || "disabled",
|
||||||
region_name: params.regionName || "",
|
region_name: params.regionName || "",
|
||||||
agent_id: params.agentId || "",
|
agent_id: params.agentId || "",
|
||||||
// Conditionally add fields based on service type
|
// Conditionally add fields based on service type
|
||||||
@@ -98,7 +99,8 @@ export const serviceService = {
|
|||||||
retries: record.max_retries || 3,
|
retries: record.max_retries || 3,
|
||||||
notificationChannel: record.notification_id,
|
notificationChannel: record.notification_id,
|
||||||
alertTemplate: record.template_id,
|
alertTemplate: record.template_id,
|
||||||
regional_monitoring_enabled: record.regional_monitoring_enabled || false,
|
regional_status: record.regional_status || "disabled",
|
||||||
|
regional_monitoring_enabled: record.regional_status === "enabled",
|
||||||
region_name: record.region_name || "",
|
region_name: record.region_name || "",
|
||||||
agent_id: record.agent_id || "",
|
agent_id: record.agent_id || "",
|
||||||
} as Service;
|
} as Service;
|
||||||
@@ -128,8 +130,8 @@ export const serviceService = {
|
|||||||
max_retries: params.retries,
|
max_retries: params.retries,
|
||||||
notification_id: params.notificationChannel || null,
|
notification_id: params.notificationChannel || null,
|
||||||
template_id: params.alertTemplate || null,
|
template_id: params.alertTemplate || null,
|
||||||
// Regional monitoring fields
|
// Regional monitoring fields - use regional_status
|
||||||
regional_monitoring_enabled: params.regionalMonitoringEnabled || false,
|
regional_status: params.regionalStatus || "disabled",
|
||||||
region_name: params.regionName || "",
|
region_name: params.regionName || "",
|
||||||
agent_id: params.agentId || "",
|
agent_id: params.agentId || "",
|
||||||
// Conditionally update fields based on service type
|
// Conditionally update fields based on service type
|
||||||
@@ -171,7 +173,8 @@ export const serviceService = {
|
|||||||
retries: record.max_retries || 3,
|
retries: record.max_retries || 3,
|
||||||
notificationChannel: record.notification_id,
|
notificationChannel: record.notification_id,
|
||||||
alertTemplate: record.template_id,
|
alertTemplate: record.template_id,
|
||||||
regional_monitoring_enabled: record.regional_monitoring_enabled || false,
|
regional_status: record.regional_status || "disabled",
|
||||||
|
regional_monitoring_enabled: record.regional_status === "enabled",
|
||||||
region_name: record.region_name || "",
|
region_name: record.region_name || "",
|
||||||
agent_id: record.agent_id || "",
|
agent_id: record.agent_id || "",
|
||||||
} as Service;
|
} as Service;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export interface Service {
|
|||||||
// Regional monitoring fields
|
// Regional monitoring fields
|
||||||
region_name?: string;
|
region_name?: string;
|
||||||
agent_id?: string;
|
agent_id?: string;
|
||||||
|
regional_status?: "enabled" | "disabled"; // Add regional_status field
|
||||||
regional_monitoring_enabled?: boolean;
|
regional_monitoring_enabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ export interface CreateServiceParams {
|
|||||||
alertTemplate?: string;
|
alertTemplate?: string;
|
||||||
// Regional monitoring params
|
// Regional monitoring params
|
||||||
regionalMonitoringEnabled?: boolean;
|
regionalMonitoringEnabled?: boolean;
|
||||||
|
regionalStatus?: "enabled" | "disabled"; // Add regionalStatus field
|
||||||
regionName?: string;
|
regionName?: string;
|
||||||
agentId?: string;
|
agentId?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user