Skip to content

Commit

Permalink
fix: isSelected -> selected
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanVor committed Apr 3, 2024
1 parent 2f8acf7 commit 3fc22f9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 57 deletions.
6 changes: 3 additions & 3 deletions src/components/Table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ const MyTable1 = withTableSettings({sortable: false})(Table);
```ts
type TableSettingsData = Array<{
id: string;
isSelected?: boolean;
selected?: boolean;
}>;
```

Expand All @@ -288,8 +288,8 @@ const data = [
];
const columns = [{id: 'id'}, {id: 'text'}];
const initialSettings = [
{id: 'id', isSelected: false},
{id: 'text', isSelected: true},
{id: 'id', selected: false},
{id: 'text', selected: true},
];

function SelectionTable() {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Table/__stories__/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export const HOCWithTableSelection = WithTableSelectionTemplate.bind({});
// ---------------------------------
const WithTableSettingsTemplate: StoryFn<TableProps<DataItem>> = (args, context) => {
const [settings, setSettings] = React.useState<TableSettingsData>(() =>
columns.map((x) => ({id: x.id, isSelected: true})),
columns.map((x) => ({id: x.id, selected: true})),
);

const updateSettings = React.useCallback(
Expand Down Expand Up @@ -255,10 +255,10 @@ const WithTableSettingsCustomActionsTemplate: StoryFn<TableProps<DataItem>> = (a
const settings = React.useMemo(() => {
const newSettings: TableSettingsData = columns.map((x) => ({
id: x.id,
isSelected: true,
selected: true,
}));
newSettings[0].isSelected = false;
newSettings[2].isSelected = false;
newSettings[0].selected = false;
newSettings[2].selected = false;

return newSettings;
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const WithTableSettingsCustomActionsShowcase = ({
);

const showSelectAllButton = React.useMemo(
() => innerSettings.some(({isSelected}) => !isSelected),
() => innerSettings.some(({selected}) => !selected),
[innerSettings],
);

Expand All @@ -51,7 +51,7 @@ export const WithTableSettingsCustomActionsShowcase = ({
setInnerSettings((prevState) =>
prevState.map((setting) => ({
...setting,
isSelected: true,
selected: true,
})),
);
}}
Expand Down
58 changes: 29 additions & 29 deletions src/components/Table/__tests__/Table.withTableSettings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ describe('withTableSettings', () => {
const settings: TableSettingsData = [
{
id: 'id',
isSelected: true,
selected: true,
},
{
id: 'name',
isSelected: false,
selected: false,
},
{
id: 'description',
isSelected: true,
selected: true,
},
];
const updatedColumns = [...columns, {id: 'os'}];
Expand All @@ -117,15 +117,15 @@ describe('withTableSettings', () => {
const settings: TableSettingsData = [
{
id: 'id',
isSelected: true,
selected: true,
},
{
id: 'name',
isSelected: false,
selected: false,
},
{
id: 'description',
isSelected: true,
selected: true,
},
];
const updatedColumns = [
Expand All @@ -150,9 +150,9 @@ describe('withTableSettings', () => {
expect(osSettings).toBeDefined();
expect(osxSettings).toBeDefined();
// @ts-ignore
expect(osSettings.isSelected).toBe(true);
expect(osSettings.selected).toBe(true);
// @ts-ignore
expect(osxSettings.isSelected).toBe(false);
expect(osxSettings.selected).toBe(false);
});

it('should return columns when no settings provided', () => {
Expand All @@ -163,19 +163,19 @@ describe('withTableSettings', () => {
const settings: TableSettingsData = [
{
id: 'description',
isSelected: true,
selected: true,
},
{
id: 'name',
isSelected: true,
selected: true,
},
{
id: 'id',
isSelected: true,
selected: true,
},
{
id: 'removed',
isSelected: true,
selected: true,
},
];
expect(ids(getActualItems(columns, settings))).toEqual(
Expand All @@ -189,15 +189,15 @@ describe('withTableSettings', () => {
const settings: TableSettingsData = [
{
id: 'id',
isSelected: true,
selected: true,
},
{
id: 'name',
isSelected: false,
selected: false,
},
{
id: 'description',
isSelected: true,
selected: true,
},
];
expect(filterColumns(columns, settings)).toEqual([columns[0], columns[2]]);
Expand All @@ -207,15 +207,15 @@ describe('withTableSettings', () => {
const settings: TableSettingsData = [
{
id: 'description',
isSelected: true,
selected: true,
},
{
id: 'name',
isSelected: true,
selected: true,
},
{
id: 'id',
isSelected: true,
selected: true,
},
];
expect(filterColumns(columns, settings)).toEqual([columns[2], columns[1], columns[0]]);
Expand All @@ -232,15 +232,15 @@ describe('withTableSettings', () => {
const settings: TableSettingsData = [
{
id: 'description',
isSelected: true,
selected: true,
},
{
id: 'name',
isSelected: true,
selected: true,
},
{
id: 'id',
isSelected: true,
selected: true,
},
];
expect(filterColumns(enhancedColumns, settings)).toEqual([
Expand All @@ -256,23 +256,23 @@ describe('withTableSettings', () => {
filterColumns(columnsWithSystem, [
{
id: 'id',
isSelected: true,
selected: true,
},
{
id: 'name',
isSelected: false,
selected: false,
},
{
id: 'description',
isSelected: false,
selected: false,
},
]),
).toEqual([columnsWithSystem[0], columnsWithSystem[1], columnsWithSystem[4]]);
});
});

describe('updateSettings', () => {
const settings = columns.map<TableSetting>((column) => ({id: column.id, isSelected: true}));
const settings = columns.map<TableSetting>((column) => ({id: column.id, selected: true}));

it('should change table columns visibility', async () => {
const updateSettings = jest.fn();
Expand All @@ -293,22 +293,22 @@ describe('withTableSettings', () => {
expect(updateSettings).toHaveBeenCalledWith([
{
id: 'id',
isSelected: true,
selected: true,
},
{
id: 'name',
isSelected: true,
selected: true,
},
{
id: 'description',
isSelected: false,
selected: false,
},
] as TableSetting[]);
});
});

describe('renderControls', () => {
const settings = columns.map<TableSetting>((column) => ({id: column.id, isSelected: true}));
const settings = columns.map<TableSetting>((column) => ({id: column.id, selected: true}));

it('should have custom controls', async () => {
const updateSettings = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ const reorderArray = <T extends unknown>(list: T[], startIndex: number, endIndex

const prepareDndItems = (tableColumnItems: TableColumnSetupItem[]) => {
return tableColumnItems.map<Item>((tableColumnItem) => {
const hasSelectionIcon = tableColumnItem.isRequired === false;
const hasSelectionIcon = tableColumnItem.required === false;

return {
...tableColumnItem,
startSlot: tableColumnItem.isRequired ? <Icon data={Lock} /> : undefined,
startSlot: tableColumnItem.required ? <Icon data={Lock} /> : undefined,
hasSelectionIcon,
selected: hasSelectionIcon ? tableColumnItem.isSelected : undefined,
selected: hasSelectionIcon ? tableColumnItem.selected : undefined,
};
});
};

const prepareValue = (tableColumnItems: TableColumnSetupItem[]) => {
const selectedIds: string[] = [];

tableColumnItems.forEach(({id, isSelected}) => {
if (isSelected) {
tableColumnItems.forEach(({id, selected}) => {
if (selected) {
selectedIds.push(id);
}
});
Expand Down Expand Up @@ -217,7 +217,7 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {
}

const onApply = () => {
const newSettings = items.map<TableSetting>(({id, isSelected}) => ({id, isSelected}));
const newSettings = items.map<TableSetting>(({id, selected}) => ({id, selected}));
propsOnUpdate(newSettings);
setOpen(false);
};
Expand Down Expand Up @@ -269,7 +269,7 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {
setItems((prevItems) => {
return prevItems.map((item) => ({
...item,
isSelected: selectedItemsIds.includes(item.id),
selected: selectedItemsIds.includes(item.id),
}));
});
};
Expand Down
24 changes: 12 additions & 12 deletions src/components/Table/hoc/withTableSettings/withTableSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ import './withTableSettings.scss';

export type TableSetting = {
id: string;
isSelected?: boolean;
selected?: boolean;
};

export type TableSettingsData = TableSetting[];

export type TableColumnSetupItem = TableSetting & {
title: React.ReactNode;
isRequired?: boolean;
required?: boolean;
};

export function filterColumns<I>(
columns: TableColumnConfig<I>[],
settings: TableSettingsData,
): TableColumnConfig<I>[] {
const filteredColumns = settings
.map(({id, isSelected}) => ({
isSelected,
.map(({id, selected}) => ({
selected,
columnSettings: columns.find((column) => id === column.id),
}))
.filter(({isSelected, columnSettings}) => isSelected && columnSettings)
.filter(({selected, columnSettings}) => selected && columnSettings)
.map(({columnSettings}) => columnSettings);

if (columns[0] && columns[0].id === selectionColumnId) {
Expand All @@ -69,15 +69,15 @@ export function getColumnStringTitle<Data>(column: TableColumnConfig<Data>) {

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

return {
id,
isSelected: isProtected ? true : isSelected,
isRequired: isProtected,
selected: isProtected ? true : selected,
required: isProtected,
title: column ? getColumnStringTitle(column) : id,
};
};
Expand All @@ -88,11 +88,11 @@ export function getActualItems<I>(
): TableColumnSetupItem[] {
const sortableItems: TableColumnSetupItem[] = [];

settings.forEach(({id, isSelected}) => {
settings.forEach(({id, selected}) => {
const column = columns.find((column) => id === column.id);

if (column) {
sortableItems.push(getTableColumnSetupItem(id, isSelected, column));
sortableItems.push(getTableColumnSetupItem(id, selected, column));
}
});

Expand All @@ -102,8 +102,8 @@ export function getActualItems<I>(
column.id !== selectionColumnId &&
settings.every((setting) => setting.id !== column.id)
) {
const isSelected = column.meta?.selectedByDefault !== false;
sortableItems.push(getTableColumnSetupItem(column.id, isSelected, column));
const selected = column.meta?.selectedByDefault !== false;
sortableItems.push(getTableColumnSetupItem(column.id, selected, column));
}
});

Expand Down

0 comments on commit 3fc22f9

Please sign in to comment.