Skip to content

Commit

Permalink
chore: pure getTableColumnSetupItem
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanVor committed Feb 11, 2024
1 parent 504d856 commit 5ae98fa
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/components/Table/hoc/withTableSettings/withTableSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,30 @@ export function getColumnStringTitle<Data>(column: TableColumnConfig<Data>) {
return column.id;
}

const getTableColumnSetupItem = <I extends unknown>(
id: string,
isSelected: boolean | undefined,
column: TableColumnConfig<I> | undefined,
): TableColumnSetupItem => {
const isProtected = Boolean(column?.meta?.selectedAlways);

return {
id,
isSelected: isProtected ? true : isSelected,
isRequired: isProtected,
title: column ? getColumnStringTitle(column) : id,
};
};

export function getActualItems<I>(
columns: TableColumnConfig<I>[],
settings: TableSettingsData,
): TableColumnSetupItem[] {
const getTableColumnSetupItem = (
id: string,
isSelected: boolean | undefined,
column = columns.find((column) => column.id === id),
): TableColumnSetupItem => {
const isProtected = Boolean(column?.meta?.selectedAlways);

return {
id,
isSelected: isProtected ? true : isSelected,
isRequired: isProtected,
title: column ? getColumnStringTitle(column) : id,
};
};

const sortableItems: TableColumnSetupItem[] = [];

settings.forEach(({id, isSelected}) => {
if (columns.some((column) => id === column.id)) {
sortableItems.push(getTableColumnSetupItem(id, isSelected));
sortableItems.push(getTableColumnSetupItem(id, isSelected, undefined));
}
});

Expand Down

0 comments on commit 5ae98fa

Please sign in to comment.