Skip to content

fix: unable to import agama project config#2595

Merged
duttarnab merged 4 commits intomainfrom
admin-ui-2589
Jan 20, 2026
Merged

fix: unable to import agama project config#2595
duttarnab merged 4 commits intomainfrom
admin-ui-2589

Conversation

@duttarnab
Copy link
Contributor

@duttarnab duttarnab commented Jan 19, 2026

closes #2589

Summary by CodeRabbit

  • Bug Fixes

    • Configuration modal now reliably accepts and normalizes config input (string or object), preventing failures when importing or saving.
    • Error handling and messages are clearer and consistently reported during save/import failures, improving user feedback.
  • Chores

    • Improved internal data and error handling for configuration workflows to increase robustness.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: duttarnab <arnab.bdutta@gmail.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

Normalize Agama project config payloads in the UI: accept string or object responses, parse or deep-clone into a plain JsonObject, and standardize error handling to use ApiError with descriptive messages.

Changes

Cohort / File(s) Summary
Agama config modal (logic change)
admin-ui/plugins/auth-server/components/Agama/AgamaProjectConfigModal.tsx
Update onSuccess to accept `string
Agama types (type additions)
admin-ui/plugins/auth-server/components/Agama/types/agamaTypes.ts, admin-ui/plugins/auth-server/components/Agama/types/index.ts
Add and export JsonValue, JsonObject, and ApiError types to represent JSON-serializable values and API error shapes; surface these types through the types index.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • syntrydy

Poem

🐰
Hop, hop — configs tidy and neat,
Strings turned safe, objects made plain.
A careful nibble, no more defeat,
Uploads hum along again. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly describes the main fix: resolving an issue with importing Agama project configurations, which aligns with the changeset's focus on improving config import handling and error management.
Linked Issues check ✅ Passed The code changes directly address the linked issue #2589 by improving error handling and data normalization in the AgamaProjectConfigModal, which resolves the config import failure described in the bug report.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the Agama project config import issue: improved error handling, data normalization, type definitions, and public API exports for JsonObject and ApiError types.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mo-auto mo-auto added comp-admin-ui Component affected by issue or PR kind-bug Issue or PR is a bug in existing functionality labels Jan 19, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

Signed-off-by: duttarnab <arnab.bdutta@gmail.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

@sonarqubecloud
Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +99 to +101
function getErrorMessage(error: ApiError, fallback = 'An error occurred'): string {
return error instanceof Error ? error.message : error?.message || fallback
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 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.

Suggested change
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.

@duttarnab duttarnab merged commit 7ccde1b into main Jan 20, 2026
9 checks passed
@duttarnab duttarnab deleted the admin-ui-2589 branch January 20, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-admin-ui Component affected by issue or PR kind-bug Issue or PR is a bug in existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(admin-ui): unable to import agama project config

3 participants