Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8121396
3.1 props refactoring (#106)
Marc-Andre-Rivet Sep 25, 2018
7bece90
3.0 clean offsets (#110)
Marc-Andre-Rivet Sep 25, 2018
33a1511
3.1 props fixes (#112)
Marc-Andre-Rivet Sep 26, 2018
8bbcb1c
:point_up: 3 new review / documentation / target apps
chriddyp Sep 25, 2018
724481f
:see_no_evil: forgot file
chriddyp Sep 26, 2018
5499429
:pencil: incorporate @cldougl suggestions :bow:
chriddyp Sep 26, 2018
b83cb97
3.1 refactor tests (#113)
Marc-Andre-Rivet Sep 27, 2018
ce05891
Merge remote-tracking branch 'origin/master' into develop
Oct 1, 2018
e98dfd8
:100: add percent examples
cldougl Oct 1, 2018
877dd7c
:memo: title/example clarification
cldougl Oct 1, 2018
96df001
Merge pull request #116 from plotly/percent_ex
cldougl Oct 2, 2018
14fdde7
reformat sizing test app for failing tests (#125)
cldougl Oct 3, 2018
a2217e3
Merged with develop & fixed merge conflicts
valentijnnieman Oct 4, 2018
bcd1b49
Removed .only from dash_test.ts
valentijnnieman Oct 4, 2018
957e147
Production build instead of dev :see_no_evil:
valentijnnieman Oct 4, 2018
43b0182
Fix failing tests
valentijnnieman Oct 4, 2018
fb418fc
Merge pull request #126 from plotly/107-save-on-tab
valentijnnieman Oct 4, 2018
0612c4c
3.1 refactor cells rendering (#123)
Marc-Andre-Rivet Oct 5, 2018
e369cce
3.1 issue118 width behavior (#130)
Marc-Andre-Rivet Oct 11, 2018
ea9d83c
Merge remote-tracking branch 'origin/master' into develop
Oct 11, 2018
71e9b0c
styling examples (#117)
chriddyp Oct 11, 2018
d87b866
Backend examples (#119)
chriddyp Oct 11, 2018
8a3dc8b
Dropdown usage examples (#120)
chriddyp Oct 11, 2018
682feaa
- additional tests for editable/readonly
Oct 11, 2018
f40ab2c
bump version
Oct 11, 2018
1e3c395
Merge remote-tracking branch 'origin/master' into 3.1-issue132-readon…
Oct 11, 2018
f059bcc
remove useless test column
Oct 11, 2018
d2431c1
add editable prop to fixtures
Oct 11, 2018
77a7a53
update tests to take into account readonly 'rows' column
Oct 11, 2018
b3df3bb
- refactor column isEditable calculation
Oct 12, 2018
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,7 @@ Derived properties allow the component to expose complex state that can be usefu
### Interaction between width, min-width and max-width

Column min-width and max-width do not default to width value is not defined.

## RC5 - Tests and fixes for editable/readonly

Issue: https://github.com/plotly/dash-table/issues/132
4 changes: 2 additions & 2 deletions dash_table/bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions 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.0rc4",
"version": "3.1.0rc5",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

bump version

"description": "Dash table",
"main": "build/index.js",
"scripts": {
Expand Down
20 changes: 20 additions & 0 deletions demo/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,32 @@ export const mockData = unpackIntoColumnsAndDataFrames([
)
},

{
id: 'bbb-readonly',
name: ['', 'Weather', 'Climate-RO'],
type: 'dropdown',
editable: false,
width: 200,
data: gendata(
i => ['Humid', 'Wet', 'Snowy', 'Tropical Beaches'][i % 4]
)
},

{
id: 'aaa',
name: ['', 'Weather', 'Temperature'],
type: 'numeric',
width: 150,
data: gendata(i => i + 1),
},

{
id: 'aaa-readonly',
name: ['', 'Weather', 'Temperature-RO'],
type: 'numeric',
editable: false,
width: 150,
data: gendata(i => i + 1),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

adding two additional readonly fields to the demo app to test out readonly cases

}
]);

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.0rc4",
"version": "3.1.0rc5",
"description": "Dash table",
"main": "build/index.js",
"scripts": {
Expand Down
26 changes: 23 additions & 3 deletions src/dash-table/components/CellInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,33 @@ export default class CellInput extends PureComponent<ICellProps, ICellState> {

private renderDropdown() {
const {
active,
clearable,
dropdown,
editable,
focused,
onChange,
onClick,
onDoubleClick,
value
} = this.propsWithDefaults;

return !dropdown ?
this.renderValue() :
const classes = [
...(active ? ['input-active'] : []),
...(focused ? ['focused'] : ['unfocused']),
...['dash-cell-value']
];

const attributes = {
className: classes.join(' '),
onClick: onClick,
onDoubleClick: onDoubleClick
};

const readonly = !editable;

return !dropdown || readonly ?
this.renderValue(attributes) :
(<div className='dash-dropdown-cell-value-container dash-cell-value-container'>
{this.renderValue(
{ className: 'dropdown-cell-value-shadow cell-value-shadow' },
Expand All @@ -70,6 +89,7 @@ export default class CellInput extends PureComponent<ICellProps, ICellState> {
private renderInput() {
const {
active,
editable,
focused,
onClick,
onDoubleClick,
Expand All @@ -88,7 +108,7 @@ export default class CellInput extends PureComponent<ICellProps, ICellState> {
onDoubleClick: onDoubleClick
};

const readonly = !active && this.state.value === this.props.value;
const readonly = (!active && this.state.value === this.props.value) || !editable;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cell content is readonly if not focused or if not editable (table+column configuration)


return readonly ?
this.renderValue(attributes) :
Expand Down
10 changes: 5 additions & 5 deletions src/dash-table/components/ControlledTable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { PureComponent } from 'react';
import * as R from 'ramda';
import Stylesheet from 'core/Stylesheet';
import { colIsEditable } from 'dash-table/components/derivedState';
import {
KEY_CODES,
isCtrlMetaKey,
Expand All @@ -21,6 +20,7 @@ import dropdownHelper from 'dash-table/components/dropdownHelper';

import derivedTable from 'dash-table/derived/table';
import derivedTableFragments from 'dash-table/derived/table/fragments';
import isEditable from 'dash-table/derived/cell/isEditable';

const sortNumerical = R.sort<number>((a, b) => a - b);

Expand Down Expand Up @@ -208,7 +208,7 @@ export default class ControlledTable extends PureComponent<ControlledTableProps,
if (
e.keyCode === KEY_CODES.ENTER &&
!is_focused &&
colIsEditable(editable, columns[active_cell[1]])
isEditable(editable, columns[active_cell[1]])
) {
setProps({ is_focused: true });
return;
Expand All @@ -235,7 +235,7 @@ export default class ControlledTable extends PureComponent<ControlledTableProps,
// if we have any non-meta key enter editable mode

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

realCells.forEach(cell => {
if (colIsEditable(editable, columns[cell[1]])) {
if (isEditable(editable, columns[cell[1]])) {
newDataframe = R.set(
R.lensPath([cell[0], columns[cell[1]].id]),
'',
Expand Down Expand Up @@ -620,7 +620,7 @@ export default class ControlledTable extends PureComponent<ControlledTableProps,
id,
content_style,
n_fixed_columns,
n_fixed_rows,
n_fixed_rows
} = this.props;

const classes = [
Expand Down
5 changes: 0 additions & 5 deletions src/dash-table/components/derivedState.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/dash-table/derived/cell/inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import CellInput from 'dash-table/components/CellInput';
import derivedCellEventHandlerProps from 'dash-table/derived/cell/eventHandlerProps';
import isActiveCell from 'dash-table/derived/cell/isActive';
import isEditable from './isEditable';

const mapDataframe = R.addIndex<Datum, JSX.Element[]>(R.map);
const mapRow = R.addIndex<IVisibleColumn, JSX.Element>(R.map);
Expand Down Expand Up @@ -43,7 +44,7 @@ const getter = (
clearable={column.clearable}
datum={datum}
dropdown={dropdown}
editable={editable}
editable={isEditable(editable, column)}
focused={isFocused}
property={column.id}
tableId={tableId}
Expand Down
6 changes: 6 additions & 0 deletions src/dash-table/derived/cell/isEditable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IVisibleColumn } from 'dash-table/components/Table/props';

export default (
editable: boolean,
column: IVisibleColumn
): boolean => editable && (column.editable === undefined || column.editable);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@valentijnnieman As per suggestion, renaming and TS-ing

5 changes: 3 additions & 2 deletions src/dash-table/derived/cell/wrappers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Cell from 'dash-table/components/Cell';
import isActiveCell from 'dash-table/derived/cell/isActive';
import isSelectedCell from 'dash-table/derived/cell/isSelected';
import memoizerCache from 'core/memoizerCache';
import isEditable from './isEditable';

type Key = [number, number];
type ElementCacheFn = (
Expand Down Expand Up @@ -35,7 +36,7 @@ function getter(
'dash-cell' +
` column-${columnIndex}` +
(active ? ' focused' : '') +
(!editable ? ' cell--uneditable' : '') +
(!isEditable(editable, column) ? ' cell--uneditable' : '') +
(selected ? ' cell--selected' : '') +
(column.type === ColumnType.Dropdown ? ' dropdown' : '');

Expand All @@ -44,7 +45,7 @@ function getter(
columns
),
dataframe
)
);
}

function decorator(_id: string): ((
Expand Down
4 changes: 2 additions & 2 deletions src/dash-table/utils/TableClipboardHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import SheetClip from 'sheetclip';
import Clipboard from 'core/Clipboard';
import Logger from 'core/Logger';

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

export default class TableClipboardHelper {
public static toClipboard(e: any, selectedCells: SelectedCells, columns: Columns, dataframe: Dataframe) {
Expand Down Expand Up @@ -94,7 +94,7 @@ export default class TableClipboardHelper {

const jOffset = activeCell[1] + j;
const col = newColumns[jOffset];
if (col && colIsEditable(true, col)) {
if (col && isEditable(true, col)) {
newDataframe = R.set(
R.lensPath([iRealCell, col.id]),
cell,
Expand Down
4 changes: 4 additions & 0 deletions tests/cypress/src/DashTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export default class DashTable {
return cy.get(`#table tbody tr td.column-${column}`).eq(row);
}

static getCellById(row: number, column: number | string) {
return cy.get(`#table tbody tr td[data-dash-column="${column}"]`).eq(row);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

new selector for tests that uses the column id attribute instead of the index -- when applied to everything, will make tests more robust to changes in the demo app


static getDelete(row: number) {
return cy.get(`#table tbody tr td.dash-delete-cell`).eq(row);
}
Expand Down
44 changes: 32 additions & 12 deletions tests/cypress/tests/standalone/edit_cell_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@ import DashTable from 'cypress/DashTable';
import DOM from 'cypress/DOM';
import Key from 'cypress/Key';

describe('edit cell', () => {
describe('edit', () => {
beforeEach(() => {
cy.visit('http://localhost:8080');
});

describe('readonly cell', () => {
describe('with input', () => {
it('does not modify value', () => {
DashTable.getCellById(0, 'aaa-readonly').click();
DashTable.getCellById(0, 'aaa-readonly').within(() => {
cy.get('input').should('not.exist');
});
});
});

describe('with dropdown', () => {
it('does not modify value', () => {
DashTable.getCellById(0, 'bbb-readonly').click();
DashTable.getCellById(0, 'bbb-readonly').within(() => {
cy.get('.Select-value-label').should('not.exist');
});
});
});
});

it('can delete dropdown', () => {
DashTable.getCell(0, 6).trigger('mouseover');
DashTable.getCell(0, 6).within(() => cy.get('.Select-clear').click());
Expand Down Expand Up @@ -63,27 +83,27 @@ describe('edit cell', () => {
});

it('can edit on 2nd page', () => {
DashTable.getCell(0, 0).click();
DashTable.getCell(0, 0).within(() => cy.get('input').should('have.value', '1'));
DashTable.getCell(0, 1).click();
DashTable.getCell(0, 1).within(() => cy.get('input').should('have.value', '1'));
cy.get('button.next-page').click();
DashTable.getCell(0, 0).within(() => cy.get('input').should('have.value', '251'));
DashTable.getCell(0, 1).within(() => cy.get('input').should('have.value', '251'));

DOM.focused.type(`abc${Key.Enter}`);
DashTable.getCell(0, 0).click();
DashTable.getCell(0, 0).within(() => cy.get('input').should('have.value', 'abc'));
DashTable.getCell(0, 1).click();
DashTable.getCell(0, 1).within(() => cy.get('input').should('have.value', 'abc'));
});

it('can delete then edit on 2nd page', () => {
DashTable.getCell(0, 0).click();
DashTable.getCell(0, 0).within(() => cy.get('input').should('have.value', '1'));
DashTable.getCell(0, 1).click();
DashTable.getCell(0, 1).within(() => cy.get('input').should('have.value', '1'));
cy.get('button.next-page').click();
DashTable.getCell(0, 0).within(() => cy.get('input').should('have.value', '251'));
DashTable.getCell(0, 1).within(() => cy.get('input').should('have.value', '251'));
DashTable.getDelete(0).click();
DashTable.getCell(0, 0).within(() => cy.get('input').should('have.value', '252'));
DashTable.getCell(0, 1).within(() => cy.get('input').should('have.value', '252'));

DOM.focused.type(`abc${Key.Enter}`);
DashTable.getCell(0, 0).click();
DashTable.getCell(0, 0).within(() => cy.get('input').should('have.value', 'abc'));
DashTable.getCell(0, 1).click();
DashTable.getCell(0, 1).within(() => cy.get('input').should('have.value', 'abc'));
});

// https://github.com/plotly/dash-table/issues/50
Expand Down
4 changes: 4 additions & 0 deletions tests/visual/percy-storybook/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default [
{'column-1': 'boston'}
],
n_fixed_rows: 1,
editable: true,
table_style: [{
selector: '.dash-spreadsheet.dash-freeze-top',
rule: 'height: 100px;'
Expand Down Expand Up @@ -150,6 +151,7 @@ export default [
{'column-1': 'mtl'},
{'column-1': 'boston'}
],
editable: true,
id: 'table'
}
},
Expand Down Expand Up @@ -211,6 +213,7 @@ export default [
{'column-1': 'mtl', 'column-2': 'mtl', 'column-3': 'mtl'},
{'column-1': 'mtl', 'column-2': 'mtl', 'column-3': 'mtl'}
],
editable: true,
id: 'table'
}
},
Expand Down Expand Up @@ -274,6 +277,7 @@ export default [
region: 'costa-rica'
}
],
editable: true,
id: 'table'
}
},
Expand Down