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 || "";
|
||||
}
|
||||
|
||||
// Handle regional monitoring data - ensure proper assignment display
|
||||
const regionalAgent = initialData.region_name && initialData.agent_id
|
||||
// Handle regional monitoring data - check regional_status field
|
||||
const isRegionalEnabled = initialData.regional_status === "enabled";
|
||||
const regionalAgent = isRegionalEnabled && initialData.region_name && initialData.agent_id
|
||||
? `${initialData.region_name}|${initialData.agent_id}`
|
||||
: "";
|
||||
|
||||
@@ -89,7 +90,7 @@ export function ServiceForm({
|
||||
retries: String(initialData.retries || 3),
|
||||
notificationChannel: initialData.notificationChannel === "none" ? "" : initialData.notificationChannel || "",
|
||||
alertTemplate: initialData.alertTemplate === "default" ? "" : initialData.alertTemplate || "",
|
||||
regionalMonitoringEnabled: Boolean(initialData.regional_monitoring_enabled),
|
||||
regionalMonitoringEnabled: isRegionalEnabled,
|
||||
regionalAgent: regionalAgent,
|
||||
});
|
||||
|
||||
@@ -99,7 +100,8 @@ export function ServiceForm({
|
||||
url: urlValue,
|
||||
port: portValue,
|
||||
regionalAgent,
|
||||
regionalMonitoringEnabled: Boolean(initialData.regional_monitoring_enabled),
|
||||
regionalMonitoringEnabled: isRegionalEnabled,
|
||||
regional_status: initialData.regional_status,
|
||||
region_name: initialData.region_name,
|
||||
agent_id: initialData.agent_id
|
||||
});
|
||||
@@ -118,12 +120,16 @@ export function ServiceForm({
|
||||
// Parse regional agent selection
|
||||
let regionName = "";
|
||||
let agentId = "";
|
||||
let regionalStatus: "enabled" | "disabled" = "disabled";
|
||||
|
||||
// Only set region and agent if regional monitoring is enabled AND an agent is selected (not unassign)
|
||||
if (data.regionalMonitoringEnabled && data.regionalAgent && data.regionalAgent !== "") {
|
||||
const [parsedRegionName, parsedAgentId] = data.regionalAgent.split("|");
|
||||
regionName = parsedRegionName || "";
|
||||
agentId = parsedAgentId || "";
|
||||
// Set regional status and agent data based on form values
|
||||
if (data.regionalMonitoringEnabled) {
|
||||
regionalStatus = "enabled";
|
||||
if (data.regionalAgent && data.regionalAgent !== "") {
|
||||
const [parsedRegionName, parsedAgentId] = data.regionalAgent.split("|");
|
||||
regionName = parsedRegionName || "";
|
||||
agentId = parsedAgentId || "";
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare service data with proper field mapping
|
||||
@@ -134,8 +140,8 @@ export function ServiceForm({
|
||||
retries: parseInt(data.retries),
|
||||
notificationChannel: data.notificationChannel === "none" ? "" : data.notificationChannel,
|
||||
alertTemplate: data.alertTemplate === "default" ? "" : data.alertTemplate,
|
||||
regionalMonitoringEnabled: data.regionalMonitoringEnabled || false,
|
||||
// Always set region_name and agent_id - empty strings when unassigned
|
||||
// Use regional_status field instead of regionalMonitoringEnabled
|
||||
regionalStatus: regionalStatus,
|
||||
regionName: regionName,
|
||||
agentId: agentId,
|
||||
// Map the URL field to appropriate database field based on service type
|
||||
|
||||
@@ -22,8 +22,10 @@ export function ServiceRegionalFields({ form }: ServiceRegionalFieldsProps) {
|
||||
enabled: regionalMonitoringEnabled,
|
||||
});
|
||||
|
||||
// Filter only online agents
|
||||
const onlineAgents = regionalAgents.filter(agent => agent.connection === 'online');
|
||||
// Filter only online agents and exclude the default localhost agent (ID 1)
|
||||
const onlineAgents = regionalAgents.filter(agent =>
|
||||
agent.connection === 'online' && agent.agent_id !== "1"
|
||||
);
|
||||
|
||||
// Find the current agent name for display
|
||||
const getCurrentAgentDisplay = () => {
|
||||
@@ -31,7 +33,7 @@ export function ServiceRegionalFields({ form }: ServiceRegionalFieldsProps) {
|
||||
return "Select a regional agent or unassign";
|
||||
}
|
||||
|
||||
const [regionName] = currentRegionalAgent.split("|");
|
||||
const [regionName, agentId] = currentRegionalAgent.split("|");
|
||||
const agent = onlineAgents.find(agent =>
|
||||
`${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
|
||||
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 (
|
||||
@@ -82,7 +102,7 @@ export function ServiceRegionalFields({ form }: ServiceRegionalFieldsProps) {
|
||||
// Handle the unassign case by setting to empty string
|
||||
field.onChange(value === "unassign" ? "" : value);
|
||||
}}
|
||||
value={field.value || "unassign"}
|
||||
value={getSelectValue()}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<FormControl>
|
||||
@@ -135,12 +155,12 @@ export function ServiceRegionalFields({ form }: ServiceRegionalFieldsProps) {
|
||||
No online regional agents found. Services will use default monitoring.
|
||||
</p>
|
||||
)}
|
||||
{currentRegionalAgent && currentRegionalAgent !== "" && currentRegionalAgent !== "unassign" && (
|
||||
{currentRegionalAgent && currentRegionalAgent !== "" && (
|
||||
<p className="text-sm text-green-600">
|
||||
Currently assigned to: {getCurrentAgentDisplay()}
|
||||
</p>
|
||||
)}
|
||||
{(!currentRegionalAgent || currentRegionalAgent === "" || currentRegionalAgent === "unassign") && (
|
||||
{(!currentRegionalAgent || currentRegionalAgent === "") && regionalMonitoringEnabled && (
|
||||
<p className="text-sm text-orange-600">
|
||||
Service is unassigned and will use default monitoring.
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user