Skip to content

Fix alphabetical sorting of documents within document type groups in Dev Portal#1361

Open
Shakir5665 wants to merge 2 commits into
wso2:mainfrom
Shakir5665:fix/document-alphabetical-sorting
Open

Fix alphabetical sorting of documents within document type groups in Dev Portal#1361
Shakir5665 wants to merge 2 commits into
wso2:mainfrom
Shakir5665:fix/document-alphabetical-sorting

Conversation

@Shakir5665
Copy link
Copy Markdown

Purpose

This PR fixes the document ordering in the Dev Portal document dropdown.

Previously, documents were only sorted by document type (HOWTO, SAMPLES, PUBLIC_FORUM, SUPPORT_FORUM, OTHER). As a result, documents within the same type were displayed in the order received from the backend API, which could appear inconsistent.

Goals

  • Preserve the existing document type ordering.
  • Sort documents alphabetically by document name within each document type group.
  • Avoid mutating the original document list while sorting.

Solution

Updated the document sorting logic in the Dev Portal document dropdown to:

  1. Sort documents based on the predefined document type order.
  2. Apply a secondary alphabetical sort using the document name when documents belong to the same type.
  3. Use a copied array for sorting instead of mutating the original documentList prop.

Testing

Verified the document dropdown ordering using multiple documents with different names under the same document type.

Example:

Before:

HOWTO
  Zebra Guide
  Apple Guide
  Mango Guide

After:

HOWTO
  Apple Guide
  Mango Guide
  Zebra Guide

The existing document type grouping and ordering remain unchanged.

Fixes #5060

Added sorting functionality for document list based on type and name.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e55ba7af-147f-4b99-a5d0-c56f9aad9b2b

📥 Commits

Reviewing files that changed from the base of the PR and between feba712 and ef004b1.

📒 Files selected for processing (1)
  • portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Documents/DocList.jsx

📝 Walkthrough

Walkthrough

DocList now computes a non-mutating sorted copy of documents using new helpers that apply a document-type priority and localeCompare tie-breakers; Autocomplete receives this precomputed sortedDocuments instead of sorting documentList in-place.

Changes

Document sorting refactoring

Layer / File(s) Summary
Compute sortedDocuments and use in Autocomplete
portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Documents/DocList.jsx
Adds getDocumentOrder and sortDocuments, creates sortedDocuments (non-mutating) ordered by type priority then by type and name with localeCompare, and changes Autocomplete to use sortedDocuments instead of inline in-place documentList.sort(...).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • lasanthaS
  • tharikaGitHub
  • piyumaldk
  • RakhithaRR
  • hisanhunais
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing alphabetical sorting of documents within document type groups, which is the core focus of the PR.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the purpose, goals, solution, and testing approach for the document sorting fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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
Copy Markdown

@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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Documents/DocList.jsx`:
- Around line 272-285: getDocumentOrder currently returns -1 for unknown types
which makes unknowns sort before known types and allows different unknown-type
documents to interleave by name; change getDocumentOrder to return
documentTypeOrder.length (or another large index) when type is unknown so
unknowns sort after known groups, and update sortDocuments so after computing
typeOrder === 0 it first compares types when both types are unknown (e.g., if
getDocumentOrder(a.type) === documentTypeOrder.length &&
getDocumentOrder(b.type) === documentTypeOrder.length then return
a.type.localeCompare(b.type)) before falling back to name comparison; reference
functions: getDocumentOrder, sortDocuments and the documentTypeOrder array.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 032f8749-7362-4822-ac4a-63b669c5b77f

📥 Commits

Reviewing files that changed from the base of the PR and between 58bf129 and feba712.

📒 Files selected for processing (1)
  • portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Documents/DocList.jsx

Update document sorting logic to handle missing types.
@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant