Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unsorted option for KTable #803

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/KTable/useSorting/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('useSorting', () => {
]);
});

it('should sort rows by numeric column in ascending and descending order', () => {
it('should sort rows by numeric column in ascending then descending order then back to default order', () => {
const { handleSort, sortedRows, sortOrder } = useSorting(headers, rows, useLocalSorting);

handleSort(1); // Sort by 'Age'
Expand All @@ -65,6 +65,15 @@ describe('useSorting', () => {
['Jane', 25, new Date(1995, 10, 20)],
]);
expect(sortOrder.value).toBe(SORT_ORDER_DESC);

handleSort(1); //Sort by 'Age' again to default order

expect(sortedRows.value).toEqual([
['John', 30, new Date(1990, 5, 15)],
['Jane', 25, new Date(1995, 10, 20)],
['Alice', 28, new Date(1992, 8, 10)],
]);
expect(sortOrder.value).toBe(null);
});

it('should sort rows by date column in ascending order', () => {
Expand Down
8 changes: 7 additions & 1 deletion lib/KTable/useSorting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ export default function useSorting(headers, rows, useLocalSorting) {
if (headers.value[index].dataType === DATA_TYPE_OTHERS) return;

if (sortKey.value === index) {
sortOrder.value = sortOrder.value === SORT_ORDER_ASC ? SORT_ORDER_DESC : SORT_ORDER_ASC;
if (sortOrder.value === SORT_ORDER_ASC) {
sortOrder.value = SORT_ORDER_DESC;
} else if (sortOrder.value === SORT_ORDER_DESC) {
sortKey.value = null;
sortOrder.value = null;
}
} else {
sortKey.value = index;
sortOrder.value = SORT_ORDER_ASC;
}
};

/**
* Method to get the ARIA sort attribute value for a column header.
*
Expand Down