Skip to content

Commit

Permalink
[EditModel] Only show access message on add
Browse files Browse the repository at this point in the history
The created using public access could be confusing on editing an
object. The sharing notification is therefore only shown when adding
an item that has sharing.

Closes #124
  • Loading branch information
Markionium committed Apr 21, 2016
1 parent 19b5d97 commit 8ab3ef1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/EditModel/EditModel.component.js
Expand Up @@ -159,6 +159,10 @@ export default React.createClass({
};
},

isAddOperation() {
return this.props.modelId === 'add';
},

componentWillMount() {
const modelType = this.props.modelType;

Expand All @@ -175,7 +179,7 @@ export default React.createClass({
.map(fieldConfig => {
fieldConfig.fieldOptions.model = modelToEdit;

if (this.props.modelId !== 'add' && disabledOnEdit.for(modelType).indexOf(fieldConfig.name) !== -1) {
if (!this.isAddOperation() && disabledOnEdit.for(modelType).indexOf(fieldConfig.name) !== -1) {
fieldConfig.props.disabled = true;
}

Expand Down Expand Up @@ -248,6 +252,14 @@ export default React.createClass({
return this.getTranslation(camelCaseToUnderscores(propertyName));
},

renderSharingNotification(formPaperStyle) {
if (this.isAddOperation()) {
return (<SharingNotification style={formPaperStyle} modelType={this.props.modelType} />);
}

return null;
},

render() {
const formPaperStyle = {
width: '100%',
Expand Down Expand Up @@ -294,7 +306,7 @@ export default React.createClass({
<div style={{ display: 'flex', flexDirection: 'row', marginBottom: '2rem' }}>
<FormHeading>{camelCaseToUnderscores(this.props.modelType)}</FormHeading>
</div>
<SharingNotification style={formPaperStyle} modelType={this.props.modelType} />
{this.renderSharingNotification(formPaperStyle)}
{this.state.isLoading ? 'Loading data...' : renderForm()}
</div>
);
Expand Down

0 comments on commit 8ab3ef1

Please sign in to comment.