Skip to content

fix(roles): display status in Roles list using safe type extension#56

Open
khushisahu476 wants to merge 6 commits intoopenMF:devfrom
khushisahu476:fix/roles-status
Open

fix(roles): display status in Roles list using safe type extension#56
khushisahu476 wants to merge 6 commits intoopenMF:devfrom
khushisahu476:fix/roles-status

Conversation

@khushisahu476
Copy link

@khushisahu476 khushisahu476 commented Feb 26, 2026

Description

The /system/roles-and-permissions endpoint returns the field status,
but it is missing from the OpenAPI-generated interface.

This change safely extends the GetRolesResponse type locally in the
Roles list page and displays the value without modifying generated SDK code.

Related issues and discussion

Addresses the item in ISSUES.md:

Admin System → /system/roles-and-permissions
GetRolesResponse missing status

Screenshots, if any

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • If you have multiple commits please combine them into one commit by squashing them.

  • Read and understood the contribution guidelines at CONTRIBUTING.md.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Entity subtypes in data tables now display actual values instead of placeholder text, improving data visibility.
    • Role status information in the roles and permissions view now displays correctly instead of showing placeholder text.
    • Enhanced data type handling for office information to ensure consistent data retrieval and storage.

@gkbishnoi07
Copy link
Collaborator

Hey @khushisahu476 why did you deleted the package-lock json file?

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

📝 Walkthrough

Walkthrough

This pull request replaces hardcoded placeholder values with proper type definitions and dynamic data rendering. It updates type imports in CreateClosure, introduces local type extensions in ManageDataTables and RolesAndPermissions to support optional fields, and modifies display logic to render dynamic values instead of static placeholders.

Changes

Cohort / File(s) Summary
Type Import Update
src/pages/accounting/closing-entries/CreateClosure.tsx
Replaced GetOfficesResponse[] with OfficeData[] type for offices state and API response handling; updated import accordingly.
Type Extension & UI Updates
src/pages/system/manage-data-tables/ManageDataTables.tsx, src/pages/system/roles-and-permissions/RolesAndPermissions.tsx
Introduced local types extending API response types with optional fields (DataTableWithSubtype and RoleWithStatus); replaced hardcoded placeholder strings with dynamic value rendering (with fallback to '—' or equivalent).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 With types now true and placeholders gone,
We render data dancing on and on,
From static strings to values so bright,
The forms now sing with proper light!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title refers to displaying status in the Roles list using type extension, which is a significant change in the PR. However, the raw summary shows changes across three files (CreateClosure.tsx, ManageDataTables.tsx, and RolesAndPermissions.tsx) with similar type extension patterns, not just roles. The title focuses only on the roles-and-permissions change and misses the equally significant changes to closing-entries and manage-data-tables files. Consider revising the title to reflect the broader scope, such as: 'fix: use safe type extensions for missing OpenAPI fields across multiple pages' or similar.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/pages/accounting/closing-entries/CreateClosure.tsx`:
- Line 46: Replace the unsafe cast in the setOffices call by guarding the API
payload and providing a safe fallback: when calling setOffices(use the
response.data from the API call and instead of casting to OfficeData[]
unconditionally, coerce/validate it with a runtime fallback such as using
response.data ?? [] or response.data || [] so setOffices always receives an
array), so that subsequent usage like the .map() in CreateClosure does not throw
when response.data is null/undefined; update the call site where
setOffices(response.data as OfficeData[]) is used to pass a guaranteed array.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between df36c42 and 8b8d46b.

📒 Files selected for processing (3)
  • src/pages/accounting/closing-entries/CreateClosure.tsx
  • src/pages/system/manage-data-tables/ManageDataTables.tsx
  • src/pages/system/roles-and-permissions/RolesAndPermissions.tsx

try {
const response = await officesApi.retrieveOffices()
setOffices(response.data || [])
setOffices(response.data as OfficeData[])
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for OfficesApi and retrieveOffices method definition
rg -n -C3 'class\s+OfficesApi|retrieveOffices\s*\(' --type ts --type tsx

Repository: openMF/mifos-x-web-app-react

Length of output: 99


🏁 Script executed:

#!/bin/bash
# Search for OfficeData type definition
rg -n -C3 'export\s+(type|interface)\s+OfficeData\b' --type ts --type tsx

Repository: openMF/mifos-x-web-app-react

Length of output: 99


🏁 Script executed:

#!/bin/bash
# Check how setOffices is used in CreateClosure.tsx
rg -n -C5 'setOffices\s*\(' src/pages/accounting/closing-entries/CreateClosure.tsx

Repository: openMF/mifos-x-web-app-react

Length of output: 421


🏁 Script executed:

#!/bin/bash
# Get the full context around line 46 in CreateClosure.tsx
cat -n src/pages/accounting/closing-entries/CreateClosure.tsx | sed -n '35,60p'

Repository: openMF/mifos-x-web-app-react

Length of output: 949


🏁 Script executed:

#!/bin/bash
# Search for OfficesApi class definition
rg -n -C3 'class\s+OfficesApi|retrieveOffices\s*\('

Repository: openMF/mifos-x-web-app-react

Length of output: 13626


🏁 Script executed:

#!/bin/bash
# Search for OfficeData type/interface definition
rg -n -C3 'export\s+(type|interface)\s+OfficeData'

Repository: openMF/mifos-x-web-app-react

Length of output: 54


🏁 Script executed:

#!/bin/bash
# Search for officesApi initialization in CreateClosure.tsx
rg -n -C2 'officesApi' src/pages/accounting/closing-entries/CreateClosure.tsx | head -20

Repository: openMF/mifos-x-web-app-react

Length of output: 422


🏁 Script executed:

#!/bin/bash
# Check imports at the top of CreateClosure.tsx
head -30 src/pages/accounting/closing-entries/CreateClosure.tsx

Repository: openMF/mifos-x-web-app-react

Length of output: 1049


🏁 Script executed:

#!/bin/bash
# Find OfficeData interface in fineract-api
find . -path "*/fineract-api*" -name "*.ts" -o -name "*.tsx" | head -20

Repository: openMF/mifos-x-web-app-react

Length of output: 814


🏁 Script executed:

#!/bin/bash
# Search for OfficeData interface definition
rg -n 'interface\s+OfficeData|type\s+OfficeData|export.*OfficeData'

Repository: openMF/mifos-x-web-app-react

Length of output: 148


🏁 Script executed:

#!/bin/bash
# Search for OfficesApi class
rg -n 'class OfficesApi' -A 10

Repository: openMF/mifos-x-web-app-react

Length of output: 54


🏁 Script executed:

#!/bin/bash
# Check if fineract-api is a local directory or path alias
find . -type d -name "fineract-api" 2>/dev/null | grep -v node_modules

Repository: openMF/mifos-x-web-app-react

Length of output: 54


🏁 Script executed:

#!/bin/bash
# Check tsconfig to understand `@/fineract-api` path alias
cat tsconfig.json | grep -A 5 "paths"

Repository: openMF/mifos-x-web-app-react

Length of output: 137


🏁 Script executed:

#!/bin/bash
# Search for fineract-api in package.json
cat package.json | grep -i fineract

Repository: openMF/mifos-x-web-app-react

Length of output: 226


🏁 Script executed:

#!/bin/bash
# List files in the generated fineract-api directory
ls -la src/fineract-api/ | head -30

Repository: openMF/mifos-x-web-app-react

Length of output: 136


🏁 Script executed:

#!/bin/bash
# Search for OfficeData and OfficesApi in the generated API code
rg -n 'interface OfficeData|type OfficeData|class OfficesApi' src/fineract-api/ -A 5 | head -50

Repository: openMF/mifos-x-web-app-react

Length of output: 129


🏁 Script executed:

#!/bin/bash
# Check the index file to understand exports
cat src/fineract-api/index.ts 2>/dev/null | grep -i office | head -20

Repository: openMF/mifos-x-web-app-react

Length of output: 54


🏁 Script executed:

#!/bin/bash
# Check if fineract-api is in node_modules
ls -la node_modules/@fineract* 2>/dev/null | head -20

Repository: openMF/mifos-x-web-app-react

Length of output: 54


🏁 Script executed:

#!/bin/bash
# Look for any API type definitions or models in src
find src -type f -name "*.ts" -o -name "*.tsx" | xargs rg -l "OfficeData|OfficesApi" | grep -v node_modules

Repository: openMF/mifos-x-web-app-react

Length of output: 1328


🏁 Script executed:

#!/bin/bash
# Get a broader context around the setOffices calls to understand patterns
rg -B 2 -A 1 'setOffices\(.*\.data' src/pages --type ts --type tsx 2>/dev/null | head -80

Repository: openMF/mifos-x-web-app-react

Length of output: 54


🏁 Script executed:

#!/bin/bash
# Check how offices is used after setOffices in CreateClosure.tsx
rg -n 'offices\.' src/pages/accounting/closing-entries/CreateClosure.tsx -A 2

Repository: openMF/mifos-x-web-app-react

Length of output: 212


🏁 Script executed:

#!/bin/bash
# Get the complete usage of offices state in CreateClosure.tsx
cat src/pages/accounting/closing-entries/CreateClosure.tsx | grep -n "offices" | head -20

Repository: openMF/mifos-x-web-app-react

Length of output: 393


🏁 Script executed:

#!/bin/bash
# Check how many other files use the same unsafe pattern vs. the safe pattern
echo "=== Files using '|| []' or '?? []' pattern ==="
rg -c 'setOffices\(.*\|\|.*\[\]|setOffices\(.*\?\?.*\[\]' src/pages

echo ""
echo "=== Files using unconditional cast 'as OfficeData[]' pattern ==="
rg -c 'setOffices\(.*as OfficeData' src/pages

echo ""
echo "=== Specific instances with unconditional casts ==="
rg -n 'setOffices.*as (Office|any)' src/pages

Repository: openMF/mifos-x-web-app-react

Length of output: 1016


Use runtime guard instead of unconditional cast on API payload.

setOffices(response.data as OfficeData[]) suppresses type safety without validation. If the API returns undefined or null, the subsequent .map() call at line 117 will fail at runtime. The codebase consistently uses safe fallbacks (|| [] or ?? []) across 12+ similar patterns; align with this convention.

Suggested fix
-        setOffices(response.data as OfficeData[])
+        setOffices(response.data || [])
📝 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
setOffices(response.data as OfficeData[])
setOffices(response.data || [])
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/accounting/closing-entries/CreateClosure.tsx` at line 46, Replace
the unsafe cast in the setOffices call by guarding the API payload and providing
a safe fallback: when calling setOffices(use the response.data from the API call
and instead of casting to OfficeData[] unconditionally, coerce/validate it with
a runtime fallback such as using response.data ?? [] or response.data || [] so
setOffices always receives an array), so that subsequent usage like the .map()
in CreateClosure does not throw when response.data is null/undefined; update the
call site where setOffices(response.data as OfficeData[]) is used to pass a
guaranteed array.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants