Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

issue175 editable column #182

Merged
merged 8 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,8 @@ Derived properties allow the component to expose complex state that can be usefu

## RC12 - Rename selected_cell -> selected_cells

Issue: https://github.com/plotly/dash-table/issues/177
Issue: https://github.com/plotly/dash-table/issues/177

## RC13 - Column 'editable' takes precedence over table 'editable'

Issue: https://github.com/plotly/dash-table/issues/175
2 changes: 1 addition & 1 deletion dash_table/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_table/demo.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_table/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-table",
"version": "3.1.0rc12",
"version": "3.1.0rc13",
"description": "Dash table",
"main": "build/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-table",
"version": "3.1.0rc12",
"version": "3.1.0rc13",
"description": "Dash table",
"main": "build/index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/dash-table/components/ControlledTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class ControlledTable extends PureComponent<ControlledTableProps,
if (
e.keyCode === KEY_CODES.ENTER &&
!is_focused &&
isEditable(editable, columns[active_cell[1]])
isEditable(editable, columns[active_cell[1]].editable)
) {
setProps({ is_focused: true });
return;
Expand All @@ -237,7 +237,7 @@ export default class ControlledTable extends PureComponent<ControlledTableProps,
// if we have any non-meta key enter editable mode

!this.props.is_focused &&
isEditable(editable, columns[active_cell[1]]) &&
isEditable(editable, columns[active_cell[1]].editable) &&
!isMetaKey(e.keyCode)
) {
setProps({ is_focused: true });
Expand Down Expand Up @@ -380,7 +380,7 @@ export default class ControlledTable extends PureComponent<ControlledTableProps,
);

realCells.forEach(cell => {
if (isEditable(editable, columns[cell[1]])) {
if (isEditable(editable, columns[cell[1]].editable)) {
newData = R.set(
R.lensPath([cell[0], columns[cell[1]].id]),
'',
Expand Down
2 changes: 1 addition & 1 deletion src/dash-table/derived/cell/inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const getter = (
clearable={column.clearable}
datum={datum}
dropdown={dropdown}
editable={isEditable(editable, column)}
editable={isEditable(editable, column.editable)}
focused={isFocused}
property={column.id}
tableId={tableId}
Expand Down
8 changes: 4 additions & 4 deletions src/dash-table/derived/cell/isEditable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IVisibleColumn } from 'dash-table/components/Table/props';

export default (
editable: boolean,
column: IVisibleColumn
): boolean => editable && (column.editable === undefined || column.editable);
editableColumn: boolean | undefined
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the dependency on the column structure here -- we just care about the editable props

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit nitpicky, but perhaps naming it columnIsEditable is better, so that it's more clear that it's a boolean and not some sort of column object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will update to isEditableTable and isEditableColumn

): boolean => editableColumn === undefined ?
editable :
editableColumn;
2 changes: 1 addition & 1 deletion src/dash-table/derived/cell/wrappers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getter(
'dash-cell' +
` column-${columnIndex}` +
(active ? ' focused' : '') +
(!isEditable(editable, column) ? ' cell--uneditable' : '') +
(!isEditable(editable, column.editable) ? ' cell--uneditable' : '') +
(selected ? ' cell--selected' : '') +
(column.type === ColumnType.Dropdown ? ' dropdown' : '');

Expand Down
2 changes: 1 addition & 1 deletion src/dash-table/utils/TableClipboardHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class TableClipboardHelper {

const jOffset = activeCell[1] + j;
const col = newColumns[jOffset];
if (col && isEditable(true, col)) {
if (col && isEditable(true, col.editable)) {
newData = R.set(
R.lensPath([iRealCell, col.id]),
cell,
Expand Down
86 changes: 86 additions & 0 deletions src/dash-table/utils/applyClipboardToData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import * as R from 'ramda';

import Logger from 'core/Logger';

import { ActiveCell, Columns, Data, ColumnType } from 'dash-table/components/Table/props';
import isEditable from 'dash-table/derived/cell/isEditable';

export default (
values: string[][],
activeCell: ActiveCell,
derived_viewport_indices: number[],
columns: Columns,
data: Data,
overflowColumns: boolean = true,
overflowRows: boolean = true
): { data: Data, columns: Columns } | void => {
if (!overflowRows) {
Logger.debug(`Clipboard -- Sorting or filtering active, do not create new rows`);
}

if (!overflowColumns) {
Logger.debug(`Clipboard -- Do not create new columns`);
}

let newData = data;
const newColumns = columns;

if (overflowColumns && values[0].length + activeCell[1] >= columns.length) {
for (
let i = columns.length;
i < values[0].length + activeCell[1];
i++
) {
newColumns.push({
id: `Column ${i + 1}`,
name: `Column ${i + 1}`,
type: ColumnType.Text
});
newData.forEach(row => (row[`Column ${i}`] = ''));
}
}

const realActiveRow = derived_viewport_indices[activeCell[0]];
if (overflowRows && values.length + realActiveRow >= data.length) {
const emptyRow: any = {};
columns.forEach(c => (emptyRow[c.id] = ''));
newData = R.concat(
newData,
R.repeat(
emptyRow,
values.length + realActiveRow - data.length
)
);
}

const lastEntry = derived_viewport_indices.slice(-1)[0] || 0;
const viewportSize = derived_viewport_indices.length;

values.forEach((row: string[], i: number) =>
row.forEach((cell: string, j: number) => {
const viewportIndex = activeCell[0] + i;

let iRealCell: number | undefined = viewportSize > viewportIndex ?
derived_viewport_indices[viewportIndex] :
overflowRows ?
lastEntry + (viewportIndex - viewportSize + 1) :
undefined;

if (iRealCell === undefined) {
return;
}

const jOffset = activeCell[1] + j;
const col = newColumns[jOffset];
if (col && isEditable(true, col.editable)) {
newData = R.set(
R.lensPath([iRealCell, col.id]),
cell,
newData
);
}
})
);

return { data: newData, columns: newColumns };
};
27 changes: 27 additions & 0 deletions tests/cypress/tests/unit/isEditable_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import isEditable from 'dash-table/derived/cell/isEditable';

describe('isEditable', () => {
it('returns false if table=false, column=false', () =>
expect(isEditable(false, false)).to.equal(false)
);

it('returns false if table=false, column=undefined', () =>
expect(isEditable(false, undefined)).to.equal(false)
);

it('returns true if table=false, column=true', () =>
expect(isEditable(false, true)).to.equal(true)
);

it('returns false if table=true, column=false', () =>
expect(isEditable(true, false)).to.equal(false)
);

it('returns true if table=true, column=undefined', () =>
expect(isEditable(true, undefined)).to.equal(true)
);

it('returns true if table=true, column=true', () =>
expect(isEditable(true, true)).to.equal(true)
);
});