From ffd95d113b0cc952b18b30cc27165b9393fd780f Mon Sep 17 00:00:00 2001 From: maria-hambardzumian Date: Wed, 26 Jun 2024 11:46:02 +0400 Subject: [PATCH 1/2] EPMRPP-92222 || Update sorting for the table component --- src/components/table/table.stories.tsx | 1 + src/components/table/table.tsx | 4 ++++ src/components/table/types.ts | 1 + src/components/table/utils.ts | 6 +++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/table/table.stories.tsx b/src/components/table/table.stories.tsx index f7ea707..529f676 100644 --- a/src/components/table/table.stories.tsx +++ b/src/components/table/table.stories.tsx @@ -114,6 +114,7 @@ export const Default: Story = { { let { direction } = sortConfigParam; const { key } = sortConfigParam; diff --git a/src/components/table/table.tsx b/src/components/table/table.tsx index 7d0c8de..2c0849e 100644 --- a/src/components/table/table.tsx +++ b/src/components/table/table.tsx @@ -4,6 +4,7 @@ import classNames from 'classnames/bind'; import { ArrowDownIcon, ArrowUpIcon } from '@components/icons'; import { FixedColumn, PrimaryColumn, RowData, TableComponentProps, SortDirection } from './types'; import { Checkbox } from '@components/checkbox'; +import { getColumnsKeys } from '@components/table/utils'; const cx = classNames.bind(styles); @@ -17,6 +18,7 @@ export const Table: FC = ({ selectedRowIds = [], sortingDirection = SortDirection.ASC, sortingColumn = primaryColumn, + sortableColumns = getColumnsKeys([primaryColumn, ...fixedColumns]), onChangeSorting = () => {}, onToggleRowSelection = () => {}, onToggleAllRowsSelection = () => {}, @@ -29,6 +31,7 @@ export const Table: FC = ({ }, [primaryColumn, fixedColumns]); const handleSort = (key: string) => { + if (!sortableColumns.includes(key)) return; onChangeSorting({ key, direction: sortingDirection }); }; @@ -72,6 +75,7 @@ export const Table: FC = ({ }; const getSortIcon = (columnKey: string) => { + if (!sortableColumns.includes(columnKey)) return; if (sortingColumn?.key === columnKey) { return sortingDirection === SortDirection.ASC ? : ; } diff --git a/src/components/table/types.ts b/src/components/table/types.ts index a530d44..929edcc 100644 --- a/src/components/table/types.ts +++ b/src/components/table/types.ts @@ -41,6 +41,7 @@ export interface TableComponentProps { selectedRowIds?: (string | number)[]; sortingDirection?: SortDirection; sortingColumn?: Column; + sortableColumns?: string[]; onChangeSorting?: (sortConfig?: SortConfig) => void; onToggleRowSelection?: (id: string | number) => void; onToggleAllRowsSelection?: () => void; diff --git a/src/components/table/utils.ts b/src/components/table/utils.ts index 610f407..0ac46b2 100644 --- a/src/components/table/utils.ts +++ b/src/components/table/utils.ts @@ -1,4 +1,4 @@ -import { RowData, SortConfig, SortDirection } from './types'; +import { Column, RowData, SortConfig, SortDirection } from './types'; export const sortTableData = (tableData: RowData[], sortConfig?: SortConfig): RowData[] => { if (sortConfig) { @@ -17,3 +17,7 @@ export const sortTableData = (tableData: RowData[], sortConfig?: SortConfig): Ro } return tableData; }; + +export const getColumnsKeys = (columns: Column[]): string[] => { + return columns.map((column) => column.key); +}; From 26ec140b77f08e9090d56fa6724fffb27efe055d Mon Sep 17 00:00:00 2001 From: maria-hambardzumian Date: Wed, 26 Jun 2024 12:20:02 +0400 Subject: [PATCH 2/2] EPMRPP-92222 || code review fix -1 --- src/components/table/table.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/table/table.tsx b/src/components/table/table.tsx index 2c0849e..73cfbe1 100644 --- a/src/components/table/table.tsx +++ b/src/components/table/table.tsx @@ -4,7 +4,7 @@ import classNames from 'classnames/bind'; import { ArrowDownIcon, ArrowUpIcon } from '@components/icons'; import { FixedColumn, PrimaryColumn, RowData, TableComponentProps, SortDirection } from './types'; import { Checkbox } from '@components/checkbox'; -import { getColumnsKeys } from '@components/table/utils'; +import { getColumnsKeys } from './utils'; const cx = classNames.bind(styles);