From 3e43a5f50e025af0b1188388cb91eaec0060ba5a Mon Sep 17 00:00:00 2001 From: OpenShift Cherrypick Robot Date: Wed, 10 Jul 2024 16:51:16 +0200 Subject: [PATCH] [redhat-3.12] ui: fix for negative integers in image expiry days (PROJQUAY-7442) (#3014) ui: fix for negative integers in image expiry days (PROJQUAY-7442) Co-authored-by: Sunandadadi --- web/cypress/e2e/repository-notifications.cy.ts | 16 ++++++++++++++++ .../Settings/NotificationsCreateNotification.tsx | 2 +- .../Settings/RepoEventExpiry.tsx | 11 ++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/web/cypress/e2e/repository-notifications.cy.ts b/web/cypress/e2e/repository-notifications.cy.ts index 2886051c1..d1907aa41 100644 --- a/web/cypress/e2e/repository-notifications.cy.ts +++ b/web/cypress/e2e/repository-notifications.cy.ts @@ -398,4 +398,20 @@ describe('Repository Settings - Notifications', () => { cy.get(`[data-label="status"]`).should('have.text', 'Enabled'); }); }); + + it('Incorrect form for repo image expiry notification', () => { + cy.contains('Create notification').click(); + cy.get('#create-notification-form').within(() => { + cy.contains('Select event').click(); + cy.contains('Image expiry trigger').click(); + cy.get('#days-to-image-expiry').type('-5'); + cy.contains('Select method').click(); + cy.contains('Slack Notification').click(); + cy.get('#slack-webhook-url-field').type( + 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX', + ); + cy.get('#notification-title').type('image expiry notification'); + cy.contains('button', 'Submit').should('be.disabled'); + }); + }); }); diff --git a/web/src/routes/RepositoryDetails/Settings/NotificationsCreateNotification.tsx b/web/src/routes/RepositoryDetails/Settings/NotificationsCreateNotification.tsx index 7a1291446..00710af84 100644 --- a/web/src/routes/RepositoryDetails/Settings/NotificationsCreateNotification.tsx +++ b/web/src/routes/RepositoryDetails/Settings/NotificationsCreateNotification.tsx @@ -46,7 +46,7 @@ export default function CreateNotification(props: CreateNotificationProps) { const isValidateConfig = () => { if (event?.type == NotificationEventType.imageExpiry) { - return eventConfig?.days != undefined; + return eventConfig?.days != undefined && eventConfig?.days > 0; } return true; }; diff --git a/web/src/routes/RepositoryDetails/Settings/RepoEventExpiry.tsx b/web/src/routes/RepositoryDetails/Settings/RepoEventExpiry.tsx index cb1869a5a..db7d80cf5 100644 --- a/web/src/routes/RepositoryDetails/Settings/RepoEventExpiry.tsx +++ b/web/src/routes/RepositoryDetails/Settings/RepoEventExpiry.tsx @@ -1,9 +1,17 @@ -import {FormGroup, TextInput} from '@patternfly/react-core'; +import {FormGroup, TextInput, ValidatedOptions} from '@patternfly/react-core'; import {NotificationEventConfig} from 'src/hooks/UseEvents'; +import {useState} from 'react'; export default function RepoEventExpiry(props: RepoEventExpiryProps) { + const [valid, setValid] = useState(ValidatedOptions.default); + const onChange = (_event, value) => { props.setEventConfig({days: Number(value)}); + if (value < 1) { + setValid(ValidatedOptions.error); + } else { + setValid(ValidatedOptions.success); + } }; return ( @@ -18,6 +26,7 @@ export default function RepoEventExpiry(props: RepoEventExpiryProps) { type={'number'} id="days-to-image-expiry" required + validated={valid} /> );