-
Notifications
You must be signed in to change notification settings - Fork 295
fix(UI): Conditional error message based on ruleType for PZ Create Rule functionality Fixes BED-7291 #2414
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
base: main
Are you sure you want to change the base?
fix(UI): Conditional error message based on ruleType for PZ Create Rule functionality Fixes BED-7291 #2414
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22337,7 +22337,8 @@ | |
| "Groups", | ||
| "Data Quality", | ||
| "Datapipe", | ||
| "Cypher" | ||
| "Cypher", | ||
| "OpenGraph" | ||
| ] | ||
| }, | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,15 +14,20 @@ | |||||||||
| // | ||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||
|
|
||||||||||
| import { isAxiosError } from 'js-client-library'; | ||||||||||
| import { isAxiosError, SeedTypeCypher, SeedTypeObjectId, SeedTypes, SeedTypesMap } from 'js-client-library'; | ||||||||||
| import { OptionsObject } from 'notistack'; | ||||||||||
|
|
||||||||||
| export const getErrorMessage = (apiMessage: string, action: string, entity: string) => { | ||||||||||
| export const getErrorMessage = (apiMessage: string, action: string, entity: string, ruleType?: SeedTypes) => { | ||||||||||
| switch (apiMessage) { | ||||||||||
| case 'name must be unique': | ||||||||||
| return `Error ${action} ${entity}: ${entity} names must be unique. Please provide a unique name for your new ${entity} and try again.`; | ||||||||||
|
|
||||||||||
| case 'seeds are required': | ||||||||||
| if (ruleType === SeedTypeObjectId) { | ||||||||||
| return `To create a ${entity} using ${SeedTypesMap[SeedTypeObjectId]}, add at least one object using the field below.`; | ||||||||||
|
Comment on lines
+26
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded For the patch/update flow, Either incorporate 💡 Suggested fix to use action context- if (ruleType === SeedTypeObjectId) {
- return `To create a ${entity} using ${SeedTypesMap[SeedTypeObjectId]}, add at least one object using the field below.`;
+ if (ruleType === SeedTypeObjectId) {
+ return `To ${action} a ${entity} using ${SeedTypesMap[SeedTypeObjectId]}, add at least one object using the field below.`;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting comment from coderabbit, seems like the bug addressed in this PR is related to creating and updating. Yet when updating the error includes "To create" which could be misleading. Maybe something like the cypher one? where it says To save a... So it would say To save a rule using ObjectID... in either created or updating and it would make sense. |
||||||||||
| } else if (ruleType === SeedTypeCypher) { | ||||||||||
| return `To save a ${entity} created using ${SeedTypesMap[SeedTypeCypher]}, the ${SeedTypesMap[SeedTypeCypher]} must be run first. Click "Run" to continue`; | ||||||||||
| } | ||||||||||
| return `To save a ${entity} created using Cypher, the Cypher must be run first. Click "Run" to continue`; | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fully read on the context of this feature, but for this default returned error should we consider something a bit more generic ? Seems like if there was an error that wasn't related to Cypher that did not match an above case, it would show as related to a Cypher which would not necessarily be true. |
||||||||||
|
|
||||||||||
| default: | ||||||||||
|
|
@@ -34,7 +39,8 @@ export const handleError = ( | |||||||||
| error: unknown, | ||||||||||
| action: 'creating' | 'updating' | 'deleting', | ||||||||||
| entity: 'rule' | 'zone' | 'label', | ||||||||||
| addNotification: (notification: string, key?: string, options?: OptionsObject) => void | ||||||||||
| addNotification: (notification: string, key?: string, options?: OptionsObject) => void, | ||||||||||
| optionalParams?: { ruleType?: SeedTypes } | ||||||||||
| ) => { | ||||||||||
| console.error(error); | ||||||||||
|
|
||||||||||
|
|
@@ -49,7 +55,7 @@ export const handleError = ( | |||||||||
| const apiMessage = errorsList.length ? errorsList[0].message : error.response?.statusText || undefined; | ||||||||||
|
|
||||||||||
| if (apiMessage) { | ||||||||||
| message = getErrorMessage(apiMessage, action, entity); | ||||||||||
| message = getErrorMessage(apiMessage, action, entity, optionalParams?.ruleType); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test confirms
actionis ignored in the Object ID message — downstream corroboration of theutils.tsissue.The assertion
expect(result).toBe('To create a zone using Object ID, ...')withaction: 'updating'passed in explicitly documents that the hardcoded"To create"verb inutils.tsline 27 ignoresaction. This aligns with the minor issue flagged inutils.ts. If that verb is corrected there, update this test expectation accordingly.🤖 Prompt for AI Agents