Skip to content

Commit

Permalink
Allow edits to be rejected for EditableCell (palantir#2228)
Browse files Browse the repository at this point in the history
  • Loading branch information
giladgray authored and adidahiya committed Mar 14, 2018
1 parent 74e7c1a commit 0fe776f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/table/src/cell/editableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class EditableCell extends React.Component<IEditableCellProps, IEditableC

public componentWillReceiveProps(nextProps: IEditableCellProps) {
const { value } = nextProps;
if (value !== this.props.value) {
if (value != null) {
this.setState({ savedValue: value, dirtyValue: value });
}
}
Expand Down
15 changes: 8 additions & 7 deletions packages/table/test/editableCellTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("<EditableCell>", () => {
expect(onConfirm.called).to.be.true;
});

it("doesn't change edited value on non-value prop changes", () => {
it("changes value state on non-value prop changes", () => {
const onCancel = sinon.spy();
const onChange = sinon.spy();
const onConfirm = sinon.spy();
Expand All @@ -83,16 +83,17 @@ describe("<EditableCell>", () => {
expect(onConfirm.called).to.be.false;
expect(elem.find(`.${Classes.TABLE_EDITABLE_TEXT} .pt-editable-content`).text()).to.equal("new-text");

// set non-value prop
elem.setProps({ onChange: null });

// value stays the same
expect(elem.find(`.${Classes.TABLE_EDITABLE_TEXT} .pt-editable-content`).text()).to.equal("new-text");

// confirm
input.simulate("blur");
expect(onCancel.called).to.be.false;
expect(onConfirm.called).to.be.true;
// cell shows user-entered text until re-render
expect(elem.find(`.${Classes.TABLE_EDITABLE_TEXT}`).text()).to.equal("new-text");

// set non-value prop, forces EditableCell update
elem.setProps({ onChange: null });
// value resets to prop
expect(elem.find(`.${Classes.TABLE_EDITABLE_TEXT}`).text()).to.equal("test-value-5000");
});

it("passes index prop to callbacks if index was provided", () => {
Expand Down

1 comment on commit 0fe776f

@reiv
Copy link
Owner

@reiv reiv commented on 0fe776f Mar 14, 2018

Choose a reason for hiding this comment

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

Allow edits to be rejected for EditableCell (palantir#2228)

Preview: documentation | landing | table

Please sign in to comment.