Skip to content

fix(data-table): align defaultSort optionality across internal types and fix sort icon direction#841

Open
Shreyag02 wants to merge 1 commit into
mainfrom
fix/data-table/sort_icon_direction_fix_and_default_sort_type_error_fixes
Open

fix(data-table): align defaultSort optionality across internal types and fix sort icon direction#841
Shreyag02 wants to merge 1 commit into
mainfrom
fix/data-table/sort_icon_direction_fix_and_default_sort_type_error_fixes

Conversation

@Shreyag02

Copy link
Copy Markdown
Contributor

Description

This PR contains two changes to the data-table component's Ordering control and surrounding types.

1. Corrected the sort direction icons. In the Ordering toggle the ascending/descending icons were swapped — ascending (asc) showed the "align bottom" icon and descending (desc) showed the "align top" icon. They are now correct: asc shows TextAlignTopIcon and desc shows TextAlignBottomIcon, so the icon matches the actual sort direction.

2. Fixed defaultSort type-safety issues. The defaultSort prop is optional on the public DataTableProps, but several internal types incorrectly required it (DataTableSort instead of DataTableSort | undefined), producing latent type errors and a possible runtime crash in the Ordering control when no defaultSort is provided.

Changes:

  • Swapped the ascending/descending sort icons in Ordering so the direction shown matches the applied sort order.
  • Relaxed getDefaultTableQuery and hasActiveQuery parameters to optional defaultSort? (their bodies already guarded for undefined).
  • Made TableContextType.defaultSort optional to match the public prop.
  • Guarded the display-settings reset handler so it builds sort: defaultSort ? [defaultSort] : [] instead of [undefined].
  • Made Ordering's value optional and guarded its internal accesses (value?.name, value?.order, early-return in the order toggle), preventing a deref of a possibly-undefined value.

The public API is unchanged — defaultSort remains optional and the change is fully backward-compatible.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes, no bug fixes just code improvements)
  • Chore (changes to the build process or auxiliary tools and libraries such as documentation generation)
  • Style (changes that do not affect the meaning of the code (white-space, formatting, etc))
  • Test (adding missing tests or correcting existing tests)
  • Improvement (Improvements to existing code)
  • Other (please specify)

How Has This Been Tested?

  • Type-checked the full raystack package; the four changed files (ordering.tsx, data-table.tsx, data-table.types.tsx, utils/index.tsx) produce zero type errors, and no new cross-errors were introduced in any other file.
  • Ran the data-table test suite — 164 passed (data-table.test.tsx, utils/index.test.tsx, utils/filter-operations.test.tsx).
  • Ran the sibling data-view / data-view-beta suites as a sanity check (they keep independent copies of these utils/components) — 59 passed, 1 skipped, unaffected.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (.mdx files)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Screenshots (if appropriate):

[Add screenshots here]

Related Issues

[Link any related issues here using #issue-number]

@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment Jun 25, 2026 12:25pm

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The data-table sort flow now allows defaultSort to be omitted in shared types, query helpers, and reset logic. Ordering accepts an optional selected value, defaults column changes to ascending when no value is present, and skips order toggling without a current selection. The display-settings reset path now clears sort to an empty array when no default sort exists.

Suggested reviewers

  • rsbh
  • paanSinghCoder
🚥 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
Title check ✅ Passed The title accurately summarizes the two main changes: defaultSort optionality alignment and corrected sort icon direction.
Description check ✅ Passed The description is clearly aligned with the implemented data-table ordering and defaultSort type-safety changes.
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.


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 `@packages/raystack/components/data-table/components/ordering.tsx`:
- Around line 74-80: The sort icon logic in ordering.tsx should treat an
undefined value as ascending instead of falling through to the descending icon.
Update the conditional around value.order in the ordering render so the default
branch maps to SortOrders.ASC, and remove the unnecessary optional chaining on
SortOrders since it is a non-nullable constant. Keep the fix localized to the
icon selection in this component.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b2459c9a-9cfb-4adb-9e8f-9285043e0cf6

📥 Commits

Reviewing files that changed from the base of the PR and between 51d18b2 and abd2663.

📒 Files selected for processing (4)
  • packages/raystack/components/data-table/components/ordering.tsx
  • packages/raystack/components/data-table/data-table.tsx
  • packages/raystack/components/data-table/data-table.types.tsx
  • packages/raystack/components/data-table/utils/index.tsx

Comment on lines +74 to 80
{value?.order === SortOrders?.ASC ? (
<TextAlignTopIcon className={styles['display-popover-sort-icon']} />
) : (
<TextAlignBottomIcon
className={styles['display-popover-sort-icon']}
/>
) : (
<TextAlignTopIcon className={styles['display-popover-sort-icon']} />
)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm SortOrders is a non-nullable const/enum (no `?.` warranted)
fd -e tsx -e ts | xargs rg -nP '\b(SortOrders)\b\s*=' 2>/dev/null
ast-grep run --pattern 'export const SortOrders = $_' --lang typescript $(fd -e ts -e tsx) 2>/dev/null
rg -nP 'SortOrders\s*:' $(fd -e ts -e tsx) 2>/dev/null | head

Repository: raystack/apsara

Length of output: 430


Default state renders the wrong icon and uses unnecessary optional chaining

When value is undefined, the condition value?.order === SortOrders?.ASC evaluates to false, causing the component to render the descending (TextAlignBottomIcon) icon. However, the logical default for a new sort is ascending. Additionally, SortOrders is a non-nullable constant, making the optional chaining (?.) on SortOrders?.ASC redundant.

Update the logic to treat the absent state as ASC and remove the redundant optional chaining:

🔧 Proposed fix
-          {value?.order === SortOrders?.ASC ? (
+          {(value?.order ?? SortOrders.ASC) === SortOrders.ASC ? (
             <TextAlignTopIcon className={styles['display-popover-sort-icon']} />
           ) : (
             <TextAlignBottomIcon
               className={styles['display-popover-sort-icon']}
             />
           )}
📝 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
{value?.order === SortOrders?.ASC ? (
<TextAlignTopIcon className={styles['display-popover-sort-icon']} />
) : (
<TextAlignBottomIcon
className={styles['display-popover-sort-icon']}
/>
) : (
<TextAlignTopIcon className={styles['display-popover-sort-icon']} />
)}
{(value?.order ?? SortOrders.ASC) === SortOrders.ASC ? (
<TextAlignTopIcon className={styles['display-popover-sort-icon']} />
) : (
<TextAlignBottomIcon
className={styles['display-popover-sort-icon']}
/>
)}
🤖 Prompt for 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.

In `@packages/raystack/components/data-table/components/ordering.tsx` around lines
74 - 80, The sort icon logic in ordering.tsx should treat an undefined value as
ascending instead of falling through to the descending icon. Update the
conditional around value.order in the ordering render so the default branch maps
to SortOrders.ASC, and remove the unnecessary optional chaining on SortOrders
since it is a non-nullable constant. Keep the fix localized to the icon
selection in this component.

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