From f18a61f7a23fa816d7eaac68eaa33a8df5c21584 Mon Sep 17 00:00:00 2001 From: Alexander Petric Date: Thu, 24 Oct 2024 16:58:39 -0400 Subject: [PATCH] ux: job queue critical alert settings ux improvements (#4577) * improving the ux of queued jobs alert settings * minor improvements * removing name column --- .../lib/components/QueueMetricsDrawer.svelte | 95 +++++++++++-------- 1 file changed, 58 insertions(+), 37 deletions(-) diff --git a/frontend/src/lib/components/QueueMetricsDrawer.svelte b/frontend/src/lib/components/QueueMetricsDrawer.svelte index 92e9faf4b1..a75caf5ff9 100644 --- a/frontend/src/lib/components/QueueMetricsDrawer.svelte +++ b/frontend/src/lib/components/QueueMetricsDrawer.svelte @@ -9,6 +9,18 @@ import Tooltip from './Tooltip.svelte' import { enterpriseLicense } from '$lib/stores' + function updateChangesMade() { + changesMade = JSON.stringify(alerts) !== JSON.stringify(originalAlerts) + } + + function handleInput(event) { + const target = event.target + console.log(target) + if (target.tagName.toLowerCase() === 'input') { + updateChangesMade() + } + } + type Alert = { name: string tags_to_monitor: string[] @@ -70,16 +82,20 @@ } function startEditing(index) { + if (editingIndex !== -1) { + const success = saveAlert(editingIndex) + if (!success) return + } editingIndex = index updateWorkerTags() } - function saveAlert(index) { + function saveAlert(index): boolean { const newAlert = alerts[index] if (newAlert.tags_to_monitor.length === 0) { sendUserToast('Please add at least one tag before saving.', true) - return + return false } if ( @@ -88,7 +104,7 @@ newAlert.alert_time_threshold_seconds <= 0 ) { sendUserToast('All numeric values must be strictly positive.', true) - return + return false } const alertExists = originalAlerts.some( @@ -99,13 +115,15 @@ ) if (alertExists) { - sendUserToast('An identical alert already exists.', true) - return + sendUserToast('You can only define one alert per identical set of tags', true) + return false } editingIndex = -1 - changesMade = JSON.stringify(alerts) !== JSON.stringify(originalAlerts) + updateChangesMade() + stagedNewAlert = false + return true } function stageDeleteAlert(index) { @@ -126,16 +144,18 @@ } newTag = '' filteredTags = [] + updateChangesMade() } function removeTag(alertIndex, tag) { alerts[alertIndex].tags_to_monitor = alerts[alertIndex].tags_to_monitor.filter((t) => t !== tag) + updateChangesMade() } async function applyConfig() { - if (stagedNewAlert) { - sendUserToast('New alert staged. Please save or cancel the changes before applying.', true) - return + if (editingIndex !== -1) { + const success = saveAlert(editingIndex) + if (!success) return } try { @@ -146,6 +166,7 @@ removedAlerts = [] changesMade = false stagedNewAlert = false + editingIndex = -1 } catch (error) { console.error('Failed to update config:', error) } @@ -167,7 +188,7 @@ } const newAlert = { - name: 'New Alert', + name: 'Job Queue Alert', tags_to_monitor: [], jobs_num_threshold: 3, alert_cooldown_seconds: 600, @@ -177,6 +198,7 @@ alerts = [...alerts, newAlert] editingIndex = alerts.length - 1 stagedNewAlert = true + updateChangesMade() updateWorkerTags() } @@ -188,28 +210,35 @@ alerts[alertIndex].tags_to_monitor = [ ...new Set([...alerts[alertIndex].tags_to_monitor, ...workerTags]) ] - alerts = alerts // Trigger reactivity + alerts = [...alerts] + updateChangesMade() } - +
{#if $enterpriseLicense} {#if changesMade}
Non applied changes
-
- - -
{/if} +
+ + +
{#if alerts.length > 0}
@@ -217,12 +246,6 @@ - - + {#each alerts as alert, index} -
- Name - - Queue Tags to Monitor @@ -230,38 +253,31 @@ Jobs Cooldown (s) Time (s) Actions
- {#if editingIndex === index} - - {:else} - {alert.name} - {/if} - {#if editingIndex === index}
@@ -282,8 +298,9 @@ filterTags(e)} + disabled={workerTags.length === alert.tags_to_monitor.length} class="p-1 flex-grow mr-1" /> @@ -302,6 +320,7 @@ class="autocomplete-list border max-h-36 overflow-y-auto absolute z-50" > {#each filteredTags as tag} + {#if !alert.tags_to_monitor.includes(tag)}
  • + {/if} {/each} {/if} @@ -401,6 +421,7 @@

    {/if} +

    Queue Metrics