-
Notifications
You must be signed in to change notification settings - Fork 201
[Test PR] Implemented API Key For Federated APIs #1338
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?
Changes from 10 commits
ff20eb6
0560586
eceff25
47430e6
4ecf5c7
8fb755f
55fdd19
5f49924
b76b9a9
2f087e8
f95e5f0
ff42c63
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 |
|---|---|---|
|
|
@@ -80,6 +80,8 @@ | |
| } from './PlatformGatewayUtils'; | ||
|
|
||
| const PREFIX = 'AddEditGWEnvironment'; | ||
| const PLAN_MAPPING_PROPERTY_PREFIX = 'plan_mapping.'; | ||
| const FEDERATED_GATEWAY_VALIDATION_ERROR_CODE = 900520; | ||
|
|
||
| const classes = { | ||
| pageContent: `${PREFIX}-pageContent`, | ||
|
|
@@ -365,6 +367,23 @@ | |
| return false; | ||
| }; | ||
|
|
||
| const extractPlanMappingErrors = (responseBody) => { | ||
| const rowErrors = {}; | ||
| if (!responseBody | ||
| || responseBody.code !== FEDERATED_GATEWAY_VALIDATION_ERROR_CODE | ||
|
Check warning on line 373 in portals/admin/src/main/webapp/source/src/app/components/GatewayEnvironments/AddEditGWEnvironment.jsx
|
||
| || !Array.isArray(responseBody.error)) { | ||
| return rowErrors; | ||
| } | ||
|
|
||
| responseBody.error.forEach((errorItem) => { | ||
| const fieldKey = errorItem?.message; | ||
| if (fieldKey && fieldKey.startsWith(PLAN_MAPPING_PROPERTY_PREFIX)) { | ||
|
Check warning on line 380 in portals/admin/src/main/webapp/source/src/app/components/GatewayEnvironments/AddEditGWEnvironment.jsx
|
||
| rowErrors[fieldKey] = errorItem.description || 'Invalid external plan assignment'; | ||
|
Comment on lines
+377
to
+380
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. Guard Line 380 can throw if Suggested fix responseBody.error.forEach((errorItem) => {
const fieldKey = errorItem?.message;
- if (fieldKey && fieldKey.startsWith(PLAN_MAPPING_PROPERTY_PREFIX)) {
+ if (typeof fieldKey === 'string' && fieldKey.startsWith(PLAN_MAPPING_PROPERTY_PREFIX)) {
rowErrors[fieldKey] = errorItem.description || 'Invalid external plan assignment';
}
});🧰 Tools🪛 GitHub Check: SonarCloud Code Analysis[warning] 380-380: Prefer using an optional chain expression instead, as it's more concise and easier to read. 🤖 Prompt for AI Agents |
||
| } | ||
| }); | ||
| return rowErrors; | ||
| }; | ||
|
|
||
| /** | ||
| * Reducer | ||
| * @param {JSON} state State | ||
|
|
@@ -414,6 +433,7 @@ | |
| const [supportedModes, setSupportedModes] = useState([]); | ||
| const [validating, setValidating] = useState(false); | ||
| const [saving, setSaving] = useState(false); | ||
| const [planMappingErrors, setPlanMappingErrors] = useState({}); | ||
| const { gatewayTypes } = settings; | ||
| const gatewayVersions = useMemo(() => getPlatformGatewayVersions(settings), [settings]); | ||
| const { | ||
|
|
@@ -638,6 +658,10 @@ | |
| } | ||
| }, [permissions]); | ||
|
|
||
| useEffect(() => { | ||
| setPlanMappingErrors({}); | ||
| }, [gatewayType]); | ||
|
|
||
| useEffect(() => { | ||
| if (!platformHeaderEditMode) { | ||
| setPlatformDisplayNameDraft( | ||
|
|
@@ -881,6 +905,13 @@ | |
| }; | ||
|
|
||
| const setAdditionalProperties = (key, value) => { | ||
| if (key && planMappingErrors[key]) { | ||
| setPlanMappingErrors((prevErrors) => { | ||
| const updatedErrors = { ...prevErrors }; | ||
| delete updatedErrors[key]; | ||
| return updatedErrors; | ||
| }); | ||
| } | ||
| const clonedAdditionalProperties = cloneDeep(additionalProperties); | ||
| if (value === undefined) { | ||
| delete clonedAdditionalProperties[key]; | ||
|
|
@@ -1189,6 +1220,7 @@ | |
|
|
||
| promiseAPICall | ||
| .then((result) => { | ||
| setPlanMappingErrors({}); | ||
| if (id) { | ||
| Alert.success( | ||
| `${name} ${intl.formatMessage({ | ||
|
|
@@ -1226,8 +1258,28 @@ | |
| }) | ||
| .catch((error) => { | ||
| const { response } = error; | ||
| if (response.body) { | ||
| Alert.error(response.body.description); | ||
| if (response?.body) { | ||
| setPlanMappingErrors(extractPlanMappingErrors(response.body)); | ||
| Alert.error( | ||
| response.body.description | ||
| || error?.message | ||
| || intl.formatMessage({ | ||
| id: 'GatewayEnvironments.AddEditGWEnvironment.save.failed', | ||
| defaultMessage: 'Save failed', | ||
| }), | ||
| ); | ||
| } else { | ||
| setPlanMappingErrors({}); | ||
| const statusSuffix = response?.status | ||
| ? ` (${response.status}${response?.statusText ? ` ${response.statusText}` : ''})` | ||
|
Check warning on line 1274 in portals/admin/src/main/webapp/source/src/app/components/GatewayEnvironments/AddEditGWEnvironment.jsx
|
||
| : ''; | ||
| Alert.error( | ||
| error?.message | ||
| || `${intl.formatMessage({ | ||
| id: 'GatewayEnvironments.AddEditGWEnvironment.save.failed', | ||
| defaultMessage: 'Save failed', | ||
| })}${statusSuffix}`, | ||
| ); | ||
| } | ||
| setSaving(false); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
|
|
@@ -2383,6 +2435,9 @@ | |
| validating={ | ||
| validating | ||
| } | ||
| planMappingErrors={ | ||
| planMappingErrors | ||
| } | ||
| gatewayId={cloneDeep( | ||
| id, | ||
| )} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.