Skip to content

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

Merged
Shreyag02 merged 4 commits into
mainfrom
fix/data-table/sort_icon_direction_fix_and_default_sort_type_error_fixes
Jul 14, 2026
Merged

fix(data-table): align defaultSort optionality across internal types and fix sort icon direction#841
Shreyag02 merged 4 commits 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 Jul 14, 2026 7:19am

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a8b30a52-f397-4e00-9bd2-7dafcedbdbd6

📥 Commits

Reviewing files that changed from the base of the PR and between 6321ddf and 5ce748e.

📒 Files selected for processing (1)
  • packages/raystack/components/data-table/components/ordering.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/raystack/components/data-table/components/ordering.tsx

📝 Walkthrough

Walkthrough

The data-table sort flow now allows defaultSort to be omitted in shared types and query helpers. Reset logic clears sort when no default exists. Ordering accepts an optional value, defaults column changes to ascending order, skips toggling without a selection, and updates sort icon handling for missing values.

Suggested reviewers: rohanchkrabrty, 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 clearly summarizes the two main changes: defaultSort optionality alignment and sort icon direction fixes.
Description check ✅ Passed The description matches the changeset and accurately describes the sort icon and defaultSort optionality fixes.
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.

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 thread packages/raystack/components/data-table/components/ordering.tsx Outdated
@Shreyag02 Shreyag02 requested a review from rohanchkrabrty June 30, 2026 05:46
@Shreyag02

Shreyag02 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author
Screenshot 2026-07-05 at 10 36 19 PM

updated in relevance to design approved direction

}

function handleOrderChange() {
if (!value) return;

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.

Let's remove this and not block this behaviour

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Kept the guard here intentionally — with defaultSort now optional, value can be undefined when no column is selected. Removing if (!value) return would deref value.name a couple lines down and throw on the toggle click. So the toggle safely no-ops until a column is picked. Applied the currentOrder refactor from the other two comments. 👍

value?: DataTableSort;
}

export function Ordering({ columnList, onChange, value }: OrderingProps) {

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.

Let's add a const currentOrder = value?.order ?? SortOrders.ASC value here, then reuse it in this component

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added

disabled={columnList.length === 0}
>
{value.order === SortOrders?.ASC ? (
{(value?.order ?? SortOrders.ASC) === SortOrders.ASC ? (

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.

currentOrder === SortOrders.ASC

@Shreyag02 Shreyag02 merged commit 350b51b into main Jul 14, 2026
5 checks passed
@Shreyag02 Shreyag02 deleted the fix/data-table/sort_icon_direction_fix_and_default_sort_type_error_fixes branch July 14, 2026 08:15
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