Skip to content

Commit

Permalink
refactor(useSortableColumns): implement types (carbon-design-system#5464
Browse files Browse the repository at this point in the history
)
  • Loading branch information
makafsal authored Jun 12, 2024
1 parent 553f2c7 commit fef7d25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export interface DataGridState<T extends object = any>
onVirtualScroll?: (evt?: boolean) => void;
fetchMoreData?: () => void;
loadMoreThreshold?: number;
onSort?: boolean;
}

// DatagridHeaderRow related types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Button } from '@carbon/react';
import { ArrowUp, ArrowDown, ArrowsVertical } from '@carbon/react/icons';
import { SelectAll } from './Datagrid/DatagridSelectAll';
import { DatagridSlug } from './Datagrid/addons/Slug/DatagridSlug';
import { Hooks, TableInstance } from 'react-table';
import { DataGridState } from './types';

const blockClass = `${pkg.prefix}--datagrid`;

Expand All @@ -21,9 +23,9 @@ const ordering = {
NONE: 'NONE',
};

export const getNewSortOrder = (sortOrder) => {
export const getNewSortOrder = (sortOrder?: boolean | string) => {
const order = {
newSortDesc: undefined,
newSortDesc: false,
newOrder: ordering.NONE,
};
if (sortOrder === false || sortOrder === ordering.DESC) {
Expand Down Expand Up @@ -71,7 +73,7 @@ const getAriaPressedValue = (col) => {
return 'false';
};

const useSortableColumns = (hooks) => {
const useSortableColumns = (hooks: Hooks) => {
const sortableVisibleColumns = (visibleColumns, { instance }) => {
const {
onSort,
Expand Down Expand Up @@ -171,8 +173,8 @@ const useSortableColumns = (hooks) => {
: [...sortableColumns];
};

const sortInstanceProps = (instance) => {
const { onSort } = instance;
const sortInstanceProps = (instance: TableInstance) => {
const { onSort } = instance as DataGridState;
Object.assign(instance, { manualSortBy: !!onSort, isTableSortable: true });
};

Expand Down

0 comments on commit fef7d25

Please sign in to comment.