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

fix(react-grid): Fix changing a visibility of a column with selectors(T1032186) #3458

Merged
merged 2 commits into from Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -3,12 +3,18 @@ import { tableColumnsWithSelection } from './computeds';

describe('TableSelection Plugin computeds', () => {
describe('#tableColumnsWithSelection', () => {
it('should work', () => {
expect(tableColumnsWithSelection([{}], 123))
it('should work with showSelectionColumn', () => {
expect(tableColumnsWithSelection([{}], 123, true))
.toEqual([
{ key: TABLE_SELECT_TYPE.toString(), type: TABLE_SELECT_TYPE, width: 123 },
{},
]);
});
it('should work without showSelectionColumn', () => {
expect(tableColumnsWithSelection([{ key: '' }], 123, false))
.toEqual([{
key: '',
}]);
});
});
});
17 changes: 11 additions & 6 deletions packages/dx-grid-core/src/plugins/table-selection/computeds.ts
Expand Up @@ -2,9 +2,14 @@ import { PureComputed } from '@devexpress/dx-core';
import { TABLE_SELECT_TYPE } from './constants';
import { TableColumn } from '../../types';

export const tableColumnsWithSelection: PureComputed<[TableColumn[], number]> = (
tableColumns, selectionColumnWidth,
) => [
{ key: TABLE_SELECT_TYPE.toString(), type: TABLE_SELECT_TYPE, width: selectionColumnWidth },
...tableColumns,
];
export const tableColumnsWithSelection: PureComputed<[TableColumn[], number, boolean|undefined]> = (
tableColumns, selectionColumnWidth, showSelectionColumn,
) => {
if (showSelectionColumn) {
return [
{ key: TABLE_SELECT_TYPE.toString(), type: TABLE_SELECT_TYPE, width: selectionColumnWidth },
...tableColumns,
];
}
return tableColumns;
};
Expand Up @@ -80,7 +80,7 @@ describe('Table Selection', () => {
expect(getComputedState(tree).tableColumns)
.toBe('tableColumnsWithSelection');
expect(tableColumnsWithSelection)
.toBeCalledWith(defaultDeps.getter.tableColumns, 120);
.toBeCalledWith(defaultDeps.getter.tableColumns, 120, true);
});

describe('highlightSelectedRow getter', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/dx-react-grid/src/plugins/table-selection.tsx
Expand Up @@ -42,7 +42,7 @@ class TableSelectionBase extends React.PureComponent<TableSelectionProps> {

const tableColumnsComputed = (
{ tableColumns }: Getters,
) => tableColumnsWithSelection(tableColumns, selectionColumnWidth);
) => tableColumnsWithSelection(tableColumns, selectionColumnWidth, showSelectionColumn);

return (
<Plugin
Expand All @@ -53,9 +53,7 @@ class TableSelectionBase extends React.PureComponent<TableSelectionProps> {
{ name: 'IntegratedSelection', optional: !showSelectAll },
]}
>
{showSelectionColumn && (
<Getter name="tableColumns" computed={tableColumnsComputed} />
)}
<Getter name="tableColumns" computed={tableColumnsComputed} />
{highlightRow && (
<Getter name="highlightSelectedRow" value />
)}
Expand Down