Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upcoming: [DI-23769] - multiple error handling #11874

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from

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 🗓️

Please specify a release date (and environment, if applicable) to guarantee timely review of this PR. If exact date is not known, please approximate and update it as needed.

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 with no full stop',
          },
          {
            field: 'label',
            reason: 'Very long error secondary message example.',
          },
          {
            field: 'label',
            reason:
              'Very long error tertiary message example with no full stop',
          },

          { 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 and no full stop',
          },
          {
            field: 'rule_criteria',
            reason: 'Must have at least one rule.',
          },
          {
            field: 'rule_criteria',
            reason: 'Must have at least one rule.',
          },
        ],
      },
      { 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 hkhalil-akamai and cliu-akamai and removed request for a team March 18, 2025 17:09
</AlertNoticeErrorState>
);
} else {
return (
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 , I think we don't need else, we can just return here, lets remove this branching

Comment on lines +347 to +351
errors: APIError[],
errorFieldMap: Record<string, FieldPath<T>>,
multiLineErrorSeparator: string,
singleLineErrorSeparator: string,
setError: UseFormSetError<T>
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this has more than 2 arguments, better to have it in interface

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

const { queryAllByTestId, queryByTestId } = renderWithTheme(
<AlertListNoticeMessages
errorMessage={errorMessage}
separator={''}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
separator={''}
separator=""

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

fontFamily: theme.tokens.typography.Body.Bold,
})}
data-testid="alert_message_notice"
variant="body2"
Copy link
Contributor

@ankita-akamai ankita-akamai Mar 19, 2025

Choose a reason for hiding this comment

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

optional: remove this

Suggested change
variant="body2"

Comment on lines +136 to +139
if (rootError) {
enqueueSnackbar(`Creating alert failed: ${rootError.reason}`, {
variant: 'error',
});
Copy link
Contributor

Choose a reason for hiding this comment

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

we had a fallback err msg from ui for enable/disable error handling, but we don't have it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the fall back message, for fields we are handling manually everywhere. But if no fields are given, we show in snackbar.

Copy link
Contributor

Choose a reason for hiding this comment

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

still the reason is from api, cc: @venkymano-akamai

@linode-gh-bot
Copy link
Collaborator

Cloud Manager UI test results

🔺 1 failing test on test run #5 ↗︎

❌ Failing✅ Passing↪️ Skipped🕐 Duration
1 Failing538 Passing3 Skipped115m 47s

Details

Failing Tests
SpecTest
smoke-community-stackscripts.spec.tsCommunity Stackscripts integration tests » pagination works with infinite scrolling

Troubleshooting

Use this command to re-run the failing tests:

pnpm cy:run -s "cypress/e2e/core/stackscripts/smoke-community-stackscripts.spec.ts"

@santoshp210-akamai
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants