fix logger import
This commit is contained in:
@@ -11,21 +11,36 @@
|
||||
-->
|
||||
<script>
|
||||
/** @type {{ policy: any, environments: any[], onSave: (p: any) => void, onCancel: () => void }} */
|
||||
let { policy = {}, environments = [], onSave, onCancel } = $props();
|
||||
let { policy = null, environments = [], onSave, onCancel } = $props();
|
||||
|
||||
let formData = $state({
|
||||
name: policy.name || '',
|
||||
environment_id: policy.environment_id || (environments[0]?.id || ''),
|
||||
dashboard_ids: policy.dashboard_ids || [],
|
||||
schedule_days: policy.schedule_days || [1, 2, 3, 4, 5], // Default Mon-Fri
|
||||
window_start: policy.window_start || '01:00',
|
||||
window_end: policy.window_end || '05:00',
|
||||
notify_owners: policy.notify_owners ?? true,
|
||||
alert_condition: policy.alert_condition || 'FAIL_ONLY'
|
||||
});
|
||||
function getSafePolicy() {
|
||||
return policy && typeof policy === 'object' ? policy : {};
|
||||
}
|
||||
|
||||
function getSafeEnvironments() {
|
||||
return Array.isArray(environments) ? environments : [];
|
||||
}
|
||||
|
||||
function buildFormData(currentPolicy, currentEnvironments) {
|
||||
return {
|
||||
name: currentPolicy.name || '',
|
||||
environment_id: currentPolicy.environment_id || (currentEnvironments[0]?.id || ''),
|
||||
dashboard_ids: Array.isArray(currentPolicy.dashboard_ids) ? currentPolicy.dashboard_ids : [],
|
||||
schedule_days: Array.isArray(currentPolicy.schedule_days) ? currentPolicy.schedule_days : [1, 2, 3, 4, 5], // Default Mon-Fri
|
||||
window_start: currentPolicy.window_start || '01:00',
|
||||
window_end: currentPolicy.window_end || '05:00',
|
||||
notify_owners: currentPolicy.notify_owners ?? true,
|
||||
alert_condition: currentPolicy.alert_condition || 'FAIL_ONLY'
|
||||
};
|
||||
}
|
||||
|
||||
let formData = $state(buildFormData({}, []));
|
||||
let isSubmitting = $state(false);
|
||||
|
||||
$effect(() => {
|
||||
formData = buildFormData(getSafePolicy(), getSafeEnvironments());
|
||||
});
|
||||
|
||||
const days = [
|
||||
{ id: 0, label: 'Sun' },
|
||||
{ id: 1, label: 'Mon' },
|
||||
@@ -88,14 +103,14 @@
|
||||
<select id="env" bind:value={formData.environment_id}
|
||||
class="mt-1 block w-full border-gray-300 dark:border-gray-600 dark:bg-gray-700 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
|
||||
disabled={isSubmitting}>
|
||||
{#each environments as env}
|
||||
{#each getSafeEnvironments() as env}
|
||||
<option value={env.id}>{env.name || env.id}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Schedule Days</label>
|
||||
<span class="block text-sm font-medium text-gray-700 dark:text-gray-300">Schedule Days</span>
|
||||
<div class="mt-2 flex flex-wrap gap-2">
|
||||
{#each days as day}
|
||||
<button type="button"
|
||||
|
||||
@@ -36,6 +36,47 @@
|
||||
getValidationPolicies(),
|
||||
getEnvironments()
|
||||
]);
|
||||
|
||||
const policyArray = Array.isArray(policiesData) ? policiesData : [];
|
||||
const environmentArray = Array.isArray(envsData) ? envsData : [];
|
||||
|
||||
const invalidPolicies = policyArray
|
||||
.map((policy, index) => ({ index, policy }))
|
||||
.filter(({ policy }) => !policy || typeof policy !== 'object');
|
||||
const policiesWithMissingName = policyArray
|
||||
.map((policy, index) => ({ index, policy }))
|
||||
.filter(({ policy }) => policy && (policy.name === null || policy.name === undefined));
|
||||
|
||||
const invalidEnvironments = environmentArray
|
||||
.map((env, index) => ({ index, env }))
|
||||
.filter(({ env }) => !env || typeof env !== 'object');
|
||||
const environmentsWithMissingName = environmentArray
|
||||
.map((env, index) => ({ index, env }))
|
||||
.filter(({ env }) => env && (env.name === null || env.name === undefined));
|
||||
|
||||
console.log('[AutomationSettingsPage][Debug] Loaded payload shapes', {
|
||||
policiesCount: policyArray.length,
|
||||
environmentsCount: environmentArray.length,
|
||||
invalidPoliciesCount: invalidPolicies.length,
|
||||
policiesWithMissingNameCount: policiesWithMissingName.length,
|
||||
invalidEnvironmentsCount: invalidEnvironments.length,
|
||||
environmentsWithMissingNameCount: environmentsWithMissingName.length
|
||||
});
|
||||
|
||||
if (invalidPolicies.length > 0 || policiesWithMissingName.length > 0) {
|
||||
console.warn('[AutomationSettingsPage][Debug] Suspicious policy payload detected', {
|
||||
invalidPolicies,
|
||||
policiesWithMissingName
|
||||
});
|
||||
}
|
||||
|
||||
if (invalidEnvironments.length > 0 || environmentsWithMissingName.length > 0) {
|
||||
console.warn('[AutomationSettingsPage][Debug] Suspicious environments payload detected', {
|
||||
invalidEnvironments,
|
||||
environmentsWithMissingName
|
||||
});
|
||||
}
|
||||
|
||||
policies = policiesData;
|
||||
environments = envsData;
|
||||
} catch (error) {
|
||||
@@ -51,6 +92,16 @@
|
||||
}
|
||||
|
||||
function handleEdit(policy) {
|
||||
if (!policy) {
|
||||
console.error('[AutomationSettingsPage][Debug] handleEdit received invalid policy', { policy });
|
||||
return;
|
||||
}
|
||||
console.log('[AutomationSettingsPage][Debug] handleEdit policy snapshot', {
|
||||
id: policy.id,
|
||||
name: policy.name,
|
||||
environment_id: policy.environment_id,
|
||||
dashboard_ids_type: Array.isArray(policy.dashboard_ids) ? 'array' : typeof policy.dashboard_ids
|
||||
});
|
||||
selectedPolicy = policy;
|
||||
showForm = true;
|
||||
}
|
||||
@@ -83,10 +134,40 @@
|
||||
}
|
||||
|
||||
function getEnvName(id) {
|
||||
return environments.find(e => e.id === id)?.name || id;
|
||||
const envMatch = environments.find((e) => e?.id === id);
|
||||
if (!envMatch) {
|
||||
console.warn('[AutomationSettingsPage][Debug] Environment not found for policy environment_id', {
|
||||
requestedEnvironmentId: id,
|
||||
environmentsCount: Array.isArray(environments) ? environments.length : -1
|
||||
});
|
||||
} else if (envMatch.name === null || envMatch.name === undefined) {
|
||||
console.warn('[AutomationSettingsPage][Debug] Environment has null/undefined name', {
|
||||
requestedEnvironmentId: id,
|
||||
environment: envMatch
|
||||
});
|
||||
}
|
||||
return envMatch?.name || id;
|
||||
}
|
||||
|
||||
const dayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
|
||||
$effect(() => {
|
||||
if (isLoading) return;
|
||||
|
||||
const policiesWithNullName = (Array.isArray(policies) ? policies : []).filter(
|
||||
(policy) => policy && (policy.name === null || policy.name === undefined)
|
||||
);
|
||||
const policyEntriesWithNullDashboardIds = (Array.isArray(policies) ? policies : []).filter(
|
||||
(policy) => policy && !Array.isArray(policy.dashboard_ids)
|
||||
);
|
||||
|
||||
if (policiesWithNullName.length > 0 || policyEntriesWithNullDashboardIds.length > 0) {
|
||||
console.warn('[AutomationSettingsPage][Debug] Render-time suspicious policy data detected', {
|
||||
policiesWithNullName,
|
||||
policyEntriesWithNullDashboardIds
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="container mx-auto p-6 max-w-5xl">
|
||||
|
||||
Reference in New Issue
Block a user