fix: unable to import agama project config#2595
Conversation
Signed-off-by: duttarnab <arnab.bdutta@gmail.com>
📝 WalkthroughWalkthroughNormalize Agama project config payloads in the UI: accept string or object responses, parse or deep-clone into a plain Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@admin-ui/plugins/auth-server/components/Agama/AgamaProjectConfigModal.tsx`:
- Around line 68-84: Extract the duplicated parsing/normalization into a shared
function (e.g., normalizeConfigData) and use it from the success handler that
currently calls setConfigDetails; the helper should accept data: unknown and
return Record<string, unknown> by attempting JSON.parse for strings (catching
errors) or structuredClone for objects, and on parse failure call console.error
with richer context (include the raw data and the caught error) before returning
{} so refetchConfig can reconcile state. Ensure callers replace the inline logic
with a call to normalizeConfigData(data) and pass the result into
setConfigDetails.
admin-ui/plugins/auth-server/components/Agama/AgamaProjectConfigModal.tsx
Show resolved
Hide resolved
Signed-off-by: duttarnab <arnab.bdutta@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@admin-ui/plugins/auth-server/components/Agama/AgamaProjectConfigModal.tsx`:
- Around line 67-90: The onSuccess handler in AgamaProjectConfigModal.tsx is
declared async but uses no await; remove the unnecessary async keyword by
changing the property from "onSuccess: async (data: string | JsonObject) => {
... }" to "onSuccess: (data: string | JsonObject) => { ... }" so the function
remains synchronous and behavior is unchanged; keep the existing parsing,
structuredClone, setConfigDetails, and dispatch logic exactly the same.
- Around line 91-96: The error message extraction used in the onError handler
and the catch block in handleImportConfig is duplicated; extract it into a
shared helper (e.g., getErrorMessage(error: ApiError, fallback = 'An error
occurred'): string) and replace the inline ternary logic in both onError and the
catch block with calls to that helper so both locations (onError and
handleImportConfig) use a single implementation and consistent fallback message.
In `@admin-ui/plugins/auth-server/components/Agama/types/agamaTypes.ts`:
- Line 119: Add a JSDoc comment above the ApiError type declaration describing
the shape and purpose of ApiError (that it can be a native Error or an object
with optional message, status, and statusText fields), matching the format and
style used for other types in this file; ensure the JSDoc includes a short
description and `@typedef/`@property-like annotations for message, status, and
statusText so editors and docs render consistently for the ApiError type.
admin-ui/plugins/auth-server/components/Agama/AgamaProjectConfigModal.tsx
Outdated
Show resolved
Hide resolved
admin-ui/plugins/auth-server/components/Agama/AgamaProjectConfigModal.tsx
Show resolved
Hide resolved
Signed-off-by: duttarnab <arnab.bdutta@gmail.com>
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@admin-ui/plugins/auth-server/components/Agama/AgamaProjectConfigModal.tsx`:
- Around line 99-101: Hoist the pure helper function getErrorMessage out of the
AgamaProjectConfigModal component by moving its declaration to module scope
(above the component) so it isn't recreated on every render; update any internal
references to use the top-level getErrorMessage and consider exporting it if
other modules/components need to reuse it. Ensure the signature stays the same
(error: ApiError, fallback?: string) and that no component-specific imports or
closures are required.
| function getErrorMessage(error: ApiError, fallback = 'An error occurred'): string { | ||
| return error instanceof Error ? error.message : error?.message || fallback | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Consider hoisting getErrorMessage outside the component.
This pure function has no dependencies on component state or props. Moving it outside the component avoids recreating it on every render and makes it reusable.
♻️ Suggested refactor
+function getErrorMessage(error: ApiError, fallback = 'An error occurred'): string {
+ return error instanceof Error ? error.message : error?.message || fallback
+}
+
const AgamaProjectConfigModal: React.FC<AgamaProjectConfigModalProps> = ({
isOpen,
row,
handler,
handleUpdateRowData,
manageConfig = false,
}) => {
// ... component body
- function getErrorMessage(error: ApiError, fallback = 'An error occurred'): string {
- return error instanceof Error ? error.message : error?.message || fallback
- }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function getErrorMessage(error: ApiError, fallback = 'An error occurred'): string { | |
| return error instanceof Error ? error.message : error?.message || fallback | |
| } | |
| // Hoisted outside the component to avoid recreating on every render | |
| function getErrorMessage(error: ApiError, fallback = 'An error occurred'): string { | |
| return error instanceof Error ? error.message : error?.message || fallback | |
| } |
🤖 Prompt for AI Agents
In `@admin-ui/plugins/auth-server/components/Agama/AgamaProjectConfigModal.tsx`
around lines 99 - 101, Hoist the pure helper function getErrorMessage out of the
AgamaProjectConfigModal component by moving its declaration to module scope
(above the component) so it isn't recreated on every render; update any internal
references to use the top-level getErrorMessage and consider exporting it if
other modules/components need to reuse it. Ensure the signature stays the same
(error: ApiError, fallback?: string) and that no component-specific imports or
closures are required.



closes #2589
Summary by CodeRabbit
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.