Skip to content

Conversation

@santoshp210-akamai
Copy link
Contributor

@santoshp210-akamai santoshp210-akamai commented Mar 18, 2025

Description 📝

Handling multiple error messages from API and displaying it in the form accordingly.

Changes 🔄

  • Introduced a new component AlertListNoticeMessages.tsx
  • Added a util method handleMultipleError to handle the error map logic
  • Added the AlertListNoticeMessages component in AddChannelListing & MetricCriteria components
  • Modified the handleSubmit method in Create and Edit flow to include the error handling
  • Relevant tests for the components and util methods

Target release date 🗓️

08/04/2025

Preview 📷

UX Mockups Local
image image
image image

How to test 🧪

Prerequisites

(How to setup test environment)

  • In serverHandler.ts use the given snippet below as the return response for either
    http.post('*/monitor/services/:service_type/alert-definitions') request
    or
    http.put('*/monitor/services/:serviceType/alert-definitions/:id') request
return HttpResponse.json(
      {
        errors: [
          { field: 'channel_ids', reason: 'Reason 1.' },
          {
            field: 'label',
            reason: 'Very long error primary message example',
          },
          {
            field: 'label',
            reason: 'Very long error secondary message example.',
          },
          {
            field: 'label',
            reason:
              'Very long error tertiary message example',
          },

          { field: 'severity', reason: 'Wrong field.' },
          { field: 'severity', reason: 'Wrong field.' },
          { reason: 'Failed.' },
          {
            field: 'rule_criteria.rules[0].aggregate_function',
            reason: 'Must be one of avg, sum, min, max, count',
          },
          {
            field: 'rule_criteria',
            reason: 'Must have at least one rule.',
          },
          {
            field: 'rule_criteria',
            reason: 'Must have at least one rule.',
          },
          {
            field: 'entity_ids', 
            reason: 'Entity_ids must be a list of string',
          },
          {
            field: 'entity_ids', 
            reason: 'Error 2',
          },
        ],
      },
      { status: 500 }
    );
  • Navigate to monitor, see the menu items displayed. They should be these 3 in the order shown - 'Metrics', 'Alerts', 'Longview'.
  • Click on Alerts, Under Alerts either Click on Create Alert or Click on Action Item for an Alert and choose Edit
  • Fill the Create or Edit Form
  • Click on submit, the errors should be visible.

Verification steps

(How to verify changes)

  • The errors for channel_ids, rule_criteria.rules should be shown in AlertListNoticeMessages component
  • The child errors for channel_ids, rule_criteria.rules should be captured shown in AlertListNoticeMessages component.
  • The AlertListNoticeMessages should show listed errors (bulleted) only when the errorMessages are multiple
  • The AlertListNoticeMessages should show single error (non-bulleted) when the errorMessages is a single string
  • The errors for other FieldValues except channel_ids, rule_criteria.rules should be displayed in the relevant errorText handlers of the components
  • The errors for other FieldValues except channel_ids, rule_criteria.rules should be concatenated if they are multiple with a space in between.
  • The errors displayed must be unique
Author Checklists

As an Author, to speed up the review process, I considered 🤔

👀 Doing a self review
❔ Our contribution guidelines
🤏 Splitting feature into small PRs
➕ Adding a changeset
🧪 Providing/improving test coverage
🔐 Removing all sensitive information from the code and PR description
🚩 Using a feature flag to protect the release
👣 Providing comprehensive reproduction steps
📑 Providing or updating our documentation
🕛 Scheduling a pair reviewing session
📱 Providing mobile support
♿ Providing accessibility support


  • I have read and considered all applicable items listed above.

As an Author, before moving this PR from Draft to Open, I confirmed ✅

  • All unit tests are passing
  • TypeScript compilation succeeded without errors
  • Code passes all linting rules

@santoshp210-akamai santoshp210-akamai marked this pull request as ready for review March 18, 2025 17:09
@santoshp210-akamai santoshp210-akamai requested a review from a team as a code owner March 18, 2025 17:09
@santoshp210-akamai santoshp210-akamai requested review from cliu-akamai and hkhalil-akamai and removed request for a team March 18, 2025 17:09
continue;
}

const errorField = error.field.split('.')[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@santoshp210-akamai , the function is good, lets add comments above each step, explaining what it does

Copy link
Contributor

@venkymano-akamai venkymano-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@santoshp210-akamai , Looks good, we can address minor comment I left

@santoshp210-akamai
Copy link
Contributor Author

santoshp210-akamai commented Mar 19, 2025

There seems to be a case that's missing from this and an existing component can be enhanced to work with new component and reduce redundancy. So converted to draft to work on it.

Fixed it.

…d the AlertListNoticeMessages to remove redundant components
@santoshp210-akamai santoshp210-akamai marked this pull request as ready for review March 24, 2025 12:52
@santoshp210-akamai santoshp210-akamai requested a review from a team as a code owner March 24, 2025 18:06
@santoshp210-akamai santoshp210-akamai requested review from dmcintyr-akamai and removed request for a team March 24, 2025 18:06
Copy link
Contributor

@pmakode-akamai pmakode-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Able to see multiple error messages for Create/Edit Alerts

Left a couple of comments. thank you!

Optional: I'm wondering if we can remove the extra top padding between the notices to match the consistent margin-bottom of 8px (seems to be the default for Notices) used elsewhere in CM. The current spacing used here looks too large.

Screenshot 2025-03-26 at 4 44 11 PM

Comment on lines 421 to 447
style={{
alignItems: 'center',
background: theme.tokens.alias.Background.Normal,
borderRadius: 1,
display: 'flex',
flexWrap: 'nowrap',
marginBottom: 0,
padding: theme.tokens.spacing.S16,
}}
errorMessage={errorText}
separator={MULTILINE_ERROR_SEPARATOR}
variant="error"
/>
</Grid>
)}
{maxSelectionCount !== undefined && (
<AlertsNoticeMessage
text={`You can select up to ${maxSelectionCount} resources.`}
variant="warning"
/>
<Grid item md={12}>
<AlertListNoticeMessages
style={{
alignItems: 'center',
background: theme.tokens.alias.Background.Normal,
borderRadius: 1,
display: 'flex',
flexWrap: 'nowrap',
marginBottom: 0,
padding: theme.tokens.spacing.S16,
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating these styles, could we define them as constant and use it here or create a styled component to avoid importing useTheme?

Comment on lines 26 to 36
<List sx={{ listStyleType: 'disc', pl: 1.5 }}>
{errorList.map((error, index) => (
<ListItem
data-testid="alert_notice_message_list"
key={index}
sx={{ display: 'list-item', pl: 0.5, py: 0.5 }}
>
{error}
</ListItem>
))}
</List>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hardcoding the values, can we use our theme.tokens.spacing.* here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-project-automation github-project-automation bot moved this from Review to Approved in Cloud Manager Mar 26, 2025
@santoshp210-akamai
Copy link
Contributor Author

santoshp210-akamai commented Mar 27, 2025

✅ Able to see multiple error messages for Create/Edit Alerts

Left a couple of comments. thank you!

Optional: I'm wondering if we can remove the extra top padding between the notices to match the consistent margin-bottom of 8px (seems to be the default for Notices) used elsewhere in CM. The current spacing used here looks too large.

Screenshot 2025-03-26 at 4 44 11 PM

Hi, @pmakode-akamai . This was intentional as the spacing aligns with our UX Mockups.

And ideally the background color for the notice should be slightly different. I have attached screenshots to show what the desired styling should look. These are the screenshots from my localhost. Can you please confirm if the changes look the same for you ?

image
image

@pmakode-akamai
Copy link
Contributor

pmakode-akamai commented Mar 27, 2025

Hi, @pmakode-akamai . This was intentional as the spacing aligns with our UX Mockups.

And ideally the background color for the notice should be slightly different. I have attached screenshots to show what the desired styling should look. These are the screenshots from my localhost. Can you please confirm if the changes look the same for you ?

Yeah, background color for the Notice looks good to me ✅
Screenshot 2025-03-27 at 4 05 39 PM

edit: All other suggestions/required fixes have been addressed async.

@jaalah-akamai jaalah-akamai added the Approved Multiple approvals and ready to merge! label Mar 27, 2025
@linode-gh-bot
Copy link
Collaborator

Cloud Manager UI test results

🎉 534 passing tests on test run #17 ↗︎

❌ Failing✅ Passing↪️ Skipped🕐 Duration
0 Failing534 Passing4 Skipped104m 52s

@venkymano-akamai venkymano-akamai merged commit 7e23502 into linode:develop Apr 1, 2025
28 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Merged in Cloud Manager Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

8 participants