Skip to content

Commit 17ae710

Browse files
committed
Remove the buttons form the image dialoge. AltText does reset on close/open. WIP.
1 parent c0f1a81 commit 17ae710

File tree

5 files changed

+27
-47
lines changed

5 files changed

+27
-47
lines changed

lib/blocks/ImageBlock.js

+11-34
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,33 @@ class ImageBlock extends Component {
1111
super(props);
1212
const { entity } = props;
1313

14-
const { altText, alignment } = entity.getData();
14+
const { alignment } = entity.getData();
1515

1616
this.state = {
17-
altText: altText || '',
1817
alignment: alignment || 'left',
1918
};
2019

2120
this.changeText = this.changeText.bind(this);
2221
this.changeAlignment = this.changeAlignment.bind(this);
23-
this.onSave = this.onSave.bind(this);
2422
this.renderMediaOptions = this.renderMediaOptions.bind(this);
2523
}
2624

2725
componentWillReceiveProps(nextProps) {
28-
const { altText, alignment } = nextProps.entity.getData();
26+
const { alignment } = nextProps.entity.getData();
2927

3028
// Reset unsaved changes.
3129
this.setState({
32-
altText: altText || '',
3330
alignment: alignment || 'left',
3431
});
3532
}
3633

3734
changeText(e) {
38-
this.setState({
35+
36+
const { onSave } = this.props;
37+
const { alignment } = this.state;
38+
39+
onSave({
40+
alignment,
3941
altText: e.currentTarget.value,
4042
});
4143
}
@@ -46,19 +48,10 @@ class ImageBlock extends Component {
4648
});
4749
}
4850

49-
onSave() {
50-
const { onSave } = this.props;
51-
const { alignment, altText } = this.state;
52-
53-
onSave({
54-
alignment,
55-
altText,
56-
});
57-
}
5851

5952
renderMediaOptions() {
60-
const { entityConfig, onCancel } = this.props;
61-
const { alignment, altText } = this.state;
53+
const { entityConfig } = this.props;
54+
const { alignment } = this.state;
6255
const imageFormats = entityConfig.imageFormats || [];
6356

6457
// TODO Add <label> elt for Alt text field.
@@ -71,7 +64,7 @@ class ImageBlock extends Component {
7164
<p>
7265
<input
7366
type="text"
74-
value={altText}
67+
value={this.props.entity.getData().altText}
7568
onChange={this.changeText}
7669
/>
7770
</p>
@@ -96,22 +89,6 @@ class ImageBlock extends Component {
9689
</p>
9790
</div>
9891
</div>
99-
<p>
100-
<button
101-
type="button"
102-
className="button button-secondary"
103-
onClick={this.onSave}
104-
>
105-
Save changes
106-
</button>
107-
<button
108-
type="button"
109-
className="button button-secondary no"
110-
onClick={onCancel}
111-
>
112-
Cancel
113-
</button>
114-
</p>
11592
</div>
11693
);
11794
}

lib/blocks/ImageBlock.test.js

-6
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,4 @@ describe('ImageBlock', () => {
6969
).toMatchSnapshot();
7070
});
7171

72-
it('#onCancel', () => {
73-
shallow(<ImageBlock {...mockProps} isActive={true} />)
74-
.find('.button.no')
75-
.simulate('click');
76-
expect(mockProps.onCancel).toHaveBeenCalledTimes(1);
77-
});
7872
});

lib/blocks/MediaBlock.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PropTypes from 'prop-types';
22
import React, { Component } from 'react';
3+
import { EditorState } from 'draft-js';
34

45
import { ENTITY_TYPE } from '../api/constants';
56

@@ -48,11 +49,16 @@ class MediaBlock extends Component {
4849
}
4950

5051
onSave(nextData) {
51-
const { block, contentState } = this.props;
52+
const { block, contentState, editorState, onChange } = this.props;
5253

5354
// This will update in place
54-
contentState.mergeEntityData(block.getEntityAt(0), nextData);
55-
this.closeBlock();
55+
const nextContentState = contentState.mergeEntityData(block.getEntityAt(0), nextData);
56+
onChange(EditorState.push(
57+
editorState,
58+
nextContentState,
59+
'insert',
60+
));
61+
// this.closeBlock();
5662
}
5763

5864
render() {

lib/components/DraftailEditor.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ class DraftailEditor extends Component {
488488
} else {
489489
ret = {
490490
component: MediaBlock,
491-
editable: false,
491+
editable: false, // Will not contain text
492492
props: {
493493
entity: entity,
494494
entityConfig: entityTypes.find(
@@ -497,6 +497,7 @@ class DraftailEditor extends Component {
497497
lockEditor: this.lockEditor,
498498
unlockEditor: this.unlockEditor,
499499
editorState: editorState,
500+
onChange: this.onChange,
500501
onUpdate: this.onDialogComplete,
501502
},
502503
};
@@ -644,7 +645,7 @@ class DraftailEditor extends Component {
644645
editorState={editorState}
645646
onChange={this.onChange}
646647
placeholder={placeholder}
647-
readOnly={readOnly}
648+
readOnly={false}
648649
stripPastedStyles={stripPastedStyles}
649650
handleReturn={this.handleReturn}
650651
keyBindingFn={behavior.getKeyBindingFn(

package-lock.json

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)