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"
|
||||
|
||||
Reference in New Issue
Block a user