Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Stop clobbering typed input in alert Recipients textarea

rcourtman234d0bbe2868
diff --git a/frontend-modern/src/components/Alerts/EmailProviderSelect.test.tsx b/frontend-modern/src/components/Alerts/EmailProviderSelect.test.tsx
index 4106055fea..4f7a06945d 100644
--- a/frontend-modern/src/components/Alerts/EmailProviderSelect.test.tsx
+++ b/frontend-modern/src/components/Alerts/EmailProviderSelect.test.tsx
@@ -341,7 +341,7 @@ describe('EmailProviderSelect', () => {
expect(onChangeMock).toHaveBeenCalledWith(expect.objectContaining({ username: '[email protected]' }));
});
- it('parses recipients textarea into array', async () => {
+ it('splits recipients textarea into one entry per line, preserving raw text', async () => {
render(() => (
<EmailProviderSelect
config={makeConfig({ to: [] })}
@@ -356,17 +356,20 @@ describe('EmailProviderSelect', () => {
});
+ // Raw lines pass through during edit — whitespace and empty lines are
+ // preserved so the textarea cursor doesn't fight the user. Cleanup
+ // happens in buildEmailConfigPayload at save.
expect(onChangeMock).toHaveBeenCalledWith(
expect.objectContaining({
}),
);
});
- it('filters empty lines from recipients', async () => {
+ it('keeps a trailing empty line while the user is mid-type (regression for #1462)', async () => {
render(() => (
<EmailProviderSelect
- config={makeConfig({ to: [] })}
+ config={makeConfig({ to: ['[email protected]'] })}
onChange={onChangeMock}
onTest={onTestMock}
/>
@@ -374,11 +377,14 @@ describe('EmailProviderSelect', () => {
const textarea = document.querySelector('textarea') as HTMLTextAreaElement;
expect(textarea).toBeTruthy();
- fireEvent.input(textarea, {
- target: { value: '\n\n \n' },
- });
- expect(onChangeMock).toHaveBeenCalledWith(expect.objectContaining({ to: [] }));
+ // Simulates pressing Enter at the end of line 1 — previously filtered out,
+ // which made line 2 impossible to type into.
+ fireEvent.input(textarea, { target: { value: '[email protected]\n' } });
+
+ expect(onChangeMock).toHaveBeenCalledWith(
+ expect.objectContaining({ to: ['[email protected]', ''] }),
+ );
});
// --- Advanced Options ---
diff --git a/frontend-modern/src/components/Alerts/EmailProviderSelect.tsx b/frontend-modern/src/components/Alerts/EmailProviderSelect.tsx
index 5ff73e2bdd..9e041a0e45 100644
--- a/frontend-modern/src/components/Alerts/EmailProviderSelect.tsx
+++ b/frontend-modern/src/components/Alerts/EmailProviderSelect.tsx
@@ -188,11 +188,11 @@ export function EmailProviderSelect(props: EmailProviderSelectProps) {
<textarea
value={props.config.to.join('\n')}
onInput={(e) => {
- const recipients = e.currentTarget.value
- .split('\n')
- .map((entry) => entry.trim())
- .filter((entry) => entry.length > 0);
- props.onChange({ ...props.config, to: recipients });
+ // Keep raw lines while editing — trimming/filtering on every
+ // keystroke ate empty trailing lines and stripped typed
+ // whitespace, so users couldn't type past line 1. Empty
+ // entries are filtered in buildEmailConfigPayload at save.
+ props.onChange({ ...props.config, to: e.currentTarget.value.split('\n') });
}}
onKeyDown={(e) => {
if (e.key === 'Enter') {
diff --git a/frontend-modern/src/features/alerts/__tests__/alertDestinationsModel.test.ts b/frontend-modern/src/features/alerts/__tests__/alertDestinationsModel.test.ts
index 9845db1345..5bf1a31ba7 100644
--- a/frontend-modern/src/features/alerts/__tests__/alertDestinationsModel.test.ts
+++ b/frontend-modern/src/features/alerts/__tests__/alertDestinationsModel.test.ts
@@ -27,6 +27,29 @@ describe('alertDestinationsModel', () => {
);
});
+ it('trims and drops empty recipient lines when building the email payload', () => {
+ expect(
+ buildEmailConfigPayload({
+ enabled: true,
+ provider: 'smtp',
+ server: 'smtp.internal',
+ port: 587,
+ username: '[email protected]',
+ password: '',
+ // Raw lines as they would be while the user is mid-edit in the
+ // textarea — whitespace, empties, trailing newline.
+ to: ['[email protected]', '', ' [email protected] ', ''],
+ tls: true,
+ startTLS: true,
+ replyTo: '',
+ maxRetries: 3,
+ retryDelay: 60,
+ rateLimit: 0,
+ }).to,
+ });
+
it('builds outbound email and apprise payloads from UI state', () => {
expect(
buildEmailConfigPayload({
diff --git a/frontend-modern/src/features/alerts/alertDestinationsModel.ts b/frontend-modern/src/features/alerts/alertDestinationsModel.ts
index 4fed03249d..7d8d165396 100644
--- a/frontend-modern/src/features/alerts/alertDestinationsModel.ts
+++ b/frontend-modern/src/features/alerts/alertDestinationsModel.ts
@@ -36,7 +36,7 @@ export function buildEmailConfigPayload(config: UIEmailConfig): EmailConfig {
username: config.username,
password: config.password,
from: config.from,
- to: config.to,
+ to: config.to.map((entry) => entry.trim()).filter((entry) => entry.length > 0),
tls: config.tls,
startTLS: config.startTLS,
} as EmailConfig;